-
Notifications
You must be signed in to change notification settings - Fork 0
/
funcs.py
81 lines (61 loc) · 1.93 KB
/
funcs.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
76
77
78
79
80
81
import sys
import requests
import os
import json
def addLF():
print("");
# Creates a directory when it doesn't exist
def createDir (dir):
try:
if (os.path.isdir(dir) == False):
os.mkdir(dir)
return True
except Exception as e:
print (e)
return False
# Sets server information by saving to the file
def setServerInfo(name, endpoint, password, localdir):
try:
filename = "Server\\" + name + ".json"
content = { "Name" : name, "Endpoint" : endpoint, "Password" : password, "LocalDirectory" : localdir }
with open(filename, 'w') as outfile:
json.dump(content, outfile)
return True
except Exception as e:
return False
# Gets the server information from the saved server configurations
def getServerInfo(name):
try:
filename = "Server\\" + name + ".json"
file = open (filename, "r")
filecontent = (file.read())
return json.loads(filecontent)
except Exception as e:
return e
# Get all the servers from the saving directory
def getAllServers():
if (os.path.isdir("Server\\")):
return os.listdir("Server\\")
else:
return []
# Verify a specified CCVShell server
def verifyServer(endpoint, password):
url = (endpoint + "/" + "CCVShell/Handle.php?p=" + password)
response = requests.get(url)
return (response.status_code == 200)
# Add a server to the Servers/ directory
def addServer(name, endpoint, password, localdir):
print ("Connecting to the server \"" + name + "\" at " + endpoint + "...")
# Verification of the server password
verified = verifyServer(endpoint, password)
if (verified):
#Create the localdirectory and the server directory if they don't exist in the computer
createDir(localdir)
createDir("Server\\")
donesave = setServerInfo(name, endpoint, password, localdir) # Save the server information
if (donesave) :
print ("Saved the Server Configuration!")
else:
print ("Could not save the configuration please retry!")
else:
print ("Invalid credentials (403), Please retry")