Skip to content

Commit

Permalink
added initial files
Browse files Browse the repository at this point in the history
  • Loading branch information
polski-g committed Jun 17, 2017
1 parent 78e25f2 commit ed82cf4
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 0 deletions.
24 changes: 24 additions & 0 deletions vpn_looper.sh
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

9 changes: 9 additions & 0 deletions vpngate.service
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

64 changes: 64 additions & 0 deletions vpngate_fetch.py
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")

0 comments on commit ed82cf4

Please sign in to comment.