예제 #1
0
파일: server.py 프로젝트: xkortex/reveriesh
 def run_forever(self):
     self.socket_create()
     self.socket_bind()
     while True:
         self.accept()
         try:
             self.run_once()
         except BrokenPipeError:
             print(ascii_format('Broken pipe, restarting', 93))
         except EOFError:
             print(ascii_format('EOF/Broken pipe, restarting', 93))
         finally:
             print(ascii_format('...', 93))
예제 #2
0
    def run_cmd(commandstr):
        cmd = subprocess.Popen(shlex.split(commandstr),
                               shell=True,
                               stdout=subprocess.PIPE,
                               stderr=subprocess.PIPE,
                               stdin=subprocess.PIPE)
        out = cmd.stdout.read()
        err = cmd.stderr.read()

        if err:
            print(ascii_format(err.decode(), 91))
        print(ascii_format(out.decode()))
        # output_str = str(output_bytes, "utf-8")
        # sock.send(str.encode(output_str + str(os.getcwd()) + '> '))
        # print(output_str)
        return ShellRunner.pack_dict(out, err)
예제 #3
0
 def receive_commands(self):
     data = self.sock.recv(1024)
     if data == SIG_REVERIESH.KILL:
         self.quit()
     if data == SIG_REVERIESH.PROMPT:
         self.sock.send(ShellRunner.pack_dict())
         return True
     print(ascii_format(data.decode(), 100))
     infodata = ShellRunner.cmd(data)
     self.sock.send(infodata)
     return True
예제 #4
0
파일: server.py 프로젝트: xkortex/reveriesh
    def send_commands(self):
            cmd = input()
            if cmd == 'quit':
                self.quit()
            if len(str.encode(cmd)) > 0:
                self.conn.send(cmd.encode())
                data = self.conn.recv(1024)
                info = self.unmarshall(data)
                if info.get('err', None):
                    print(ascii_format(info['err'].decode(), 'red'))
                if info.get('out', None):
                    print(info['out'].decode(), end='')
                print(info['prompt'].decode(), end='')

            else:
                self.prompt()
예제 #5
0
 def fmt_prompt():
     # type: () -> bytes
     s = '\n{host}:{cwd}> '.format(host=socket.gethostname(),
                                   cwd=os.getcwd())
     return ascii_format(s, 42).encode()
예제 #6
0
 def quit(self, code=0):
     self.close()
     print(ascii_format("buh-bye", 45))
     sys.exit(code)