Skip to content

Commit

Permalink
Better detection for Debian based or Redhat based package manager; no…
Browse files Browse the repository at this point in the history
… longer clear the server list when it failed on refreshing; update proxy ip
  • Loading branch information
Dragon2fly committed Feb 14, 2017
1 parent c54e3eb commit 3585b28
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 17 deletions.
2 changes: 1 addition & 1 deletion user_script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ down)
;;
esac

# anything outside "case" block will be executed twice!
# anything outside "case" block will be executed twice!
16 changes: 9 additions & 7 deletions vpnproxy_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@
import base64
import time
import datetime
import platform
from config import *
from Queue import Queue
from threading import Thread
from subprocess import call, Popen, PIPE
from subprocess import call, Popen, PIPE, check_output

# Get sudo privilege
euid = os.geteuid()
Expand All @@ -25,10 +24,12 @@
# os.execlpe('sudo', *args)
raise RuntimeError('Permission deny! You need to "sudo" or use "./run cli" instead')

# detect Debian based or Redhat based OS
pkg_mgr = 'apt-get'
if "generic" not in platform.platform():
pkg_mgr = 'yum' # yum or dnf; on new fedora, yum is automatically redirect to dnf
# detect Debian based or Redhat based OS's package manager
pkg_mgr = None
check_ls = ["apt-get", "yum", "dnf"]
for pkg in check_ls:
if check_output("whereis -b {}".format(pkg).split()).strip().split(":")[1]:
pkg_mgr = pkg

# Define some mirrors of vpngate.net
mirrors = ["http://www.vpngate.net"] # add your mirrors to config.ini file, not here
Expand Down Expand Up @@ -428,7 +429,8 @@ def vpn_manager(ovpn):
while True:
print ctext('Use proxy: ', 'B'), use_proxy,
print ' || ', ctext('Country: ', 'B'), s_country,
print ' || ', ctext('Min score: ', 'B'), s_score
print ' || ', ctext('Min score: ', 'B'), s_score,
print ' ||', ctext('Portal:', 'B'), s_port

if not ranked:
print '\nNo server found for "%s"\n' % s_country
Expand Down
26 changes: 17 additions & 9 deletions vpnproxy_tui.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@
import base64
import time
import datetime
import platform
from copy import deepcopy
from config import *
from Queue import Queue, Empty
from subprocess import call, Popen, PIPE
from subprocess import call, Popen, PIPE, check_output
from threading import Thread
from collections import deque, OrderedDict
from vpn_indicator import InfoClient
Expand All @@ -27,10 +26,12 @@
# os.execlpe('sudo', *args)
raise RuntimeError('Permission deny! You need to "sudo" or use "./run" instead')

# detect Debian based or Redhat based OS
pkg_mgr = 'apt-get'
if "generic" not in platform.platform():
pkg_mgr = 'yum' # yum or dnf; on new fedora, yum is automatically redirect to dnf
# detect Debian based or Redhat based OS's package manager
pkg_mgr = None
check_ls = ["apt-get", "yum", "dnf"]
for pkg in check_ls:
if check_output("whereis -b {}".format(pkg).split()).strip().split(":")[1]:
pkg_mgr = pkg

# Threading
ON_POSIX = 'posix' in sys.builtin_module_names
Expand Down Expand Up @@ -276,12 +277,14 @@ def get_data(self):
for t in my_thread: t.join()

success = 0
self.vpndict.clear()
vpndict = {}
for res in [my_queue.get() for r in xrange(self.get_limit)]:
success += res[0]
self.vpndict.update(res[1])
vpndict.update(res[1])

if success:
self.vpndict.clear()
self.vpndict.update(vpndict)
break
else:
i += self.get_limit
Expand Down Expand Up @@ -840,7 +843,12 @@ def setting(self, key=None):
if key == 'f2':
yn = config_data[index] = self.sets.contents[index][0].result[0]
proxy, port = self.sets.contents[index][0].result[1:]
ip = socket.gethostbyname(proxy)
try:
ip = socket.gethostbyname(proxy)
except socket.gaierror:
ip = ''
self.ovpn.messages['debug'].appendleft(" Can't resolve hostname of proxy, please input its ip!")

proxy_ = {'use_proxy': yn, 'address': proxy, 'port': port, 'ip': ip}
self.ovpn.rewrite('proxy', **proxy_)

Expand Down

0 comments on commit 3585b28

Please sign in to comment.