packageId: string;
callerAppId: string;
permissions: string[];
- sharedPaths: string[];
- validPaths: string[];
+ smackMap: any;
constructor(id: string, isGlobal: boolean) {
this.id = id;
this.callerAppId = ids[1] ?? '';
this.packageId = this.serviceId.split('.')[0];
this.permissions = [];
- this.sharedPaths = [
- '/opt/usr/apps/shared/res/',
- '/opt/usr/globalapps/shared/res/'
- ];
- this.validPaths = [
- '/bin/emps/empPepperPlugins/',
- `/home/owner/apps_rw/${this.packageId}/`,
- '/home/owner/content/',
- '/home/owner/share/',
- '/media/',
- '/opt/media/',
- '/opt/share/',
- `/opt/usr/apps/${this.packageId}/`,
- '/opt/usr/apps/pepper/',
- `/opt/usr/globalapps/${this.packageId}/`,
- `/opt/usr/home/owner/apps_rw/${this.packageId}/`,
- '/opt/usr/home/owner/content/',
- '/opt/usr/home/owner/share/',
- '/tmp/',
- '/usr/bin/emps/empPepperPlugins/',
- '/usr/share/wrt/'
- ];
+ this.smackMap = {};
this.initWebapis();
this.permissions = wrt.getPrivileges(this.id);
global.webapis.getServiceId = () => {
return this.serviceId;
}
- global.webapis.isValidPath = (path: string) => {
- let ret = false;
- for (const validPath of this.validPaths) {
- if (path.startsWith(validPath))
- return true;
- }
- for (const sharedPath of this.sharedPaths) {
- if (path.replace(`${path.split('/')[4]}/`, '').includes(sharedPath))
- return true;
- }
- return false;
- }
Object.defineProperties(global.webapis, {
getCallerAppId: { writable: false, enumerable: true },
getPackageId: { writable: false, enumerable: true },
getPermissions: { writable: false, enumerable: true },
getServiceId: { writable: false, enumerable: true },
- isValidPath: { writable: false, enumerable: true },
});
this.initEdgeWebapis();
this.initMDEWebapis();
this.initProductWebapis();
+ this.initSecurityWebapis();
}
initEdgeWebapis() {
}
}
+ initSecurityWebapis() {
+ if (wrt['security'] && !global.webapis.security) {
+ let security = wrt.security as NativeWRTjs.SecurityExtension;
+ global.webapis.security = {
+ checkSmack: (packageId: string, path: string, type: string) => {
+ let smackMap = this.smackMap;
+ if (smackMap[path] !== undefined && smackMap[path][type] !== undefined)
+ return smackMap[path][type];
+ if (smackMap[path] === undefined)
+ smackMap[path] = {};
+ return smackMap[path][type] = security.checkSmack(packageId, path, type);
+ }
+ }
+ Object.defineProperty(global.webapis, 'security', { writable: false, enumerable: true });
+ }
+ }
+
initAccessControlManager() {
console.log(`permissions : ${this.permissions}`);
const AccessControlManager = require('./access_control_manager');