-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
97 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#!/bin/bash | ||
|
||
export PATH=/root/bin/:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin | ||
pid=/var/run/vpngate.pid | ||
|
||
if [ "$1" = "kill" ]; then | ||
kill $pid | ||
exit 0 | ||
fi | ||
|
||
while true; do | ||
ping -I tun101 8.8.8.8 -w5 -c1 | ||
if [ $? -eq 0 ]; then | ||
sleep 28 | ||
continue | ||
fi | ||
|
||
pkill -f "openvpn --daemon --cd /etc/openvpn --config vpngate.conf" | ||
sleep 2 | ||
vpngate_fetch.py | ||
openvpn --daemon --cd /etc/openvpn --config vpngate.conf --log /var/log/openvpn-vpngate.log --writepid $pid | ||
sleep 10 | ||
done | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
[Unit] | ||
Description=vpngate fetcher | ||
After=network.target | ||
|
||
[Service] | ||
ExecStart=/usr/local/bin/vpn_looper.sh | ||
ExecStop=/usr/local/bin/vpn_looper.sh kill | ||
PIDFile=/var/run/vpngate.pid | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
#!/usr/bin/python | ||
import csv | ||
import base64 | ||
import sys | ||
import os, os.path, time | ||
from datetime import datetime | ||
import urllib | ||
from random import shuffle | ||
import commands | ||
|
||
FILE_TMP = '/root/csv_vpngate' | ||
|
||
def downloadFile(file_name, base_url): | ||
f = urllib.urlretrieve(base_url, file_name) | ||
return 0 | ||
|
||
if os.path.exists(FILE_TMP): | ||
now = datetime.now() | ||
then = datetime.fromtimestamp( os.path.getmtime(FILE_TMP) ) | ||
|
||
tdelta = now-then | ||
if int(tdelta.total_seconds()) < 900: | ||
print "tdelta < 900s, not fetching" | ||
else: | ||
os.unlink(FILE_TMP) | ||
ret = downloadFile(FILE_TMP, 'http://www.vpngate.net/api/iphone/') | ||
if ret != 0: | ||
print("download failed") | ||
sys.exit(ret) | ||
|
||
#country = raw_input("What country? ") | ||
country = ("CA", "US", "GB", "DE", "FR") | ||
|
||
possible = [] | ||
|
||
with open(FILE_TMP, 'r') as fp: | ||
creader = csv.reader(fp) | ||
i = 0 | ||
for row in creader: | ||
i += 1 | ||
if i <= 2: | ||
continue | ||
if row[0] == '*': | ||
continue | ||
|
||
if row[6] in country: | ||
data = (row[12], row[14]) | ||
possible.append(data) | ||
|
||
shuffle(possible) | ||
|
||
for row in possible: | ||
#thisone = raw_input("Do you want %s? [y]" % row[0]) | ||
thisone = 'y' | ||
if thisone is None or thisone=='' or thisone=='y': | ||
fp = open('/etc/openvpn/vpngate.conf', 'w') | ||
fp.write( base64.b64decode(row[1]) ) | ||
fp.close() | ||
print "/etc/openvpn/vpngate.conf written" | ||
break | ||
|
||
|
||
commands.getstatusoutput("sed -i 's/^dev tun.*/dev tun101/' /etc/openvpn/vpngate.conf") | ||
|