def do_install(self, service_opts: UnixServiceOpts, auto_startup: bool = False, auto_connman_dhcp: bool = False): FileHelper.mkdirs(self.opts.vpn_dir.parent) FileHelper.unpack_archive(ClientOpts.get_resource(ClientOpts.VPN_ZIP), self.opts.vpn_dir) FileHelper.mkdirs([self.opts.vpn_dir, self.opts.runtime_dir]) FileHelper.chmod(self.opts.runtime_dir, mode=0o0755) FileHelper.chmod([ os.path.join(self.opts.vpn_dir, p) for p in ('vpnclient', 'vpncmd') ], mode=0o0755) _, cmd = EnvHelper.build_executable_command() svc_opts = self._standard_service_opt(service_opts) self.device.unix_service.create( svc_opts, { '{{WORKING_DIR}}': f'{self.opts.vpn_dir}', '{{VPN_DESC}}': svc_opts.service_name, '{{START_CMD}}': f'{cmd} start --vpn-dir {self.opts.vpn_dir}', '{{STOP_CMD}}': f'{cmd} stop --vpn-dir {self.opts.vpn_dir}' }, auto_startup) self._dump_cache_service(svc_opts) self.device.ip_resolver.add_hook(svc_opts.service_name, { '{{WORKING_DIR}}': f'{self.opts.vpn_dir}', '{{VPN_CLIENT_CLI}}': cmd }) self.device.dns_resolver.create_config(svc_opts.service_name, auto_connman_dhcp) self.storage.empty() self.opts.export_env()
def _common_adapt_dnsmasq(self, vpn_service: str): identity = self.config.identity logger.debug( f'Adapt [{identity}] DNS resolver service to compatible with [dnsmasq] and [{vpn_service}]...' ) FileHelper.mkdirs(self.config.config_dir) FileHelper.copy(self.resource_dir.joinpath(f'dnsmasq-{identity}.conf'), self.config.to_fqn_cfg(self.DNSMASQ_TUNED_CFG), True) FileHelper.chmod(self.config.to_fqn_cfg(self.DNSMASQ_TUNED_CFG), mode=0o0644) return self.config.runtime_resolv
def backup_config(self): backup_dir = self.opts.backup_dir() logger.info( f'Backup VPN configuration [{self.opts.vpn_dir}] to [{backup_dir}] ...' ) FileHelper.mkdirs(backup_dir) FileHelper.copy(self.opts.config_file, backup_dir, force=True) FileHelper.copy(self.opts.runtime_dir, backup_dir.joinpath(self.opts.RUNTIME_FOLDER), force=True) default_acc = self.storage.get_default() current_acc = self.storage.get_current() svc_opt = self._standard_service_opt() return default_acc, current_acc, svc_opt, backup_dir