mirror of
https://github.com/sharevb/it-tools.git
synced 2026-11-25 07:04:39 +03:00
Compare commits
5
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4f5a09ed89 | ||
|
|
703988880e | ||
|
|
3d63fde283 | ||
|
|
ee04bfed87 | ||
|
|
3ead4d37ad |
No files matched your search
Vendored
+8
-2
@@ -129,18 +129,25 @@ declare module '@vue/runtime-core' {
|
|||||||
MetaTagGenerator: typeof import('./src/tools/meta-tag-generator/meta-tag-generator.vue')['default']
|
MetaTagGenerator: typeof import('./src/tools/meta-tag-generator/meta-tag-generator.vue')['default']
|
||||||
MimeTypes: typeof import('./src/tools/mime-types/mime-types.vue')['default']
|
MimeTypes: typeof import('./src/tools/mime-types/mime-types.vue')['default']
|
||||||
NavbarButtons: typeof import('./src/components/NavbarButtons.vue')['default']
|
NavbarButtons: typeof import('./src/components/NavbarButtons.vue')['default']
|
||||||
|
NCheckbox: typeof import('naive-ui')['NCheckbox']
|
||||||
NCode: typeof import('naive-ui')['NCode']
|
NCode: typeof import('naive-ui')['NCode']
|
||||||
NCollapseTransition: typeof import('naive-ui')['NCollapseTransition']
|
NCollapseTransition: typeof import('naive-ui')['NCollapseTransition']
|
||||||
NConfigProvider: typeof import('naive-ui')['NConfigProvider']
|
NConfigProvider: typeof import('naive-ui')['NConfigProvider']
|
||||||
NDivider: typeof import('naive-ui')['NDivider']
|
|
||||||
NEllipsis: typeof import('naive-ui')['NEllipsis']
|
NEllipsis: typeof import('naive-ui')['NEllipsis']
|
||||||
|
NForm: typeof import('naive-ui')['NForm']
|
||||||
|
NFormItem: typeof import('naive-ui')['NFormItem']
|
||||||
NH1: typeof import('naive-ui')['NH1']
|
NH1: typeof import('naive-ui')['NH1']
|
||||||
NH3: typeof import('naive-ui')['NH3']
|
NH3: typeof import('naive-ui')['NH3']
|
||||||
NIcon: typeof import('naive-ui')['NIcon']
|
NIcon: typeof import('naive-ui')['NIcon']
|
||||||
|
NInputNumber: typeof import('naive-ui')['NInputNumber']
|
||||||
NLayout: typeof import('naive-ui')['NLayout']
|
NLayout: typeof import('naive-ui')['NLayout']
|
||||||
NLayoutSider: typeof import('naive-ui')['NLayoutSider']
|
NLayoutSider: typeof import('naive-ui')['NLayoutSider']
|
||||||
NMenu: typeof import('naive-ui')['NMenu']
|
NMenu: typeof import('naive-ui')['NMenu']
|
||||||
NScrollbar: typeof import('naive-ui')['NScrollbar']
|
NScrollbar: typeof import('naive-ui')['NScrollbar']
|
||||||
|
NSpin: typeof import('naive-ui')['NSpin']
|
||||||
|
NTable: typeof import('naive-ui')['NTable']
|
||||||
|
NSlider: typeof import('naive-ui')['NSlider']
|
||||||
|
NSwitch: typeof import('naive-ui')['NSwitch']
|
||||||
NumeronymGenerator: typeof import('./src/tools/numeronym-generator/numeronym-generator.vue')['default']
|
NumeronymGenerator: typeof import('./src/tools/numeronym-generator/numeronym-generator.vue')['default']
|
||||||
OtpCodeGeneratorAndValidator: typeof import('./src/tools/otp-code-generator-and-validator/otp-code-generator-and-validator.vue')['default']
|
OtpCodeGeneratorAndValidator: typeof import('./src/tools/otp-code-generator-and-validator/otp-code-generator-and-validator.vue')['default']
|
||||||
PasswordStrengthAnalyser: typeof import('./src/tools/password-strength-analyser/password-strength-analyser.vue')['default']
|
PasswordStrengthAnalyser: typeof import('./src/tools/password-strength-analyser/password-strength-analyser.vue')['default']
|
||||||
@@ -148,7 +155,6 @@ declare module '@vue/runtime-core' {
|
|||||||
PdfSignatureDetails: typeof import('./src/tools/pdf-signature-checker/components/pdf-signature-details.vue')['default']
|
PdfSignatureDetails: typeof import('./src/tools/pdf-signature-checker/components/pdf-signature-details.vue')['default']
|
||||||
PercentageCalculator: typeof import('./src/tools/percentage-calculator/percentage-calculator.vue')['default']
|
PercentageCalculator: typeof import('./src/tools/percentage-calculator/percentage-calculator.vue')['default']
|
||||||
PhoneParserAndFormatter: typeof import('./src/tools/phone-parser-and-formatter/phone-parser-and-formatter.vue')['default']
|
PhoneParserAndFormatter: typeof import('./src/tools/phone-parser-and-formatter/phone-parser-and-formatter.vue')['default']
|
||||||
PunycodeConverter: typeof import('./src/tools/punycode-converter/punycode-converter.vue')['default']
|
|
||||||
QrCodeGenerator: typeof import('./src/tools/qr-code-generator/qr-code-generator.vue')['default']
|
QrCodeGenerator: typeof import('./src/tools/qr-code-generator/qr-code-generator.vue')['default']
|
||||||
RandomPortGenerator: typeof import('./src/tools/random-port-generator/random-port-generator.vue')['default']
|
RandomPortGenerator: typeof import('./src/tools/random-port-generator/random-port-generator.vue')['default']
|
||||||
ResultRow: typeof import('./src/tools/ipv4-range-expander/result-row.vue')['default']
|
ResultRow: typeof import('./src/tools/ipv4-range-expander/result-row.vue')['default']
|
||||||
|
|||||||
@@ -42,7 +42,6 @@
|
|||||||
"@tiptap/starter-kit": "2.1.6",
|
"@tiptap/starter-kit": "2.1.6",
|
||||||
"@tiptap/vue-3": "2.0.3",
|
"@tiptap/vue-3": "2.0.3",
|
||||||
"@types/figlet": "^1.5.8",
|
"@types/figlet": "^1.5.8",
|
||||||
"@types/punycode": "^2.1.4",
|
|
||||||
"@vicons/material": "^0.12.0",
|
"@vicons/material": "^0.12.0",
|
||||||
"@vicons/tabler": "^0.12.0",
|
"@vicons/tabler": "^0.12.0",
|
||||||
"@vueuse/core": "^10.3.0",
|
"@vueuse/core": "^10.3.0",
|
||||||
@@ -82,7 +81,6 @@
|
|||||||
"pdf-signature-reader": "^1.4.2",
|
"pdf-signature-reader": "^1.4.2",
|
||||||
"pinia": "^2.0.34",
|
"pinia": "^2.0.34",
|
||||||
"plausible-tracker": "^0.3.8",
|
"plausible-tracker": "^0.3.8",
|
||||||
"punycode": "^2.3.1",
|
|
||||||
"qrcode": "^1.5.1",
|
"qrcode": "^1.5.1",
|
||||||
"sql-formatter": "^13.0.0",
|
"sql-formatter": "^13.0.0",
|
||||||
"ua-parser-js": "^1.0.35",
|
"ua-parser-js": "^1.0.35",
|
||||||
|
|||||||
Generated
+16
-20
@@ -26,9 +26,6 @@ dependencies:
|
|||||||
'@types/figlet':
|
'@types/figlet':
|
||||||
specifier: ^1.5.8
|
specifier: ^1.5.8
|
||||||
version: 1.5.8
|
version: 1.5.8
|
||||||
'@types/punycode':
|
|
||||||
specifier: ^2.1.4
|
|
||||||
version: 2.1.4
|
|
||||||
'@vicons/material':
|
'@vicons/material':
|
||||||
specifier: ^0.12.0
|
specifier: ^0.12.0
|
||||||
version: 0.12.0
|
version: 0.12.0
|
||||||
@@ -146,9 +143,6 @@ dependencies:
|
|||||||
plausible-tracker:
|
plausible-tracker:
|
||||||
specifier: ^0.3.8
|
specifier: ^0.3.8
|
||||||
version: 0.3.8
|
version: 0.3.8
|
||||||
punycode:
|
|
||||||
specifier: ^2.3.1
|
|
||||||
version: 2.3.1
|
|
||||||
qrcode:
|
qrcode:
|
||||||
specifier: ^1.5.1
|
specifier: ^1.5.1
|
||||||
version: 1.5.1
|
version: 1.5.1
|
||||||
@@ -3038,10 +3032,6 @@ packages:
|
|||||||
resolution: {integrity: sha512-ZREFYlpUmPQJ0esjxoG1fMvB2HNaD3z+mjqdSosZvd3RalncI9NEur73P8ZJz4YQdL64CmV1w0RuqoRUlhQRBw==}
|
resolution: {integrity: sha512-ZREFYlpUmPQJ0esjxoG1fMvB2HNaD3z+mjqdSosZvd3RalncI9NEur73P8ZJz4YQdL64CmV1w0RuqoRUlhQRBw==}
|
||||||
dev: true
|
dev: true
|
||||||
|
|
||||||
/@types/punycode@2.1.4:
|
|
||||||
resolution: {integrity: sha512-trzh6NzBnq8yw5e35f8xe8VTYjqM3NE7bohBtvDVf/dtUer3zYTLK1Ka3DG3p7bdtoaOHZucma6FfVKlQ134pQ==}
|
|
||||||
dev: false
|
|
||||||
|
|
||||||
/@types/qrcode@1.5.0:
|
/@types/qrcode@1.5.0:
|
||||||
resolution: {integrity: sha512-x5ilHXRxUPIMfjtM+1vf/GPTRWZ81nqscursm5gMznJeK9M0YnZ1c3bEvRLQ0zSSgedLx1J6MGL231ObQGGhaA==}
|
resolution: {integrity: sha512-x5ilHXRxUPIMfjtM+1vf/GPTRWZ81nqscursm5gMznJeK9M0YnZ1c3bEvRLQ0zSSgedLx1J6MGL231ObQGGhaA==}
|
||||||
dependencies:
|
dependencies:
|
||||||
@@ -3370,7 +3360,7 @@ packages:
|
|||||||
dependencies:
|
dependencies:
|
||||||
'@unhead/dom': 0.5.1
|
'@unhead/dom': 0.5.1
|
||||||
'@unhead/schema': 0.5.1
|
'@unhead/schema': 0.5.1
|
||||||
'@vueuse/shared': 11.0.3(vue@3.3.4)
|
'@vueuse/shared': 10.11.1(vue@3.3.4)
|
||||||
unhead: 0.5.1
|
unhead: 0.5.1
|
||||||
vue: 3.3.4
|
vue: 3.3.4
|
||||||
transitivePeerDependencies:
|
transitivePeerDependencies:
|
||||||
@@ -4003,19 +3993,19 @@ packages:
|
|||||||
- vue
|
- vue
|
||||||
dev: false
|
dev: false
|
||||||
|
|
||||||
/@vueuse/shared@10.3.0(vue@3.3.4):
|
/@vueuse/shared@10.11.1(vue@3.3.4):
|
||||||
resolution: {integrity: sha512-kGqCTEuFPMK4+fNWy6dUOiYmxGcUbtznMwBZLC1PubidF4VZY05B+Oht7Jh7/6x4VOWGpvu3R37WHi81cKpiqg==}
|
resolution: {integrity: sha512-LHpC8711VFZlDaYUXEBbFBCQ7GS3dVU9mjOhhMhXP6txTV4EhYQg/KGnQuvt/sPAtoUKq7VVUnL6mVtFoL42sA==}
|
||||||
dependencies:
|
dependencies:
|
||||||
vue-demi: 0.14.5(vue@3.3.4)
|
vue-demi: 0.14.10(vue@3.3.4)
|
||||||
transitivePeerDependencies:
|
transitivePeerDependencies:
|
||||||
- '@vue/composition-api'
|
- '@vue/composition-api'
|
||||||
- vue
|
- vue
|
||||||
dev: false
|
dev: false
|
||||||
|
|
||||||
/@vueuse/shared@11.0.3(vue@3.3.4):
|
/@vueuse/shared@10.3.0(vue@3.3.4):
|
||||||
resolution: {integrity: sha512-0rY2m6HS5t27n/Vp5cTDsKTlNnimCqsbh/fmT2LgE+aaU42EMfXo8+bNX91W9I7DDmxfuACXMmrd7d79JxkqWA==}
|
resolution: {integrity: sha512-kGqCTEuFPMK4+fNWy6dUOiYmxGcUbtznMwBZLC1PubidF4VZY05B+Oht7Jh7/6x4VOWGpvu3R37WHi81cKpiqg==}
|
||||||
dependencies:
|
dependencies:
|
||||||
vue-demi: 0.14.10(vue@3.3.4)
|
vue-demi: 0.14.5(vue@3.3.4)
|
||||||
transitivePeerDependencies:
|
transitivePeerDependencies:
|
||||||
- '@vue/composition-api'
|
- '@vue/composition-api'
|
||||||
- vue
|
- vue
|
||||||
@@ -7692,9 +7682,15 @@ packages:
|
|||||||
resolution: {integrity: sha512-E/ZsdU4HLs/68gYzgGTkMicWTLPdAftJLfJFlLUAAKZGkStNU72sZjT66SnMDVOfOWY/YAoiD7Jxa9iHvngcag==}
|
resolution: {integrity: sha512-E/ZsdU4HLs/68gYzgGTkMicWTLPdAftJLfJFlLUAAKZGkStNU72sZjT66SnMDVOfOWY/YAoiD7Jxa9iHvngcag==}
|
||||||
dev: true
|
dev: true
|
||||||
|
|
||||||
|
/punycode@2.3.0:
|
||||||
|
resolution: {integrity: sha512-rRV+zQD8tVFys26lAGR9WUuS4iUAngJScM+ZRSKtvl5tKeZ2t5bvdNFdNHBW9FWR4guGHlgmsZ1G7BSm2wTbuA==}
|
||||||
|
engines: {node: '>=6'}
|
||||||
|
dev: true
|
||||||
|
|
||||||
/punycode@2.3.1:
|
/punycode@2.3.1:
|
||||||
resolution: {integrity: sha512-vYt7UD1U9Wg6138shLtLOvdAu+8DsC/ilFtEVHcH+wydcSpNE20AfSOduf6MkRFahL5FY7X1oU7nKVZFtfq8Fg==}
|
resolution: {integrity: sha512-vYt7UD1U9Wg6138shLtLOvdAu+8DsC/ilFtEVHcH+wydcSpNE20AfSOduf6MkRFahL5FY7X1oU7nKVZFtfq8Fg==}
|
||||||
engines: {node: '>=6'}
|
engines: {node: '>=6'}
|
||||||
|
dev: true
|
||||||
|
|
||||||
/qrcode@1.5.1:
|
/qrcode@1.5.1:
|
||||||
resolution: {integrity: sha512-nS8NJ1Z3md8uTjKtP+SGGhfqmTCs5flU/xR623oI0JX+Wepz9R8UrRVCTBTJm3qGw3rH6jJ6MUHjkDx15cxSSg==}
|
resolution: {integrity: sha512-nS8NJ1Z3md8uTjKtP+SGGhfqmTCs5flU/xR623oI0JX+Wepz9R8UrRVCTBTJm3qGw3rH6jJ6MUHjkDx15cxSSg==}
|
||||||
@@ -8484,7 +8480,7 @@ packages:
|
|||||||
engines: {node: '>=6'}
|
engines: {node: '>=6'}
|
||||||
dependencies:
|
dependencies:
|
||||||
psl: 1.9.0
|
psl: 1.9.0
|
||||||
punycode: 2.3.1
|
punycode: 2.3.0
|
||||||
universalify: 0.2.0
|
universalify: 0.2.0
|
||||||
url-parse: 1.5.10
|
url-parse: 1.5.10
|
||||||
dev: true
|
dev: true
|
||||||
@@ -8499,7 +8495,7 @@ packages:
|
|||||||
resolution: {integrity: sha512-2lv/66T7e5yNyhAAC4NaKe5nVavzuGJQVVtRYLyQ2OI8tsJ61PMLlelehb0wi2Hx6+hT/OJUWZcw8MjlSRnxvw==}
|
resolution: {integrity: sha512-2lv/66T7e5yNyhAAC4NaKe5nVavzuGJQVVtRYLyQ2OI8tsJ61PMLlelehb0wi2Hx6+hT/OJUWZcw8MjlSRnxvw==}
|
||||||
engines: {node: '>=14'}
|
engines: {node: '>=14'}
|
||||||
dependencies:
|
dependencies:
|
||||||
punycode: 2.3.1
|
punycode: 2.3.0
|
||||||
dev: true
|
dev: true
|
||||||
|
|
||||||
/treemate@0.3.11:
|
/treemate@0.3.11:
|
||||||
@@ -8939,7 +8935,7 @@ packages:
|
|||||||
/uri-js@4.4.1:
|
/uri-js@4.4.1:
|
||||||
resolution: {integrity: sha512-7rKUyy33Q1yc98pQ1DAmLtwX109F7TIfWlW1Ydo8Wl1ii1SeHieeh0HHfPeL2fMXK6z0s8ecKs9frCuLJvndBg==}
|
resolution: {integrity: sha512-7rKUyy33Q1yc98pQ1DAmLtwX109F7TIfWlW1Ydo8Wl1ii1SeHieeh0HHfPeL2fMXK6z0s8ecKs9frCuLJvndBg==}
|
||||||
dependencies:
|
dependencies:
|
||||||
punycode: 2.3.1
|
punycode: 2.3.0
|
||||||
dev: true
|
dev: true
|
||||||
|
|
||||||
/url-parse@1.5.10:
|
/url-parse@1.5.10:
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { describe, expect, it } from 'vitest';
|
import { describe, expect, it } from 'vitest';
|
||||||
import { computeChmodOctalRepresentation, computeChmodSymbolicRepresentation } from './chmod-calculator.service';
|
import { computeChmodOctalRepresentation, computeChmodSymbolicRepresentation, computePermissionsFromChmodOctalRepresentation, computePermissionsFromChmodSymbolicRepresentation, computeUmaskRepresentation } from './chmod-calculator.service';
|
||||||
|
|
||||||
describe('chmod-calculator', () => {
|
describe('chmod-calculator', () => {
|
||||||
describe('computeChmodOctalRepresentation', () => {
|
describe('computeChmodOctalRepresentation', () => {
|
||||||
@@ -10,6 +10,7 @@ describe('chmod-calculator', () => {
|
|||||||
owner: { read: true, write: true, execute: true },
|
owner: { read: true, write: true, execute: true },
|
||||||
group: { read: true, write: true, execute: true },
|
group: { read: true, write: true, execute: true },
|
||||||
public: { read: true, write: true, execute: true },
|
public: { read: true, write: true, execute: true },
|
||||||
|
flags: { setuid: false, setgid: false, stickybit: false },
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
).to.eql('777');
|
).to.eql('777');
|
||||||
@@ -20,6 +21,7 @@ describe('chmod-calculator', () => {
|
|||||||
owner: { read: false, write: false, execute: false },
|
owner: { read: false, write: false, execute: false },
|
||||||
group: { read: false, write: false, execute: false },
|
group: { read: false, write: false, execute: false },
|
||||||
public: { read: false, write: false, execute: false },
|
public: { read: false, write: false, execute: false },
|
||||||
|
flags: { setuid: false, setgid: false, stickybit: false },
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
).to.eql('000');
|
).to.eql('000');
|
||||||
@@ -30,6 +32,7 @@ describe('chmod-calculator', () => {
|
|||||||
owner: { read: false, write: true, execute: false },
|
owner: { read: false, write: true, execute: false },
|
||||||
group: { read: false, write: true, execute: true },
|
group: { read: false, write: true, execute: true },
|
||||||
public: { read: true, write: false, execute: true },
|
public: { read: true, write: false, execute: true },
|
||||||
|
flags: { setuid: false, setgid: false, stickybit: false },
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
).to.eql('235');
|
).to.eql('235');
|
||||||
@@ -40,6 +43,7 @@ describe('chmod-calculator', () => {
|
|||||||
owner: { read: true, write: false, execute: false },
|
owner: { read: true, write: false, execute: false },
|
||||||
group: { read: false, write: true, execute: false },
|
group: { read: false, write: true, execute: false },
|
||||||
public: { read: false, write: false, execute: true },
|
public: { read: false, write: false, execute: true },
|
||||||
|
flags: { setuid: false, setgid: false, stickybit: false },
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
).to.eql('421');
|
).to.eql('421');
|
||||||
@@ -50,6 +54,7 @@ describe('chmod-calculator', () => {
|
|||||||
owner: { read: false, write: false, execute: true },
|
owner: { read: false, write: false, execute: true },
|
||||||
group: { read: false, write: true, execute: false },
|
group: { read: false, write: true, execute: false },
|
||||||
public: { read: true, write: false, execute: false },
|
public: { read: true, write: false, execute: false },
|
||||||
|
flags: { setuid: false, setgid: false, stickybit: false },
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
).to.eql('124');
|
).to.eql('124');
|
||||||
@@ -60,11 +65,57 @@ describe('chmod-calculator', () => {
|
|||||||
owner: { read: false, write: true, execute: false },
|
owner: { read: false, write: true, execute: false },
|
||||||
group: { read: false, write: true, execute: false },
|
group: { read: false, write: true, execute: false },
|
||||||
public: { read: false, write: true, execute: false },
|
public: { read: false, write: true, execute: false },
|
||||||
|
flags: { setuid: false, setgid: false, stickybit: false },
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
).to.eql('222');
|
).to.eql('222');
|
||||||
});
|
|
||||||
|
|
||||||
|
expect(
|
||||||
|
computeChmodOctalRepresentation({
|
||||||
|
permissions: {
|
||||||
|
owner: { read: false, write: true, execute: false },
|
||||||
|
group: { read: false, write: true, execute: false },
|
||||||
|
public: { read: false, write: true, execute: false },
|
||||||
|
flags: { setuid: true, setgid: true, stickybit: true },
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
).to.eql('7222');
|
||||||
|
|
||||||
|
expect(
|
||||||
|
computeChmodOctalRepresentation({
|
||||||
|
permissions: {
|
||||||
|
owner: { read: false, write: true, execute: false },
|
||||||
|
group: { read: false, write: true, execute: false },
|
||||||
|
public: { read: false, write: true, execute: false },
|
||||||
|
flags: { setuid: true, setgid: false, stickybit: false },
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
).to.eql('4222');
|
||||||
|
|
||||||
|
expect(
|
||||||
|
computeChmodOctalRepresentation({
|
||||||
|
permissions: {
|
||||||
|
owner: { read: false, write: true, execute: false },
|
||||||
|
group: { read: false, write: true, execute: false },
|
||||||
|
public: { read: false, write: true, execute: false },
|
||||||
|
flags: { setuid: false, setgid: true, stickybit: false },
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
).to.eql('2222');
|
||||||
|
|
||||||
|
expect(
|
||||||
|
computeChmodOctalRepresentation({
|
||||||
|
permissions: {
|
||||||
|
owner: { read: false, write: true, execute: false },
|
||||||
|
group: { read: false, write: true, execute: false },
|
||||||
|
public: { read: false, write: true, execute: false },
|
||||||
|
flags: { setuid: false, setgid: false, stickybit: true },
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
).to.eql('1222');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
describe('computeChmodSymbolicRepresentation', () => {
|
||||||
it('get the symbolic representation from permissions', () => {
|
it('get the symbolic representation from permissions', () => {
|
||||||
expect(
|
expect(
|
||||||
computeChmodSymbolicRepresentation({
|
computeChmodSymbolicRepresentation({
|
||||||
@@ -72,6 +123,7 @@ describe('chmod-calculator', () => {
|
|||||||
owner: { read: true, write: true, execute: true },
|
owner: { read: true, write: true, execute: true },
|
||||||
group: { read: true, write: true, execute: true },
|
group: { read: true, write: true, execute: true },
|
||||||
public: { read: true, write: true, execute: true },
|
public: { read: true, write: true, execute: true },
|
||||||
|
flags: { setuid: false, setgid: false, stickybit: false },
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
).to.eql('rwxrwxrwx');
|
).to.eql('rwxrwxrwx');
|
||||||
@@ -82,6 +134,7 @@ describe('chmod-calculator', () => {
|
|||||||
owner: { read: false, write: false, execute: false },
|
owner: { read: false, write: false, execute: false },
|
||||||
group: { read: false, write: false, execute: false },
|
group: { read: false, write: false, execute: false },
|
||||||
public: { read: false, write: false, execute: false },
|
public: { read: false, write: false, execute: false },
|
||||||
|
flags: { setuid: false, setgid: false, stickybit: false },
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
).to.eql('---------');
|
).to.eql('---------');
|
||||||
@@ -92,6 +145,7 @@ describe('chmod-calculator', () => {
|
|||||||
owner: { read: false, write: true, execute: false },
|
owner: { read: false, write: true, execute: false },
|
||||||
group: { read: false, write: true, execute: true },
|
group: { read: false, write: true, execute: true },
|
||||||
public: { read: true, write: false, execute: true },
|
public: { read: true, write: false, execute: true },
|
||||||
|
flags: { setuid: false, setgid: false, stickybit: false },
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
).to.eql('-w--wxr-x');
|
).to.eql('-w--wxr-x');
|
||||||
@@ -102,6 +156,7 @@ describe('chmod-calculator', () => {
|
|||||||
owner: { read: true, write: false, execute: false },
|
owner: { read: true, write: false, execute: false },
|
||||||
group: { read: false, write: true, execute: false },
|
group: { read: false, write: true, execute: false },
|
||||||
public: { read: false, write: false, execute: true },
|
public: { read: false, write: false, execute: true },
|
||||||
|
flags: { setuid: false, setgid: false, stickybit: false },
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
).to.eql('r---w---x');
|
).to.eql('r---w---x');
|
||||||
@@ -112,6 +167,7 @@ describe('chmod-calculator', () => {
|
|||||||
owner: { read: false, write: false, execute: true },
|
owner: { read: false, write: false, execute: true },
|
||||||
group: { read: false, write: true, execute: false },
|
group: { read: false, write: true, execute: false },
|
||||||
public: { read: true, write: false, execute: false },
|
public: { read: true, write: false, execute: false },
|
||||||
|
flags: { setuid: false, setgid: false, stickybit: false },
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
).to.eql('--x-w-r--');
|
).to.eql('--x-w-r--');
|
||||||
@@ -122,9 +178,382 @@ describe('chmod-calculator', () => {
|
|||||||
owner: { read: false, write: true, execute: false },
|
owner: { read: false, write: true, execute: false },
|
||||||
group: { read: false, write: true, execute: false },
|
group: { read: false, write: true, execute: false },
|
||||||
public: { read: false, write: true, execute: false },
|
public: { read: false, write: true, execute: false },
|
||||||
|
flags: { setuid: false, setgid: false, stickybit: false },
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
).to.eql('-w--w--w-');
|
).to.eql('-w--w--w-');
|
||||||
|
|
||||||
|
expect(
|
||||||
|
computeChmodSymbolicRepresentation({
|
||||||
|
permissions: {
|
||||||
|
owner: { read: false, write: false, execute: true },
|
||||||
|
group: { read: false, write: true, execute: false },
|
||||||
|
public: { read: true, write: false, execute: false },
|
||||||
|
flags: { setuid: false, setgid: false, stickybit: true },
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
).to.eql('--x-w-r-t');
|
||||||
|
|
||||||
|
expect(
|
||||||
|
computeChmodSymbolicRepresentation({
|
||||||
|
permissions: {
|
||||||
|
owner: { read: false, write: false, execute: true },
|
||||||
|
group: { read: false, write: true, execute: false },
|
||||||
|
public: { read: true, write: false, execute: false },
|
||||||
|
flags: { setuid: false, setgid: true, stickybit: true },
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
).to.eql('--x-wsr-t');
|
||||||
|
|
||||||
|
expect(
|
||||||
|
computeChmodSymbolicRepresentation({
|
||||||
|
permissions: {
|
||||||
|
owner: { read: false, write: false, execute: true },
|
||||||
|
group: { read: false, write: true, execute: false },
|
||||||
|
public: { read: true, write: false, execute: false },
|
||||||
|
flags: { setuid: true, setgid: true, stickybit: true },
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
).to.eql('--s-wsr-t');
|
||||||
|
|
||||||
|
expect(
|
||||||
|
computeChmodSymbolicRepresentation({
|
||||||
|
permissions: {
|
||||||
|
owner: { read: true, write: false, execute: true },
|
||||||
|
group: { read: true, write: true, execute: false },
|
||||||
|
public: { read: true, write: false, execute: false },
|
||||||
|
flags: { setuid: false, setgid: false, stickybit: false },
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
).to.eql('r-xrw-r--');
|
||||||
|
|
||||||
|
expect(
|
||||||
|
computeChmodSymbolicRepresentation({
|
||||||
|
permissions: {
|
||||||
|
owner: { read: true, write: true, execute: true },
|
||||||
|
group: { read: true, write: true, execute: true },
|
||||||
|
public: { read: true, write: true, execute: true },
|
||||||
|
flags: { setuid: true, setgid: true, stickybit: true },
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
).to.eql('rwsrwsrwt');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
describe('computePermissionsFromChmodOctalRepresentation', () => {
|
||||||
|
it('throws on invalid octal values', () => {
|
||||||
|
expect(() => computePermissionsFromChmodOctalRepresentation('12')).to.throw();
|
||||||
|
expect(() => computePermissionsFromChmodOctalRepresentation('12345')).to.throw();
|
||||||
|
expect(() => computePermissionsFromChmodOctalRepresentation('999')).to.throw();
|
||||||
|
expect(() => computePermissionsFromChmodOctalRepresentation('9999')).to.throw();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('get permissions from octal representation', () => {
|
||||||
|
expect(
|
||||||
|
computePermissionsFromChmodOctalRepresentation('777'),
|
||||||
|
).to.eql({
|
||||||
|
owner: { read: true, write: true, execute: true },
|
||||||
|
group: { read: true, write: true, execute: true },
|
||||||
|
public: { read: true, write: true, execute: true },
|
||||||
|
flags: { setuid: false, setgid: false, stickybit: false },
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(
|
||||||
|
computePermissionsFromChmodOctalRepresentation('000'),
|
||||||
|
).to.eql({
|
||||||
|
owner: { read: false, write: false, execute: false },
|
||||||
|
group: { read: false, write: false, execute: false },
|
||||||
|
public: { read: false, write: false, execute: false },
|
||||||
|
flags: { setuid: false, setgid: false, stickybit: false },
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(
|
||||||
|
computePermissionsFromChmodOctalRepresentation('235'),
|
||||||
|
).to.eql({
|
||||||
|
owner: { read: false, write: true, execute: false },
|
||||||
|
group: { read: false, write: true, execute: true },
|
||||||
|
public: { read: true, write: false, execute: true },
|
||||||
|
flags: { setuid: false, setgid: false, stickybit: false },
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(
|
||||||
|
computePermissionsFromChmodOctalRepresentation('421'),
|
||||||
|
).to.eql({
|
||||||
|
owner: { read: true, write: false, execute: false },
|
||||||
|
group: { read: false, write: true, execute: false },
|
||||||
|
public: { read: false, write: false, execute: true },
|
||||||
|
flags: { setuid: false, setgid: false, stickybit: false },
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(
|
||||||
|
computePermissionsFromChmodOctalRepresentation('124'),
|
||||||
|
).to.eql({
|
||||||
|
owner: { read: false, write: false, execute: true },
|
||||||
|
group: { read: false, write: true, execute: false },
|
||||||
|
public: { read: true, write: false, execute: false },
|
||||||
|
flags: { setuid: false, setgid: false, stickybit: false },
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(
|
||||||
|
computePermissionsFromChmodOctalRepresentation('222'),
|
||||||
|
).to.eql({
|
||||||
|
owner: { read: false, write: true, execute: false },
|
||||||
|
group: { read: false, write: true, execute: false },
|
||||||
|
public: { read: false, write: true, execute: false },
|
||||||
|
flags: { setuid: false, setgid: false, stickybit: false },
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(
|
||||||
|
computePermissionsFromChmodOctalRepresentation('7222'),
|
||||||
|
).to.eql({
|
||||||
|
owner: { read: false, write: true, execute: false },
|
||||||
|
group: { read: false, write: true, execute: false },
|
||||||
|
public: { read: false, write: true, execute: false },
|
||||||
|
flags: { setuid: true, setgid: true, stickybit: true },
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(
|
||||||
|
computePermissionsFromChmodOctalRepresentation('4222'),
|
||||||
|
).to.eql({
|
||||||
|
owner: { read: false, write: true, execute: false },
|
||||||
|
group: { read: false, write: true, execute: false },
|
||||||
|
public: { read: false, write: true, execute: false },
|
||||||
|
flags: { setuid: true, setgid: false, stickybit: false },
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(
|
||||||
|
computePermissionsFromChmodOctalRepresentation('2222'),
|
||||||
|
).to.eql({
|
||||||
|
owner: { read: false, write: true, execute: false },
|
||||||
|
group: { read: false, write: true, execute: false },
|
||||||
|
public: { read: false, write: true, execute: false },
|
||||||
|
flags: { setuid: false, setgid: true, stickybit: false },
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(
|
||||||
|
computePermissionsFromChmodOctalRepresentation('1222'),
|
||||||
|
).to.eql({
|
||||||
|
owner: { read: false, write: true, execute: false },
|
||||||
|
group: { read: false, write: true, execute: false },
|
||||||
|
public: { read: false, write: true, execute: false },
|
||||||
|
flags: { setuid: false, setgid: false, stickybit: true },
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
describe('computePermissionsFromChmodSymbolicRepresentation', () => {
|
||||||
|
it('throws on invalid symbolic values', () => {
|
||||||
|
expect(() => computePermissionsFromChmodSymbolicRepresentation('rr---')).to.throw();
|
||||||
|
expect(() => computePermissionsFromChmodSymbolicRepresentation('rwxrwx--w')).to.throw();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('get permissions from symbolic representation', () => {
|
||||||
|
expect(
|
||||||
|
computePermissionsFromChmodSymbolicRepresentation('dr-xr-xr-x'),
|
||||||
|
).to.eql({
|
||||||
|
owner: { read: true, write: false, execute: true },
|
||||||
|
group: { read: true, write: false, execute: true },
|
||||||
|
public: { read: true, write: false, execute: true },
|
||||||
|
flags: { setuid: false, setgid: false, stickybit: false },
|
||||||
|
});
|
||||||
|
expect(
|
||||||
|
computePermissionsFromChmodSymbolicRepresentation('-rw-r--r--'),
|
||||||
|
).to.eql({
|
||||||
|
owner: { read: true, write: true, execute: false },
|
||||||
|
group: { read: true, write: false, execute: false },
|
||||||
|
public: { read: true, write: false, execute: false },
|
||||||
|
flags: { setuid: false, setgid: false, stickybit: false },
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(
|
||||||
|
computePermissionsFromChmodSymbolicRepresentation('rwxrwxrwx'),
|
||||||
|
).to.eql({
|
||||||
|
owner: { read: true, write: true, execute: true },
|
||||||
|
group: { read: true, write: true, execute: true },
|
||||||
|
public: { read: true, write: true, execute: true },
|
||||||
|
flags: { setuid: false, setgid: false, stickybit: false },
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(
|
||||||
|
computePermissionsFromChmodSymbolicRepresentation('---------'),
|
||||||
|
).to.eql({
|
||||||
|
owner: { read: false, write: false, execute: false },
|
||||||
|
group: { read: false, write: false, execute: false },
|
||||||
|
public: { read: false, write: false, execute: false },
|
||||||
|
flags: { setuid: false, setgid: false, stickybit: false },
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(
|
||||||
|
computePermissionsFromChmodSymbolicRepresentation('r---wxr-x'),
|
||||||
|
).to.eql({
|
||||||
|
owner: { read: true, write: false, execute: false },
|
||||||
|
group: { read: false, write: true, execute: true },
|
||||||
|
public: { read: true, write: false, execute: true },
|
||||||
|
flags: { setuid: false, setgid: false, stickybit: false },
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(
|
||||||
|
computePermissionsFromChmodSymbolicRepresentation('r---w---x'),
|
||||||
|
).to.eql({
|
||||||
|
owner: { read: true, write: false, execute: false },
|
||||||
|
group: { read: false, write: true, execute: false },
|
||||||
|
public: { read: false, write: false, execute: true },
|
||||||
|
flags: { setuid: false, setgid: false, stickybit: false },
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(
|
||||||
|
computePermissionsFromChmodSymbolicRepresentation('--x-w-r--'),
|
||||||
|
).to.eql({
|
||||||
|
owner: { read: false, write: false, execute: true },
|
||||||
|
group: { read: false, write: true, execute: false },
|
||||||
|
public: { read: true, write: false, execute: false },
|
||||||
|
flags: { setuid: false, setgid: false, stickybit: false },
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(
|
||||||
|
computePermissionsFromChmodSymbolicRepresentation('-w--w--w-'),
|
||||||
|
).to.eql({
|
||||||
|
owner: { read: false, write: true, execute: false },
|
||||||
|
group: { read: false, write: true, execute: false },
|
||||||
|
public: { read: false, write: true, execute: false },
|
||||||
|
flags: { setuid: false, setgid: false, stickybit: false },
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(
|
||||||
|
computePermissionsFromChmodSymbolicRepresentation('-ws-ws-wt'),
|
||||||
|
).to.eql({
|
||||||
|
owner: { read: false, write: true, execute: true },
|
||||||
|
group: { read: false, write: true, execute: true },
|
||||||
|
public: { read: false, write: true, execute: true },
|
||||||
|
flags: { setuid: true, setgid: true, stickybit: true },
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(
|
||||||
|
computePermissionsFromChmodSymbolicRepresentation('-ws-w--w-'),
|
||||||
|
).to.eql({
|
||||||
|
owner: { read: false, write: true, execute: true },
|
||||||
|
group: { read: false, write: true, execute: false },
|
||||||
|
public: { read: false, write: true, execute: false },
|
||||||
|
flags: { setuid: true, setgid: false, stickybit: false },
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(
|
||||||
|
computePermissionsFromChmodSymbolicRepresentation('-w--ws-w-'),
|
||||||
|
).to.eql({
|
||||||
|
owner: { read: false, write: true, execute: false },
|
||||||
|
group: { read: false, write: true, execute: true },
|
||||||
|
public: { read: false, write: true, execute: false },
|
||||||
|
flags: { setuid: false, setgid: true, stickybit: false },
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(
|
||||||
|
computePermissionsFromChmodSymbolicRepresentation('-w--w--wt'),
|
||||||
|
).to.eql({
|
||||||
|
owner: { read: false, write: true, execute: false },
|
||||||
|
group: { read: false, write: true, execute: false },
|
||||||
|
public: { read: false, write: true, execute: true },
|
||||||
|
flags: { setuid: false, setgid: false, stickybit: true },
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('computeUmaskRepresentation', () => {
|
||||||
|
it('get the umask from permissions', () => {
|
||||||
|
expect(
|
||||||
|
computeUmaskRepresentation({
|
||||||
|
permissions: {
|
||||||
|
owner: { read: true, write: true, execute: true },
|
||||||
|
group: { read: true, write: true, execute: true },
|
||||||
|
public: { read: true, write: true, execute: true },
|
||||||
|
flags: { setuid: false, setgid: false, stickybit: false },
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
).to.deep.eq({
|
||||||
|
octal: '000',
|
||||||
|
symbolic: 'umask u=rwx,g=rwx,o=rwx',
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(
|
||||||
|
computeUmaskRepresentation({
|
||||||
|
permissions: {
|
||||||
|
owner: { read: false, write: false, execute: false },
|
||||||
|
group: { read: false, write: false, execute: false },
|
||||||
|
public: { read: false, write: false, execute: false },
|
||||||
|
flags: { setuid: false, setgid: false, stickybit: false },
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
).to.deep.eq({
|
||||||
|
octal: '777',
|
||||||
|
symbolic: 'umask u=,g=,o=',
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(
|
||||||
|
computeUmaskRepresentation({
|
||||||
|
permissions: {
|
||||||
|
owner: { read: false, write: true, execute: false },
|
||||||
|
group: { read: false, write: true, execute: true },
|
||||||
|
public: { read: true, write: false, execute: true },
|
||||||
|
flags: { setuid: false, setgid: false, stickybit: false },
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
).to.deep.eq({
|
||||||
|
octal: '542',
|
||||||
|
symbolic: 'umask u=w,g=wx,o=rx',
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(
|
||||||
|
computeUmaskRepresentation({
|
||||||
|
permissions: {
|
||||||
|
owner: { read: true, write: false, execute: false },
|
||||||
|
group: { read: false, write: true, execute: false },
|
||||||
|
public: { read: false, write: false, execute: true },
|
||||||
|
flags: { setuid: false, setgid: false, stickybit: false },
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
).to.deep.eq({
|
||||||
|
octal: '356',
|
||||||
|
symbolic: 'umask u=r,g=w,o=x',
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(
|
||||||
|
computeUmaskRepresentation({
|
||||||
|
permissions: {
|
||||||
|
owner: { read: false, write: false, execute: true },
|
||||||
|
group: { read: false, write: true, execute: false },
|
||||||
|
public: { read: true, write: false, execute: false },
|
||||||
|
flags: { setuid: false, setgid: false, stickybit: false },
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
).to.deep.eq({
|
||||||
|
octal: '653',
|
||||||
|
symbolic: 'umask u=x,g=w,o=r',
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(
|
||||||
|
computeUmaskRepresentation({
|
||||||
|
permissions: {
|
||||||
|
owner: { read: false, write: true, execute: false },
|
||||||
|
group: { read: false, write: true, execute: false },
|
||||||
|
public: { read: false, write: true, execute: false },
|
||||||
|
flags: { setuid: false, setgid: false, stickybit: false },
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
).to.deep.eq({
|
||||||
|
octal: '555',
|
||||||
|
symbolic: 'umask u=w,g=w,o=w',
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(
|
||||||
|
computeUmaskRepresentation({
|
||||||
|
permissions: {
|
||||||
|
owner: { read: false, write: false, execute: true },
|
||||||
|
group: { read: false, write: true, execute: false },
|
||||||
|
public: { read: true, write: false, execute: false },
|
||||||
|
flags: { setuid: true, setgid: true, stickybit: true },
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
).to.deep.eq({
|
||||||
|
octal: '653',
|
||||||
|
symbolic: 'umask u=x,g=w,o=r',
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -1,15 +1,21 @@
|
|||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import type { GroupPermissions, Permissions } from './chmod-calculator.types';
|
import type { GroupPermissions, Permissions, SpecialPermissions } from './chmod-calculator.types';
|
||||||
|
|
||||||
export { computeChmodOctalRepresentation, computeChmodSymbolicRepresentation };
|
export { computeUmaskRepresentation, computeChmodOctalRepresentation, computeChmodSymbolicRepresentation, computePermissionsFromChmodOctalRepresentation, computePermissionsFromChmodSymbolicRepresentation };
|
||||||
|
|
||||||
function computeChmodOctalRepresentation({ permissions }: { permissions: Permissions }): string {
|
function computeChmodOctalRepresentation({ permissions }: { permissions: Permissions }): string {
|
||||||
const permissionValue = { read: 4, write: 2, execute: 1 };
|
const permissionValue = { read: 4, write: 2, execute: 1 };
|
||||||
|
const specialPermissionValue = { setuid: 4, setgid: 2, stickybit: 1 };
|
||||||
|
|
||||||
const getGroupPermissionValue = (permission: GroupPermissions) =>
|
const getGroupPermissionValue = (permission: GroupPermissions) =>
|
||||||
_.reduce(permission, (acc, isPermSet, key) => acc + (isPermSet ? _.get(permissionValue, key, 0) : 0), 0);
|
_.reduce(permission, (acc, isPermSet, key) => acc + (isPermSet ? _.get(permissionValue, key, 0) : 0), 0);
|
||||||
|
const getSpecialPermissionValue = (permission: SpecialPermissions) => {
|
||||||
|
const octalValue = _.reduce(permission, (acc, isPermSet, key) => acc + (isPermSet ? _.get(specialPermissionValue, key, 0) : 0), 0);
|
||||||
|
return octalValue > 0 ? octalValue.toString() : '';
|
||||||
|
};
|
||||||
|
|
||||||
return [
|
return [
|
||||||
|
getSpecialPermissionValue(permissions.flags || { setuid: false, setgid: false, stickybit: false }),
|
||||||
getGroupPermissionValue(permissions.owner),
|
getGroupPermissionValue(permissions.owner),
|
||||||
getGroupPermissionValue(permissions.group),
|
getGroupPermissionValue(permissions.group),
|
||||||
getGroupPermissionValue(permissions.public),
|
getGroupPermissionValue(permissions.public),
|
||||||
@@ -18,13 +24,92 @@ function computeChmodOctalRepresentation({ permissions }: { permissions: Permiss
|
|||||||
|
|
||||||
function computeChmodSymbolicRepresentation({ permissions }: { permissions: Permissions }): string {
|
function computeChmodSymbolicRepresentation({ permissions }: { permissions: Permissions }): string {
|
||||||
const permissionValue = { read: 'r', write: 'w', execute: 'x' };
|
const permissionValue = { read: 'r', write: 'w', execute: 'x' };
|
||||||
|
const specialFlagPermission = 'execute';
|
||||||
|
|
||||||
const getGroupPermissionValue = (permission: GroupPermissions) =>
|
const getGroupPermissionValue = (permission: GroupPermissions, specialFlag: null | 's' | 't') =>
|
||||||
_.reduce(permission, (acc, isPermSet, key) => acc + (isPermSet ? _.get(permissionValue, key, '') : '-'), '');
|
_.reduce(permission, (acc, isPermSet, key) => acc + ((key === specialFlagPermission ? specialFlag : undefined)
|
||||||
|
|| (isPermSet ? _.get(permissionValue, key, '') : '-')), '');
|
||||||
|
|
||||||
return [
|
return [
|
||||||
getGroupPermissionValue(permissions.owner),
|
getGroupPermissionValue(permissions.owner, permissions.flags?.setuid ? 's' : null),
|
||||||
getGroupPermissionValue(permissions.group),
|
getGroupPermissionValue(permissions.group, permissions.flags?.setgid ? 's' : null),
|
||||||
getGroupPermissionValue(permissions.public),
|
getGroupPermissionValue(permissions.public, permissions.flags?.stickybit ? 't' : null),
|
||||||
].join('');
|
].join('');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function computePermissionsFromChmodOctalRepresentation(octalPermissions: string): Permissions {
|
||||||
|
const permissionValue = { read: 4, write: 2, execute: 1 };
|
||||||
|
const specialPermissionValue = { setuid: 4, setgid: 2, stickybit: 1 };
|
||||||
|
|
||||||
|
if (!octalPermissions || !octalPermissions.match(/^[0-7]{3,4}$/)) {
|
||||||
|
throw new Error(`Invalid octal permissions (must be 3 or 4 octal digits): ${octalPermissions}`);
|
||||||
|
}
|
||||||
|
const fullOctalPermissions = octalPermissions.length === 3 ? `0${octalPermissions}` : octalPermissions;
|
||||||
|
|
||||||
|
const hasSet = (position: number, flagValue: number) => (Number(fullOctalPermissions[position]) & flagValue) === flagValue;
|
||||||
|
function computePermissionObject<T>(permissionSet: object, position: number): T {
|
||||||
|
return _.reduce(permissionSet, (acc, flag, key) => ({ ...acc, [key]: hasSet(position, flag) }), {}) as T;
|
||||||
|
}
|
||||||
|
const flagsPosition = 0;
|
||||||
|
const ownerPosition = 1;
|
||||||
|
const groupPosition = 2;
|
||||||
|
const publicPosition = 3;
|
||||||
|
return {
|
||||||
|
owner: computePermissionObject(permissionValue, ownerPosition),
|
||||||
|
group: computePermissionObject(permissionValue, groupPosition),
|
||||||
|
public: computePermissionObject(permissionValue, publicPosition),
|
||||||
|
flags: computePermissionObject(specialPermissionValue, flagsPosition),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function computePermissionsFromChmodSymbolicRepresentation(symbolicPermissions: string): Permissions {
|
||||||
|
const formatRegex = /^[-dlbcsp]?([r-])([w-])([xs-])([r-])([w-])([xs-])([r-])([w-])([xt-])$/;
|
||||||
|
if (!symbolicPermissions || !symbolicPermissions.match(formatRegex)) {
|
||||||
|
throw new Error(`Invalid string permissions (must be in form 'rwxrwxrwx'): ${symbolicPermissions}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const [_, rOwner, wOwner, xOwner, rGroup, wGroup, xGroup, rAll, wAll, xAll] = formatRegex.exec(symbolicPermissions) || [];
|
||||||
|
const getOctal = (flag: string, flagLetter: string, flagValue: number) => flag === flagLetter ? flagValue : 0;
|
||||||
|
const owner = getOctal(rOwner, 'r', 4)
|
||||||
|
+ getOctal(wOwner, 'w', 2)
|
||||||
|
+ getOctal(xOwner, 'x', 1) + getOctal(xOwner, 's', 1);
|
||||||
|
const groups = getOctal(rGroup, 'r', 4)
|
||||||
|
+ getOctal(wGroup, 'w', 2)
|
||||||
|
+ getOctal(xGroup, 'x', 1) + getOctal(xGroup, 's', 1);
|
||||||
|
const all = getOctal(rAll, 'r', 4)
|
||||||
|
+ getOctal(wAll, 'w', 2)
|
||||||
|
+ getOctal(xAll, 'x', 1) + getOctal(xAll, 't', 1);
|
||||||
|
const flags = getOctal(xOwner, 's', 4)
|
||||||
|
+ getOctal(xGroup, 's', 2)
|
||||||
|
+ getOctal(xAll, 't', 1);
|
||||||
|
const octalString = `${(flags > 0 ? flags : '')}${owner}${groups}${all}`;
|
||||||
|
|
||||||
|
return computePermissionsFromChmodOctalRepresentation(octalString);
|
||||||
|
}
|
||||||
|
|
||||||
|
function computeUmaskRepresentation({ permissions }: { permissions: Permissions }): {
|
||||||
|
octal: string
|
||||||
|
symbolic: string
|
||||||
|
} {
|
||||||
|
const permissionValue = { read: 'r', write: 'w', execute: 'x' };
|
||||||
|
const getGroupPermissionValue = (permission: GroupPermissions) =>
|
||||||
|
_.reduce(permission, (acc, isPermSet, key) => acc + ((isPermSet ? _.get(permissionValue, key, '') : '')), '');
|
||||||
|
|
||||||
|
const symbolic = `umask u=${getGroupPermissionValue(permissions.owner)},g=${getGroupPermissionValue(permissions.group)},o=${getGroupPermissionValue(permissions.public)}`;
|
||||||
|
const octal = (0o777 - Number.parseInt(
|
||||||
|
computeChmodOctalRepresentation({
|
||||||
|
permissions:
|
||||||
|
{
|
||||||
|
owner: permissions.owner,
|
||||||
|
group: permissions.group,
|
||||||
|
public: permissions.public,
|
||||||
|
flags: { setuid: false, setgid: false, stickybit: false },
|
||||||
|
},
|
||||||
|
}), 8))
|
||||||
|
.toString(8)
|
||||||
|
.padStart(3, '0');
|
||||||
|
|
||||||
|
return {
|
||||||
|
symbolic, octal,
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -1,10 +1,17 @@
|
|||||||
export type Scope = 'read' | 'write' | 'execute';
|
export type Scope = 'read' | 'write' | 'execute';
|
||||||
export type Group = 'owner' | 'group' | 'public';
|
export type Group = 'owner' | 'group' | 'public';
|
||||||
|
export type SpecialFlags = 'setuid' | 'setgid' | 'stickybit';
|
||||||
|
|
||||||
export type GroupPermissions = {
|
export type GroupPermissions = {
|
||||||
[k in Scope]: boolean;
|
[k in Scope]: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type SpecialPermissions = {
|
||||||
|
[k in SpecialFlags]: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
export type Permissions = {
|
export type Permissions = {
|
||||||
[k in Group]: GroupPermissions;
|
[k in Group]: GroupPermissions;
|
||||||
|
} & {
|
||||||
|
flags: SpecialPermissions
|
||||||
};
|
};
|
||||||
@@ -2,9 +2,10 @@
|
|||||||
import { useThemeVars } from 'naive-ui';
|
import { useThemeVars } from 'naive-ui';
|
||||||
|
|
||||||
import InputCopyable from '../../components/InputCopyable.vue';
|
import InputCopyable from '../../components/InputCopyable.vue';
|
||||||
import { computeChmodOctalRepresentation, computeChmodSymbolicRepresentation } from './chmod-calculator.service';
|
import { computeChmodOctalRepresentation, computeChmodSymbolicRepresentation, computePermissionsFromChmodOctalRepresentation, computePermissionsFromChmodSymbolicRepresentation, computeUmaskRepresentation } from './chmod-calculator.service';
|
||||||
|
|
||||||
import type { Group, Scope } from './chmod-calculator.types';
|
import type { Group, Scope } from './chmod-calculator.types';
|
||||||
|
import { useValidation } from '@/composable/validation';
|
||||||
|
|
||||||
const themeVars = useThemeVars();
|
const themeVars = useThemeVars();
|
||||||
|
|
||||||
@@ -19,14 +20,92 @@ const permissions = ref({
|
|||||||
owner: { read: false, write: false, execute: false },
|
owner: { read: false, write: false, execute: false },
|
||||||
group: { read: false, write: false, execute: false },
|
group: { read: false, write: false, execute: false },
|
||||||
public: { read: false, write: false, execute: false },
|
public: { read: false, write: false, execute: false },
|
||||||
|
flags: { setuid: false, setgid: false, stickybit: false },
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const octalPermissionsInput = ref('000');
|
||||||
|
const octalPermissionsInputValidation = useValidation({
|
||||||
|
source: octalPermissionsInput,
|
||||||
|
rules: [
|
||||||
|
{
|
||||||
|
message: 'Invalid octal permission string',
|
||||||
|
validator: (value) => {
|
||||||
|
try {
|
||||||
|
computePermissionsFromChmodOctalRepresentation(value.trim());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
watch(
|
||||||
|
octalPermissionsInput,
|
||||||
|
(newPermissions) => {
|
||||||
|
if (!octalPermissionsInputValidation.isValid) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
permissions.value = computePermissionsFromChmodOctalRepresentation(newPermissions.trim());
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
const symbolicPermissionsInput = ref('---------');
|
||||||
|
const symbolicPermissionsInputValidation = useValidation({
|
||||||
|
source: symbolicPermissionsInput,
|
||||||
|
rules: [
|
||||||
|
{
|
||||||
|
message: 'Invalid symbolic permission string',
|
||||||
|
validator: (value) => {
|
||||||
|
try {
|
||||||
|
computePermissionsFromChmodSymbolicRepresentation(value.trim());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
watch(
|
||||||
|
symbolicPermissionsInput,
|
||||||
|
(newPermissions) => {
|
||||||
|
if (!symbolicPermissionsInputValidation.isValid) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
permissions.value = computePermissionsFromChmodSymbolicRepresentation(newPermissions.trim());
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
const octal = computed(() => computeChmodOctalRepresentation({ permissions: permissions.value }));
|
const octal = computed(() => computeChmodOctalRepresentation({ permissions: permissions.value }));
|
||||||
const symbolic = computed(() => computeChmodSymbolicRepresentation({ permissions: permissions.value }));
|
const symbolic = computed(() => computeChmodSymbolicRepresentation({ permissions: permissions.value }));
|
||||||
|
const umask = computed(() => computeUmaskRepresentation({ permissions: permissions.value }));
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div>
|
<div>
|
||||||
|
<c-input-text
|
||||||
|
v-model:value="octalPermissionsInput"
|
||||||
|
placeholder="Put your octal permissions here..."
|
||||||
|
label="Copy your octal permissions"
|
||||||
|
:validation="octalPermissionsInputValidation"
|
||||||
|
mb-2
|
||||||
|
/>
|
||||||
|
|
||||||
|
<n-divider />
|
||||||
|
|
||||||
|
<c-input-text
|
||||||
|
v-model:value="symbolicPermissionsInput"
|
||||||
|
placeholder="Put your symbolic permissions here..."
|
||||||
|
label="Copy your symbolic permissions"
|
||||||
|
:validation="symbolicPermissionsInputValidation"
|
||||||
|
mb-2
|
||||||
|
/>
|
||||||
|
|
||||||
|
<n-divider />
|
||||||
|
|
||||||
<n-table :bordered="false" :bottom-bordered="false" single-column class="permission-table">
|
<n-table :bordered="false" :bottom-bordered="false" single-column class="permission-table">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
@@ -52,6 +131,20 @@ const symbolic = computed(() => computeChmodSymbolicRepresentation({ permissions
|
|||||||
<n-checkbox v-model:checked="permissions[group][scope]" size="large" />
|
<n-checkbox v-model:checked="permissions[group][scope]" size="large" />
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="line-header">
|
||||||
|
Flags
|
||||||
|
</td>
|
||||||
|
<td class="text-center">
|
||||||
|
<n-checkbox v-model:checked="permissions.flags.setuid" size="large" />
|
||||||
|
</td>
|
||||||
|
<td class="text-center">
|
||||||
|
<n-checkbox v-model:checked="permissions.flags.setgid" size="large" />
|
||||||
|
</td>
|
||||||
|
<td class="text-center">
|
||||||
|
<n-checkbox v-model:checked="permissions.flags.stickybit" size="large" />
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</n-table>
|
</n-table>
|
||||||
|
|
||||||
@@ -63,6 +156,11 @@ const symbolic = computed(() => computeChmodSymbolicRepresentation({ permissions
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<InputCopyable :value="`chmod ${octal} path`" readonly />
|
<InputCopyable :value="`chmod ${octal} path`" readonly />
|
||||||
|
|
||||||
|
<c-card title="Umask">
|
||||||
|
<InputCopyable :value="umask.octal" readonly />
|
||||||
|
<InputCopyable :value="umask.symbolic" readonly />
|
||||||
|
</c-card>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,10 @@
|
|||||||
import { FileInvoice } from '@vicons/tabler';
|
import { FileInvoice } from '@vicons/tabler';
|
||||||
import { defineTool } from '../tool';
|
import { defineTool } from '../tool';
|
||||||
import { translate } from '@/plugins/i18n.plugin';
|
|
||||||
|
|
||||||
export const tool = defineTool({
|
export const tool = defineTool({
|
||||||
name: translate('tools.chmod-calculator.title'),
|
name: 'Chmod calculator',
|
||||||
path: '/chmod-calculator',
|
path: '/chmod-calculator',
|
||||||
description: translate('tools.chmod-calculator.description'),
|
description: 'Compute your chmod permissions and commands with this online chmod calculator.',
|
||||||
keywords: [
|
keywords: [
|
||||||
'chmod',
|
'chmod',
|
||||||
'calculator',
|
'calculator',
|
||||||
@@ -17,6 +16,7 @@ export const tool = defineTool({
|
|||||||
'recursive',
|
'recursive',
|
||||||
'generator',
|
'generator',
|
||||||
'octal',
|
'octal',
|
||||||
|
'umask',
|
||||||
],
|
],
|
||||||
component: () => import('./chmod-calculator.vue'),
|
component: () => import('./chmod-calculator.vue'),
|
||||||
icon: FileInvoice,
|
icon: FileInvoice,
|
||||||
|
|||||||
+1
-11
@@ -2,7 +2,6 @@ import { tool as base64FileConverter } from './base64-file-converter';
|
|||||||
import { tool as base64StringConverter } from './base64-string-converter';
|
import { tool as base64StringConverter } from './base64-string-converter';
|
||||||
import { tool as basicAuthGenerator } from './basic-auth-generator';
|
import { tool as basicAuthGenerator } from './basic-auth-generator';
|
||||||
import { tool as emailNormalizer } from './email-normalizer';
|
import { tool as emailNormalizer } from './email-normalizer';
|
||||||
import { tool as punycodeConverter } from './punycode-converter';
|
|
||||||
|
|
||||||
import { tool as asciiTextDrawer } from './ascii-text-drawer';
|
import { tool as asciiTextDrawer } from './ascii-text-drawer';
|
||||||
|
|
||||||
@@ -159,16 +158,7 @@ export const toolsByCategory: ToolCategory[] = [
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'Network',
|
name: 'Network',
|
||||||
components: [
|
components: [ipv4SubnetCalculator, ipv4AddressConverter, ipv4RangeExpander, macAddressLookup, macAddressGenerator, ipv6UlaGenerator],
|
||||||
ipv4SubnetCalculator,
|
|
||||||
ipv4AddressConverter,
|
|
||||||
// ipv6AddressConverter,
|
|
||||||
ipv4RangeExpander,
|
|
||||||
macAddressLookup,
|
|
||||||
macAddressGenerator,
|
|
||||||
ipv6UlaGenerator,
|
|
||||||
punycodeConverter,
|
|
||||||
],
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'Math',
|
name: 'Math',
|
||||||
|
|||||||
@@ -1,12 +0,0 @@
|
|||||||
import { World } from '@vicons/tabler';
|
|
||||||
import { defineTool } from '../tool';
|
|
||||||
|
|
||||||
export const tool = defineTool({
|
|
||||||
name: 'Punycode Converter',
|
|
||||||
path: '/punycode-converter',
|
|
||||||
description: 'Convert international unicode domain names or emails from/to ASCII Punycode version',
|
|
||||||
keywords: ['punycode', 'converter', 'rfc3492', 'bootstring', 'domain', 'dns'],
|
|
||||||
component: () => import('./punycode-converter.vue'),
|
|
||||||
icon: World,
|
|
||||||
createdAt: new Date('2024-08-15'),
|
|
||||||
});
|
|
||||||
@@ -1,66 +0,0 @@
|
|||||||
<script setup lang="ts">
|
|
||||||
import { toASCII, toUnicode } from 'punycode/';
|
|
||||||
import TextareaCopyable from '@/components/TextareaCopyable.vue';
|
|
||||||
|
|
||||||
const punycodeInput = ref('');
|
|
||||||
const intlOutput = computed(
|
|
||||||
() => {
|
|
||||||
try {
|
|
||||||
return toUnicode(punycodeInput.value?.trim());
|
|
||||||
}
|
|
||||||
catch (e: any) {
|
|
||||||
return e.toString();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
const intlInput = ref('');
|
|
||||||
const punycodeOutput = computed(
|
|
||||||
() => {
|
|
||||||
try {
|
|
||||||
return toASCII(intlInput.value?.trim());
|
|
||||||
}
|
|
||||||
catch (e: any) {
|
|
||||||
return e.toString();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
);
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<template>
|
|
||||||
<div max-w-600>
|
|
||||||
<c-card title="Punycode to International">
|
|
||||||
<c-input-text
|
|
||||||
v-model:value="punycodeInput"
|
|
||||||
placeholder="Put your punycode domain name or email to decode..."
|
|
||||||
label="Punycode Domain name/Email"
|
|
||||||
raw-text
|
|
||||||
/>
|
|
||||||
|
|
||||||
<n-divider />
|
|
||||||
|
|
||||||
<TextareaCopyable
|
|
||||||
label="Decoded Domain name/Email"
|
|
||||||
:value="intlOutput"
|
|
||||||
readonly
|
|
||||||
/>
|
|
||||||
</c-card>
|
|
||||||
|
|
||||||
<c-card title="International to Punycode" mt-5>
|
|
||||||
<c-input-text
|
|
||||||
v-model:value="intlInput"
|
|
||||||
placeholder="Put your international domain or email name here..."
|
|
||||||
label="Domain name or email to encode"
|
|
||||||
raw-text
|
|
||||||
/>
|
|
||||||
|
|
||||||
<n-divider />
|
|
||||||
|
|
||||||
<TextareaCopyable
|
|
||||||
label="Punycode Domain name/Email"
|
|
||||||
:value="punycodeOutput"
|
|
||||||
readonly
|
|
||||||
/>
|
|
||||||
</c-card>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
Reference in new issue
Block a user