11import os
2+ os .environ ["damp11113_load_all_module" ] = "NO"
3+
4+ from damp11113 .utils import TextFormatter
5+ from damp11113 .file import sort_files , allfiles
26import socket
37import time
48import cv2
59import traceback
610import requests
711from bs4 import BeautifulSoup
812import numpy as np
13+ import logging
914
10- #import logging
11- # logging.basicConfig(level=logging.DEBUG)
15+ # Configure logging
16+ logging .basicConfig (format = '[{asctime}] [{levelname}] {name}: {message}' , datefmt = '%Y-%m-%d %H:%M:%S' , style = '{' , level = logging .DEBUG )
1217
1318from PyserSSH import Server , AccountManager
14- from PyserSSH .interactive import Send , wait_input , wait_inputkey , wait_choose , Clear , wait_inputmouse
15- from PyserSSH .system .info import __version__ , Flag_TH
19+ from PyserSSH .interactive import Send , wait_input , wait_inputkey , wait_choose , Clear , wait_inputmouse
20+ from PyserSSH .system .info import version , Flag_TH
1621from PyserSSH .extensions .processbar import indeterminateStatus , LoadingProgress
1722from PyserSSH .extensions .dialog import MenuDialog , TextDialog , TextInputDialog
1823from PyserSSH .extensions .moredisplay import clickable_url , Send_karaoke_effect
1924from PyserSSH .extensions .moreinteractive import ShowCursor
2025from PyserSSH .extensions .remodesk import RemoDesk
2126from PyserSSH .extensions .XHandler import XHandler
2227from PyserSSH .system .clientype import Client
23- from PyserSSH .system .remotestatus import remotestatus
28+ from PyserSSH .system .RemoteStatus import remotestatus
29+ from PyserSSH .utils .ServerManager import ServerManager
30+
31+ useraccount = AccountManager (allow_guest = True , autoload = True , autosave = True )
2432
25- useraccount = AccountManager ( allow_guest = True )
26- useraccount .add_account ("admin" , "" ) # create user without password
27- useraccount .add_account ("test" , "test" ) # create user without password
28- useraccount .add_account ("demo" )
29- useraccount .add_account ("remote" , "12345" , permissions = ["remote_desktop" ])
30- useraccount .set_user_enable_inputsystem_echo ("remote" , False )
31- useraccount .set_user_sftp_allow ("admin" , True )
33+ if not os . path . isfile ( "autosave_session.ses" ):
34+ useraccount .add_account ("admin" , "" , sudo = True ) # create user without password
35+ useraccount .add_account ("test" , "test" ) # create user without password
36+ useraccount .add_account ("demo" )
37+ useraccount .add_account ("remote" , "12345" , permissions = ["remote_desktop" ])
38+ useraccount .set_user_enable_inputsystem_echo ("remote" , False )
39+ useraccount .set_user_sftp_allow ("admin" , True )
3240
3341XH = XHandler ()
3442ssh = Server (useraccount ,
4250
4351servername = "PyserSSH"
4452
45- loading = ["PyserSSH" , "Extensions" ]
46-
47- class TextFormatter :
48- RESET = "\033 [0m"
49- TEXT_COLORS = {
50- "black" : "\033 [30m" ,
51- "red" : "\033 [31m" ,
52- "green" : "\033 [32m" ,
53- "yellow" : "\033 [33m" ,
54- "blue" : "\033 [34m" ,
55- "magenta" : "\033 [35m" ,
56- "cyan" : "\033 [36m" ,
57- "white" : "\033 [37m"
58- }
59- TEXT_COLOR_LEVELS = {
60- "light" : "\033 [1;{}m" , # Light color prefix
61- "dark" : "\033 [2;{}m" # Dark color prefix
62- }
63- BACKGROUND_COLORS = {
64- "black" : "\033 [40m" ,
65- "red" : "\033 [41m" ,
66- "green" : "\033 [42m" ,
67- "yellow" : "\033 [43m" ,
68- "blue" : "\033 [44m" ,
69- "magenta" : "\033 [45m" ,
70- "cyan" : "\033 [46m" ,
71- "white" : "\033 [47m"
72- }
73- TEXT_ATTRIBUTES = {
74- "bold" : "\033 [1m" ,
75- "italic" : "\033 [3m" ,
76- "underline" : "\033 [4m" ,
77- "blink" : "\033 [5m" ,
78- "reverse" : "\033 [7m" ,
79- "strikethrough" : "\033 [9m"
80- }
81-
82- @staticmethod
83- def format_text_truecolor (text , color = None , background = None , attributes = None , target_text = '' ):
84- formatted_text = ""
85- start_index = text .find (target_text )
86- end_index = start_index + len (target_text ) if start_index != - 1 else len (text )
87-
88- if color :
89- formatted_text += f"\033 [38;2;{ color } m"
90-
91- if background :
92- formatted_text += f"\033 [48;2;{ background } m"
93-
94- if attributes in TextFormatter .TEXT_ATTRIBUTES :
95- formatted_text += TextFormatter .TEXT_ATTRIBUTES [attributes ]
96-
97- if target_text == "" :
98- formatted_text += text + TextFormatter .RESET
99- else :
100- formatted_text += text [:start_index ] + text [start_index :end_index ] + TextFormatter .RESET + text [end_index :]
101-
102- return formatted_text
53+ loading = ["PyserSSH" , "openRemoDesk" , "XHandler" , "RemoteStatus" ]
10354
10455@ssh .on_user ("pre-shell" )
10556def guestauth (client ):
@@ -185,7 +136,7 @@ def connect(client):
185136 wm = f"""{ Flag_TH ()} { '–' * 50 }
186137Hello { client ['current_user' ]} ,
187138
188- This is testing server of PyserSSH v{ __version__ } .
139+ This is testing server of PyserSSH v{ version } .
189140
190141Visit: { clickable_url ("https://damp11113.xyz" , "DPCloudev" )}
191142{ '–' * 50 } """
@@ -258,9 +209,9 @@ def xh_typing(client: Client, messages, speed = 1):
258209 Send (client , "" )
259210
260211@XH .command (name = "renimtest" )
261- def xh_renimtest (client : Client , path : str ):
212+ def xh_renimtest (client : Client ):
262213 Clear (client )
263- image = cv2 .imread (f "opensource.png" , cv2 .IMREAD_COLOR )
214+ image = cv2 .imread ("opensource.png" , cv2 .IMREAD_COLOR )
264215 image = cv2 .cvtColor (image , cv2 .COLOR_BGR2RGB )
265216
266217 width , height = client ['windowsize' ]["width" ] - 5 , client ['windowsize' ]["height" ] - 5
@@ -458,12 +409,14 @@ def xh_status(client: Client):
458409#@ssh.on_user("command")
459410#def command(client: Client, command: str):
460411
461- ssh .run (os .path .join (os .path .dirname (os .path .realpath (__file__ )), 'private_key.pem' ))
412+ # ssh.run(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'private_key.pem'))
462413
463- # manager = ServerManager()
414+ manager = ServerManager ()
464415
465416# Add servers to the manager
466- #manager.add_server("server1", server1)
417+ manager .add_server ("ssh" , ssh , os .path .join (os .path .dirname (os .path .realpath (__file__ )), 'private_key.pem' ))
418+ manager .add_server ("telnet" , ssh , "" , protocol = "telnet" )
467419
468420# Start a specific server
469- #manager.start_server("server1", private_key_path="key")
421+ manager .start_server ("ssh" )
422+ manager .start_server ("telnet" )
0 commit comments