From f9c836fba533c8f0b83922ccebe71a6cf7368172 Mon Sep 17 00:00:00 2001 From: Dragon2fly Date: Tue, 15 Nov 2016 16:10:18 +0900 Subject: [PATCH] Use only one file `run` for everything. --- README.md | 88 +++++++++++++++---------- config.py | 2 +- connected.svg => icon/connected.svg | 0 connecting1.svg => icon/connecting1.svg | 0 connecting2.svg => icon/connecting2.svg | 0 connecting3.svg => icon/connecting3.svg | 0 connectnot.svg => icon/connectnot.svg | 0 run | 26 +++++++- vpn_indicator.py | 11 ++-- vpnproxy_cli.py | 5 +- vpnproxy_tui.py | 16 ++--- 11 files changed, 90 insertions(+), 58 deletions(-) rename connected.svg => icon/connected.svg (100%) rename connecting1.svg => icon/connecting1.svg (100%) rename connecting2.svg => icon/connecting2.svg (100%) rename connecting3.svg => icon/connecting3.svg (100%) rename connectnot.svg => icon/connectnot.svg (100%) diff --git a/README.md b/README.md index 9fe9f19..53c01e4 100644 --- a/README.md +++ b/README.md @@ -8,17 +8,28 @@ Work on debian based system. Tested on Ubuntu and Raspbian. I will wrap SoftEther_vpn later when I have time. You are welcome to fork this repo and wrap SoftEther_vpn yourself. -**Indicator**: Tested on Ubuntu and is only enabled by default on Ubuntu. For other distro, -you can test it by *$ ./vpn_indicator.py* after launching *vpnproxy_tui.py* +**Indicator**: is optional. + + + +Tested on Ubuntu and is only enabled by default on Ubuntu. + +For other unix os, you need to modify the `run` file and install packages below: + + sudo apt-get install gir1.2-appindicator3-0.1 python-gobject + + +If you have any trouble or request about the program, +please make a new issue at https://github.com/Dragon2fly/vpngate-with-proxy/issues + -![](http://s19.postimg.org/580s2qyo3/2connect_success.png) # Dependency: * **openvpn**: ```$ sudo apt-get install openvpn``` * **resolvconf**: ```$ sudo apt-get install resolvconf``` Only if you use the version in 'old' directory * **python 2.7.x**: should already be shipped with your linux * **python-requests**: ```$ sudo apt-get install python-requests``` -* **python-urwid 1.3+**: ```$ sudo apt-get install python-urwid``` Only if you use `tui` version (terminal user interface) +* **python-urwid 1.3+**: ```$ sudo apt-get install python-urwid``` , only if you use `tui` version (terminal user interface) Except *python 2.7.x*, all other dependencies should be automatically installed at first run. @@ -69,17 +80,12 @@ Except *python 2.7.x*, all other dependencies should be automatically installed ```Shell $ cd vpngate-with-proxy - $ ./vpnproxy_tui.py - ``` - - or - ```Shell - $ cd vpngate-with-proxy - $ ./vpnproxy_cli.py + $ ./run [arg] ``` - - - **vpnproxy_tui.py** has better UI, colorful and easier to use. - - **vpnproxy_cli.py** is normal terminal application, lightweight and is aim to run on server (RaspberryPi ?) + - **arg** could be either none or **tui** or **cli**. + - **vpnproxy_tui.py** has better UI, colorful and easier to use. Run when `arg` is none or **tui** + - **vpnproxy_cli.py** is normal terminal application, lightweight and is aim to run on server (RaspberryPi ?). + Run when `arg` is **cli** Then the program will first setup a configuration file `config.ini` by asking you for **proxy** if needed to connect to the Internet. After that it will show the default configuration of the program. @@ -88,12 +94,13 @@ Next time launching this program, you won't see this configuration again. Either If no thing goes wrong, the vpn server's list will show up. - ![](http://s19.postimg.org/qgegk6d4z/1startup.png) + ![](https://s19.postimg.org/tg0eofvwj/1startup.png) ### 3. Interaction: - * Connect to a specific vpn server by typing its *index* number (eg: 11) and then Enter. + * Connect to a specific vpn server by typing its *index* number (eg: 3) and then Enter. If nothing went wrong, a `successfully` message show up. - ![](http://s19.postimg.org/603g1y2v7/4oldandnew.png) + + ![](https://s19.postimg.org/m3uyiwdoj/4oldandnew.png) * Your currently chosen server will be highlighted with `dark blue` color. * All connected servers before the current one is show in `dark red` color. @@ -103,7 +110,7 @@ Next time launching this program, you won't see this configuration again. Either * **F4**: **Country**, looking for a specific country or all that available? * **F5**: **Sort by**, sort these servers by what parameter? - ![](http://s19.postimg.org/xtyfwvmkj/6menu.png) + ![](https://s19.postimg.org/q2s61q2bn/6menu.png) * **Vpn command**: As you mentioned above, give an index of the server then hit Enter will open a vpn tunnel from your to that server. And there are still some more. @@ -136,10 +143,10 @@ server, that doesn't mean you are totally safe. If you are serious about privacy, this is necessary. DNS server knows the web addresses that you connected to, unless you type IP address directly. - To know your current DNS provider, https://www.dnsleaktest.com or https://ipleak.net + To know your current DNS provider, https://www.dnsleaktest.com or https://ipleak.net - * Turn on `DNS fix` by press `F3` before connecting to vpn server. Choose some good DNS from http://pcsupport.about.com/od/tipstricks/a/free-public-dns-servers.htm - * Connect to any VPN server and test if your dns provider is changed. + * Turn on `DNS fix` by press `F3` before connecting to vpn server. Choose some good DNS from http://pcsupport.about.com/od/tipstricks/a/free-public-dns-servers.htm + * Connect to any VPN server and test if your dns provider is changed. If DNS is not changed, make sure that you have turned off your system wide proxy and try again. While using the ethernet for vpn, connected to wifi may reset your DNS. @@ -150,9 +157,15 @@ You could also use below command in Ubuntu to see trace route: ``` ### 5. Some notes: - * To view or change settings before the program fetches server's list: + * To view or change settings before the program fetches server's list, use one of below: + ```Shell + $ ./run config + ``` ```Shell - $ ./vpnproxy_tui.py config + $ ./run cli config + ``` + ```Shell + $ ./run tui config ``` * (vpnproxy_cli.py only) To view or change settings at server's list: type *Vpn command* **c** or **config** then Enter @@ -162,29 +175,34 @@ You could also use below command in Ubuntu to see trace route: * The program only shows the last log line at the bottom of terminal. In fact, there is 20 last lines of the log. To view these lines, you just need to extend the high of the terminal window. - ![log](http://s19.postimg.org/5c48tuzur/7loglines.png) + ![log](https://s19.postimg.org/a5te509xf/7loglines.png) The log is shown up side down so the latest information will be in the highest place * If your terminal looks weird after program crashed or `Ctrtl+z`, `$ reset` would help # Troubleshoot: - Symptom: The program is unable to fetch new server data nor connect to any vpn server, your networking is not back to normal. + If the program is unable to fetch new server data nor connect to any vpn server, your networking is not back to normal. - That is when `restore`, `kill` and `log on` *command* come in handy. + That is when `restore`, `kill` and `log on` *command* come in handy. + + You will need to reset your network setting by: 1. **kill** all openvpn processes - 2. **quit** the program and launch it again. If it can fetch the server data, OK. - - If it doesn't - 3. `sudo iptables -F` to delete all changes to the iptable, then `$ sudo service network-manager restart` - and do step 2 again. + 2. `$ sudo service network-manager restart` Restart your system or reconnect to wifi or ethernet will also help. If it still doesn't, your proxy may be offline or `\etc\resolv.conf`'s content is incorrect. Ping your proxy from another computer to test. And double check `\etc\resolv.conf` - If your network is behind a proxy, although the program has limited the number of socket connection per second, - there is a chance that your ip will be blocked because of spamming too many socket connection - (to test if OpenVPN servers are still alive) during a short time, in other words, DDoS your proxy. - Search in the source code for **test_interval** and increase it a little bit. \ No newline at end of file + If your network is behind a proxy, there is a chance that your ip will be blocked. + Testing if OpenVPN servers are dead or alive requires spamming many socket connection. + Although the program has limited the number of socket connection per second, the proxy may think it is being DDoS. + Search in the source code for **test_interval** and increase it a little bit. + + If vpn_indicator is unresponsive, kill it by: + + $ kill -9 `pgrep -f vpn_indicator` + + + FOr other problems and bugs, please make an issue at https://github.com/Dragon2fly/vpngate-with-proxy/issues \ No newline at end of file diff --git a/config.py b/config.py index 1d0c41d..15694af 100644 --- a/config.py +++ b/config.py @@ -43,7 +43,7 @@ def get_input(s, option): if option[0] not in ['c', 'config']: print 'Wrong argument. Do you mean "config" or "restore" ?' - return + sys.exit() while 1: use_proxy, proxy, port, ip, sort_by, s_country, s_port, s_score, fix_dns, dns, verbose, mirrors = s[:] diff --git a/connected.svg b/icon/connected.svg similarity index 100% rename from connected.svg rename to icon/connected.svg diff --git a/connecting1.svg b/icon/connecting1.svg similarity index 100% rename from connecting1.svg rename to icon/connecting1.svg diff --git a/connecting2.svg b/icon/connecting2.svg similarity index 100% rename from connecting2.svg rename to icon/connecting2.svg diff --git a/connecting3.svg b/icon/connecting3.svg similarity index 100% rename from connecting3.svg rename to icon/connecting3.svg diff --git a/connectnot.svg b/icon/connectnot.svg similarity index 100% rename from connectnot.svg rename to icon/connectnot.svg diff --git a/run b/run index dfa9fff..8ca5444 100755 --- a/run +++ b/run @@ -1,4 +1,24 @@ #!/bin/bash -stdbuf -oL python vpn_indicator.py > indicator.log & -sleep 0.5 -sudo python vpnproxy_tui.py \ No newline at end of file + +# allow running from anywhere +dir=$(cd -P -- "$(dirname -- "$0")" && pwd -P) +cd "$(dirname "$(realpath "$0")")"; + +type=$1 +arg=$2 + +if [ "$type" == "cli" ]; then + sudo python vpnproxy_cli.py $arg +else + if [ "$type" != "tui" ]; then + arg=$type + fi + + # check if this os is *ubuntu and launch vpn_indicator + os_id=`lsb_release -i` + target="buntu" + test "${os_id#*$target}" != "$os_id" && stdbuf -oL python vpn_indicator.py > logs/indicator.log & + + sleep 0.2 + sudo python vpnproxy_tui.py $arg +fi \ No newline at end of file diff --git a/vpn_indicator.py b/vpn_indicator.py index 94066da..6ebafac 100755 --- a/vpn_indicator.py +++ b/vpn_indicator.py @@ -9,7 +9,6 @@ import signal, os, sys import socket, errno import time -import platform try: import gi @@ -193,9 +192,9 @@ def __init__(self, q_info, sender): self.send = sender self.APPINDICATOR_ID = 'myappindicator' - self.icon1 = os.path.abspath('connected.svg') - self.icon2 = os.path.abspath('connectnot.svg') - self.icon345 = [os.path.abspath(icon) for icon in ['connecting1.svg','connecting2.svg','connecting3.svg']] + self.icon1 = os.path.abspath('icon/connected.svg') + self.icon2 = os.path.abspath('icon/connectnot.svg') + self.icon345 = [os.path.abspath(icon) for icon in ['icon/connecting1.svg','icon/connecting2.svg','icon/connecting3.svg']] self.hang = False self.is_connecting = False self.icon_th = 0 @@ -362,7 +361,7 @@ def callback(self): except Empty: pass except Exception as e: - with open('indicator.log','w+') as log: + with open('logs/indicator.log','a+') as log: log.write(str(e)) self.notifier.update("Error", str(e), icon=None) self.notifier.show() @@ -373,7 +372,7 @@ def callback(self): another_me = Popen(['pgrep', '-f', 'python vpn_indicator.py'], stdout=PIPE).communicate()[0] another_me = another_me.strip().split('\n') - if 'buntu' not in platform.platform() or len(another_me) > 1: + if len(another_me) > 1: print 'exist another me', another_me[1:] sys.exit() diff --git a/vpnproxy_cli.py b/vpnproxy_cli.py index 432c57e..29396ad 100755 --- a/vpnproxy_cli.py +++ b/vpnproxy_cli.py @@ -20,8 +20,9 @@ # Get sudo privilege euid = os.geteuid() if euid != 0: - args = ['sudo', '-E', sys.executable] + sys.argv + [os.environ] - os.execlpe('sudo', *args) + # args = ['sudo', '-E', sys.executable] + sys.argv + [os.environ] + # os.execlpe('sudo', *args) + raise RuntimeError('Permission deny! You need to "sudo" or use "./run cli" instead') # Define some mirrors of vpngate.net mirrors = ["http://www.vpngate.net"] # add your mirrors to config.ini file, not here diff --git a/vpnproxy_tui.py b/vpnproxy_tui.py index 60004e9..8b35e75 100755 --- a/vpnproxy_tui.py +++ b/vpnproxy_tui.py @@ -22,14 +22,9 @@ # Get sudo privilege euid = os.geteuid() if euid != 0: - import platform - - if 'buntu' in platform.platform() and not Popen(['pgrep', '-f', 'vpn_indicator'], stdout=PIPE).communicate()[0]: - print 'Launch vpn_indicator' - Popen(['python', 'vpn_indicator.py'], stdout=PIPE, stderr=PIPE, bufsize=1, ) - - args = ['sudo', '-E', sys.executable] + sys.argv + [os.environ] - os.execlpe('sudo', *args) + # args = ['sudo', '-E', sys.executable] + sys.argv + [os.environ] + # os.execlpe('sudo', *args) + raise RuntimeError('Permission deny! You need to "sudo" or use "./run" instead') # Threading ON_POSIX = 'posix' in sys.builtin_module_names @@ -880,7 +875,7 @@ def setting(self, key=None): self.ovpn.cfg.write() def status(self, msg=None): - logpath = self.ovpn.config_file[:-10] + 'vpn.log' + logpath = self.ovpn.config_file[:-10] + 'logs/vpn.log' if msg is None: # backup last season log if os.path.exists(logpath): @@ -1006,7 +1001,7 @@ def exit(self, loop, data=None): ctext("Have you 'sudo apt-get update' recently?", 'B') + "([yes] | no): ") else 'no' if update_now == 'yes': - call(['apt-get', 'update'], env=env) + call(['apt-get', '-y', 'update'], env=env) for package in need: print '\n___Now installing', ctext(package, 'gB') @@ -1024,7 +1019,6 @@ def exit(self, loop, data=None): # -------- all dependencies should be available after this line -------- # raw_input('for debugging') -# clear system proxy so that request only go through the one specified screen = Display(vpn_connect) screen.get_data_status = 'call' screen.run()