From 7255e0ec1bf1fe7f49d3e76f4e7b30c62f6a0570 Mon Sep 17 00:00:00 2001 From: ed Date: Sat, 16 Sep 2023 22:32:08 +0000 Subject: [PATCH] misc cleanup: * change start-r0c.* to invoke argparse * improve help-texts, messages * make-sfx works on windows --- README.md | 2 +- r0c/__main__.py | 12 ++++++------ scripts/make-sfx.sh | 15 +++++++++------ start-r0c.bat | 13 ++++++------- start-r0c.ps1 | 13 ++++++------- start-r0c.sh | 26 ++++++-------------------- 6 files changed, 34 insertions(+), 47 deletions(-) diff --git a/README.md b/README.md index 7b14d31..ec1ef39 100644 --- a/README.md +++ b/README.md @@ -76,7 +76,7 @@ if you enable TLS with `-tpt 2424` (telnet) and/or `-tpn 1515` (netcat) you can * `socat -,raw,echo=0 openssl:r0c.int:1515,cafile=cert.crt` * `stty -icanon; ncat --ssl --ssl-trustfile r0c.crt -v r0c.int 1515` * `stty -icanon; openssl s_client -CAfile ~/.r0c/cert.crt -nbio -connect r0c.int:1515` -* windows: powershell client with port `+1515` (the `+` enables TLS) +* windows: [powershell client](https://github.com/9001/r0c/blob/master/clients/powershell.ps1) with port `+1515` (the `+` enables TLS) * powershell does not verify certificate; the other clients do diff --git a/r0c/__main__.py b/r0c/__main__.py index 3b494fc..c8a49ab 100644 --- a/r0c/__main__.py +++ b/r0c/__main__.py @@ -43,8 +43,8 @@ def optgen(ap, pwd): ac.add_argument("-i", metavar="IP", type=u, default="0.0.0.0", help="address to listen on") ac.add_argument("-pt", metavar="PORT", type=int, default=pt, help="telnet port (disable with 0)") ac.add_argument("-pn", metavar="PORT", type=int, default=pn, help="netcat port (disable with 0)") - ac.add_argument("-tpt", metavar="PORT", type=int, default=0, help="TLS telnet port (disable with 0)") - ac.add_argument("-tpn", metavar="PORT", type=int, default=0, help="TLS netcat port (disable with 0)") + ac.add_argument("-tpt", metavar="PORT", type=int, default=0, help="TLS telnet port, e.g. 2424 (disable with 0)") + ac.add_argument("-tpn", metavar="PORT", type=int, default=0, help="TLS netcat port, e.g. 1515 (disable with 0)") ac.add_argument("-pw", metavar="PWD", type=u, default=pwd, help="admin password") ac.add_argument("--nsalt", metavar="TXT", type=u, default="lammo/", help="salt for generated nicknames based on IP") @@ -90,7 +90,7 @@ def run_fap(argv, pwd): ap = Fargparse() optgen(ap, pwd) - if "-h" in unicode(argv + [""])[1]: + if "-h" in unicode(([""] + argv)[-1]): print() print("arg 1: Telnet port (0=disable), default: {0}".format(ap.pt)) print("arg 2: NetCat port (0=disable), default: {0}".format(ap.pn)) @@ -227,9 +227,9 @@ printf '%s\\n' GK . . . . r0c.int . | openssl req -newkey rsa:2048 -sha256 -keyo if ar.pw == "hunter2": print("\033[1;31m") - print(" using the default password;") - print(" change it with argument -pw") - print(" or save it here: " + pwd_file) + print(" using default password '{0}'".format(ar.pw)) + print(" change it with argument -pw or save it here:") + print(" " + pwd_file) print("\033[0m") print(" * Logs at " + EP.log) diff --git a/scripts/make-sfx.sh b/scripts/make-sfx.sh index 2e8a01c..405eee0 100755 --- a/scripts/make-sfx.sh +++ b/scripts/make-sfx.sh @@ -5,8 +5,7 @@ echo # optional args: # -# `clean` uses files from git (everything except web/deps), -# so local changes won't affect the produced sfx +# `clean` uses files from git so local changes won't affect the produced sfx # differences from copyparty sfx: @@ -20,8 +19,7 @@ echo name=r0c [ -e $name/__main__.py ] || cd .. -[ -e $name/__main__.py ] || -{ +[ -e $name/__main__.py ] || { printf "run me from within the project root folder\n\n" exit 1 } @@ -47,6 +45,11 @@ gtar=$(command -v gtar || command -v gnutar) || true bzip2() { /opt/local/bin/bzip2 "$@"; } } +pybin=$(command -v python3 || command -v python) || { + echo need python + exit 1 +} + while [ ! -z "$1" ]; do [ "$1" = clean ] && clean=1 && shift && continue break @@ -145,7 +148,7 @@ unc="$HOME/dev/copyparty/scripts/uncomment.py" find | grep -E '\.py$' | grep -vE '__version__' | tr '\n' '\0' | - xargs -0 python3 $unc 1 + xargs -0 $pybin $unc 1 echo echo creating tar @@ -173,7 +176,7 @@ mv -v $minf tar.bz2 rm t.* echo creating sfx -python3 ../scripts/sfx.py --sfx-make tar.bz2 $ver $ts +$pybin ../scripts/sfx.py --sfx-make tar.bz2 $ver $ts mv sfx.out $sfx_out.py chmod 755 $sfx_out.* diff --git a/start-r0c.bat b/start-r0c.bat index d7828bc..1b8257b 100644 --- a/start-r0c.bat +++ b/start-r0c.bat @@ -1,8 +1,7 @@ -python -m r0c.__main__ 23 531 %1 || pause +python -m r0c.__main__ %* || pause -@REM if an argument is provided to this bat file, -@REM it will be used as the admin password. -@REM -@REM "r0c.__main__" is required by python 2.6; -@REM all other python versions are happy with: -@REM python -m r0c 23 531 +@REM additional arguments can be given to this batch file, for example +@REM -pw goodpassword +@REM -tpt 2424 (enable tls telnet on port 2424) +@REM -tpn 1515 (enable tls netcat on port 1515) +@REM --old-tls (allow old/buggy software to connect (centos6, powershell)) diff --git a/start-r0c.ps1 b/start-r0c.ps1 index b724ef8..42d49b0 100644 --- a/start-r0c.ps1 +++ b/start-r0c.ps1 @@ -1,5 +1,5 @@ try { - Invoke-Expression "python -m r0c.__main__ 23 531 $args" + Invoke-Expression "python -m r0c.__main__ $args" } catch { Write-Host -NoNewLine "press ENTER to terminate " @@ -13,9 +13,8 @@ if ($LASTEXITCODE -ne 0) { exit 1 } -# if an argument is provided to this ps1 file, -# it will be used as the admin password. -# -# "r0c.__main__" is required by python 2.6; -# all other python versions are happy with: -# python -m r0c 23 531 +# additional arguments can be given to this batch file, for example +# -pw goodpassword +# -tpt 2424 (enable tls telnet on port 2424) +# -tpn 1515 (enable tls netcat on port 1515) +# --old-tls (allow old/buggy software to connect (centos6, powershell)) diff --git a/start-r0c.sh b/start-r0c.sh index e5754c9..b964976 100755 --- a/start-r0c.sh +++ b/start-r0c.sh @@ -1,23 +1,9 @@ #!/bin/bash -preferred_ports="23 531" -fallback_ports="2323 1531" +python3 -m r0c.__main__ "$@" -# use preferred ports if root, -# otherwise use fallback ports -[ $(id -u) -eq 0 ] && - ports="$preferred_ports" || - ports="$fallback_ports" - -# if no arguments: -# start r0c with password from config file -[ "x$1" == "x" ] && - python3 -m r0c.__main__ $ports - -# otherwise, -# start r0c with the provided password -[ "x$1" == "x" ] || - python3 -m r0c.__main__ $ports "$1" - -# usually just "r0c" is enough, -# but python 2.6 needs the full "r0c.__main__" +# additional arguments can be given to this batch file, for example +# -pw goodpassword +# -tpt 2424 (enable tls telnet on port 2424) +# -tpn 1515 (enable tls netcat on port 1515) +# --old-tls (allow old/buggy software to connect (centos6, powershell))