1- import os
2- import requests
1+ import argparse
32import json
43import logging
4+ import os
5+ import requests
56from typing import Optional , Dict , List , Union
67
78# Configuration
@@ -171,9 +172,43 @@ def sync_profiles(keys_to_sync: List[str], payload: Optional[Dict] = None) -> No
171172 logger .error ("[SYNC] Failed to sync profiles: %s" , e )
172173 raise
173174
174- # Run the sync process
175- keys_to_sync = ["allowlist" , "denylist" , "parentalControl" , "security" , "privacy" ]
176- sync_profiles (keys_to_sync )
177-
178- # Ad Hoc Main Updates
179- update_security_settings (PROFILE_MAIN , TLD_BAN_PAYLOAD )
175+ def output_profile_settings (profile_id : str = PROFILE_MAIN ) -> None :
176+ """Fetches and prints the settings of a profile."""
177+ try :
178+ settings = fetch_profile_settings (profile_id )
179+ print (json .dumps (settings , indent = 2 ))
180+ except Exception as e :
181+ logger .error ("[GET] Failed to fetch profile settings: %s" , e )
182+
183+
184+ def main ():
185+ parser = argparse .ArgumentParser (description = "NextDNS profile sync and update tool" )
186+ parser .add_argument (
187+ "action" ,
188+ choices = ["sync" , "update" , "get" ],
189+ help = "Action to perform: 'sync' to sync profiles, 'update' to update security, 'get' to print profile settings"
190+ )
191+ parser .add_argument (
192+ "--profile" ,
193+ default = PROFILE_MAIN ,
194+ help = "Profile ID to get settings for (default: MAIN)"
195+ )
196+ args = parser .parse_args ()
197+
198+ if args .action == "sync" :
199+ keys_to_sync = ["allowlist" , "denylist" , "parentalControl" , "security" , "privacy" ]
200+ logging .info ("Starting profile sync..." )
201+ sync_profiles (keys_to_sync )
202+
203+ elif args .action == "update" :
204+ logging .info ("Updating main profile security settings..." )
205+ update_security_settings (PROFILE_MAIN , TLD_BAN_PAYLOAD )
206+
207+ elif args .action == "get" :
208+ output_profile_settings (args .profile )
209+
210+ logging .info ("Done." )
211+
212+ if __name__ == "__main__" :
213+ logging .basicConfig (level = logging .INFO , format = "%(levelname)s | %(message)s" )
214+ main ()
0 commit comments