Guest User

WebServer

a guest
Mar 18th, 2019
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.84 KB | None | 0 0
  1. import subprocess
  2. import cherrypy
  3.  
  4. WEBHOOK_PORT = 8443  # 443, 80, 88 или 8443
  5. WEBHOOK_LISTEN = '0.0.0.0'  # Слушаем отовсюду
  6. #WEBHOOK_SSL_CERT = 'webhook_cert.pem'  # Путь к сертификату
  7. #WEBHOOK_SSL_PRIV = 'webhook_pkey.pem'  # Путь к закрытому ключу
  8.  
  9. class WebServer(object):
  10.     @cherrypy.expose
  11.     def winbox(self,ip,login,pswd):
  12.         ip = ip.strip()
  13.         login = login.strip()
  14.         pswd = pswd.strip()
  15.         if not ip:
  16.             return "Please give an ip address... ;-)"
  17.  
  18.         data = ["c:/dev/winbox/winbox.exe", ip, login, pswd]
  19.         subprocess.Popen(data, shell=False, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, creationflags = 0x00000008)
  20.         return 'Starting winbox to ' + ip
  21.  
  22.     @cherrypy.expose
  23.     def ssh(self,ip,login,pswd):
  24.         ip = ip.strip()
  25.         login = login.strip()
  26.         pswd = pswd.strip()
  27.         if not ip:
  28.             return "Please give an ip address... ;-)"
  29.  
  30.         cmd = "c:/dev/putty/putty.exe -ssh "
  31.         if login:
  32.             cmd = cmd + login + "@"
  33.         cmd = cmd + ip
  34.         if pswd:
  35.             cmd = cmd + " -pw " + pswd
  36.         subprocess.Popen(cmd, shell=False, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, creationflags = 0x00000008)
  37.         return "Starting ssh to " + ip
  38.            
  39.     @cherrypy.expose
  40.     def index(self):
  41.         return "Hello world"
  42.  
  43. if __name__ == '__main__':
  44.     cherrypy.config.update({
  45.         'server.socket_host': WEBHOOK_LISTEN,
  46.         'server.socket_port': WEBHOOK_PORT,
  47.         'server.ssl_module': 'builtin',
  48.         #'server.ssl_certificate': WEBHOOK_SSL_CERT,
  49.         #'server.ssl_private_key': WEBHOOK_SSL_PRIV,
  50.         'engine.autoreload.on': False
  51.     })
  52.     cherrypy.quickstart(WebServer(), '/', {'/': {}})
Advertisement
Add Comment
Please, Sign In to add comment