vpspilot 1.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- vpspilot-1.0.0/PKG-INFO +131 -0
- vpspilot-1.0.0/README.md +100 -0
- vpspilot-1.0.0/pyproject.toml +65 -0
- vpspilot-1.0.0/setup.cfg +4 -0
- vpspilot-1.0.0/setup.py +72 -0
- vpspilot-1.0.0/tests/test_auth.py +32 -0
- vpspilot-1.0.0/tests/test_metrics.py +53 -0
- vpspilot-1.0.0/tests/test_services.py +28 -0
- vpspilot-1.0.0/vpspilot/__init__.py +6 -0
- vpspilot-1.0.0/vpspilot/cli.py +319 -0
- vpspilot-1.0.0/vpspilot/config.py +133 -0
- vpspilot-1.0.0/vpspilot/server.py +288 -0
- vpspilot-1.0.0/vpspilot/static/css/dashboard.css +609 -0
- vpspilot-1.0.0/vpspilot/static/index.html +475 -0
- vpspilot-1.0.0/vpspilot/static/js/app.js +729 -0
- vpspilot-1.0.0/vpspilot/static/js/terminal.js +168 -0
- vpspilot-1.0.0/vpspilot/static/vendor/xterm-addon-fit.js +2 -0
- vpspilot-1.0.0/vpspilot/static/vendor/xterm.css +209 -0
- vpspilot-1.0.0/vpspilot/static/vendor/xterm.js +2 -0
- vpspilot-1.0.0/vpspilot/system/__init__.py +3 -0
- vpspilot-1.0.0/vpspilot/system/auth.py +119 -0
- vpspilot-1.0.0/vpspilot/system/metrics.py +173 -0
- vpspilot-1.0.0/vpspilot/system/processes.py +59 -0
- vpspilot-1.0.0/vpspilot/system/services.py +158 -0
- vpspilot-1.0.0/vpspilot/system/terminal.py +164 -0
- vpspilot-1.0.0/vpspilot/system/vps_config.py +287 -0
- vpspilot-1.0.0/vpspilot/templates/vpspilot.service +18 -0
- vpspilot-1.0.0/vpspilot.egg-info/PKG-INFO +131 -0
- vpspilot-1.0.0/vpspilot.egg-info/SOURCES.txt +31 -0
- vpspilot-1.0.0/vpspilot.egg-info/dependency_links.txt +1 -0
- vpspilot-1.0.0/vpspilot.egg-info/entry_points.txt +2 -0
- vpspilot-1.0.0/vpspilot.egg-info/requires.txt +2 -0
- vpspilot-1.0.0/vpspilot.egg-info/top_level.txt +1 -0
vpspilot-1.0.0/PKG-INFO
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: vpspilot
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: VPSPilot: The Autonomous Next-Gen VPS Command Center & Online Management Dashboard
|
|
5
|
+
Author: Technology Innovision Team
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://github.com/technologyinnovision-team/VPSPILOT
|
|
8
|
+
Project-URL: Documentation, https://github.com/technologyinnovision-team/VPSPILOT#readme
|
|
9
|
+
Project-URL: Repository, https://github.com/technologyinnovision-team/VPSPILOT.git
|
|
10
|
+
Project-URL: Bug Tracker, https://github.com/technologyinnovision-team/VPSPILOT/issues
|
|
11
|
+
Keywords: vps,dashboard,terminal,web-terminal,systemd,server-management,monitoring,telemetry,cloud
|
|
12
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
13
|
+
Classifier: Intended Audience :: System Administrators
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
22
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
23
|
+
Classifier: Topic :: System :: Systems Administration
|
|
24
|
+
Classifier: Topic :: System :: Monitoring
|
|
25
|
+
Classifier: Topic :: Terminals :: Terminal Emulators/X Terminals
|
|
26
|
+
Requires-Python: >=3.9
|
|
27
|
+
Description-Content-Type: text/markdown
|
|
28
|
+
Requires-Dist: aiohttp>=3.8.0
|
|
29
|
+
Requires-Dist: psutil>=5.8.0
|
|
30
|
+
Dynamic: requires-python
|
|
31
|
+
|
|
32
|
+
# ⚡ VPSPilot: Precision VPS Management Deck & Web Command Center
|
|
33
|
+
|
|
34
|
+
**VPSPilot** is an autonomous, production-grade Python package and web dashboard engineered specifically for Linux Virtual Private Servers (VPS). It equips VPS owners and sysadmins with an online command center for host configuration, real-time hardware telemetry, full-duplex interactive web terminal, and complete systemd service management.
|
|
35
|
+
|
|
36
|
+
---
|
|
37
|
+
|
|
38
|
+
## 🌟 Key Capabilities
|
|
39
|
+
|
|
40
|
+
- 📊 **Real-Time Telemetry**: Live per-core CPU utilization, RAM usage, swap space, mounted filesystem quotas, and live RX/TX network transfer rates.
|
|
41
|
+
- 💻 **Interactive Web Terminal**: Full-featured web shell powered by `xterm.js` and `/dev/pts` pseudo-terminals with resize detection (`TIOCSWINSZ`), ANSI colors, and shortcut toolbar (Ctrl+C, Ctrl+D, Clear, Reconnect).
|
|
42
|
+
- ⚙️ **All Services Manager**: Real-time listing of all systemd units with state filters (`active`, `inactive`, `failed`), one-click controls (Start, Stop, Restart), and an integrated Journalctl log inspector modal.
|
|
43
|
+
- 🛠️ **VPS Configuration Deck**:
|
|
44
|
+
- Hostname changer (`hostnamectl`)
|
|
45
|
+
- Timezone selector (`timedatectl`)
|
|
46
|
+
- DNS resolvers viewer (`/etc/resolv.conf`)
|
|
47
|
+
- SSH daemon security inspection (Port, Root Login, Password Auth)
|
|
48
|
+
- Firewall manager (UFW rules: Allow/Deny, rule removal, enable/disable toggle)
|
|
49
|
+
- System maintenance (package update status, cache cleanup, safe Reboot/Poweroff)
|
|
50
|
+
- 🗂️ **Process Explorer**: Live running processes list sorted by CPU% or Memory% with instant `SIGTERM` / `SIGKILL` signals.
|
|
51
|
+
- 🔒 **Enterprise-Grade Security**: PBKDF2-HMAC-SHA256 password hashing, secure session tokens, rate-limited login defense, and strict permission enforcement (`0600` on credentials).
|
|
52
|
+
- 📦 **Offline-Ready & Zero CDN Dependency**: `xterm.js` and vendor assets are bundled inside the Python package, ensuring the terminal functions flawlessly on isolated or restricted networks.
|
|
53
|
+
|
|
54
|
+
---
|
|
55
|
+
|
|
56
|
+
## 🚀 Installation
|
|
57
|
+
|
|
58
|
+
### Global Install via pip
|
|
59
|
+
```bash
|
|
60
|
+
pip install --break-system-packages .
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Or install in development/editable mode:
|
|
64
|
+
```bash
|
|
65
|
+
pip install --break-system-packages -e .
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
---
|
|
69
|
+
|
|
70
|
+
## 🖥️ Command Line Usage
|
|
71
|
+
|
|
72
|
+
Once installed, the global `vpspilot` executable is available anywhere:
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
# Start VPSPilot in foreground
|
|
76
|
+
vpspilot start --port 8888
|
|
77
|
+
|
|
78
|
+
# Start VPSPilot as a background daemon
|
|
79
|
+
vpspilot start --port 8888 --daemon
|
|
80
|
+
|
|
81
|
+
# Check daemon status
|
|
82
|
+
vpspilot status
|
|
83
|
+
|
|
84
|
+
# Stop daemon
|
|
85
|
+
vpspilot stop
|
|
86
|
+
|
|
87
|
+
# Restart daemon
|
|
88
|
+
vpspilot restart
|
|
89
|
+
|
|
90
|
+
# Change admin password
|
|
91
|
+
vpspilot set-password
|
|
92
|
+
|
|
93
|
+
# View current configuration
|
|
94
|
+
vpspilot config show
|
|
95
|
+
|
|
96
|
+
# Install as an automated systemd service (boots on server start)
|
|
97
|
+
sudo vpspilot install-service
|
|
98
|
+
|
|
99
|
+
# Uninstall systemd service
|
|
100
|
+
sudo vpspilot uninstall-service
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
---
|
|
104
|
+
|
|
105
|
+
## 🌐 Web Dashboard Access
|
|
106
|
+
|
|
107
|
+
After launching, open your browser and navigate to:
|
|
108
|
+
```
|
|
109
|
+
http://<YOUR-VPS-IP>:8888
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
On first launch, an initial administrative password is automatically generated and printed to the terminal console if one has not been specified.
|
|
113
|
+
|
|
114
|
+
---
|
|
115
|
+
|
|
116
|
+
## 🏗️ Architecture
|
|
117
|
+
|
|
118
|
+
```
|
|
119
|
+
Client Browser (SPA)
|
|
120
|
+
│
|
|
121
|
+
├── REST API (/api/*) ──> aiohttp Web Server
|
|
122
|
+
├── Telemetry WS (/ws/metrics) ──> psutil + /proc Kernel Telemetry
|
|
123
|
+
└── Web Terminal WS (/ws/terminal) ──> Python PTY Bridge (pty.openpty)
|
|
124
|
+
│
|
|
125
|
+
└── /dev/pts (bash/zsh login shell)
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
---
|
|
129
|
+
|
|
130
|
+
## 📄 License
|
|
131
|
+
Apache-2.0 / MIT. Crafted with precision for Linux VPS systems.
|
vpspilot-1.0.0/README.md
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
# ⚡ VPSPilot: Precision VPS Management Deck & Web Command Center
|
|
2
|
+
|
|
3
|
+
**VPSPilot** is an autonomous, production-grade Python package and web dashboard engineered specifically for Linux Virtual Private Servers (VPS). It equips VPS owners and sysadmins with an online command center for host configuration, real-time hardware telemetry, full-duplex interactive web terminal, and complete systemd service management.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## 🌟 Key Capabilities
|
|
8
|
+
|
|
9
|
+
- 📊 **Real-Time Telemetry**: Live per-core CPU utilization, RAM usage, swap space, mounted filesystem quotas, and live RX/TX network transfer rates.
|
|
10
|
+
- 💻 **Interactive Web Terminal**: Full-featured web shell powered by `xterm.js` and `/dev/pts` pseudo-terminals with resize detection (`TIOCSWINSZ`), ANSI colors, and shortcut toolbar (Ctrl+C, Ctrl+D, Clear, Reconnect).
|
|
11
|
+
- ⚙️ **All Services Manager**: Real-time listing of all systemd units with state filters (`active`, `inactive`, `failed`), one-click controls (Start, Stop, Restart), and an integrated Journalctl log inspector modal.
|
|
12
|
+
- 🛠️ **VPS Configuration Deck**:
|
|
13
|
+
- Hostname changer (`hostnamectl`)
|
|
14
|
+
- Timezone selector (`timedatectl`)
|
|
15
|
+
- DNS resolvers viewer (`/etc/resolv.conf`)
|
|
16
|
+
- SSH daemon security inspection (Port, Root Login, Password Auth)
|
|
17
|
+
- Firewall manager (UFW rules: Allow/Deny, rule removal, enable/disable toggle)
|
|
18
|
+
- System maintenance (package update status, cache cleanup, safe Reboot/Poweroff)
|
|
19
|
+
- 🗂️ **Process Explorer**: Live running processes list sorted by CPU% or Memory% with instant `SIGTERM` / `SIGKILL` signals.
|
|
20
|
+
- 🔒 **Enterprise-Grade Security**: PBKDF2-HMAC-SHA256 password hashing, secure session tokens, rate-limited login defense, and strict permission enforcement (`0600` on credentials).
|
|
21
|
+
- 📦 **Offline-Ready & Zero CDN Dependency**: `xterm.js` and vendor assets are bundled inside the Python package, ensuring the terminal functions flawlessly on isolated or restricted networks.
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
## 🚀 Installation
|
|
26
|
+
|
|
27
|
+
### Global Install via pip
|
|
28
|
+
```bash
|
|
29
|
+
pip install --break-system-packages .
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Or install in development/editable mode:
|
|
33
|
+
```bash
|
|
34
|
+
pip install --break-system-packages -e .
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
---
|
|
38
|
+
|
|
39
|
+
## 🖥️ Command Line Usage
|
|
40
|
+
|
|
41
|
+
Once installed, the global `vpspilot` executable is available anywhere:
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
# Start VPSPilot in foreground
|
|
45
|
+
vpspilot start --port 8888
|
|
46
|
+
|
|
47
|
+
# Start VPSPilot as a background daemon
|
|
48
|
+
vpspilot start --port 8888 --daemon
|
|
49
|
+
|
|
50
|
+
# Check daemon status
|
|
51
|
+
vpspilot status
|
|
52
|
+
|
|
53
|
+
# Stop daemon
|
|
54
|
+
vpspilot stop
|
|
55
|
+
|
|
56
|
+
# Restart daemon
|
|
57
|
+
vpspilot restart
|
|
58
|
+
|
|
59
|
+
# Change admin password
|
|
60
|
+
vpspilot set-password
|
|
61
|
+
|
|
62
|
+
# View current configuration
|
|
63
|
+
vpspilot config show
|
|
64
|
+
|
|
65
|
+
# Install as an automated systemd service (boots on server start)
|
|
66
|
+
sudo vpspilot install-service
|
|
67
|
+
|
|
68
|
+
# Uninstall systemd service
|
|
69
|
+
sudo vpspilot uninstall-service
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
---
|
|
73
|
+
|
|
74
|
+
## 🌐 Web Dashboard Access
|
|
75
|
+
|
|
76
|
+
After launching, open your browser and navigate to:
|
|
77
|
+
```
|
|
78
|
+
http://<YOUR-VPS-IP>:8888
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
On first launch, an initial administrative password is automatically generated and printed to the terminal console if one has not been specified.
|
|
82
|
+
|
|
83
|
+
---
|
|
84
|
+
|
|
85
|
+
## 🏗️ Architecture
|
|
86
|
+
|
|
87
|
+
```
|
|
88
|
+
Client Browser (SPA)
|
|
89
|
+
│
|
|
90
|
+
├── REST API (/api/*) ──> aiohttp Web Server
|
|
91
|
+
├── Telemetry WS (/ws/metrics) ──> psutil + /proc Kernel Telemetry
|
|
92
|
+
└── Web Terminal WS (/ws/terminal) ──> Python PTY Bridge (pty.openpty)
|
|
93
|
+
│
|
|
94
|
+
└── /dev/pts (bash/zsh login shell)
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
---
|
|
98
|
+
|
|
99
|
+
## 📄 License
|
|
100
|
+
Apache-2.0 / MIT. Crafted with precision for Linux VPS systems.
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "vpspilot"
|
|
7
|
+
version = "1.0.0"
|
|
8
|
+
description = "VPSPilot: The Autonomous Next-Gen VPS Command Center & Online Management Dashboard"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.9"
|
|
11
|
+
license = "Apache-2.0"
|
|
12
|
+
authors = [
|
|
13
|
+
{ name = "Technology Innovision Team" }
|
|
14
|
+
]
|
|
15
|
+
keywords = [
|
|
16
|
+
"vps",
|
|
17
|
+
"dashboard",
|
|
18
|
+
"terminal",
|
|
19
|
+
"web-terminal",
|
|
20
|
+
"systemd",
|
|
21
|
+
"server-management",
|
|
22
|
+
"monitoring",
|
|
23
|
+
"telemetry",
|
|
24
|
+
"cloud"
|
|
25
|
+
]
|
|
26
|
+
classifiers = [
|
|
27
|
+
"Development Status :: 5 - Production/Stable",
|
|
28
|
+
"Intended Audience :: System Administrators",
|
|
29
|
+
"Intended Audience :: Developers",
|
|
30
|
+
"Programming Language :: Python :: 3",
|
|
31
|
+
"Programming Language :: Python :: 3.9",
|
|
32
|
+
"Programming Language :: Python :: 3.10",
|
|
33
|
+
"Programming Language :: Python :: 3.11",
|
|
34
|
+
"Programming Language :: Python :: 3.12",
|
|
35
|
+
"Programming Language :: Python :: 3.13",
|
|
36
|
+
"Programming Language :: Python :: 3.14",
|
|
37
|
+
"Operating System :: POSIX :: Linux",
|
|
38
|
+
"Topic :: System :: Systems Administration",
|
|
39
|
+
"Topic :: System :: Monitoring",
|
|
40
|
+
"Topic :: Terminals :: Terminal Emulators/X Terminals"
|
|
41
|
+
]
|
|
42
|
+
dependencies = [
|
|
43
|
+
"aiohttp>=3.8.0",
|
|
44
|
+
"psutil>=5.8.0"
|
|
45
|
+
]
|
|
46
|
+
|
|
47
|
+
[project.scripts]
|
|
48
|
+
vpspilot = "vpspilot.cli:main"
|
|
49
|
+
|
|
50
|
+
[project.urls]
|
|
51
|
+
Homepage = "https://github.com/technologyinnovision-team/VPSPILOT"
|
|
52
|
+
Documentation = "https://github.com/technologyinnovision-team/VPSPILOT#readme"
|
|
53
|
+
Repository = "https://github.com/technologyinnovision-team/VPSPILOT.git"
|
|
54
|
+
"Bug Tracker" = "https://github.com/technologyinnovision-team/VPSPILOT/issues"
|
|
55
|
+
|
|
56
|
+
[tool.setuptools.packages.find]
|
|
57
|
+
where = ["."]
|
|
58
|
+
include = ["vpspilot*"]
|
|
59
|
+
|
|
60
|
+
[tool.setuptools.package-data]
|
|
61
|
+
vpspilot = [
|
|
62
|
+
"static/*",
|
|
63
|
+
"static/**/*",
|
|
64
|
+
"templates/*"
|
|
65
|
+
]
|
vpspilot-1.0.0/setup.cfg
ADDED
vpspilot-1.0.0/setup.py
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import sys
|
|
3
|
+
import shutil
|
|
4
|
+
import subprocess
|
|
5
|
+
from setuptools import setup, find_packages
|
|
6
|
+
from setuptools.command.install import install
|
|
7
|
+
|
|
8
|
+
class CustomInstallCommand(install):
|
|
9
|
+
"""Custom installation command that automatically sets up and starts the systemd service when run as root."""
|
|
10
|
+
def run(self):
|
|
11
|
+
super().run()
|
|
12
|
+
# If running on Linux as root with systemd available, auto-install and start the daemon
|
|
13
|
+
if os.name == "posix" and os.geteuid() == 0 and os.path.exists("/run/systemd/system"):
|
|
14
|
+
try:
|
|
15
|
+
vpspilot_bin = shutil.which("vpspilot") or f"{sys.executable} -m vpspilot.cli"
|
|
16
|
+
service_content = f"""[Unit]
|
|
17
|
+
Description=VPSPilot - The Autonomous VPS Command Center
|
|
18
|
+
After=network.target network-online.target
|
|
19
|
+
Wants=network-online.target
|
|
20
|
+
|
|
21
|
+
[Service]
|
|
22
|
+
Type=simple
|
|
23
|
+
User=root
|
|
24
|
+
WorkingDirectory=/
|
|
25
|
+
ExecStart={vpspilot_bin} start --host 0.0.0.0 --port 8888 --foreground
|
|
26
|
+
Restart=always
|
|
27
|
+
RestartSec=3
|
|
28
|
+
LimitNOFILE=65536
|
|
29
|
+
StandardOutput=journal
|
|
30
|
+
StandardError=journal
|
|
31
|
+
|
|
32
|
+
[Install]
|
|
33
|
+
WantedBy=multi-user.target
|
|
34
|
+
"""
|
|
35
|
+
service_path = "/etc/systemd/system/vpspilot.service"
|
|
36
|
+
with open(service_path, "w", encoding="utf-8") as f:
|
|
37
|
+
f.write(service_content)
|
|
38
|
+
subprocess.run(["systemctl", "daemon-reload"], check=False)
|
|
39
|
+
subprocess.run(["systemctl", "enable", "--now", "vpspilot.service"], check=False)
|
|
40
|
+
print("\n[+] VPSPilot systemd service automatically installed & started! It will always run in the background.\n")
|
|
41
|
+
except Exception as e:
|
|
42
|
+
print(f"\n[!] Note: To enable always-running background service, run: sudo vpspilot install-service ({e})\n")
|
|
43
|
+
|
|
44
|
+
setup(
|
|
45
|
+
name="vpspilot",
|
|
46
|
+
version="1.0.0",
|
|
47
|
+
description="VPSPilot: The Autonomous Next-Gen VPS Command Center & Online Management Dashboard",
|
|
48
|
+
packages=find_packages(),
|
|
49
|
+
include_package_data=True,
|
|
50
|
+
package_data={
|
|
51
|
+
"vpspilot": [
|
|
52
|
+
"static/*",
|
|
53
|
+
"static/css/*",
|
|
54
|
+
"static/js/*",
|
|
55
|
+
"static/vendor/*",
|
|
56
|
+
"templates/*"
|
|
57
|
+
]
|
|
58
|
+
},
|
|
59
|
+
install_requires=[
|
|
60
|
+
"aiohttp>=3.8.0",
|
|
61
|
+
"psutil>=5.8.0"
|
|
62
|
+
],
|
|
63
|
+
entry_points={
|
|
64
|
+
"console_scripts": [
|
|
65
|
+
"vpspilot=vpspilot.cli:main"
|
|
66
|
+
]
|
|
67
|
+
},
|
|
68
|
+
cmdclass={
|
|
69
|
+
"install": CustomInstallCommand
|
|
70
|
+
},
|
|
71
|
+
python_requires=">=3.9"
|
|
72
|
+
)
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import unittest
|
|
2
|
+
from vpspilot.config import hash_password, verify_password
|
|
3
|
+
from vpspilot.system.auth import create_session, validate_session, destroy_session, is_rate_limited, record_attempt
|
|
4
|
+
|
|
5
|
+
class TestAuth(unittest.TestCase):
|
|
6
|
+
def test_password_hashing_and_verification(self):
|
|
7
|
+
pwd = "SuperSecretPassword123!"
|
|
8
|
+
hashed, salt = hash_password(pwd)
|
|
9
|
+
self.assertTrue(len(hashed) > 0)
|
|
10
|
+
self.assertTrue(len(salt) > 0)
|
|
11
|
+
|
|
12
|
+
# Valid password
|
|
13
|
+
self.assertTrue(verify_password(pwd, hashed, salt))
|
|
14
|
+
|
|
15
|
+
# Invalid password
|
|
16
|
+
self.assertFalse(verify_password("WrongPassword", hashed, salt))
|
|
17
|
+
|
|
18
|
+
def test_session_lifecycle(self):
|
|
19
|
+
token = create_session("admin", "127.0.0.1", ttl=60)
|
|
20
|
+
self.assertTrue(validate_session(token))
|
|
21
|
+
destroy_session(token)
|
|
22
|
+
self.assertFalse(validate_session(token))
|
|
23
|
+
|
|
24
|
+
def test_rate_limiting(self):
|
|
25
|
+
test_ip = "192.168.99.99"
|
|
26
|
+
self.assertFalse(is_rate_limited(test_ip))
|
|
27
|
+
for _ in range(12):
|
|
28
|
+
record_attempt(test_ip)
|
|
29
|
+
self.assertTrue(is_rate_limited(test_ip))
|
|
30
|
+
|
|
31
|
+
if __name__ == "__main__":
|
|
32
|
+
unittest.main()
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import unittest
|
|
2
|
+
from vpspilot.system.metrics import (
|
|
3
|
+
get_system_info,
|
|
4
|
+
get_cpu_metrics,
|
|
5
|
+
get_memory_metrics,
|
|
6
|
+
get_disk_metrics,
|
|
7
|
+
get_network_metrics,
|
|
8
|
+
get_telemetry_snapshot
|
|
9
|
+
)
|
|
10
|
+
|
|
11
|
+
class TestMetrics(unittest.TestCase):
|
|
12
|
+
def test_system_info(self):
|
|
13
|
+
info = get_system_info()
|
|
14
|
+
self.assertIn("hostname", info)
|
|
15
|
+
self.assertIn("os", info)
|
|
16
|
+
self.assertIn("kernel", info)
|
|
17
|
+
self.assertIn("uptime_seconds", info)
|
|
18
|
+
self.assertGreater(info["uptime_seconds"], 0)
|
|
19
|
+
|
|
20
|
+
def test_cpu_metrics(self):
|
|
21
|
+
cpu = get_cpu_metrics()
|
|
22
|
+
self.assertIn("total_percent", cpu)
|
|
23
|
+
self.assertIn("cores", cpu)
|
|
24
|
+
self.assertIn("core_count", cpu)
|
|
25
|
+
self.assertGreater(cpu["core_count"], 0)
|
|
26
|
+
self.assertIsInstance(cpu["cores"], list)
|
|
27
|
+
|
|
28
|
+
def test_memory_metrics(self):
|
|
29
|
+
mem = get_memory_metrics()
|
|
30
|
+
self.assertIn("ram", mem)
|
|
31
|
+
self.assertIn("swap", mem)
|
|
32
|
+
self.assertIn("total", mem["ram"])
|
|
33
|
+
self.assertIn("percent", mem["ram"])
|
|
34
|
+
self.assertGreater(mem["ram"]["total"], 0)
|
|
35
|
+
|
|
36
|
+
def test_disk_metrics(self):
|
|
37
|
+
disks = get_disk_metrics()
|
|
38
|
+
self.assertIsInstance(disks, list)
|
|
39
|
+
self.assertGreater(len(disks), 0)
|
|
40
|
+
root = disks[0]
|
|
41
|
+
self.assertIn("mountpoint", root)
|
|
42
|
+
self.assertIn("total", root)
|
|
43
|
+
|
|
44
|
+
def test_telemetry_snapshot(self):
|
|
45
|
+
snapshot = get_telemetry_snapshot()
|
|
46
|
+
self.assertIn("system", snapshot)
|
|
47
|
+
self.assertIn("cpu", snapshot)
|
|
48
|
+
self.assertIn("memory", snapshot)
|
|
49
|
+
self.assertIn("disks", snapshot)
|
|
50
|
+
self.assertIn("network", snapshot)
|
|
51
|
+
|
|
52
|
+
if __name__ == "__main__":
|
|
53
|
+
unittest.main()
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import unittest
|
|
2
|
+
from vpspilot.system.services import sanitize_service_name, list_services, control_service
|
|
3
|
+
|
|
4
|
+
class TestServices(unittest.TestCase):
|
|
5
|
+
def test_sanitize_service_name(self):
|
|
6
|
+
self.assertEqual(sanitize_service_name("cron"), "cron.service")
|
|
7
|
+
self.assertEqual(sanitize_service_name("ssh.service"), "ssh.service")
|
|
8
|
+
self.assertEqual(sanitize_service_name("user@1000.service"), "user@1000.service")
|
|
9
|
+
|
|
10
|
+
with self.assertRaises(ValueError):
|
|
11
|
+
sanitize_service_name("cron; rm -rf /")
|
|
12
|
+
|
|
13
|
+
def test_list_services(self):
|
|
14
|
+
services = list_services()
|
|
15
|
+
self.assertIsInstance(services, list)
|
|
16
|
+
self.assertGreater(len(services), 0)
|
|
17
|
+
first = services[0]
|
|
18
|
+
self.assertIn("name", first)
|
|
19
|
+
self.assertIn("active", first)
|
|
20
|
+
self.assertIn("sub", first)
|
|
21
|
+
|
|
22
|
+
def test_disallowed_service_action(self):
|
|
23
|
+
res = control_service("cron", "destroy_everything")
|
|
24
|
+
self.assertFalse(res["success"])
|
|
25
|
+
self.assertIn("not permitted", res["error"])
|
|
26
|
+
|
|
27
|
+
if __name__ == "__main__":
|
|
28
|
+
unittest.main()
|