@@ -265,7 +265,7 @@ def get_vpn_status(self, vpn_acc: str) -> dict:
265
265
logger .debug (f'Something wrong when getting VPN status. Error[{ err } ]' )
266
266
return {'connected' : False }
267
267
268
- def do_install (self , service_opts : UnixServiceOpts , auto_startup : bool = False ):
268
+ def do_install (self , service_opts : UnixServiceOpts , auto_startup : bool = False , auto_connman_dhcp : bool = False ):
269
269
FileHelper .mkdirs (self .opts .vpn_dir .parent )
270
270
FileHelper .unpack_archive (ClientOpts .get_resource (ClientOpts .VPN_ZIP ), self .opts .vpn_dir )
271
271
FileHelper .mkdirs ([self .opts .vpn_dir , self .opts .runtime_dir ])
@@ -282,7 +282,7 @@ def do_install(self, service_opts: UnixServiceOpts, auto_startup: bool = False):
282
282
self ._dump_cache_service (svc_opts )
283
283
self .device .ip_resolver .add_hook (svc_opts .service_name ,
284
284
{'{{WORKING_DIR}}' : f'{ self .opts .vpn_dir } ' , '{{VPN_CLIENT_CLI}}' : cmd })
285
- self .device .dns_resolver .create_config (svc_opts .service_name )
285
+ self .device .dns_resolver .create_config (svc_opts .service_name , auto_connman_dhcp )
286
286
self .storage .empty ()
287
287
self .opts .export_env ()
288
288
@@ -383,7 +383,7 @@ def lease_vpn_ip(self, account: str, log_lvl=logger.DEBUG):
383
383
loop_interval (lambda : self .get_vpn_status (account )['connected' ],
384
384
'Unable connect VPN. Please check log for more detail' , max_retries = 3 , interval = 1 )
385
385
nic = self .opts .account_to_nic (account )
386
- if self .device .dns_resolver .is_connman ():
386
+ if not self .device .dns_resolver .is_enable_connman_dhcp ():
387
387
logger .log (logger .WARN , f'Please lease VPN IP manually by ' +
388
388
f'[{ self .device .ip_resolver .lease_ip (account , nic , daemon = True , is_execute = False )} ]' )
389
389
return
@@ -477,6 +477,8 @@ def __download(downloader_opts: DownloaderOpt):
477
477
@click .option ("--auto-dnsmasq" , type = bool , default = False , flag_value = True , help = "Give a try to install dnsmasq" )
478
478
@click .option ("--dnsmasq/--no-dnsmasq" , type = bool , default = True , flag_value = False ,
479
479
help = "By default, dnsmasq is used as local DNS cache. Disabled it if using default System DNS resolver" )
480
+ @click .option ("--auto-connman-dhcp" , type = bool , flag_value = True ,
481
+ help = "Auto start DHCP Client after connecting VPN when using connman" )
480
482
@vpn_client_opts
481
483
@dev_mode_opts (opt_name = ClientOpts .OPT_NAME )
482
484
@unix_service_opts (ClientOpts .vpn_service_name ())
@@ -485,7 +487,7 @@ def __download(downloader_opts: DownloaderOpt):
485
487
@verbose_opts
486
488
@permission
487
489
def install (vpn_opts : ClientOpts , svc_opts : UnixServiceOpts , auto_startup : bool , auto_dnsmasq : bool , dnsmasq : bool ,
488
- force : bool ):
490
+ auto_connman_dhcp : bool , force : bool ):
489
491
executor = VPNClientExecutor (vpn_opts ).probe (log_lvl = logger .INFO )
490
492
dns_resolver = executor .device .dns_resolver
491
493
if not dnsmasq and not dns_resolver .is_connman ():
@@ -501,7 +503,7 @@ def install(vpn_opts: ClientOpts, svc_opts: UnixServiceOpts, auto_startup: bool,
501
503
if dnsmasq and not dns_resolver .is_dnsmasq_available () and not dns_resolver .is_connman ():
502
504
executor .device .install_dnsmasq (auto_dnsmasq )
503
505
logger .info (f'Installing VPN client into [{ vpn_opts .vpn_dir } ] and register service[{ svc_opts .service_name } ]...' )
504
- executor .do_install (svc_opts , auto_startup )
506
+ executor .do_install (svc_opts , auto_startup , auto_connman_dhcp )
505
507
logger .done ()
506
508
507
509
@@ -544,7 +546,8 @@ def _reconnect_vpn(_executor: VPNClientExecutor, _default_acc: str, _current_acc
544
546
default_acc , current_acc , svc_opts , backup_dir = executor .backup_config ()
545
547
executor .do_uninstall (keep_vpn = False , keep_dnsmasq = True , service_opts = svc_opts )
546
548
logger .info (f'Re-install VPN client into [{ vpn_opts .vpn_dir } ]...' )
547
- executor .do_install (service_opts = svc_opts , auto_startup = False )
549
+ executor .do_install (service_opts = svc_opts , auto_startup = False ,
550
+ auto_connman_dhcp = executor .device .dns_resolver .is_enable_connman_dhcp ())
548
551
executor .restore_config (backup_dir , keep_backup )
549
552
_reconnect_vpn (executor , default_acc , current_acc )
550
553
logger .done ()
0 commit comments