Skip to content

Commit

Permalink
Done first version
Browse files Browse the repository at this point in the history
  • Loading branch information
yourtion committed Nov 16, 2016
1 parent f06a475 commit fd445b6
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 31 deletions.
70 changes: 39 additions & 31 deletions Source/SSR.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
class Client:

httpClient = None
SERVER="/servers"
STATUS="/status"
TOGGLE="/toggle"
MODE="/mode"
SERVER='/servers'
STATUS='/status'
TOGGLE='/toggle'
MODE='/mode'
MODES=['auto','global','manual','bypasschian']

def __init__(self):
Expand All @@ -27,8 +27,8 @@ def _get(self, url):
def _post(self, url, parma):
try:
params = urllib.urlencode(parma)
headers = {"Content-type": "application/x-www-form-urlencoded"
, "Accept": "text/plain"}
headers = {'Content-type': 'application/x-www-form-urlencoded'
, 'Accept': 'text/plain'}
self.httpClient.request('POST', url, params, headers)
return self.httpClient.getresponse()
except Exception, e:
Expand All @@ -39,40 +39,40 @@ def _parseArgs(self, str):

def _getServers(self):
res = self._get(self.SERVER)
if res and res.status == 200 and res.reason == "OK":
if res and res.status == 200 and res.reason == 'OK':
return json.loads(res.read())

def _getStatus(self):
res = self._get(self.STATUS)
if res and res.status == 200 and res.reason == "OK":
if res and res.status == 200 and res.reason == 'OK':
data = json.loads(res.read())
return data['enable']

def _getMode(self):
res = self._get(self.MODE)
if res and res.status == 200 and res.reason == "OK":
if res and res.status == 200 and res.reason == 'OK':
data = json.loads(res.read())
return data['mode']

def _setStatus(self):
res = self._post(self.TOGGLE, {})
if res.status == 200 and res.reason == "OK":
if res.status == 200 and res.reason == 'OK':
data = json.loads(res.read())
return data['Status'] == 1
return False

def _setServer(self, id):
parma = {'uuid': id}
res = self._post(self.SERVER, parma)
if res.status == 200 and res.reason == "OK":
if res.status == 200 and res.reason == 'OK':
data = json.loads(res.read())
return data['Status'] == 1
return False

def _setMode(self, mode):
parma = {'vaule': mode}
res = self._post(self.MODE, parma)
if res.status == 200 and res.reason == "OK":
if res.status == 200 and res.reason == 'OK':
data = json.loads(res.read())
return data['Status'] == 1
return False
Expand All @@ -83,44 +83,52 @@ def action(self, query):
value = args[1]
if(command == 'enable'):
if(self._setStatus()):
print("Set ShadowSock " + value + ' Succeed!')
print('Set ShadowSock ' + value + ' Succeed!')
# if(command == 'server'):
# if(self._setServer(value)):
# print("Set Server " + args[2])
# print('Set Server ' + args[2])
if(command == 'mode'):
if(self._setMode(value)):
print("Set Server Mode: " + value + ' Succeed!')
print('Set Server Mode: ' + value + ' Succeed!')
return ''


def getList(self):
list = self._getServers()
enable = self._getStatus()
enableStr = "True" if enable else "False"
enableOptStr = "Disable" if enable else "Enable"
enableStr = 'True' if enable else 'False'
enableOptStr = 'Disable' if enable else 'Enable'
mode = self._getMode()
items = []
enableItem = {
"title":"Enable: " + enableStr,
"subtitle": "Select to "+ enableOptStr,
"arg": "enable:"+enableOptStr,
"icon": "icon.png"
'title':'Enable: ' + enableStr,
'subtitle': 'Select to '+ enableOptStr,
'arg': 'enable:'+enableOptStr,
'icon': {'path': 'icon.png'}
}
if not enable:
enableItem['icon']['path'] = 'iconb.png'
items.append(enableItem)
modeItem = {
"title": "Mode: "+mode,
"arg": "mode:"+mode,
"icon": "icon.png"
}
items.append(modeItem)
for m in self.MODES:
modeItem = {
'title': 'Mode: '+m,
'arg': 'mode:'+m,
'icon': {'path': 'iconb.png'}
}
if m == mode:
modeItem['icon']['path'] = 'icon.png'
modeItem['subtitle'] = 'Current Mode'
else:
modeItem['subtitle'] = 'Switch to' + m
items.append(modeItem)

for item in list:
serverItem = {
"title": "Server:" + item['note'],
"arg": "server:" +item['id']+":"+item['note'],
"icon": "icon.png"
'title': 'Server: ' + item['note'],
'arg': 'server:' +item['id']+':'+item['note'],
}
items.append(serverItem)
result = {"items": items}
result = {'items': items}
print(json.dumps(result))


Binary file added Source/iconb.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions Source/info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ ss.action(query)</string>
<integer>120</integer>
</dict>
</dict>
<key>version</key>
<string>0.1</string>
<key>webaddress</key>
<string>https://github.com/yourtion</string>
</dict>
Expand Down

0 comments on commit fd445b6

Please sign in to comment.