Skip to content

Commit f33be3b

Browse files
committed
4.4
no demo folder but it on library python -m PyserSSH
1 parent 79353cf commit f33be3b

14 files changed

Lines changed: 233 additions & 125 deletions

File tree

README.md

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ This project is part from [damp11113-library](https://github.com/damp11113/damp1
66

77
This Server use port **2222** for default port
88

9+
> [!WARNING]
10+
> For use in product please **generate new private key**! If you still use this demo private key maybe your product getting **hacked**! up to 90%. Please don't use this demo private key for real product.
11+
912
# Install
1013
Install from pypi
1114
```bash
@@ -40,11 +43,25 @@ If you input `hello` the response is `world`
4043
# Demo
4144
https://github.com/damp11113/PyserSSH/assets/64675096/49bef3e2-3b15-4b64-b88e-3ca84a955de7
4245

43-
See [server.py](https://github.com/damp11113/PyserSSH/blob/main/demo/server.py)
46+
For run this demo you can use this command
47+
```
48+
$ python -m PyserSSH
49+
```
50+
then
51+
```
52+
Do you want to run demo? (y/n): y
53+
```
54+
But if no [damp11113-library](https://github.com/damp11113/damp11113-library)
55+
```
56+
No 'damp11113-library'
57+
This demo is require 'damp11113-library' for run
58+
```
59+
you need to install [damp11113-library](https://github.com/damp11113/damp11113-library) for run this demo by choose `y` or `yes` in lowercase or uppercase
60+
```
61+
Do you want to install 'damp11113-library'? (y/n): y
62+
```
63+
For exit demo you can use `ctrl+c` or use `shutdown now` in PyserSSH shell **(not in real terminal)**
4464

4565
I intend to leaked private key because that key i generated new. I recommend to generate new key if you want to use on your host because that key is for demo only.
4666
why i talk about this? because when i push private key into this repo in next 5 min++ i getting new email from GitGuardian. in that email say "
47-
GitGuardian has detected the following RSA Private Key exposed within your GitHub account" i dont knows what is GitGuardian and i not install this app into my account.
48-
49-
50-
67+
GitGuardian has detected the following RSA Private Key exposed within your GitHub account" i dont knows what is GitGuardian and i not install this app into my account.

demo/private_key.pem

Lines changed: 0 additions & 27 deletions
This file was deleted.

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
setup(
77
name='PyserSSH',
8-
version='4.3',
8+
version='4.4',
99
license='MIT',
1010
author='damp11113',
1111
author_email='[email protected]',

src/PyserSSH/__init__.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,10 @@
4242
from .interactive import *
4343
from .server import Server
4444
from .account import AccountManager
45-
from .system.info import system_banner
4645

4746

47+
from .system.info import system_banner
48+
4849
try:
4950
os.environ["pyserssh_systemmessage"]
5051
except:
@@ -66,3 +67,10 @@
6667

6768
if os.environ["pyserssh_systemmessage"] == "YES":
6869
print(system_banner)
70+
71+
if __name__ == "__main__":
72+
stadem = input("Do you want to run demo? (y/n): ")
73+
if stadem.upper() in ["Y", "YES"]:
74+
from .demo import demo1
75+
else:
76+
exit()

src/PyserSSH/account.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ def __autosave(self):
6060
self.save("autosave_session.ses")
6161
self.__autosaveworknexttime = time.time() + self.autosavedelay
6262

63+
time.sleep(1) # fix cpu load
64+
6365
def __saveexit(self):
6466
self.__autosavework = False
6567
self.save("autosave_session.ses")
@@ -140,6 +142,15 @@ def get_user_sftp_path(self, username):
140142
return self.accounts[username]["sftp_path"]
141143
return ""
142144

145+
def set_banner(self, username, banner):
146+
if username in self.accounts:
147+
self.accounts[username]["banner"] = banner
148+
149+
def get_banner(self, username):
150+
if username in self.accounts and "banner" in self.accounts[username]:
151+
return self.accounts[username]["banner"]
152+
return None
153+
143154
def get_user_timeout(self, username):
144155
if username in self.accounts and "timeout" in self.accounts[username]:
145156
return self.accounts[username]["timeout"]

src/PyserSSH/demo/__init__.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
"""
2+
PyserSSH - A Scriptable SSH server. For more info visit https://github.com/damp11113/PyserSSH
3+
Copyright (C) 2023-2024 damp11113 (MIT)
4+
5+
Visit https://github.com/damp11113/PyserSSH
6+
7+
MIT License
8+
9+
Permission is hereby granted, free of charge, to any person obtaining a copy
10+
of this software and associated documentation files (the "Software"), to deal
11+
in the Software without restriction, including without limitation the rights
12+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13+
copies of the Software, and to permit persons to whom the Software is
14+
furnished to do so, subject to the following conditions:
15+
16+
The above copyright notice and this permission notice shall be included in all
17+
copies or substantial portions of the Software.
18+
19+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25+
SOFTWARE.
26+
"""
27+
28+
"""
29+
note
30+
31+
ansi cursor arrow
32+
up - \x1b[A
33+
down - \x1b[B
34+
left - \x1b[D
35+
right - \x1b[C
36+
37+
https://en.wikipedia.org/wiki/ANSI_escape_code
38+
"""

demo/server.py renamed to src/PyserSSH/demo/demo1.py

Lines changed: 48 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -2,68 +2,72 @@
22
import socket
33
import time
44
import shlex
5-
from damp11113 import TextFormatter, sort_files, allfiles
65
import cv2
76
import traceback
87
import requests
98
from bs4 import BeautifulSoup
10-
11-
from PyserSSH import Server, AccountManager, Send, wait_input, wait_inputkey, wait_choose, Clear, Title
12-
from PyserSSH.system.info import system_banner
13-
from PyserSSH.extensions.processbar import indeterminateStatus, LoadingProgress
14-
from PyserSSH.extensions.dialog import MenuDialog, TextDialog, TextInputDialog
15-
from PyserSSH.extensions.moredisplay import clickable_url
9+
import pyfiglet
10+
11+
from ..server import Server
12+
from ..account import AccountManager
13+
from ..interactive import Send, Clear, wait_input, wait_inputkey, wait_choose
14+
from ..system.info import system_banner, __version__
15+
from ..extensions.processbar import (indeterminateStatus, LoadingProgress)
16+
from ..extensions.dialog import MenuDialog, TextDialog, TextInputDialog
17+
from ..extensions.moredisplay import clickable_url
18+
19+
try:
20+
from damp11113 import TextFormatter
21+
except:
22+
print("No 'damp11113-library'")
23+
print("This demo is require 'damp11113-library' for run")
24+
ins = input("Do you want to install 'damp11113-library'? (y/n): ")
25+
if ins.upper() in ["Y", "YES"]:
26+
import pip
27+
pip.main(["install", "damp11113"])
28+
from damp11113 import TextFormatter
29+
else:
30+
exit()
1631

1732
useraccount = AccountManager()
1833
useraccount.add_account("admin", "") # create user without password
19-
useraccount.add_account("test", "test") # create user without password
20-
21-
ssh = Server(useraccount, system_commands=True, system_message=False)
2234

23-
nonamewarning = """Connection Warning:
24-
Unauthorized access or improper use of this system is prohibited.
25-
Please ensure you have proper authorization before proceeding."""
26-
27-
Authorizedmessage = """You have successfully connected to the server.
28-
Enjoy your session and remember to follow security protocols."""
35+
ssh = Server(useraccount, system_commands=True, system_message=False, sftp=False)
2936

3037
loading = ["PyserSSH", "Extensions"]
3138

39+
print("you connect to this demo using 'ssh admin@localhost -p 2222' (no password)")
40+
print("command list: passtest, colortest, typing <speed> <text>, renimtest, errortest, inloadtest, loadtest, dialogtest, dialogtest2, dialogtest3, passdialogtest3, choosetest, vieweb <url>, shutdown now")
41+
print("Do not you this demo private key for real production")
42+
3243
@ssh.on_user("connect")
3344
def connect(client):
34-
Title(client, "PyserSSH")
35-
#print(client["windowsize"])
36-
if client['current_user'] == "":
37-
warningmessage = nonamewarning
38-
else:
39-
warningmessage = Authorizedmessage
40-
41-
wm = f"""*********************************************************************************************
45+
wm = f"""{pyfiglet.figlet_format('PyserSSH', font='usaflag', width=client["windowsize"]["width"])}*********************************************************************************************
4246
Hello {client['current_user']},
4347
44-
{warningmessage}
48+
This is the testing server of PyserSSH v{__version__}.
49+
For use in product please use new private key.
4550
4651
Visit: {clickable_url("https://damp11113.xyz", "DPCloudev")}
4752
4853
{system_banner}
4954
*********************************************************************************************"""
5055

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()
56+
for i in loading:
57+
P = indeterminateStatus(client, f"Starting {i}", f"[ OK ] Started {i}")
58+
P.start()
5559

56-
time.sleep(len(i) / 20)
60+
time.sleep(len(i) / 20)
5761

58-
P.stop()
62+
P.stop()
5963

60-
Di1 = TextDialog(client, "PyserSSH Extension", "Welcome!\n to PyserSSH test server")
61-
Di1.render()
64+
Di1 = TextDialog(client, "PyserSSH Extension", "Welcome!\n to PyserSSH test server")
65+
Di1.render()
6266

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
67+
for char in wm:
68+
Send(client, char, ln=False)
69+
# time.sleep(0.005) # Adjust the delay as needed
70+
Send(client, '\n') # Send newline after each line
6771

6872
@ssh.on_user("error")
6973
def error(client, error):
@@ -72,7 +76,6 @@ def error(client, error):
7276
else:
7377
Send(client, traceback.format_exc())
7478

75-
7679
#@ssh.on_user("onrawtype")
7780
#def onrawtype(client, key):
7881
# print(key)
@@ -95,11 +98,11 @@ def command(client, command: str):
9598
Send(client, "")
9699
Send(client, "TrueColors 24-Bit")
97100
elif command == "keytest":
98-
user = wait_inputkey(client, "press any key", raw=True)
101+
user = wait_inputkey(client, "press any key", raw=True, timeout=1)
99102
Send(client, "")
100103
Send(client, f"key: {user}")
101104
for i in range(10):
102-
user = wait_inputkey(client, "press any key", raw=True)
105+
user = wait_inputkey(client, "press any key", raw=True, timeout=1)
103106
Send(client, "")
104107
Send(client, f"key: {user}")
105108
elif command.startswith("typing"):
@@ -110,10 +113,9 @@ def command(client, command: str):
110113
Send(client, w, ln=False)
111114
time.sleep(speed)
112115
Send(client, "")
113-
elif command.startswith("renimtest"):
114-
args = shlex.split(command)
116+
elif command == "renimtest":
115117
Clear(client)
116-
image = cv2.imread(f"opensource.png", cv2.IMREAD_COLOR)
118+
image = cv2.imread(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'opensource.png'), cv2.IMREAD_COLOR)
117119
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
118120

119121
width, height = client['windowsize']["width"]-5, client['windowsize']["height"]-5
@@ -126,7 +128,6 @@ def command(client, command: str):
126128
for y in range(0, height):
127129
for x in range(0, width):
128130
pixel_color = resized[y, x]
129-
# PyserSSH.Send(channel, f"Pixel color at ({x}, {y}): {pixel_color}")
130131
if pixel_color.tolist() != [0, 0, 0]:
131132
t += TextFormatter.format_text_truecolor(" ", background=f"{pixel_color[0]};{pixel_color[1]};{pixel_color[2]}")
132133
else:
@@ -192,6 +193,7 @@ def command(client, command: str):
192193
loading.stop()
193194
Di1 = TextDialog(client, url, text_content)
194195
Di1.render()
196+
elif command == "shutdown now":
197+
ssh.stop_server()
195198

196-
197-
ssh.run(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'private_key.pem'))
199+
ssh.run(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'private_key.pem'))

src/PyserSSH/demo/private_key.pem

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
-----BEGIN RSA PRIVATE KEY-----
2+
MIIEpQIBAAKCAQEAwNfkia91HNrpyqlHwjYrVKDV5SkDt5P27MxKZDjwOokGBX7E
3+
g5cMXb1wxQeCm+zptg680qIXHfSaaOi1E/DAutaTIQa3GI+gDMphlWMxrEWFuZOB
4+
ylvTuFAxLB8xKcuBjelQX4TYlcgA1WgyeI6LFPNdJPekVHnzkLCZnW+y05PkT6a0
5+
QY1Eoa6DY2TtY8w4NZmnyCy1ZPYV5qLKN/P7aVSU52AD8u25St1WprvxpM4TtZiG
6+
2O9X1Unx+wtco2P8G1M4qcuWqPDdITn4n19DcR7rhuACjUo2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vQFBBPEgVjGT3toG1UOI9Ya9Ia55anQoNt4wd90v
23+
Ur/CKoCU0mb9JEvahVBsdr0ZExPEuqDDTtqHAvHtwHk2MPOxikpaeOmy1EuaUT3w
24+
0vp2BMUCgYEAsLL592l8pclhxk2b0lmgvhPLOmZuQ7QkcnMMyYCeUr9Kt95VN40J
25+
N/LK9LIbf/l9CUN4eO1JqCJkAiMIW2Gvumw3g+TMj+nqcfsufSHJCG1EZNYMUftG
26+
aL7KtccPyFwotMD/P+OaAeJimwuC5247hCep1SSf1A41gbdmutiirM4=
27+
-----END RSA PRIVATE KEY-----

src/PyserSSH/interactive.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,15 @@ def Send(client, string, ln=True):
3636
else:
3737
channel.send(replace_enter_with_crlf(str(string)))
3838

39-
def Clear(client, oldclear=False):
39+
def Clear(client, oldclear=False, keep=False):
4040
sx, sy = client["windowsize"]["width"], client["windowsize"]["height"]
4141

4242
if oldclear:
4343
for x in range(sy):
4444
Send(client, '\b \b' * sx, ln=False) # Send newline after each line
45+
elif keep:
46+
Send(client, "\033[2J", ln=False)
47+
Send(client, "\033[H", ln=False)
4548
else:
4649
Send(client, "\033[3J", ln=False)
4750
Send(client, "\033[1J", ln=False)

0 commit comments

Comments
 (0)