synology-api icon indicating copy to clipboard operation
synology-api copied to clipboard

Add reverse proxy settings function

Open ohyeah521 opened this issue 1 year ago • 4 comments

Is it possible to add a reverse proxy interface? Because when using a reverse proxy, you need to set up access control rules to automatically block some malicious IP addresses.

http://ip:port/webapi/entry.cgi/SYNO.Core.AppPortal.AccessControl

ohyeah521 avatar Sep 27 '24 23:09 ohyeah521

If I understood correctly you wish to have the ability to setup the built-in reverse proxy via API, is it right?

N4S4 avatar Sep 28 '24 02:09 N4S4

Yes, this is a screenshot of the web interface setting

settings

ohyeah521 avatar Sep 28 '24 02:09 ohyeah521

Add the following code to the core_sys_info.py file


    def list_accesscontrol(self) -> dict[str, object] | str:
        api_name = 'SYNO.Core.AppPortal.AccessControl'
        info = self.core_list[api_name]
        api_path = info['path']
        req_param = {'version': info['maxVersion'], 'method': 'list'}

        return self.request_data(api_name, api_path, req_param)

    def update_accesscontrol(self, entry: str) -> dict[str, object] | str:
        api_name = 'SYNO.Core.AppPortal.AccessControl'
        info = self.core_list[api_name]

        api_path = info['path'] +"/SYNO.Core.AppPortal.AccessControl"

        req_param = {'version': info['maxVersion'], 'method': 'update', 'entry': str(entry)}

        return self.request_data(api_name, api_path, req_param)

Usage:

syno  = core_sys_info.SysInfo(...)
lac = syno.list_accesscontrol()

print(lac)
# output: {'data': {'entries': [{'UUID': 'xxxx', '_key': 'xxxxxx', 'name': 'block', 'rules': [{'access': True, 'address': '192.164.74.88'}, {'access': False, 'address': '188.125.2.23'}]}]}, 'success': True}

ip={}
ip["address"]="19.64.74.88"
ip["access"]=True
rules.append(ip)
org_entries["rules"]=rules
entry = str(org_entries).replace("True","true").replace("False","false").replace(" ","")




# The execution here fails and returns 502
uac = syno.update_accesscontrol( entry)

ohyeah521 avatar Oct 12 '24 06:10 ohyeah521

Thank you i will have a look this afternoon and implement as suggested

N4S4 avatar Oct 12 '24 07:10 N4S4