Fix links

This commit is contained in:
Penguinehis
2026-09-29 10:18:56 -03:00
parent b4a8a70e54
commit 4673f8c58e
6 changed files with 88 additions and 33 deletions
+12 -4
View File
@@ -4,15 +4,23 @@ DragonCoreSSH server with a terminal administration menu and HTTP API. Based on
## Install on a fresh Linux/systemd host
Extract this archive, then run `sudo bash install.sh` from the extracted `DragonCoreSSH-CLI` directory. The installer sets up the Go server, PostgreSQL, Xray, service, and the `menu` command. If `/usr/local/bin/menu` already exists, it is saved as `menu.backup.<timestamp>` before the DragonCoreSSH command is installed. It generates all credentials. It needs a compatible Linux distribution and access to its system packages, the Go toolchain download, and Xray release download. Run it only on a fresh server: like the original installer it generates new database and configuration credentials.
Clone [DragonCoreNEWCLI](https://git.dr2.site/penguinehis/DragonCoreNEWCLI) and run the installer from the repository root:
Run `menu` from a root shell, or `sudo menu` otherwise. The `dragoncore` command remains an alias. Other commands: `sudo menu status`, `sudo menu users`, `sudo menu logs`, `sudo menu api-password show`, `sudo menu api-password change`. The change command generates a new API password, restarts the service, verifies it, and restores the old one if verification fails. It never prompts for a password. Creating/resetting SSH users generates credentials and prints them once.
```bash
git clone https://git.dr2.site/penguinehis/DragonCoreNEWCLI
cd DragonCoreNEWCLI
sudo bash install.sh
```
The installer sets up the Go server, PostgreSQL, Xray, service, and the `menu` command. If `/usr/local/bin/menu` already exists, it is saved as `menu.backup.<timestamp>` before the DragonCoreSSH command is installed. It generates all credentials. It needs a compatible Linux distribution and access to its system packages, the Go toolchain download, and Xray release download. Run it only on a fresh server: like the original installer it generates new database and configuration credentials. An extracted source archive also works for a local install.
Run `menu` from a root shell, or `sudo menu` otherwise. The `dragoncore` command remains an alias. Other commands: `sudo menu status`, `sudo menu users`, `sudo menu logs`, `sudo menu update`, `sudo menu api-password show`, `sudo menu api-password change`. The change command generates a new API password, restarts the service, verifies it, and restores the old one if verification fails. It never prompts for a password. Creating/resetting SSH users generates credentials and prints them once.
The menu detects the terminal width. On a phone it uses a compact status header and wraps menu labels and account details; on a wider terminal it uses the fuller layout. If an SSH app reports the wrong width, run `menu --mobile` to force 40 columns, or set `DRAGONCORE_COLUMNS=36` to choose another width. For editing advanced JSON from a phone SSH client, install `nano` or set `$EDITOR` to your preferred terminal editor.
## Migrate an existing DragonCoreSSH-NewWEB installation
Back up `/opt/sshpanel`, its PostgreSQL database, and `/etc/systemd/system/sshpanel.service` first. Extract this release on the server and run `sudo bash update.sh` from its directory. The updater builds the CLI version, preserves `.env`, `config.json`, Xray configuration, SSH keys, accounts, and database, then restarts the service. It reads this local release only; it does not fetch the NewWEB branch. The previous binary is saved as `/opt/sshpanel/sshpanel.bak`. The old `admin/` directory is no longer served. The existing `ADMIN_HTTP_ADDR` setting is preserved; set it to `127.0.0.1:9090` and restart if remote API access is unnecessary.
Back up `/opt/sshpanel`, its PostgreSQL database, and `/etc/systemd/system/sshpanel.service` first. Run `sudo menu update` or `sudo bash /opt/sshpanel/update.sh`. The updater fetches the latest commit from the default branch of `https://git.dr2.site/penguinehis/DragonCoreNEWCLI`, builds it before stopping the service, preserves `.env`, `config.json`, Xray configuration, SSH keys, accounts, and database, then restarts the service. The previous binary is saved as `/opt/sshpanel/sshpanel.bak`. To select a branch, run `sudo env UPDATE_REF=branch-name bash /opt/sshpanel/update.sh`. For an extracted offline release, run `sudo env UPDATE_SOURCE=local bash update.sh` in its source directory. The old `admin/` directory is no longer served. The existing `ADMIN_HTTP_ADDR` setting is preserved; set it to `127.0.0.1:9090` and restart if remote API access is unnecessary.
## API
@@ -30,7 +38,7 @@ Example: `curl -H "Authorization: Bearer $TOKEN" http://127.0.0.1:9090/api/users
- Configuration: banner, guided SSH listener ports and default limits, full server JSON, Xray JSON, bot settings display, managed servers display. The service validates settings through its API and applies server settings live.
- Reseller management remains in the Telegram bot; the CLI has no reseller menu.
- API password: view and rotate.
- Service status, logs, and restart.
- Service status, logs, restart, and Git update.
Full configuration remains available through the server API. Use the JSON editor option for settings not covered by guided prompts. This uses the editor in `$EDITOR`, or `nano` if unset. The CLI never requests a login or password. Root access to `.env` is its local authentication boundary.
+14 -1
View File
@@ -815,6 +815,16 @@ def logs():
subprocess.run(["journalctl", "-u", SERVICE, "-n", "80", "--no-pager"])
def update_from_git():
updater = INSTALL_DIR / "update.sh"
if not updater.is_file():
raise CLIError(f"Updater missing: {updater}")
result = subprocess.run(["bash", str(updater)], check=False)
if result.returncode:
raise CLIError(f"Update failed (exit {result.returncode}); see the output above")
print("Update complete. Reopen menu to load the updated CLI.")
def render_menu(title, options, vps_status=None, columns=None):
cols = columns or terminal_columns()
width = min(48, max(20, cols - 2))
@@ -908,13 +918,14 @@ def main_menu_options():
"6": ("API password (view / rotate)", api_menu),
"7": ("Recent logs", logs),
"8": ("Restart service", lambda: service_action("restart")),
"9": ("Update from Git", lambda: update_from_git() if confirm("Update from Git now?") else None),
}
def main():
parser = argparse.ArgumentParser(description="DragonCoreSSH CLI administration")
parser.add_argument("--mobile", action="store_true", help="force a 40-column phone layout")
parser.add_argument("command", nargs="?", choices=("menu", "status", "users", "api-password", "logs"), default="menu")
parser.add_argument("command", nargs="?", choices=("menu", "status", "users", "api-password", "logs", "update"), default="menu")
parser.add_argument("action", nargs="?", choices=("show", "change"))
args = parser.parse_args()
require_root()
@@ -935,6 +946,8 @@ def main():
status()
elif args.command == "logs":
logs()
elif args.command == "update":
update_from_git()
else:
menu("MAIN MENU", main_menu_options())
+2 -2
View File
@@ -15,7 +15,7 @@ LOG_TMPFS_SIZE="${LOG_TMPFS_SIZE:-15m}"
PANEL_LOG_MAX_BYTES="${PANEL_LOG_MAX_BYTES:-1048576}"
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
GO_VERSION="${GO_VERSION:-$(awk '$1 == "go" {print $2; exit}' "$SCRIPT_DIR/go.mod" 2>/dev/null || echo "1.22.5")}"
REPO_URL="DragonCoreSSH-CLI local release"
REPO_URL="${REPO_URL:-https://git.dr2.site/penguinehis/DragonCoreNEWCLI}"
MKDIR_BIN="$(command -v mkdir 2>/dev/null || true)"
[[ -n "$MKDIR_BIN" ]] || MKDIR_BIN="/bin/mkdir"
# ────────────────────────────────────────────────────────────────────────────
@@ -298,7 +298,7 @@ rsync -a --delete --exclude '.git' --exclude 'source/' --exclude '__pycache__/'
if [[ -f "$SCRIPT_DIR/update.sh" ]]; then
cp "$SCRIPT_DIR/update.sh" "$INSTALL_DIR/update.sh"
chmod 700 "$INSTALL_DIR/update.sh"
info " Local CLI updater copied"
info " Git-based CLI updater copied"
fi
# ── 6. Xray binary ──────────────────────────────────────────────────────────
+10
View File
@@ -116,6 +116,16 @@ class TokenManagementTest(unittest.TestCase):
with self.assertRaisesRegex(cli.CLIError, "native"):
cli.xray_shared_port()
def test_git_update_uses_installed_updater_without_prompt(self):
updater = Path(self.temp.name) / "update.sh"
updater.write_text("#!/bin/bash\n")
with patch.object(cli, "INSTALL_DIR", Path(self.temp.name)), \
patch.object(cli.subprocess, "run", return_value=SimpleNamespace(returncode=0)) as run, \
patch("builtins.input", side_effect=AssertionError("prompted")), \
redirect_stdout(io.StringIO()):
cli.update_from_git()
run.assert_called_once_with(["bash", str(updater)], check=False)
if __name__ == "__main__":
unittest.main()
+49 -25
View File
@@ -1,5 +1,5 @@
#!/bin/bash
# Update the DragonCoreSSH CLI from a local extracted release.
# Update the DragonCoreSSH CLI from its Git repository.
#
# Preserved:
# - /opt/sshpanel/.env
@@ -11,8 +11,8 @@
# sudo bash /opt/sshpanel/update.sh
# sudo bash update.sh
#
# Run from an extracted DragonCoreSSH-CLI source directory to apply that release.
# Installed /opt/sshpanel/update.sh rebuilds the cached CLI source.
# UPDATE_SOURCE=local sudo bash update.sh applies a checked-out/offline release.
# UPDATE_REF selects an optional remote branch; empty follows remote HEAD.
set -euo pipefail
RED='\033[0;31m'; GREEN='\033[0;32m'; YELLOW='\033[1;33m'; NC='\033[0m'
@@ -25,13 +25,17 @@ INSTALL_DIR="${INSTALL_DIR:-/opt/sshpanel}"
SERVICE_NAME="${SERVICE_NAME:-sshpanel}"
LOG_TMPFS_SIZE="${LOG_TMPFS_SIZE:-15m}"
PANEL_LOG_MAX_BYTES="${PANEL_LOG_MAX_BYTES:-1048576}"
REPO_URL="local-cli-source"
REPO_URL="${REPO_URL:-https://git.dr2.site/penguinehis/DragonCoreNEWCLI}"
UPDATE_REF="${UPDATE_REF:-}"
UPDATE_SOURCE="${UPDATE_SOURCE:-git}"
export GIT_TERMINAL_PROMPT=0
export GIT_ASKPASS=/bin/false
SOURCE_CACHE_DIR="${SOURCE_CACHE_DIR:-${INSTALL_DIR}/source}"
MKDIR_BIN="$(command -v mkdir 2>/dev/null || true)"
[[ -n "$MKDIR_BIN" ]] || MKDIR_BIN="/bin/mkdir"
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
SOURCE_DIR=""
FETCH_DIR=""
RESTART_NEEDED=false
BUILD_COMMIT=""
BUILD_BRANCH=""
@@ -186,25 +190,35 @@ install_git_if_missing() {
pkg_install git ca-certificates
}
remote_default_branch() {
local branch
branch="$(git ls-remote --symref "$REPO_URL" HEAD 2>/dev/null | awk '/^ref:/ {sub("refs/heads/", "", $2); print $2; exit}')"
if [[ -n "$branch" ]]; then
printf '%s\n' "$branch"
prepare_source_from_git() {
if [[ "$UPDATE_SOURCE" == "local" ]]; then
SOURCE_DIR="${SOURCE_DIR:-$SCRIPT_DIR}"
if [[ ! -f "$SOURCE_DIR/go.mod" ]]; then
SOURCE_DIR="$SOURCE_CACHE_DIR"
fi
info "[1/7] Using local CLI source: $SOURCE_DIR"
elif [[ "$UPDATE_SOURCE" == "git" ]]; then
FETCH_DIR="$(mktemp -d "${TMPDIR:-/tmp}/dragoncore-update.XXXXXXXX")"
info "[1/7] Fetching CLI source from $REPO_URL..."
if [[ -n "$UPDATE_REF" ]]; then
git clone --depth 1 --branch "$UPDATE_REF" "$REPO_URL" "$FETCH_DIR" || error "Git fetch failed; service and installed files were not changed"
else
git clone --depth 1 "$REPO_URL" "$FETCH_DIR" || error "Git fetch failed; service and installed files were not changed"
fi
SOURCE_DIR="$FETCH_DIR"
else
printf 'main\n'
error "UPDATE_SOURCE must be git or local"
fi
[[ -f "$SOURCE_DIR/go.mod" && -f "$SOURCE_DIR/dragoncore_cli.py" && -f "$SOURCE_DIR/update.sh" ]] || \
error "Update source is missing go.mod, dragoncore_cli.py, or update.sh; service was not changed"
}
prepare_source_from_git() {
SOURCE_DIR="${SOURCE_DIR:-$SCRIPT_DIR}"
if [[ ! -f "$SOURCE_DIR/go.mod" ]]; then
SOURCE_DIR="$SOURCE_CACHE_DIR"
cleanup_fetch() {
if [[ -n "$FETCH_DIR" && -d "$FETCH_DIR" ]]; then
rm -rf -- "$FETCH_DIR"
fi
info "[1/7] Using local CLI source: $SOURCE_DIR"
[[ -f "$SOURCE_DIR/go.mod" ]] || error "go.mod not found; run update.sh from an extracted CLI release"
[[ -f "$SOURCE_DIR/dragoncore_cli.py" ]] || error "Source is missing dragoncore_cli.py"
}
trap cleanup_fetch EXIT
install_go_if_needed() {
local go_version machine goarch go_url current_go need_go
@@ -252,11 +266,16 @@ build_binary() {
export GOCACHE=/tmp/gocache_sshpanel
BUILD_COMMIT="$(git -C "$SOURCE_DIR" rev-parse HEAD 2>/dev/null || true)"
BUILD_BRANCH="${UPDATE_REF:-$(git -C "$SOURCE_DIR" rev-parse --abbrev-ref HEAD 2>/dev/null || true)}"
BUILD_BRANCH="$(git -C "$SOURCE_DIR" rev-parse --abbrev-ref HEAD 2>/dev/null || true)"
BUILD_TIME="$(date -u +%Y-%m-%dT%H:%M:%SZ)"
BUILD_REPO_URL="DragonCoreSSH-CLI local release"
if [[ "$UPDATE_SOURCE" == "local" ]]; then
BUILD_REPO_URL="$(git -C "$SOURCE_DIR" config --get remote.origin.url 2>/dev/null || true)"
[[ -n "$BUILD_REPO_URL" ]] || BUILD_REPO_URL="DragonCoreSSH-CLI local release"
else
BUILD_REPO_URL="$REPO_URL"
fi
[[ -n "$BUILD_COMMIT" ]] || BUILD_COMMIT="unknown"
[[ -n "$BUILD_BRANCH" && "$BUILD_BRANCH" != "HEAD" ]] || BUILD_BRANCH="main"
[[ -n "$BUILD_BRANCH" && "$BUILD_BRANCH" != "HEAD" ]] || BUILD_BRANCH="${UPDATE_REF:-unknown}"
go mod download
go mod tidy
@@ -278,12 +297,13 @@ stop_service() {
}
copy_optional_script() {
local name mode
local name mode staged
name="$1"
mode="$2"
if [[ -f "$SOURCE_DIR/$name" ]]; then
cp "$SOURCE_DIR/$name" "$INSTALL_DIR/$name"
chmod "$mode" "$INSTALL_DIR/$name"
staged="$(mktemp "$INSTALL_DIR/.${name}.XXXXXX")"
install -m "$mode" "$SOURCE_DIR/$name" "$staged"
mv -f "$staged" "$INSTALL_DIR/$name"
info " Updated $name"
fi
}
@@ -549,7 +569,9 @@ restart_service() {
warn " $SERVICE_NAME was not running before update; starting it now."
fi
"$SYSTEMCTL_BIN" start "$SERVICE_NAME"
if ! "$SYSTEMCTL_BIN" start "$SERVICE_NAME"; then
error "$SERVICE_NAME could not start. Restore $INSTALL_DIR/sshpanel.bak and inspect journalctl -u $SERVICE_NAME"
fi
sleep 2
if "$SYSTEMCTL_BIN" is-active --quiet "$SERVICE_NAME"; then
info " $SERVICE_NAME is running."
@@ -560,6 +582,7 @@ restart_service() {
warn " Restore command:"
warn " cp $INSTALL_DIR/sshpanel.bak $INSTALL_DIR/sshpanel && systemctl start $SERVICE_NAME"
fi
error "$SERVICE_NAME is not running after the update"
exit 1
fi
}
@@ -578,6 +601,7 @@ need_cmd wget
info " Install dir : $INSTALL_DIR"
info " Cache dir : $SOURCE_CACHE_DIR"
info " Update source : $UPDATE_SOURCE"
info " Package manager : $PKG_MANAGER"
info " Service manager : systemd"
@@ -595,7 +619,7 @@ echo -e "${GREEN} Update complete! ${NC}"
echo -e "${GREEN}==========================================${NC}"
echo ""
echo -e " Updated from: ${YELLOW}${REPO_URL}${NC}"
echo -e " Source ref : ${YELLOW}${UPDATE_REF}${NC}"
echo -e " Source ref : ${YELLOW}${BUILD_BRANCH} (${BUILD_COMMIT})${NC}"
echo -e " Source cache: ${YELLOW}${SOURCE_CACHE_DIR}${NC}"
echo -e " Logs : ${YELLOW}journalctl -u ${SERVICE_NAME} -f${NC}"
echo -e " ${YELLOW}tail -f ${INSTALL_DIR}/logs/panel.log${NC}"
+1 -1
View File
@@ -15,7 +15,7 @@ import (
)
const (
defaultUpdateRepoURL = "https://git.dr2.site/penguinehis/DragonCoreSSH-NewWEB.git"
defaultUpdateRepoURL = "https://git.dr2.site/penguinehis/DragonCoreNEWCLI"
defaultUpdateBranch = "main"
updateStatusCacheTTL = 5 * time.Minute
updateCheckTimeout = 12 * time.Second