mirror of
https://github.com/damp11113/PyserSSH.git
synced 2025-04-27 22:48:11 +00:00
Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
b9e4bb5887 | |||
3a751972c1 | |||
a3f1b50303 | |||
64bb2b0616 |
@ -1,8 +1,6 @@
|
||||
import os
|
||||
os.environ["damp11113_load_all_module"] = "NO"
|
||||
|
||||
from damp11113.utils import TextFormatter
|
||||
from damp11113.file import sort_files, allfiles
|
||||
import socket
|
||||
import time
|
||||
import cv2
|
||||
@ -28,6 +26,63 @@ from PyserSSH.system.clientype import Client
|
||||
from PyserSSH.system.RemoteStatus import remotestatus
|
||||
from PyserSSH.utils.ServerManager import ServerManager
|
||||
|
||||
class TextFormatter:
|
||||
RESET = "\033[0m"
|
||||
TEXT_COLORS = {
|
||||
"black": "\033[30m",
|
||||
"red": "\033[31m",
|
||||
"green": "\033[32m",
|
||||
"yellow": "\033[33m",
|
||||
"blue": "\033[34m",
|
||||
"magenta": "\033[35m",
|
||||
"cyan": "\033[36m",
|
||||
"white": "\033[37m"
|
||||
}
|
||||
TEXT_COLOR_LEVELS = {
|
||||
"light": "\033[1;{}m", # Light color prefix
|
||||
"dark": "\033[2;{}m" # Dark color prefix
|
||||
}
|
||||
BACKGROUND_COLORS = {
|
||||
"black": "\033[40m",
|
||||
"red": "\033[41m",
|
||||
"green": "\033[42m",
|
||||
"yellow": "\033[43m",
|
||||
"blue": "\033[44m",
|
||||
"magenta": "\033[45m",
|
||||
"cyan": "\033[46m",
|
||||
"white": "\033[47m"
|
||||
}
|
||||
TEXT_ATTRIBUTES = {
|
||||
"bold": "\033[1m",
|
||||
"italic": "\033[3m",
|
||||
"underline": "\033[4m",
|
||||
"blink": "\033[5m",
|
||||
"reverse": "\033[7m",
|
||||
"strikethrough": "\033[9m"
|
||||
}
|
||||
|
||||
@staticmethod
|
||||
def format_text_truecolor(text, color=None, background=None, attributes=None, target_text=''):
|
||||
formatted_text = ""
|
||||
start_index = text.find(target_text)
|
||||
end_index = start_index + len(target_text) if start_index != -1 else len(text)
|
||||
|
||||
if color:
|
||||
formatted_text += f"\033[38;2;{color}m"
|
||||
|
||||
if background:
|
||||
formatted_text += f"\033[48;2;{background}m"
|
||||
|
||||
if attributes in TextFormatter.TEXT_ATTRIBUTES:
|
||||
formatted_text += TextFormatter.TEXT_ATTRIBUTES[attributes]
|
||||
|
||||
if target_text == "":
|
||||
formatted_text += text + TextFormatter.RESET
|
||||
else:
|
||||
formatted_text += text[:start_index] + text[start_index:end_index] + TextFormatter.RESET + text[end_index:]
|
||||
|
||||
return formatted_text
|
||||
|
||||
useraccount = AccountManager(allow_guest=True, autoload=True, autosave=True)
|
||||
|
||||
if not os.path.isfile("autosave_session.ses"):
|
||||
|
5
setup.py
5
setup.py
@ -2,7 +2,7 @@ from setuptools import setup, find_packages
|
||||
|
||||
setup(
|
||||
name='PyserSSH',
|
||||
version='5.1',
|
||||
version='5.1.4',
|
||||
license='MIT',
|
||||
author='DPSoftware Foundation',
|
||||
author_email='contact@damp11113.xyz',
|
||||
@ -37,7 +37,8 @@ setup(
|
||||
"keyboard",
|
||||
"Brotli",
|
||||
"pillow",
|
||||
"numpy"
|
||||
"numpy",
|
||||
"opencv-python"
|
||||
],
|
||||
}
|
||||
)
|
@ -240,8 +240,14 @@ class Server:
|
||||
if echo:
|
||||
channel.send(replace_enter_with_crlf(self.client_handlers[channel.getpeername()]["prompt"] + " "))
|
||||
|
||||
while True:
|
||||
expect(self, self.client_handlers[channel.getpeername()], echo)
|
||||
isConnect = True
|
||||
|
||||
while isConnect:
|
||||
isConnect = expect(self, self.client_handlers[channel.getpeername()], echo)
|
||||
|
||||
self._handle_event("disconnected", self.client_handlers[peername])
|
||||
channel.close()
|
||||
bh_session.close()
|
||||
except KeyboardInterrupt:
|
||||
self._handle_event("disconnected", self.client_handlers[peername])
|
||||
channel.close()
|
||||
@ -252,6 +258,7 @@ class Server:
|
||||
finally:
|
||||
self._handle_event("disconnected", self.client_handlers[peername])
|
||||
channel.close()
|
||||
bh_session.close()
|
||||
else:
|
||||
if self.sftpena:
|
||||
logger.info("user is sftp")
|
||||
|
@ -25,7 +25,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
"""
|
||||
|
||||
import serial
|
||||
#import serial
|
||||
import socket
|
||||
import paramiko
|
||||
from abc import ABC, abstractmethod
|
||||
|
@ -25,7 +25,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
"""
|
||||
|
||||
version = "5.1"
|
||||
version = "5.1.4"
|
||||
|
||||
system_banner = (
|
||||
f"\033[36mPyserSSH V{version} \033[0m"
|
||||
|
@ -212,8 +212,7 @@ def expect(self, client, echo=True):
|
||||
finally:
|
||||
try:
|
||||
if not byte:
|
||||
logger.info(f"{peername} is disconnected")
|
||||
self._handle_event("disconnected", self.client_handlers[peername])
|
||||
return False
|
||||
return True
|
||||
except:
|
||||
logger.info(f"{peername} is disconnected")
|
||||
self._handle_event("disconnected", self.client_handlers[peername])
|
||||
return False
|
@ -42,11 +42,12 @@ if platform.system() == "Windows":
|
||||
|
||||
logger = logging.getLogger("PyserSSH.RemoteStatus")
|
||||
|
||||
class LASTINPUTINFO(ctypes.Structure):
|
||||
_fields_ = [
|
||||
('cbSize', ctypes.c_uint),
|
||||
('dwTime', ctypes.c_uint),
|
||||
]
|
||||
if platform.system() == "Windows":
|
||||
class LASTINPUTINFO(ctypes.Structure):
|
||||
_fields_ = [
|
||||
('cbSize', ctypes.c_uint),
|
||||
('dwTime', ctypes.c_uint),
|
||||
]
|
||||
|
||||
def get_idle_time():
|
||||
if platform.system() == "Windows":
|
||||
|
38
src/PyserSSH/utils/__init__.py
Normal file
38
src/PyserSSH/utils/__init__.py
Normal file
@ -0,0 +1,38 @@
|
||||
"""
|
||||
PyserSSH - A Scriptable SSH server. For more info visit https://github.com/DPSoftware-Foundation/PyserSSH
|
||||
Copyright (C) 2023-present DPSoftware Foundation (MIT)
|
||||
|
||||
Visit https://github.com/DPSoftware-Foundation/PyserSSH
|
||||
|
||||
MIT License
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
"""
|
||||
|
||||
"""
|
||||
note
|
||||
|
||||
ansi cursor arrow
|
||||
up - \x1b[A
|
||||
down - \x1b[B
|
||||
left - \x1b[D
|
||||
right - \x1b[C
|
||||
|
||||
https://en.wikipedia.org/wiki/ANSI_escape_code
|
||||
"""
|
@ -9,4 +9,5 @@ python setup.py sdist
|
||||
title uploading to pypi
|
||||
twine upload -r pypi dist/*
|
||||
|
||||
title done!
|
||||
pause
|
Loading…
x
Reference in New Issue
Block a user