22import socket
33import time
44import shlex
5- from damp11113 import TextFormatter
5+ from damp11113 import TextFormatter , sort_files , allfiles
66import cv2
77import traceback
8+ import requests
9+ from bs4 import BeautifulSoup
810
9- from PyserSSH import Server , AccountManager , Send , wait_input , wait_inputkey
11+ from PyserSSH import Server , AccountManager , Send , wait_input , wait_inputkey , wait_choose , Clear , Title
1012from PyserSSH .system .info import system_banner
1113from PyserSSH .extensions .processbar import indeterminateStatus , LoadingProgress
14+ from PyserSSH .extensions .dialog import MenuDialog , TextDialog , TextInputDialog
15+ from PyserSSH .extensions .moredisplay import clickable_url
1216
1317useraccount = AccountManager ()
1418useraccount .add_account ("admin" , "" ) # create user without password
19+ useraccount .add_account ("test" , "test" ) # create user without password
1520
1621ssh = Server (useraccount , system_commands = True , system_message = False )
1722
2227Authorizedmessage = """You have successfully connected to the server.
2328Enjoy your session and remember to follow security protocols."""
2429
30+ loading = ["PyserSSH" , "Extensions" ]
31+
2532@ssh .on_user ("connect" )
26- def connect (channel , client ):
33+ def connect (client ):
34+ Title (client , "PyserSSH" )
2735 #print(client["windowsize"])
2836 if client ['current_user' ] == "" :
2937 warningmessage = nonamewarning
3038 else :
3139 warningmessage = Authorizedmessage
3240
33-
3441 wm = f"""*********************************************************************************************
3542Hello { client ['current_user' ]} ,
3643
3744{ warningmessage }
3845
46+ Visit: { clickable_url ("https://damp11113.xyz" , "DPCloudev" )}
47+
3948{ system_banner }
4049*********************************************************************************************"""
4150
42- for char in wm :
43- Send (channel , char , ln = False )
44- time .sleep (0.005 ) # Adjust the delay as needed
45- Send (channel , '\n ' ) # Send newline after each line
51+ if client ['current_user' ] != "test" :
52+ for i in loading :
53+ P = indeterminateStatus (client , f"Starting { i } " , f"[ OK ] Started { i } " )
54+ P .start ()
55+
56+ time .sleep (len (i ) / 20 )
57+
58+ P .stop ()
59+
60+ Di1 = TextDialog (client , "PyserSSH Extension" , "Welcome!\n to PyserSSH test server" )
61+ Di1 .render ()
62+
63+ for char in wm :
64+ Send (client , char , ln = False )
65+ # time.sleep(0.005) # Adjust the delay as needed
66+ Send (client , '\n ' ) # Send newline after each line
4667
4768@ssh .on_user ("error" )
48- def error (channel , error , client ):
69+ def error (client , error ):
4970 if isinstance (error , socket .error ):
5071 pass
5172 else :
52- Send (channel , traceback .format_exc ())
73+ Send (client , traceback .format_exc ())
74+
75+
76+ #@ssh.on_user("onrawtype")
77+ #def onrawtype(client, key):
78+ # print(key)
5379
5480@ssh .on_user ("command" )
55- def command (channel , command : str , client ):
81+ def command (client , command : str ):
5682 if command == "passtest" :
57- user = wait_input (channel , "username: " )
58- password = wait_input (channel , "password: " , password = True )
59- Send (channel , f"username: { user } | password: { password } " )
83+ user = wait_input (client , "username: " )
84+ password = wait_input (client , "password: " , password = True )
85+ Send (client , f"username: { user } | password: { password } " )
6086 elif command == "colortest" :
6187 for i in range (0 , 255 , 5 ):
62- Send (channel , TextFormatter .format_text_truecolor (" " , background = f"{ i } ;0;0" ), ln = False )
63- Send (channel , "" )
88+ Send (client , TextFormatter .format_text_truecolor (" " , background = f"{ i } ;0;0" ), ln = False )
89+ Send (client , "" )
6490 for i in range (0 , 255 , 5 ):
65- Send (channel , TextFormatter .format_text_truecolor (" " , background = f"0;{ i } ;0" ), ln = False )
66- Send (channel , "" )
91+ Send (client , TextFormatter .format_text_truecolor (" " , background = f"0;{ i } ;0" ), ln = False )
92+ Send (client , "" )
6793 for i in range (0 , 255 , 5 ):
68- Send (channel , TextFormatter .format_text_truecolor (" " , background = f"0;0;{ i } " ), ln = False )
69- Send (channel , "" )
70-
71- Send (channel , "TrueColors 24-Bit" )
94+ Send (client , TextFormatter .format_text_truecolor (" " , background = f"0;0;{ i } " ), ln = False )
95+ Send (client , "" )
96+ Send (client , "TrueColors 24-Bit" )
7297 elif command == "keytest" :
73- user = wait_inputkey (channel , "press any key" , raw = True )
74- Send (channel , "" )
75- Send (channel , f"key: { user } " )
98+ user = wait_inputkey (client , "press any key" , raw = True )
99+ Send (client , "" )
100+ Send (client , f"key: { user } " )
76101 for i in range (10 ):
77- user = wait_inputkey (channel , "press any key" , raw = True )
78- Send (channel , "" )
79- Send (channel , f"key: { user } " )
102+ user = wait_inputkey (client , "press any key" , raw = True )
103+ Send (client , "" )
104+ Send (client , f"key: { user } " )
80105 elif command .startswith ("typing" ):
81106 args = shlex .split (command )
82107 messages = args [1 ]
83108 speed = float (args [2 ])
84109 for w in messages :
85- Send (channel , w , ln = False )
110+ Send (client , w , ln = False )
86111 time .sleep (speed )
87- Send (channel , "" )
88- elif command == "renimtest" :
89- image = cv2 .imread (r"opensource.png" , cv2 .IMREAD_COLOR )
112+ Send (client , "" )
113+ elif command .startswith ("renimtest" ):
114+ args = shlex .split (command )
115+ Clear (client )
116+ image = cv2 .imread (f"opensource.png" , cv2 .IMREAD_COLOR )
90117 image = cv2 .cvtColor (image , cv2 .COLOR_BGR2RGB )
91118
92- width , height = client ['windowsize' ]["width" ], client ['windowsize' ]["height" ]
119+ width , height = client ['windowsize' ]["width" ]- 5 , client ['windowsize' ]["height" ]- 5
93120
94121 # resize image
95122 resized = cv2 .resize (image , (width , height ))
123+ t = ""
96124
97125 # Scan all pixels
98126 for y in range (0 , height ):
99127 for x in range (0 , width ):
100128 pixel_color = resized [y , x ]
101- #PyserSSH.Send(channel, f"Pixel color at ({x}, {y}): {pixel_color}")
129+ # PyserSSH.Send(channel, f"Pixel color at ({x}, {y}): {pixel_color}")
102130 if pixel_color .tolist () != [0 , 0 , 0 ]:
103- Send ( channel , TextFormatter .format_text_truecolor (" " , background = f"{ pixel_color [0 ]} ;{ pixel_color [1 ]} ;{ pixel_color [2 ]} " ), ln = False )
131+ t += TextFormatter .format_text_truecolor (" " , background = f"{ pixel_color [0 ]} ;{ pixel_color [1 ]} ;{ pixel_color [2 ]} " )
104132 else :
105- Send (channel , " " , ln = False )
133+ t += " "
134+
135+ Send (client , t , ln = False )
136+ Send (client , "" )
137+ t = ""
106138
107- Send (channel , "" )
108139 elif command == "errortest" :
109140 raise Exception ("hello error" )
110141 elif command == "inloadtest" :
@@ -117,8 +148,50 @@ def command(channel, command: str, client):
117148 l .start ()
118149 for i in range (101 ):
119150 l .current = i
120- l .desc = "loading... "
151+ l .status = f "loading { i } "
121152 time .sleep (0.05 )
122153 l .stop ()
154+ elif command == "dialogtest" :
155+ Di1 = TextDialog (client , "PyserSSH Extension" , "Hello Dialog!" )
156+ Di1 .render ()
157+ elif command == "dialogtest2" :
158+ Di2 = MenuDialog (client , ["H1" , "H2" , "H3" ], "PyserSSH Extension" , "Hello world" )
159+ Di2 .render ()
160+ Send (client , f"selected index: { Di2 .output ()} " )
161+ elif command == "dialogtest3" :
162+ Di3 = TextInputDialog (client , "PyserSSH Extension" )
163+ Di3 .render ()
164+ Send (client , f"input: { Di3 .output ()} " )
165+ elif command == "passdialogtest3" :
166+ Di3 = TextInputDialog (client , "PyserSSH Extension" , inputtitle = "Password Here" , password = True )
167+ Di3 .render ()
168+ Send (client , f"password: { Di3 .output ()} " )
169+ elif command == "choosetest" :
170+ cindex = wait_choose (client , ["H1" , "H2" , "H3" ], "select: " )
171+ Send (client , f"selected index: { cindex } " )
172+ elif command .startswith ("vieweb" ):
173+ args = shlex .split (command )
174+ url = args [1 ]
175+ loading = indeterminateStatus (client , desc = f"requesting { url } ..." )
176+ loading .start ()
177+ try :
178+ content = requests .get (url ).content
179+ except :
180+ loading .stopfail ()
181+ return
182+ loading .stop ()
183+ loading = indeterminateStatus (client , desc = f"parsing html { url } ..." )
184+ loading .start ()
185+ try :
186+ soup = BeautifulSoup (content , 'html.parser' )
187+ # Extract only the text content
188+ text_content = soup .get_text ()
189+ except :
190+ loading .stopfail ()
191+ return
192+ loading .stop ()
193+ Di1 = TextDialog (client , url , text_content )
194+ Di1 .render ()
195+
123196
124- ssh .run (os .path .join (os .path .dirname (os .path .realpath (__file__ )), 'private_key.pem' ))
197+ ssh .run (os .path .join (os .path .dirname (os .path .realpath (__file__ )), 'private_key.pem' ))
0 commit comments