From 9cedab6543716c2507abd7a3405c47efa2be61e3 Mon Sep 17 00:00:00 2001 From: Mostafa Hussein Date: Sun, 10 Apr 2016 20:36:16 +0200 Subject: [PATCH 1/3] enhance the output in case of socket.error --- pritunl_client/shell_app.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/pritunl_client/shell_app.py b/pritunl_client/shell_app.py index cd033f6..9147bd6 100644 --- a/pritunl_client/shell_app.py +++ b/pritunl_client/shell_app.py @@ -9,6 +9,7 @@ import threading import json import httplib +from socket import error as socket_error class ThreadingHTTPServer(SocketServer.ThreadingMixIn, BaseHTTPServer.HTTPServer): @@ -226,12 +227,16 @@ def connect_callback(): args=(status_callback, connect_callback)).start() def start_server(self): - server = ThreadingHTTPServer( - ('127.0.0.1', 9797), - Request, - ) - logger.info('Starting pritunl-client daemon...', 'shell') + try: + server = ThreadingHTTPServer( + ('127.0.0.1', 9797), + Request, + ) + logger.info('Starting pritunl-client daemon...', 'shell') - self.autostart() + self.autostart() - server.serve_forever() + server.serve_forever() + except socket_error: + logger.info('Address already in use. Make sure that port 9797 is + available.', 'shell') From dbbc5bb29c5ba3bfb2e3675b426f3d02939acd28 Mon Sep 17 00:00:00 2001 From: Mostafa Hussein Date: Fri, 15 Apr 2016 09:24:01 +0300 Subject: [PATCH 2/3] fix for "EOL error" --- pritunl_client/shell_app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pritunl_client/shell_app.py b/pritunl_client/shell_app.py index 9147bd6..add431e 100644 --- a/pritunl_client/shell_app.py +++ b/pritunl_client/shell_app.py @@ -238,5 +238,5 @@ def start_server(self): server.serve_forever() except socket_error: - logger.info('Address already in use. Make sure that port 9797 is + logger.info('Address already in use. Make sure that port 9797 is\ available.', 'shell') From a9436aab302b9fbb62364c617157dbac3036ce9e Mon Sep 17 00:00:00 2001 From: Mostafa Hussein Date: Fri, 15 Apr 2016 11:24:23 +0200 Subject: [PATCH 3/3] Add Support for using name along with profile_id --- pritunl_client/shell_app.py | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/pritunl_client/shell_app.py b/pritunl_client/shell_app.py index add431e..6d5c374 100644 --- a/pritunl_client/shell_app.py +++ b/pritunl_client/shell_app.py @@ -9,6 +9,7 @@ import threading import json import httplib +import urllib from socket import error as socket_error class ThreadingHTTPServer(SocketServer.ThreadingMixIn, @@ -16,6 +17,20 @@ class ThreadingHTTPServer(SocketServer.ThreadingMixIn, pass class Request(BaseHTTPServer.BaseHTTPRequestHandler): + def prfl_lookup(self): + vpn_list_url = 'http://localhost:9797/list' + vpn_table = urllib.urlopen(vpn_list_url) + vpn_headers = vpn_table.readline().strip().split() + vpn_info = [] + for row in vpn_table: + row = row.strip().split() + vpn_data = dict(zip(vpn_headers, row)) + vpn_info.append(vpn_data) + for vpn_data in vpn_info: + if self.args[2] == vpn_data['NAME']: + self.args[2] = vpn_data['PROFILE_ID'] + return self.args[2] + def send_text_response(self, text, status_code=200): self.send_response(status_code) self.send_header('Content-type', 'text/plain') @@ -118,6 +133,7 @@ def do_import(self): self.send_response(200) def do_remove(self): + self.args[2] = self.prfl_lookup() prfl = profile.Profile.get_profile(self.args[2]) if prfl: prfl.delete() @@ -135,6 +151,7 @@ def connect_callback(): evt.set() pass + self.args[2] = self.prfl_lookup() prfl = profile.Profile.get_profile(self.args[2]) prfl.sync_conf() @@ -163,18 +180,21 @@ def connect_callback(): self.send_response(200) def do_stop(self): + self.args[2] = self.prfl_lookup() prfl = profile.Profile.get_profile(self.args[2]) prfl.stop() self.send_response(200) def do_enable(self): + self.args[2] = self.prfl_lookup() prfl = profile.Profile.get_profile(self.args[2]) prfl.set_autostart(True) self.send_response(200) def do_disable(self): + self.args[2] = self.prfl_lookup() prfl = profile.Profile.get_profile(self.args[2]) prfl.set_autostart(False) @@ -238,5 +258,4 @@ def start_server(self): server.serve_forever() except socket_error: - logger.info('Address already in use. Make sure that port 9797 is\ - available.', 'shell') + logger.info('Address already in use. Make sure that port 9797 is available.', 'shell')