HEX
Server: Apache/2.2.34 (Unix) mod_fastcgi/mod_fastcgi-SNAP-0910052141
System: Linux Kou-Etsu-Dou 4.4.59+ #25556 SMP PREEMPT Thu Mar 4 18:03:46 CST 2021 x86_64
User: hosam (1026)
PHP: 7.2.29
Disabled: NONE
Upload Files
File: /volume1/@appstore/Contacts/scripts/sdk_plugin/contacts_app_privilege_set.py
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Copyright (c) 2000-2019 Synology Inc. All rights reserved.

from os import environ
from importlib import util

spec = util.spec_from_file_location('common', '/var/packages/Contacts/target/scripts/sdk_plugin/contacts_common.py')
common = util.module_from_spec(spec)
spec.loader.exec_module(common)


class AppPrivilegeSet(common.Hook):
    def post(self):
        item_size = int(environ.get('NITEM'))
        should_reload = False
        for i in range(1, item_size + 1):
            app_name = environ.get('APP_' + str(i))
            # type example: 'USER' or 'GROUP' or 'EVERYONE'
            privilege_type = environ.get('TYPE_' + str(i))
            # id can be uid or gid
            privilege_id = environ.get('ID_' + str(i))
            if app_name == 'SYNO.Contacts.AppInstance':
                should_reload = True
                break

        if should_reload:
            # principal should also be update here
            # because we need to create the new principal whenever the privilege is granted
            common.update_principal_and_directory_object()


common.Main(AppPrivilegeSet())