Ejemplo n.º 1
0
class exe_dialog(QDialog):

    def __init__(self,username,hostname,password):
        super().__init__()
        self.resize(280,40)
        self.setWindowTitle("正在运行")
        self.tip = QLabel("程序正在进行...请不要关闭此窗口",self)
        self.show()
        self.exe(username,hostname,password)


    def exe(self,username, hostname, password):
        self.conn = SSHConnection(username, hostname, password)
        self.conn.exec_command('python3 /home/pi/Project/data_create.py')
Ejemplo n.º 2
0
def executeCommand(host, command, hostname):
    c = SSHConnection(host, "root", "")
    response = c.connectWithoutPass(
        "/usr/share/controlies-ltspserver/.ssh/id_rsa")

    try:
        WS.websocket_send(
            'http://ldap:8888', '<span style="font-size:14pt;">' + hostname +
            '</span> > <span style="font-size:10pt;">' + command +
            '</span><br>', 'mykey', 'mygroup')
    except:
        #return dict(response="fail", host=host, message="No se pudo conectar con el servidor websocket.<br/>")
        print "no_websocket"
        sys.exit(0)

    if response != True:
        print "no_ssh"
        sys.exit(0)
        #return dict(response="fail", host=host, message="No se pudo conectar. ¿Está encendido el equipo? ¿Has establecido la relación de confianza?<br/>")

    channel = c.exec_command(command)
    import select

    while True:
        if channel.exit_status_ready():
            break
        rl, wl, xl = select.select([channel], [], [], 0.0)
        if len(rl) > 0:

            stdout_data = []
            try:
                part = channel.recv(4096)
                while part:
                    stdout_data.append(part)
                    part = channel.recv(4096)
            except:
                raise

            complete = ''.join(stdout_data)

            n = 500
            pieces = [complete[i:i + n] for i in range(0, len(complete), n)]

            HTML_PARSER = ansi2html()
            for i in pieces:
                html = HTML_PARSER.parse(i)
                try:
                    WS.websocket_send('http://ldap:8888', html, 'mykey',
                                      'mygroup')
                except:
                    pass

    channel.close()
    c.close()
Ejemplo n.º 3
0
def executeCommand(host, command, hostname):
	c = SSHConnection(host,"root","")
	response = c.connectWithoutPass("/usr/share/controlies-ltspserver/.ssh/id_rsa")

	try:
		WS.websocket_send('http://ldap:8888','<span style="font-size:14pt;">'+hostname+'</span> > <span style="font-size:10pt;">'+command+'</span><br>','mykey','mygroup')
	except:
		#return dict(response="fail", host=host, message="No se pudo conectar con el servidor websocket.<br/>")
		print "no_websocket"
		sys.exit(0)
	    
	if response != True:
		print "no_ssh"
		sys.exit(0)
		#return dict(response="fail", host=host, message="No se pudo conectar. ¿Está encendido el equipo? ¿Has establecido la relación de confianza?<br/>")

	channel = c.exec_command(command)
	import select

	while True:
		if channel.exit_status_ready():
			break
		rl, wl, xl = select.select([channel], [], [], 0.0)
		if len(rl) > 0:

			stdout_data = []
			try:
			    part = channel.recv(4096)
			    while part:
				stdout_data.append(part)
				part = channel.recv(4096)
			except:
			    raise

			complete = ''.join(stdout_data)

			n = 500
			pieces = [complete[i:i+n] for i in range(0, len(complete), n)]

			HTML_PARSER = ansi2html()
			for i in pieces:
				html = HTML_PARSER.parse(i)			
				try:        
					WS.websocket_send('http://ldap:8888',html,'mykey','mygroup')
				except:
					pass

	channel.close()
	c.close()