diff --git a/modules/pi_control/pages/hosts.php b/modules/pi_control/pages/hosts.php index e450ff2..bf1fa7d 100644 --- a/modules/pi_control/pages/hosts.php +++ b/modules/pi_control/pages/hosts.php @@ -47,10 +47,19 @@ if (isset($_GET['update_json'])) { $strictHostKey = !empty($settings['terminal_strict_hostkey']); $updateCmd = <<<'SH' -sh -lc 'if ! command -v apt-get >/dev/null 2>&1; then echo "__ERR__NO_APT"; exit 2; fi; if sudo -n apt update -qq >/dev/null 2>&1; then echo "__APT_UPDATE__=1"; else echo "__APT_UPDATE__=0"; fi; count=$(apt-get -s dist-upgrade 2>/dev/null | grep -c "^Inst "); echo "__COUNT__=$count"' +if ! command -v apt-get >/dev/null 2>&1; then echo "__ERR__NO_APT"; exit 2; fi; +if sudo -n apt update -qq >/dev/null 2>&1; then echo "__APT_UPDATE__=1"; else echo "__APT_UPDATE__=0"; fi; +count=$(apt-get -s dist-upgrade 2>/dev/null | grep -c "^Inst "); +echo "__COUNT__=$count" SH; $upgradeCmd = <<<'SH' -sh -lc 'id="$(. /etc/os-release 2>/dev/null && echo "${ID:-}")"; current="$(. /etc/os-release 2>/dev/null && echo "${VERSION_CODENAME:-}")"; if [ "$id" != "debian" ] || [ -z "$current" ]; then echo "__UPGRADE__=0"; exit 0; fi; latest="$( (command -v curl >/dev/null 2>&1 && curl -fsSL https://deb.debian.org/debian/dists/stable/Release) || (command -v wget >/dev/null 2>&1 && wget -qO- https://deb.debian.org/debian/dists/stable/Release) )"; latest="$(printf "%s" "$latest" | awk -F": " "/^Codename:/{print $2}")"; if [ -z "$latest" ]; then echo "__UPGRADE__=0"; echo "__RAW__=NO_FETCH"; exit 0; fi; if [ "$current" != "$latest" ]; then echo "__UPGRADE__=1"; else echo "__UPGRADE__=0"; fi' +id="$(. /etc/os-release 2>/dev/null && echo "${ID:-}")"; +current="$(. /etc/os-release 2>/dev/null && echo "${VERSION_CODENAME:-}")"; +if [ "$id" != "debian" ] || [ -z "$current" ]; then echo "__UPGRADE__=0"; exit 0; fi; +latest="$( (command -v curl >/dev/null 2>&1 && curl -fsSL https://deb.debian.org/debian/dists/stable/Release) || (command -v wget >/dev/null 2>&1 && wget -qO- https://deb.debian.org/debian/dists/stable/Release) )"; +latest="$(printf "%s" "$latest" | awk -F": " "/^Codename:/{print $2}")"; +if [ -z "$latest" ]; then echo "__UPGRADE__=0"; echo "__RAW__=NO_FETCH"; exit 0; fi; +if [ "$current" != "$latest" ]; then echo "__UPGRADE__=1"; else echo "__UPGRADE__=0"; fi SH; [$updExit, $updOut, $updErr] = runSshCommandCapture($host, $updateCmd, $strictHostKey, 20); @@ -243,11 +252,11 @@ function runSshCommandCapture(array $host, string $command, bool $strictHostKey, $opts = $strictHostKey ? '-o StrictHostKeyChecking=accept-new -o UserKnownHostsFile=/root/.ssh/known_hosts' : '-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null'; - $opts .= ' -o ConnectTimeout=6 -o NumberOfPasswordPrompts=1'; + $opts .= ' -o ConnectTimeout=6 -o NumberOfPasswordPrompts=1 -o LogLevel=ERROR -o RequestTTY=no'; $target = escapeshellarg($user . '@' . $hostAddr); - $remote = '/bin/bash -lc ' . escapeshellarg($command); - $cmd = 'ssh ' . $opts . ' -p ' . (int)$port . ' '; + $remote = '/bin/sh -c ' . escapeshellarg($command); + $cmd = 'ssh -T ' . $opts . ' -p ' . (int)$port . ' '; if ($authType === 'key' && $keyPath !== '') { $cmd .= '-i ' . escapeshellarg($keyPath) . ' -o BatchMode=yes '; } elseif ($authType === 'key') { diff --git a/tools/pi_control/check_updates.php b/tools/pi_control/check_updates.php index 3360576..a5426cb 100644 --- a/tools/pi_control/check_updates.php +++ b/tools/pi_control/check_updates.php @@ -14,10 +14,19 @@ $settings = modules()->settings($module); $strictHostKey = !empty($settings['terminal_strict_hostkey']); $updateCmd = <<<'SH' -sh -lc 'if ! command -v apt-get >/dev/null 2>&1; then echo "__ERR__NO_APT"; exit 2; fi; if sudo -n apt update -qq >/dev/null 2>&1; then echo "__APT_UPDATE__=1"; else echo "__APT_UPDATE__=0"; fi; count=$(apt-get -s dist-upgrade 2>/dev/null | grep -c "^Inst "); echo "__COUNT__=$count"' +if ! command -v apt-get >/dev/null 2>&1; then echo "__ERR__NO_APT"; exit 2; fi; +if sudo -n apt update -qq >/dev/null 2>&1; then echo "__APT_UPDATE__=1"; else echo "__APT_UPDATE__=0"; fi; +count=$(apt-get -s dist-upgrade 2>/dev/null | grep -c "^Inst "); +echo "__COUNT__=$count" SH; $upgradeCmd = <<<'SH' -sh -lc 'id="$(. /etc/os-release 2>/dev/null && echo "${ID:-}")"; current="$(. /etc/os-release 2>/dev/null && echo "${VERSION_CODENAME:-}")"; if [ "$id" != "debian" ] || [ -z "$current" ]; then echo "__UPGRADE__=0"; exit 0; fi; latest="$( (command -v curl >/dev/null 2>&1 && curl -fsSL https://deb.debian.org/debian/dists/stable/Release) || (command -v wget >/dev/null 2>&1 && wget -qO- https://deb.debian.org/debian/dists/stable/Release) )"; latest="$(printf "%s" "$latest" | awk -F": " "/^Codename:/{print $2}")"; if [ -z "$latest" ]; then echo "__UPGRADE__=0"; echo "__RAW__=NO_FETCH"; exit 0; fi; if [ "$current" != "$latest" ]; then echo "__UPGRADE__=1"; else echo "__UPGRADE__=0"; fi' +id="$(. /etc/os-release 2>/dev/null && echo "${ID:-}")"; +current="$(. /etc/os-release 2>/dev/null && echo "${VERSION_CODENAME:-}")"; +if [ "$id" != "debian" ] || [ -z "$current" ]; then echo "__UPGRADE__=0"; exit 0; fi; +latest="$( (command -v curl >/dev/null 2>&1 && curl -fsSL https://deb.debian.org/debian/dists/stable/Release) || (command -v wget >/dev/null 2>&1 && wget -qO- https://deb.debian.org/debian/dists/stable/Release) )"; +latest="$(printf "%s" "$latest" | awk -F": " "/^Codename:/{print $2}")"; +if [ -z "$latest" ]; then echo "__UPGRADE__=0"; echo "__RAW__=NO_FETCH"; exit 0; fi; +if [ "$current" != "$latest" ]; then echo "__UPGRADE__=1"; else echo "__UPGRADE__=0"; fi SH; $driver = (string)$pdo->getAttribute(PDO::ATTR_DRIVER_NAME); @@ -94,11 +103,11 @@ function runSshCommandCapture(array $host, string $command, bool $strictHostKey, $opts = $strictHostKey ? '-o StrictHostKeyChecking=accept-new -o UserKnownHostsFile=/root/.ssh/known_hosts' : '-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null'; - $opts .= ' -o ConnectTimeout=6 -o NumberOfPasswordPrompts=1'; + $opts .= ' -o ConnectTimeout=6 -o NumberOfPasswordPrompts=1 -o LogLevel=ERROR -o RequestTTY=no'; $target = escapeshellarg($user . '@' . $hostAddr); - $remote = '/bin/bash -lc ' . escapeshellarg($command); - $cmd = 'ssh ' . $opts . ' -p ' . (int)$port . ' '; + $remote = '/bin/sh -c ' . escapeshellarg($command); + $cmd = 'ssh -T ' . $opts . ' -p ' . (int)$port . ' '; if ($authType === 'key' && $keyPath !== '') { $cmd .= '-i ' . escapeshellarg($keyPath) . ' -o BatchMode=yes '; } elseif ($authType === 'key') {