Skip to content

Commit

Permalink
Move config.ini, user_script.sh into $HOME/.config/vpngate-with-proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
ductin committed Apr 22, 2017
1 parent 541baee commit 43bf43b
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 2 deletions.
34 changes: 34 additions & 0 deletions user_script.sh.tmp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/bash
# This file must be bash script.
# If you need sh/csh/ksh ... then call them within this file.
# This file will be executed with "root" privilege!
# Drop privilege by: su user_name -c "cmd to run"
# DNS should be changed within main program, not here!
# If you manually change your DNS here, you should turn of 'DNS fix' of main program.

# setup any environment variable that you need
set -e
export PATH="$PATH:/usr/sbin:/sbin"

USER=$(whoami)
echo $USER

# Don't modified this block
case "$1" in
up)
# _____ your code here _____
echo "called Up script"
notify-send "$(hostname): LINK IS UP." --icon=network-idle

# _____ end up script ______
;;
down)
# _____ your code here _____
echo "called Down script"
notify-send "$(hostname): LINK IS DOWN !" --icon=dialog-error

# _____ end down script ____
;;
esac

# anything outside "case" block will be executed twice!
5 changes: 5 additions & 0 deletions vpnproxy_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@ def vpn_manager(ovpn):
# get config file path
path = os.path.realpath(sys.argv[0])
config_file = os.path.expanduser('~/.config/vpngate-with-proxy/config.ini')
user_script_file = os.path.expanduser('~/.config/vpngate-with-proxy/user_script.sh')
cfg = Setting(config_file)
args = sys.argv[1:]

Expand Down Expand Up @@ -391,6 +392,10 @@ def vpn_manager(ovpn):
if not os.path.exists("config.ini"):
os.symlink(config_file, "config.ini")

if not os.path.exists(user_script_file):
call(["cp", "user_script.sh.tmp", user_script_file])
os.symlink(user_script_file, "user_script.sh")

# ------------------- check_dependencies: ----------------------
mirrors.extend(cfg.mirror['url'].split(', '))
use_proxy, proxy, port, ip = cfg.proxy.values()
Expand Down
16 changes: 14 additions & 2 deletions vpnproxy_tui.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ def __repr__(self):
class Connection:
def __init__(self):
self.path = os.path.realpath(sys.argv[0])
self.config_file = os.path.split(self.path)[0] + '/config.ini'
self.config_file = os.path.expanduser('~/.config/vpngate-with-proxy/config.ini')
self.user_script_file = os.path.expanduser('~/.config/vpngate-with-proxy/user_script.sh')
self.cfg = Setting(self.config_file)
self.args = sys.argv[1:]
self.debug = []
Expand Down Expand Up @@ -137,6 +138,14 @@ def __init__(self):
if not os.path.exists(self.config_file):
self.first_config()

# make sure there are symlink files of them in this script's directory
if not os.path.exists("config.ini"):
os.symlink(self.config_file, "config.ini")

if not os.path.exists(self.user_script_file):
call(["cp", "user_script.sh.tmp", self.user_script_file])
os.symlink(self.user_script_file, "user_script.sh")

self.cfg.load()
if len(self.args):
# process commandline arguments
Expand Down Expand Up @@ -165,6 +174,9 @@ def rewrite(self, section, **contents):
self.reload()

def first_config(self):
if not os.path.exists(os.path.expanduser('~/.config/vpngate-with-proxy')):
os.makedirs(os.path.expanduser('~/.config/vpngate-with-proxy'))

print '\n' + '_' * 12 + ctext(' First time config ', 'gB') + '_' * 12 + '\n'
self.cfg.proxy['use_proxy'] = 'no' if raw_input(
ctext('Do you need proxy to connect? ', 'B') + '(yes|[no]):') in 'no' else 'yes'
Expand Down Expand Up @@ -905,7 +917,7 @@ def setting(self, key=None):
self.ovpn.cfg.write()

def status(self, msg=None):
logpath = self.ovpn.config_file[:-10] + 'logs/vpn.log'
logpath = os.path.split(self.ovpn.path)[0] + '/logs/vpn.log'
if msg is None:
# backup last season log
if os.path.exists(logpath):
Expand Down

0 comments on commit 43bf43b

Please sign in to comment.