HEX
Server: Apache/2.4.63 (Unix)
System: Linux TOMS-220NAS 4.4.302+ #86009 SMP Wed Nov 26 18:19:17 CST 2025 x86_64
User: flavio87 (1026)
PHP: 8.3.27
Disabled: NONE
Upload Files
File: //var/packages/Contacts/target/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())