Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- #coding: utf-8
- #################
- ### MODIFY ME ###
- #################
- PORT = 7777
- PASS = 'goodpass'
- HOST = 'localhost'
- #################
- ### --------- ###
- #################
- import sys, os
- try:
- import dialog
- except:
- print "python-dialog is missing"
- sys.exit(1)
- import socket
- import time, datetime
- from threading import Thread
- import string
- class main:
- def __init__(self):
- self.FILE = file('telnet', 'a')
- self.run = 1
- self.clones = [('Back', 'Back to main menu')]
- try:
- self.start()
- except dialog.error, exc_instance:
- sys.stderr.write("Error:\n\n%s\n" % exc_instance.complete_message())
- self.exit(1)
- def start(self):
- self.d = dialog.Dialog(dialog="dialog")
- self.d.add_persistent_args(["--backtitle", "PyMuhstik"])
- self.s = self.connect()
- do_list = Thread(None, self.listing, None)
- do_list.start()
- while 1:
- choice = self.main()
- if choice == 'Clones':
- selected = self.cloneslist()
- elif choice == 'Actions':
- action = self.actionlist()
- else:
- self.exit()
- def exit(self, n=0):
- self.run = 0
- self.FILE.close()
- self.s.close()
- sys.exit(n)
- def connect(self):
- self.d.gauge_start("Creating socket...", title="Connection to Muhstik")
- s = socket.socket()
- self.d.gauge_update(33, "Connecting to %s port:%s" % (HOST, PORT), update_text=1)
- try:
- s.connect((HOST, PORT))
- except socket.error:
- self.d.gauge_stop()
- self.d.msgbox("Can't connect to muhstik, make sure it's currently running.")
- self.exit(1)
- time.sleep(2)
- self.d.gauge_update(90, "Connection successfull, sending authentification", update_text=1)
- s.send("%s\r\n" % PASS)
- time.sleep(0.3)
- self.d.gauge_update(100, "Done.", update_text=1)
- time.sleep(1)
- self.d.gauge_stop()
- return s
- def main(self):
- while 1:
- (code, tag) = self.d.menu(
- "Main menu",
- width=40,
- choices=[("Clones", "Availables clones"),
- ("Actions", ""),
- ("Quit", ""),]
- )
- if self.handle_exit_code(code):
- break
- return tag
- def cloneslist(self):
- while 1:
- (code, tag) = self.d.menu(
- "Clones list",
- width=60,
- choices=self.clones
- )
- if self.handle_exit_code(code):
- break
- return tag
- def listing(self):
- self.s.send('PyMuhstik')
- readbuffer = ''
- while self.run:
- readbuffer=readbuffer+self.s.recv(1024)
- temp=string.split(readbuffer, "\n")
- readbuffer=temp.pop( )
- for line in temp:
- line=string.rstrip(line)
- line=string.split(line)
- self.FILE.write(line)
- def handle_exit_code(self, code):
- if code in (self.d.DIALOG_CANCEL, self.d.DIALOG_ESC):
- if code == self.d.DIALOG_ESC:
- if self.d.yesno('Do you really want to quit ?') == self.d.DIALOG_OK:
- self.exit(0)
- else:
- return 0
- else:
- return 1
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement