mirror of
https://github.com/usmannasir/cyberpanel.git
synced 2025-11-11 15:56:11 +01:00
update req file
This commit is contained in:
@@ -1,18 +1,18 @@
|
|||||||
#!/usr/local/CyberCP/bin/python
|
import tornado.httpserver
|
||||||
|
import tornado.websocket
|
||||||
|
import tornado.ioloop
|
||||||
|
import tornado.web
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
sys.path.append('/usr/local/CyberCP')
|
sys.path.append('/usr/local/CyberCP')
|
||||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "CyberCP.settings")
|
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "CyberCP.settings")
|
||||||
from plogical.CyberCPLogFileWriter import CyberCPLogFileWriter as logging
|
from plogical.CyberCPLogFileWriter import CyberCPLogFileWriter as logging
|
||||||
import signal
|
|
||||||
import sys
|
|
||||||
import ssl
|
|
||||||
from SimpleWebSocketServer import WebSocket, SimpleSSLWebSocketServer
|
|
||||||
import paramiko
|
import paramiko
|
||||||
import os
|
import os
|
||||||
import json
|
import json
|
||||||
import threading as multi
|
import threading as multi
|
||||||
import time
|
import time
|
||||||
|
import asyncio
|
||||||
|
|
||||||
|
|
||||||
class SSHServer(multi.Thread):
|
class SSHServer(multi.Thread):
|
||||||
@@ -72,26 +72,22 @@ class SSHServer(multi.Thread):
|
|||||||
self.color = 0
|
self.color = 0
|
||||||
|
|
||||||
def recvData(self):
|
def recvData(self):
|
||||||
|
asyncio.set_event_loop(asyncio.new_event_loop())
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
if self.websocket.running:
|
if self.websocket.running:
|
||||||
if os.path.exists(self.websocket.verifyPath):
|
if os.path.exists(self.verifyPath) and self.filePassword == self.password:
|
||||||
if self.websocket.filePassword == self.websocket.password:
|
if self.shell.recv_ready():
|
||||||
if self.shell.recv_ready():
|
self.websocket.write_message(self.shell.recv(9000).decode("utf-8"))
|
||||||
if self.color == 0:
|
else:
|
||||||
text = '%sEnjoy your accelerated Internet by CyberPanel and LiteSpeed%s' % (SSHServer.OKGREEN, SSHServer.ENDC)
|
time.sleep(0.001)
|
||||||
nText = 'Enjoy your accelerated Internet by CyberPanel'
|
else:
|
||||||
self.websocket.sendMessage(self.shell.recv(9000).decode("utf-8").replace(nText, text))
|
return 0
|
||||||
self.color = 1
|
|
||||||
else:
|
|
||||||
self.websocket.sendMessage(self.shell.recv(9000).decode("utf-8"))
|
|
||||||
else:
|
|
||||||
time.sleep(0.01)
|
|
||||||
else:
|
else:
|
||||||
return 0
|
return 0
|
||||||
except BaseException as msg:
|
except BaseException as msg:
|
||||||
print(str(msg))
|
print('%s. [recvData]' % str(msg))
|
||||||
time.sleep(0.1)
|
time.sleep(0.001)
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
try:
|
try:
|
||||||
@@ -99,63 +95,67 @@ class SSHServer(multi.Thread):
|
|||||||
except BaseException as msg:
|
except BaseException as msg:
|
||||||
print('%s. [SSHServer.run]' % (str(msg)))
|
print('%s. [SSHServer.run]' % (str(msg)))
|
||||||
|
|
||||||
|
class WSHandler(tornado.websocket.WebSocketHandler):
|
||||||
|
|
||||||
class WebTerminalServer(WebSocket):
|
def open(self):
|
||||||
|
print('connected')
|
||||||
|
self.running = 1
|
||||||
|
self.sh = SSHServer(self)
|
||||||
|
self.shell = self.sh.shell
|
||||||
|
self.sh.start()
|
||||||
|
self.init = 1
|
||||||
|
print('connect ok')
|
||||||
|
|
||||||
def handleMessage(self):
|
def on_message(self, message):
|
||||||
try:
|
try:
|
||||||
print('handle message')
|
print('handle message')
|
||||||
data = json.loads(self.data)
|
data = json.loads(message)
|
||||||
print(str(data))
|
|
||||||
if str(self.data).find('"tp":"init"') > -1:
|
|
||||||
self.verifyPath = str(data['data']['verifyPath'])
|
|
||||||
self.password = str(data['data']['password'])
|
|
||||||
self.filePassword = open(self.verifyPath, 'r').read()
|
|
||||||
else:
|
|
||||||
if os.path.exists(self.verifyPath):
|
|
||||||
if self.filePassword == self.password:
|
|
||||||
self.shell.send(str(data['data']))
|
|
||||||
except BaseException as msg:
|
|
||||||
print('%s. [WebTerminalServer.handleMessage]' % (str(msg)))
|
|
||||||
|
|
||||||
def handleConnected(self):
|
if self.init:
|
||||||
print('connected')
|
self.sh.verifyPath = str(data['data']['verifyPath'])
|
||||||
self.running = 1
|
self.sh.password = str(data['data']['password'])
|
||||||
self.sh = SSHServer(self)
|
self.sh.filePassword = open(self.sh.verifyPath, 'r').read()
|
||||||
self.shell = self.sh.shell
|
self.init = 0
|
||||||
self.sh.start()
|
else:
|
||||||
print('connect ok')
|
if os.path.exists(self.sh.verifyPath):
|
||||||
|
if self.sh.filePassword == self.sh.password:
|
||||||
|
self.shell.send(str(data['data']))
|
||||||
|
|
||||||
def handleClose(self):
|
except BaseException as msg:
|
||||||
try:
|
print('%s. [WebTerminalServer.handleMessage]' % (str(msg)))
|
||||||
try:
|
|
||||||
os.remove(self.verifyPath)
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
self.running = 0
|
|
||||||
except BaseException as msg:
|
|
||||||
print('%s. [WebTerminalServer.handleClose]' % (str(msg)))
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
def on_close(self):
|
||||||
|
print('connection closed')
|
||||||
|
|
||||||
|
def check_origin(self, origin):
|
||||||
|
return True
|
||||||
|
|
||||||
|
application = tornado.web.Application([
|
||||||
|
(r'/', WSHandler),
|
||||||
|
])
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
pidfile = '/usr/local/CyberCP/WebTerminal/pid'
|
|
||||||
|
|
||||||
writeToFile = open(pidfile, 'w')
|
pidfile = '/usr/local/CyberCP/WebTerminal/pid'
|
||||||
writeToFile.write(str(os.getpid()))
|
|
||||||
writeToFile.close()
|
|
||||||
|
|
||||||
SSHServer.findSSHPort()
|
writeToFile = open(pidfile, 'w')
|
||||||
|
writeToFile.write(str(os.getpid()))
|
||||||
|
writeToFile.close()
|
||||||
|
|
||||||
print ('SSH Port is set to: %s' % (str(SSHServer.DEFAULT_PORT)))
|
http_server = tornado.httpserver.HTTPServer(application, ssl_options={
|
||||||
|
"certfile": "/usr/local/lscp/conf/cert.pem",
|
||||||
|
"keyfile": "/usr/local/lscp/conf/key.pem",
|
||||||
|
}, )
|
||||||
|
|
||||||
server = SimpleSSLWebSocketServer('0.0.0.0', '5678', WebTerminalServer, '/usr/local/lscp/conf/cert.pem', '/usr/local/lscp/conf/key.pem', version=ssl.PROTOCOL_TLSv1)
|
ADDR = '0.0.0.0'
|
||||||
|
http_server.listen(5678, ADDR)
|
||||||
|
print('*** Websocket Server Started at %s***' % ADDR)
|
||||||
|
|
||||||
def close_sig_handler(signal, frame):
|
import signal
|
||||||
server.close()
|
def close_sig_handler(signal, frame):
|
||||||
sys.exit()
|
http_server.stop()
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
print('server started')
|
signal.signal(signal.SIGINT, close_sig_handler)
|
||||||
|
|
||||||
signal.signal(signal.SIGINT, close_sig_handler)
|
tornado.ioloop.IOLoop.instance().start()
|
||||||
server.serveforever()
|
|
||||||
154
plogical/test.py
154
plogical/test.py
@@ -1,154 +0,0 @@
|
|||||||
import tornado.httpserver
|
|
||||||
import tornado.websocket
|
|
||||||
import tornado.ioloop
|
|
||||||
import tornado.web
|
|
||||||
import socket#!/usr/local/CyberCP/bin/python
|
|
||||||
import sys
|
|
||||||
import os
|
|
||||||
sys.path.append('/usr/local/CyberCP')
|
|
||||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "CyberCP.settings")
|
|
||||||
from plogical.CyberCPLogFileWriter import CyberCPLogFileWriter as logging
|
|
||||||
import paramiko
|
|
||||||
import os
|
|
||||||
import json
|
|
||||||
import threading as multi
|
|
||||||
import time
|
|
||||||
import asyncio
|
|
||||||
'''
|
|
||||||
This is a simple Websocket Echo server that uses the Tornado websocket handler.
|
|
||||||
Please run `pip install tornado` with python of version 2.7.9 or greater to install tornado.
|
|
||||||
This program will echo back the reverse of whatever it recieves.
|
|
||||||
Messages are output to the terminal for debuggin purposes.
|
|
||||||
'''
|
|
||||||
|
|
||||||
|
|
||||||
class SSHServer(multi.Thread):
|
|
||||||
OKGREEN = '\033[92m'
|
|
||||||
ENDC = '\033[0m'
|
|
||||||
|
|
||||||
DEFAULT_PORT = 22
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def findSSHPort():
|
|
||||||
try:
|
|
||||||
sshData = open('/etc/ssh/sshd_config', 'r').readlines()
|
|
||||||
|
|
||||||
for items in sshData:
|
|
||||||
if items.find('Port') > -1:
|
|
||||||
if items[0] == 0:
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
SSHServer.DEFAULT_PORT = int(items.split(' ')[1])
|
|
||||||
except BaseException as msg:
|
|
||||||
logging.writeToFile('%s. [SSHServer.findSSHPort]' % (str(msg)))
|
|
||||||
|
|
||||||
def loadPublicKey(self):
|
|
||||||
pubkey = '/root/.ssh/cyberpanel.pub'
|
|
||||||
data = open(pubkey, 'r').read()
|
|
||||||
authFile = '/root/.ssh/authorized_keys'
|
|
||||||
|
|
||||||
checker = 1
|
|
||||||
|
|
||||||
try:
|
|
||||||
authData = open(authFile, 'r').read()
|
|
||||||
if authData.find(data) > -1:
|
|
||||||
checker = 0
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
|
|
||||||
if checker:
|
|
||||||
writeToFile = open(authFile, 'a')
|
|
||||||
writeToFile.writelines(data)
|
|
||||||
writeToFile.close()
|
|
||||||
|
|
||||||
def __init__(self, websocket):
|
|
||||||
multi.Thread.__init__(self)
|
|
||||||
self.sshclient = paramiko.SSHClient()
|
|
||||||
self.sshclient.load_system_host_keys()
|
|
||||||
self.sshclient.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
||||||
k = paramiko.RSAKey.from_private_key_file('/root/.ssh/cyberpanel')
|
|
||||||
|
|
||||||
## Load Public Key
|
|
||||||
self.loadPublicKey()
|
|
||||||
|
|
||||||
self.sshclient.connect('127.0.0.1', SSHServer.DEFAULT_PORT, username='root', pkey=k)
|
|
||||||
self.shell = self.sshclient.invoke_shell(term='xterm')
|
|
||||||
self.shell.settimeout(0)
|
|
||||||
|
|
||||||
self.websocket = websocket
|
|
||||||
self.color = 0
|
|
||||||
|
|
||||||
def recvData(self):
|
|
||||||
asyncio.set_event_loop(asyncio.new_event_loop())
|
|
||||||
while True:
|
|
||||||
try:
|
|
||||||
if self.websocket.running:
|
|
||||||
if os.path.exists(self.verifyPath) and self.filePassword == self.password:
|
|
||||||
if self.shell.recv_ready():
|
|
||||||
self.websocket.write_message(self.shell.recv(9000).decode("utf-8"))
|
|
||||||
else:
|
|
||||||
time.sleep(0.001)
|
|
||||||
else:
|
|
||||||
return 0
|
|
||||||
else:
|
|
||||||
return 0
|
|
||||||
except BaseException as msg:
|
|
||||||
print('%s. [recvData]' % str(msg))
|
|
||||||
time.sleep(0.001)
|
|
||||||
|
|
||||||
def run(self):
|
|
||||||
try:
|
|
||||||
self.recvData()
|
|
||||||
except BaseException as msg:
|
|
||||||
print('%s. [SSHServer.run]' % (str(msg)))
|
|
||||||
|
|
||||||
|
|
||||||
class WSHandler(tornado.websocket.WebSocketHandler):
|
|
||||||
|
|
||||||
def open(self):
|
|
||||||
print('connected')
|
|
||||||
self.running = 1
|
|
||||||
self.sh = SSHServer(self)
|
|
||||||
self.shell = self.sh.shell
|
|
||||||
self.sh.start()
|
|
||||||
self.init = 1
|
|
||||||
print('connect ok')
|
|
||||||
|
|
||||||
def on_message(self, message):
|
|
||||||
try:
|
|
||||||
print('handle message')
|
|
||||||
data = json.loads(message)
|
|
||||||
|
|
||||||
if self.init:
|
|
||||||
self.sh.verifyPath = str(data['data']['verifyPath'])
|
|
||||||
self.sh.password = str(data['data']['password'])
|
|
||||||
self.sh.filePassword = open(self.sh.verifyPath, 'r').read()
|
|
||||||
self.init = 0
|
|
||||||
else:
|
|
||||||
if os.path.exists(self.sh.verifyPath):
|
|
||||||
if self.sh.filePassword == self.sh.password:
|
|
||||||
self.shell.send(str(data['data']))
|
|
||||||
|
|
||||||
except BaseException as msg:
|
|
||||||
print('%s. [WebTerminalServer.handleMessage]' % (str(msg)))
|
|
||||||
|
|
||||||
def on_close(self):
|
|
||||||
print('connection closed')
|
|
||||||
|
|
||||||
def check_origin(self, origin):
|
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
application = tornado.web.Application([
|
|
||||||
(r'/', WSHandler),
|
|
||||||
])
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
http_server = tornado.httpserver.HTTPServer(application, ssl_options={
|
|
||||||
"certfile": "/usr/local/lscp/conf/cert.pem",
|
|
||||||
"keyfile": "/usr/local/lscp/conf/key.pem",
|
|
||||||
}, )
|
|
||||||
ADDR = '0.0.0.0'
|
|
||||||
http_server.listen(5678, ADDR)
|
|
||||||
print('*** Websocket Server Started at %s***' % ADDR)
|
|
||||||
tornado.ioloop.IOLoop.instance().start()
|
|
||||||
@@ -52,7 +52,7 @@ PyYAML==3.10
|
|||||||
requests==2.18.4
|
requests==2.18.4
|
||||||
requests-file==1.4.3
|
requests-file==1.4.3
|
||||||
s3transfer==0.1.13
|
s3transfer==0.1.13
|
||||||
SimpleWebSocketServer==0.1.1
|
tornado==6.0.4
|
||||||
six==1.13.0
|
six==1.13.0
|
||||||
sqlparse==0.3.0
|
sqlparse==0.3.0
|
||||||
tldextract==2.2.0
|
tldextract==2.2.0
|
||||||
|
|||||||
Reference in New Issue
Block a user