{"id":23991306,"url":"https://github.com/loglux/vpnpolicy","last_synced_at":"2025-04-30T06:26:38.370Z","repository":{"id":169714372,"uuid":"321157226","full_name":"loglux/vpnpolicy","owner":"loglux","description":"This tool helps to create VPN Routing Rules for AsusWRT Merlin OpenVPN Client","archived":false,"fork":false,"pushed_at":"2021-12-26T14:05:35.000Z","size":89,"stargazers_count":5,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-30T13:34:08.247Z","etag":null,"topics":["asus","asus-routers","asuswrt-merlin","nvram","python","router","routing","routing-rules","routing-tables","vpn","vpn-client"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/loglux.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-12-13T20:48:51.000Z","updated_at":"2024-11-25T14:44:31.000Z","dependencies_parsed_at":null,"dependency_job_id":"f80ba124-8250-40ad-97f4-484d9959cd4b","html_url":"https://github.com/loglux/vpnpolicy","commit_stats":null,"previous_names":["loglux/vpnpolicy"],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loglux%2Fvpnpolicy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loglux%2Fvpnpolicy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loglux%2Fvpnpolicy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loglux%2Fvpnpolicy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/loglux","download_url":"https://codeload.github.com/loglux/vpnpolicy/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251653103,"owners_count":21622074,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["asus","asus-routers","asuswrt-merlin","nvram","python","router","routing","routing-rules","routing-tables","vpn","vpn-client"],"created_at":"2025-01-07T19:39:06.017Z","updated_at":"2025-04-30T06:26:38.310Z","avatar_url":"https://github.com/loglux.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# VPN Routing Rules creating tool for AsusWRT Merlin OpenVPN Client\n\n### Since version 386.3 vpn rules moved from nvram to a file. The new version of this script does not work with previous FW versions, so if you need a script for FW before 386.3, you should use the release 2.07. \n\n## What does that script do?\nThis script creates VPN Policy rules for OpenVPN client in AsusWRT Merlin Firmware. It helps to obtain IP addresses that belong to the domains and save it in the router’s configuration. It also takes a new list of IP addresses, so you can use this script regularly, to keep the list of IPs fresh.\n\nVPN client uses rules to redirect traffic for your device or network based on the destination IP addresses. Instead of pushing all traffic through the VPN, you can redirect it to VPN only if you need to get access to particular network resources. That gives your incredible flexibility using  VPN.\n\nIt takes domain names from file domains.txt and obtains IP addresses.\nFile domains.txt contains a list of domains\n```\ndomain1.com\ndomain2.com\n```\nAlso, it’s possible to use static IP records.\nFile static.csv contains a list of static routes (that don’t need to be changed by the script) in CSV format:\nDescription,Source IP,Destination IP,Iface\n```\nADomain,0.0.0.0,194.200.22.87/26,VPN\n```\n## Where can you find domains?\nSome resources like online cinema theatres have not just more than 1 IP address but also more than one domain.\nTurn on ‘Web History’ option at the router’s page ‘Adaptive QoS – Web History’. Here you can see domains are used by your computer or media player.\n\n## Reqiurements\n\n1. You need to install Entware on your router\n\n\n2. You need to install bind-tools or bind-dig on your router\n```\nopkg install bind-tools\n```\n\n3. You need to install whois utility on your router\n```\nopkg install whois\n```\n\n4. You need to install Python\n```\nopkg install python3\n```\n\n5 You need to install python3-pip\n```\nopkg install python3-pip\n```\n\n6 You need to install pydig module\n```\npip install pydig\n```\n\n## How to use the script\n\n### Set variables\nThe main library is stored in file 'vpol.py'\n\nYou can create a separate file for each client ('client1.py', 'client2.py' etc) if you have more than 1 client set up.\n\n'local' - IP address or set of addresses (192.168.0.10, 192.168.0.0/24 or just 0.0.0.0 for your entire local network.\n\n'name_length' - A limit on domain names. By default 10 symbols are set up to save NVRAM space. If you don't have many rules, you can increase this limit. But remember some domain names can be very long.\n\n'client' – a number of a VPN Client you’re using. You have five clients, so put the relevant number.\n\nYou can also put unique file names and path. \n    \n    conf_path = \"\"\n    \n    d_conf = conf_path + \"domains.txt\"\n    \n    s_conf = conf_path + \"static.csv\"\n\nYou can comment out a domain using '#' symbol if you want to exclide them from the process.\n\nUse '@' symbol at the begining if you want to grab subnets (xxx.xxx.xxx.xxx/xx) for the chosen domain. \n\nYou can comment out 'rules.nvram_commit()' if you don’t want to save your rules in the router’s memory \n\nand comment out 'rules.client_restart(client)' to prevent VPN client from restarting.\n\n### Start\n\nYou can download the script in any way you think is convenient. The best one is using 'git clone' for this purpose.\n```\nopkg install git\n```\nAnd then download the script:\n```\ngit clone https://github.com/loglux/vpnpolicy.git\n```\n\nExecute the script \n```\npython client1.py\n```\n\n### If you want to start it every time along with VPN client start/restart\nPut a reference to the script into '/jffs/scripts/openvpn-event'. \nIn that case you must comment out rules.client_restart(client) to avoid a loop.\n```\n#rules.client_restart(client)\n```\nInside of the openvpn-event put a command to start the script:\n```\n#!/bin/sh\npython /path_to_your_script/client1.py\n```\nAnd don't forget to make the openvpn-event executable\n```\nchmod a+rx /jffs/scripts/openvpn-event\n```\n\n## Known limitations (Is not actual anymore since FW 386_3)\nNVRAM has 6 variables per client for storing VPN rules list. It was noticed that each variable could store up to 1024 symbols. However, the firmware split the list in chunks by 255 symbols. 255 * 6 = 1530. It very dubious that 100 rules can be stored in 1530 symbols. Approximately 100 rules can be a summary of the rules of all 5 clients. \nIt's done by FW designers to save space in NVRAM. For compatibility purpose, here 255 symbols limit has been left, which can be changed in set_nvram() function, adjusting 'n =' variable. Theoretically, it's possible to split a list of rules by 1024 symbols (1024 * 6 = 6144) but be aware of NVRAM capacity. \n\nIn case if the list exceeds 1530 limit, it will be cut off at this point. \n\nThe 'Description' field is limited to ten symbols, to save more space for rules. \nThe script automatically cuts off all symbols that exceed this ten symbols limit. You can increase this limit changing 'name_length' parameter.\n\n## Useful references:\nhttps://github.com/RMerl/asuswrt-merlin.ng/wiki/Policy-based-routing\n\nhttps://github.com/RMerl/asuswrt-merlin.ng/wiki/User-scripts\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Floglux%2Fvpnpolicy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Floglux%2Fvpnpolicy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Floglux%2Fvpnpolicy/lists"}