Skip to content

Instantly share code, notes, and snippets.

@hvnsweeting
Created November 18, 2012 05:12
Show Gist options
  • Save hvnsweeting/4103717 to your computer and use it in GitHub Desktop.
Save hvnsweeting/4103717 to your computer and use it in GitHub Desktop.
import requests
import json
import secutils as sec
HOST = "http://0.0.0.0:8080/"
creat_url = "create"
token_url = "token"
delete_url = 'delete'
def get_token():
res = requests.get(HOST+token_url)
token = json.loads(res.text)['token']
return token
def create():
rules = [{"ip" : "123.123.123.123", "type":"all"},
{"ip" : "192.168.4.130" , "type" : "all"},
{"ip" : "192.168.3.182" , "type" : "all"},
{"ip" : "123.30.53.12" , "type" : "all"},
{"ip" : "222.255.27.156" , "type" : "all"},
{"ip" : "1.2.3.4", "type" : "ftp"},
{"ip" : "100.1.0.8", "type" : "ftp"},
{"ip" : "123.1.0.8", "type" : "custom", "ports" : "23,34,56"},
]
token = get_token()
data = {'token' : token, "email" : "vpn-admin@vccloud.vn", "id" : "4", "type" : ["editor","admin"], "rules" : rules}
jsondata = json.dumps(data)
jsondata = sec.encrypt_data(jsondata)
r = requests.post(HOST+creat_url, data=jsondata)
return r.text
def delete():
token = get_token()
data = {'token' : token, "email" : "vpn-admin@vccloud.vn"}
jsondata = json.dumps(data)
jsondata = sec.encrypt_data(jsondata)
r = requests.post(HOST+delete_url, data=jsondata)
return r.text
if __name__ == "__main__":
import sys
args = len(sys.argv)
if args > 1:
opt = sys.argv[1]
if opt == '-c':
print create()
elif opt == '-d':
print delete()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment