Skip to content

Commit e4a375f

Browse files
committed
pci compliance headers
1 parent 95a953a commit e4a375f

10 files changed

Lines changed: 55 additions & 28 deletions

File tree

CyberCP/secMiddleware.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,5 +92,12 @@ def __call__(self, request):
9292
logging.writeToFile(str(msg))
9393
response = self.get_response(request)
9494
return response
95+
96+
9597
response = self.get_response(request)
98+
99+
response['X-XSS-Protection'] = "1; mode=block"
100+
response['Strict-Transport-Security'] = "max-age=31536000; includeSubDomains; preload"
101+
response['X-Frame-Options'] = "DENY"
102+
96103
return response

CyberCP/settings.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,8 @@
127127
}
128128

129129
DATABASE_ROUTERS = ['backup.backupRouter.backupRouter']
130-
130+
SESSION_COOKIE_SECURE = True
131+
CSRF_COOKIE_SECURE = True
131132

132133
# Password validation
133134
# https://docs.djangoproject.com/en/1.11/ref/settings/#auth-password-validators

WebTerminal/CPWebSocket.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
import time
1010

1111
class SSHServer(multi.Thread):
12+
OKGREEN = '\033[92m'
13+
ENDC = '\033[0m'
1214

1315
def loadPublicKey(self):
1416
pubkey = '/root/.ssh/cyberpanel.pub'
@@ -44,17 +46,25 @@ def __init__(self, websocket):
4446
self.shell.settimeout(0)
4547

4648
self.websocket = websocket
49+
self.color = 0
4750

4851
def recvData(self):
4952
while True:
5053
try:
5154
if os.path.exists(self.websocket.verifyPath):
52-
if self.shell.recv_ready():
53-
self.websocket.sendMessage(self.shell.recv(9000).decode("utf-8"))
54-
else:
55-
time.sleep(0.1)
55+
if self.websocket.filePassword == self.websocket.filePassword:
56+
if self.shell.recv_ready():
57+
if self.color == 0:
58+
text = '%sEnjoy your accelerated Internet by CyberPanel and LiteSpeed%s' % (SSHServer.OKGREEN, SSHServer.ENDC)
59+
nText = 'Enjoy your accelerated Internet by CyberPanel'
60+
self.websocket.sendMessage(self.shell.recv(9000).decode("utf-8").replace(nText, text))
61+
self.color = 1
62+
else:
63+
self.websocket.sendMessage(self.shell.recv(9000).decode("utf-8"))
64+
else:
65+
time.sleep(0.01)
5666
except BaseException, msg:
57-
time.sleep(2)
67+
time.sleep(0.1)
5868

5969
def run(self):
6070
try:
@@ -70,9 +80,12 @@ def handleMessage(self):
7080
data = json.loads(self.data)
7181
if str(self.data).find('"tp":"init"') > -1:
7282
self.verifyPath = str(data['data']['verifyPath'])
83+
self.password = str(data['data']['password'])
84+
self.filePassword = open(self.verifyPath, 'r').read()
7385
else:
7486
if os.path.exists(self.verifyPath):
75-
self.shell.send(str(data['data']))
87+
if self.filePassword == self.filePassword:
88+
self.shell.send(str(data['data']))
7689
except:
7790
pass
7891

WebTerminal/static/WebTerminal/main.js

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,9 @@ function check() {
6767
function connect() {
6868
var remember = $("#remember").is(":checked");
6969
var options = {
70-
host: $("#host").val(),
71-
port: $("#port").val(),
72-
username: $("#username").val(),
73-
ispwd: $("input[name=ispwd]:checked").val(),
74-
secret: $("#secret").val(),
75-
verifyPath: $("#verifyPath").text()
76-
}
77-
console.debug(options);
70+
verifyPath: $("#verifyPath").text(),
71+
password: $("#password").text()
72+
};
7873
if (remember) {
7974
store(options)
8075
}

WebTerminal/static/WebTerminal/ws.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ WSSHClient.prototype.sendInitData = function (options) {
5858
}
5959

6060
WSSHClient.prototype.sendClientData = function (data) {
61-
this._connection.send(JSON.stringify({"tp": "client", "data": data, 'verifyPath': $("#verifyPath").text()}))
61+
this._connection.send(JSON.stringify({"tp": "client", "data": data, 'verifyPath': $("#verifyPath").text(), 'password': $("#password").text()}))
6262
}
6363

6464
var client = new WSSHClient();

WebTerminal/templates/WebTerminal/WebTerminal.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ <h3 class="content-box-header">
4242

4343
</div>
4444
<div style="display: none" id="verifyPath">{{ verifyPath }}</div>
45+
<div style="display: none" id="password">{{ password }}</div>
4546
</div>
4647
</div>
4748
</div>

WebTerminal/views.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from plogical.firewallUtilities import FirewallUtilities
1212
from firewall.models import FirewallRules
1313
import json
14+
import plogical.randomPassword
1415

1516
# Create your views here.
1617

@@ -24,12 +25,13 @@ def terminal(request):
2425
else:
2526
return ACLManager.loadError()
2627

28+
password = plogical.randomPassword.generate_pass()
29+
2730
verifyPath = "/home/cyberpanel/" + str(randint(100000, 999999))
2831
writeToFile = open(verifyPath, 'w')
29-
writeToFile.writelines('code')
32+
writeToFile.write(password)
3033
writeToFile.close()
3134

32-
3335
## setting up ssh server
3436
path = '/etc/systemd/system/cpssh.service'
3537
curPath = '/usr/local/CyberCP/WebTerminal/cpssh.service'
@@ -46,7 +48,7 @@ def terminal(request):
4648
newFWRule = FirewallRules(name='terminal', proto='tcp', port='5678', ipAddress='0.0.0.0/0')
4749
newFWRule.save()
4850

49-
return render(request, 'WebTerminal/WebTerminal.html', {'verifyPath': verifyPath})
51+
return render(request, 'WebTerminal/WebTerminal.html', {'verifyPath': verifyPath, 'password': password})
5052
except BaseException, msg:
5153
logging.writeToFile(str(msg))
5254
return redirect(loadLoginPage)

plogical/upgrade.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1353,6 +1353,12 @@ def downloadAndUpgrade(versionNumbring):
13531353
if items.find('WebTerminal') > -1:
13541354
WebTerminal = 0
13551355

1356+
SESSION_COOKIE_SECURE = 1
1357+
1358+
for items in data:
1359+
if items.find('SESSION_COOKIE_SECURE') > -1:
1360+
SESSION_COOKIE_SECURE = 0
1361+
13561362
Upgrade.stdOut('Restoring settings file!')
13571363

13581364
writeToFile = open("/usr/local/CyberCP/CyberCP/settings.py", 'w')
@@ -1362,6 +1368,13 @@ def downloadAndUpgrade(versionNumbring):
13621368
if csrfCheck == 1:
13631369
writeToFile.writelines(" 'django.middleware.csrf.CsrfViewMiddleware',\n")
13641370

1371+
if items.find('DATABASE_ROUTERS') > -1:
1372+
if SESSION_COOKIE_SECURE == 1:
1373+
con = """SESSION_COOKIE_SECURE = True
1374+
CSRF_COOKIE_SECURE = True
1375+
"""
1376+
writeToFile.writelines(con)
1377+
13651378
elif items.find("'filemanager',") > -1:
13661379
writeToFile.writelines(items)
13671380
if pluginCheck == 1:

static/WebTerminal/main.js

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,9 @@ function check() {
6767
function connect() {
6868
var remember = $("#remember").is(":checked");
6969
var options = {
70-
host: $("#host").val(),
71-
port: $("#port").val(),
72-
username: $("#username").val(),
73-
ispwd: $("input[name=ispwd]:checked").val(),
74-
secret: $("#secret").val(),
75-
verifyPath: $("#verifyPath").text()
76-
}
77-
console.debug(options);
70+
verifyPath: $("#verifyPath").text(),
71+
password: $("#password").text()
72+
};
7873
if (remember) {
7974
store(options)
8075
}

static/WebTerminal/ws.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ WSSHClient.prototype.sendInitData = function (options) {
5858
}
5959

6060
WSSHClient.prototype.sendClientData = function (data) {
61-
this._connection.send(JSON.stringify({"tp": "client", "data": data, 'verifyPath': $("#verifyPath").text()}))
61+
this._connection.send(JSON.stringify({"tp": "client", "data": data, 'verifyPath': $("#verifyPath").text(), 'password': $("#password").text()}))
6262
}
6363

6464
var client = new WSSHClient();

0 commit comments

Comments
 (0)