def change_server(): syslog.syslog('Changing VPN server...') newserver = request.args.get('servername') newport = request.args.get('serverport') if newserver == 'none': if not os.path.isfile(VPN_DISABLED_MARKER_FILE): disable_vpn() return_data = get_current_server() else: if (newserver is None) or (newport is None): return_data = {'error':'server and port required'} else: # get ca certificate & tls-auth key filename elements for the new server server = vpnservers_data.find(".//vpnserver[servername='" + newserver + "']") server_details = get_server_details(newserver) if server_details is None: return_data = {'error':'server not found'} return return_data else: cacertfile = server_details['cacertfile'] tlsauthkeyfile = server_details['tlsauthkeyfile'] syslog.syslog('changing...') result = shell_exec('sudo service openvpn status') if ('Active: active' in result) or ('is running' in result) or ('started' in result): # echo "Stopping VPN service...\n" syslog.syslog('Stopping VPN service...') result = util.stop_service('openvpn') else: syslog.syslog('OpenVPN service is not running...') if os.path.isfile(VPN_DISABLED_MARKER_FILE): enable_vpn(startservice = False) # modify /etc/openvpn/server.conf with new server name f = open('/etc/openvpn/server.conf','r+') configfile = f.readlines() serverconf = "" for line in configfile: line_tokens = str.split(line) if len(line_tokens) > 0: if line_tokens[0] == 'remote': existingport = line_tokens[2] if (existingport is not None) and (existingport != '0'): portnumber = existingport else: portnumber = newport serverconf += 'remote ' + newserver + ' ' + portnumber + '\n' elif line_tokens[0] == 'ca' and cacertfile is not None: serverconf += 'ca ' + cacertfile + '\n' elif line_tokens[0] == 'tls-auth' and tlsauthkeyfile is not None: serverconf += 'tls-auth ' + tlsauthkeyfile + '\n' else: serverconf += line f.seek(0) f.write(serverconf) f.truncate() f.close() # start openvpn service result = util.start_service('openvpn') return_data = get_current_server() socketio.emit('serverchange', None, broadcast=True) return return_data
def enable_vpn(startservice=True): if os.path.isfile(VPN_DISABLED_MARKER_FILE): # remove disabled marker file os.unlink(VPN_DISABLED_MARKER_FILE) # set openvpn service to start automatically on boot util.enable_service(OPENVPN_SERVICE_NAME) # remove any existing forwarding rules shell_exec('sudo iptables -F FORWARD') # add rules for forwarding via VPN shell_exec('sudo iptables -A FORWARD -j forward_rules_vpn') # enable killswitch (no outbound traffic if VPN is not connected) shell_exec('sudo iptables -F killswitch') shell_exec('sudo iptables -t filter -A killswitch -j killswitch_on') # save iptables os.system('sudo su -c \'iptables-save > /etc/iptables/rules.v4\'') if (startservice is not None) and (startservice == False): pass else: util.start_service(OPENVPN_SERVICE_NAME) socketio.emit('serverchange', None, broadcast=True, namespace='/vpncgw')
def enable_vpn(startservice = True): if os.path.isfile(VPN_DISABLED_MARKER_FILE): # remove disabled marker file os.unlink(VPN_DISABLED_MARKER_FILE) # set openvpn service to start automatically on boot util.enable_service('openvpn') # remove any existing forwarding rules shell_exec('sudo iptables -F FORWARD') # add rules for forwarding via VPN shell_exec('sudo iptables -A FORWARD -j forward_rules_vpn') # enable killswitch (no outbound traffic if VPN is not connected) shell_exec('sudo iptables -F killswitch') shell_exec('sudo iptables -t filter -A killswitch -j killswitch_on') # save iptables os.system('sudo su -c \'iptables-save > /etc/iptables/rules.v4\'') if (startservice is not None) and (startservice == False): pass else: util.start_service('openvpn') socketio.emit('serverchange', None, broadcast=True) return get_current_server()
def change_server(): CANCEL_SPEEDTEST = True clear_speedtest() syslog.syslog('Changing VPN server...') newserver = request.args.get('servername') newport = request.args.get('serverport') if newserver == 'none': if not os.path.isfile(VPN_DISABLED_MARKER_FILE): disable_vpn() return_data = get_current_server() else: if (newserver is None) or (newport is None): return_data = {'error': 'server and port required'} else: # get ca certificate & tls-auth key filename elements for the new server server = vpnservers_data.find(".//vpnserver[servername='" + newserver + "']") server_details = get_server_details(newserver) if server_details is None: return_data = {'error': 'server not found'} return return_data else: cacertfile = server_details['cacertfile'] tlsauthkeyfile = server_details['tlsauthkeyfile'] if util.service_active('openvpn'): # echo "Stopping VPN service...\n" syslog.syslog('Stopping VPN service...') result = util.stop_service('openvpn') else: syslog.syslog('OpenVPN service is not running...') if os.path.isfile(VPN_DISABLED_MARKER_FILE): enable_vpn(startservice=False) # modify /etc/openvpn/server.conf with new server name f = open('/etc/openvpn/server.conf', 'r+') configfile = f.readlines() serverconf = "" for line in configfile: line_tokens = str.split(line) if len(line_tokens) > 0: if line_tokens[0] == 'remote': existingport = line_tokens[2] if (existingport is not None) and (existingport != '0'): portnumber = existingport else: portnumber = newport serverconf += 'remote ' + newserver + ' ' + portnumber + '\n' elif line_tokens[0] == 'ca' and cacertfile is not None: serverconf += 'ca ' + cacertfile + '\n' elif line_tokens[ 0] == 'tls-auth' and tlsauthkeyfile is not None: serverconf += 'tls-auth ' + tlsauthkeyfile + '\n' else: serverconf += line f.seek(0) f.write(serverconf) f.truncate() f.close() # start openvpn service result = util.start_service('openvpn') return_data = get_current_server() socketio.emit('serverchange', None, broadcast=True) CANCEL_SPEEDTEST = False return return_data
############################## # Logging facility setup # ############################## # First things first import logging from os.path import join logging.basicConfig(filename=join("backend","persistance", "musicman.log"), format='%(asctime)s | %(levelname)s: %(message)s', level=logging.WARN) ############################## from util import start_service, process_songs, calculate_distances from frontend import cli from data_handler import STORE_IDS, fetch_store from backend.client.explorer import explore VERBOSE = True start_service(verbose = VERBOSE) #explore() songs = fetch_store(STORE_IDS["songs"]) process_songs(songs, rea = True, red = True, cs = True, ve = VERBOSE)
def _start_galaxy(): # Create directory to store galaxy service's pid file. _make_dir_for_galaxy("/var/lib/galaxy") start_service("galaxy")
def _start_nginx(env): galaxy_data = env.galaxy_data_mount env.safe_sudo("mkdir -p '%s'" % env.galaxy_data) _chown_galaxy(env, galaxy_data) start_service("nginx")