|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
from setuphelpers import *
|
|
|
|
|
|
|
|
uninstallkey = []
|
|
|
|
variables = {}
|
|
|
|
|
|
|
|
# Read local variables file if available
|
|
|
|
if isfile(makepath(programfiles32,'wapt','private','symetric.txt')) and isfile(makepath(programfiles32,'wapt','private','variables.txt')):
|
|
|
|
print('Reading local encrypted variables file')
|
|
|
|
from cryptography.fernet import Fernet
|
|
|
|
import yaml
|
|
|
|
f = Fernet(open(makepath(programfiles32,'wapt','private','symetric.txt'),'r').read())
|
|
|
|
variables.update(yaml.safe_load(f.decrypt(open(makepath(programfiles32,'wapt','private','variables.txt'),'r').read())))
|
|
|
|
|
|
|
|
def install():
|
|
|
|
import re
|
|
|
|
|
|
|
|
version = control['version'].split('-',1)[0]
|
|
|
|
|
|
|
|
print('Register OpenVPN as a trusted publisher')
|
|
|
|
run(r'certutil.exe -f -addstore trustedpublisher openvpn.p7b')
|
|
|
|
|
|
|
|
print('Installing OpenVPN client')
|
|
|
|
|
|
|
|
os_version = 'Win10'
|
|
|
|
|
|
|
|
# We need to identify the build
|
|
|
|
for file in glob.glob('openvpn-install-%s-I*-%s.exe' % (version, os_version)):
|
|
|
|
build = re.search('openvpn\-install\-%s\-(I\d+)\-%s\.exe' % (version, os_version), file).group(1)
|
|
|
|
install_exe_if_needed('openvpn-install-%s-%s-%s.exe' % (version, build, os_version), '/S', key='OpenVPN', min_version='%s-%s-%s' % (version, build, os_version), killbefore=['openvpn','openvpn-gui'])
|
|
|
|
uninstallkey.append('TAP-Windows')
|
|
|
|
|
|
|
|
if 'openvpn_config' in variables:
|
|
|
|
print('Deploying client configuration')
|
|
|
|
open(makepath(programfiles,'OpenVPN','config','vpn.ovpn'),'w').write(variables['openvpn_config'])
|
|
|
|
|
|
|
|
def update_package():
|
|
|
|
import re, os
|
|
|
|
from waptpackage import PackageEntry
|
|
|
|
print('Updating OpenVPN package')
|
|
|
|
page = wgets('https://openvpn.net/community-downloads/')
|
|
|
|
latest_version = re.search('OpenVPN (\d+(\.\d+)*) .* released on', page).group(1)
|
|
|
|
pe = PackageEntry()
|
|
|
|
control = pe.load_control_from_wapt(os.getcwd())
|
|
|
|
current_version = control['version'].split('-',1)[0]
|
|
|
|
if Version(latest_version) > Version(current_version):
|
|
|
|
print('Updating Package from %s to %s' % (current_version, latest_version))
|
|
|
|
# Win7 Would be possible, but has a problem installing the tap driver, even when the cert is added to the trust store
|
|
|
|
# Just maintain the package for Win10 and later. Win7 is EOL in 2020 anyway
|
|
|
|
for os_version in ['Win10']:
|
|
|
|
build = re.search('openvpn\-install\-%s\-(I\d+)\-%s\.exe' % (latest_version, os_version), page).group(1)
|
|
|
|
if not isfile('openvpn\-install-%s-%s.exe' % (latest_version, build)):
|
|
|
|
url = 'https://swupdate.openvpn.org/community/releases/openvpn-install-%s-%s-%s.exe' % (latest_version, build, os_version)
|
|
|
|
print('downloading %s' % url)
|
|
|
|
wget(url, os.getcwd())
|
|
|
|
for file in glob.glob('*%s.exe' % os_version):
|
|
|
|
if file != 'openvpn-install-%s-%s-%s.exe' % (latest_version, build, os_version):
|
|
|
|
print('Removing %s' % file)
|
|
|
|
remove_file(file)
|
|
|
|
|
|
|
|
pe.version = latest_version + '-0'
|
|
|
|
pe.maturity = 'PREPROD'
|
|
|
|
pe.save_control_to_wapt(os.getcwd())
|
|
|
|
print('Package updated to %s' % latest_version)
|
|
|
|
else:
|
|
|
|
print('No update available')
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
update_package()
|
|
|
|
|