From 4251d5f5e46a822b56e8a8c52c2aea53f107065b Mon Sep 17 00:00:00 2001 From: Piotr Pawlow Date: Sun, 19 Mar 2017 17:47:45 +0100 Subject: Initial commit. --- auth.php | 44 ++++++++++++++++++++++++++++++++++++++++++++ composer.json | 5 +++++ config_default.json | 8 ++++++++ 3 files changed, 57 insertions(+) create mode 100644 auth.php create mode 100644 composer.json create mode 100644 config_default.json diff --git a/auth.php b/auth.php new file mode 100644 index 0000000..7e839c9 --- /dev/null +++ b/auth.php @@ -0,0 +1,44 @@ + $v) if (!isset($config->{$k})) $config->{$k} = $v; + +if (!preg_match('/^[A-Z2-7]+$/i', $config->secret)) die("Base32 encoded secret required\n"); +$totp = new TOTP(null, $config->secret, $config->period, $config->digest, $config->digits); +while(true) { + sleep($config->delay); + echo "Czas serwera: "; + $now = new DateTime(); + echo $now->format('Y-m-d H:i:s'); + echo "\n"; + echo "Podaj kod:\n"; + $code = readline(); + if ($totp->verify($code, null, $config->window)) { + break; + } else { + echo "Zły kod\n"; + echo "Spróbuj ponownie\n"; + } +} +fclose($lockfile); + +$cmd = getenv('SSH_ORIGINAL_COMMAND'); +if ($cmd !== FALSE) passthru($cmd); +else passthru(getenv('SHELL').' -'); diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..c259f57 --- /dev/null +++ b/composer.json @@ -0,0 +1,5 @@ +{ + "require": { + "spomky-labs/otphp": "^8.3" + } +} diff --git a/config_default.json b/config_default.json new file mode 100644 index 0000000..a0f795d --- /dev/null +++ b/config_default.json @@ -0,0 +1,8 @@ +{ + "secret": "*** Base32 encoded secret ***", + "period": 30, + "window": 1, + "digest": "sha1", + "digits": 6, + "delay": 3 +} \ No newline at end of file -- cgit v1.2.3