forked from Zomboided/service.vpn.manager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.py
75 lines (70 loc) · 2.74 KB
/
api.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# Copyright (C) 2016 Zomboided
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# This module allows some limited interaction with the service via
# a set of commands
import xbmcaddon
import xbmcvfs
import string
from libs.common import setAPICommand, clearAPICommand, getAPICommand
from libs.utility import debugTrace, errorTrace, infoTrace, newPrint, getID
# Get the first argument which will indicate the connection that's being dealt with
command = sys.argv[1]
lcommand = command.lower()
debugTrace("Entered api.py with parameter " + command)
if not getID() == "":
if lcommand == "disconnect":
setAPICommand("Disconnect")
elif lcommand == "cycle":
setAPICommand("Cycle")
elif lcommand == "fake":
setAPICommand("Fake")
elif lcommand == "real":
setAPICommand("Real")
elif lcommand == "pause":
setAPICommand("Pause")
elif lcommand == "restart":
setAPICommand("Restart")
elif lcommand == "reconnect":
setAPICommand("Reconnect")
elif lcommand == "getip":
setAPICommand("GetIP")
elif lcommand.startswith("connect"):
connection = command[8:].strip(' \t\n\r')
if connection.isdigit():
c = int(connection)
addon = xbmcaddon.Addon(getID())
# Adjust the 11 below to change conn_max
if c > 0 and c < 11:
connection = addon.getSetting(str(c) + "_vpn_validated")
if not connection == "":
setAPICommand(connection)
else:
errorTrace("api.py", "Connection requested, " + str(c) + " has not been validated")
else:
errorTrace("api.py", "Invalid connection, " + str(c) + " requested")
else:
if xbmcvfs.exists(connection):
setAPICommand(connection)
else:
errorTrace("api.py", "Requested connection, " + connection + " does not exist")
else:
errorTrace("api.py", "Unrecognised command: " + command)
else:
errorTrace("api.py", "VPN service is not ready")
debugTrace("-- Exit api.py --")