This commit is contained in:
marcus hinz
2026-06-21 11:26:57 +02:00
parent f19d52bbe5
commit fe9973f831
3 changed files with 50 additions and 21 deletions
Binary file not shown.
+23
View File
@@ -0,0 +1,23 @@
openconnect --protocol=anyconnect --user ex08802409 --script 'vpn-slice gitops.apps.ocp-dev01.wgn.wuerth.com console-openshift-console.apps.ocp-dev01.wgn.wuerth.com oauth-openshift.apps.ocp-dev01.wgn.wuerth.com apm-dev.wgn.wuerth.com odatang9.wgn.wuerth.com fs.wgn.wuerth.com fahrzeugeinrichtung.apps.ocp-dev01.wgn.wuerth.com api.ocp-dev01.wgn.wuerth.com console-openshift-console.apps.ocp-01.wgn.wuerth.com gitops.apps.ocp-01.wgn.wuerth.com oauth-openshift.apps.ocp-01.wgn.wuerth.com api.ocp-01.wgn.wuerth.com proxy.wgs.wuerth.com odatang8.wgn.wuerth.com fahrzeugeinrichtung.apps.ocp-01.wgn.wuerth.com' https://loki.witglobal.net
[sudo] password for marcuh: POST https://loki.witglobal.net/
Connected to 185.101.5.240:443
SSL negotiation with loki.witglobal.net
Connected to HTTPS on loki.witglobal.net with ciphersuite (TLS1.3)-(ECDHE-SECP256R1)-(RSA-PSS-RSAE-SHA256)-(AES-128-GCM)
Got HTTP response: HTTP/1.1 404 Not Found
Unexpected 404 result from server
GET https://loki.witglobal.net/
Connected to 185.101.5.240:443
SSL negotiation with loki.witglobal.net
Connected to HTTPS on loki.witglobal.net with ciphersuite (TLS1.3)-(ECDHE-SECP256R1)-(RSA-PSS-RSAE-SHA256)-(AES-128-GCM)
Got HTTP response: HTTP/1.0 302 Object Moved
GET https://loki.witglobal.net/+webvpn+/index.html
SSL negotiation with loki.witglobal.net
Connected to HTTPS on loki.witglobal.net with ciphersuite (TLS1.3)-(ECDHE-SECP256R1)-(RSA-PSS-RSAE-SHA256)-(AES-128-GCM)
Please enter your username and password.
POST https://loki.witglobal.net/+webvpn+/index.html
Login failed.
Please enter your username and password.
Password:
fgets (stdin): Inappropriate ioctl for device
+27 -21
View File
@@ -132,27 +132,31 @@ class VpnWorker(QObject):
if not server.startswith("https://"):
server = "https://" + server
cmd_str = (
f"printf '%s\\n%s\\n' '{self.sudo_pw}' '{self.vpn_pw}'"
f" | sudo -kS openconnect"
f" --protocol=anyconnect"
f" --user {self.user}"
f" --passwd-on-stdin"
f" --pid-file {PIDFILE}"
f" --force-dpd 0"
f" --script '{vpn_slice_arg}'"
f" {server}"
)
cmd = [
"sudo", "-kS", "openconnect",
"--protocol=anyconnect",
"--user", self.user,
"--passwd-on-stdin",
"--pid-file", PIDFILE,
"--force-dpd", "0",
"--script", vpn_slice_arg,
server,
]
self.log(f"$ openconnect --protocol=anyconnect --user {self.user} --script '{vpn_slice_arg}' {server}\n\n")
p = subprocess.Popen(
cmd_str,
shell=True,
cmd,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
bufsize=0,
)
# wie die funktionierende printf-Pipe: sudo liest Zeile 1, openconnect
# Zeile 2 (--passwd-on-stdin); stdin schließen, damit openconnect EOF sieht
p.stdin.write(f"{self.sudo_pw}\n{self.vpn_pw}\n".encode())
p.stdin.flush()
p.stdin.close()
start = time.time()
results_seen = 0
@@ -187,10 +191,12 @@ class VpnWorker(QObject):
self.done.emit(False, "")
return
sudo_in = (self.sudo_pw + "\n").encode()
self.log(f"Sending SIGINT to pid {pid}...\n")
subprocess.run(
f"echo '{self.sudo_pw}' | sudo -S kill -INT {pid}",
shell=True,
["sudo", "-S", "kill", "-INT", str(pid)],
input=sudo_in,
stderr=subprocess.DEVNULL,
)
@@ -198,8 +204,8 @@ class VpnWorker(QObject):
while time.time() - start < 12:
if not _pid_is_openconnect(pid):
subprocess.run(
f"echo '{self.sudo_pw}' | sudo -S rm -f {PIDFILE}",
shell=True,
["sudo", "-S", "rm", "-f", PIDFILE],
input=sudo_in,
stderr=subprocess.DEVNULL,
)
self.log("Disconnected.\n")
@@ -210,15 +216,15 @@ class VpnWorker(QObject):
if 3.0 < elapsed < 3.5:
self.log("Escalating: SIGTERM\n")
subprocess.run(
f"echo '{self.sudo_pw}' | sudo -S kill -TERM {pid}",
shell=True,
["sudo", "-S", "kill", "-TERM", str(pid)],
input=sudo_in,
stderr=subprocess.DEVNULL,
)
if 8.0 < elapsed < 8.5:
self.log("Escalating: SIGKILL\n")
subprocess.run(
f"echo '{self.sudo_pw}' | sudo -S kill -KILL {pid}",
shell=True,
["sudo", "-S", "kill", "-KILL", str(pid)],
input=sudo_in,
stderr=subprocess.DEVNULL,
)
time.sleep(0.2)