diff --git a/ajax.php b/ajax.php index 0c4b517..7a0b96e 100644 --- a/ajax.php +++ b/ajax.php @@ -4,6 +4,7 @@ ini_set('display_errors', true); require_once 'config.php'; require_once 'utils.php'; require_once 'Net/SSH2.php'; +require_once 'Crypt/RSA.php'; global $servers; $gitstatus = 'git fetch && git status'; @@ -18,14 +19,43 @@ if (!empty($_POST['section'])) { if (!empty($_POST['action'])) { $session = new Net_SSH2($config['host'], $config['port']); - if ($session->login($config['user'], $config['pass'])) { + + if (!empty($config['key'])) { + $key = new Crypt_RSA(); + if (!empty($config['keypass'])) { + $key->setPassword($config['keypass']); + } + $keypass = $config['key']; + if (file_exists($config['key'])) { + $keypass = file_get_contents($config['key']); + } + if ($key->loadKey($keypass)) { + $session->login($config['user'], $key); + } + } + if (!$session->isConnected()) { + $session->login($config['user'], $config['pass']); + } + + if ($session->isConnected()) { if ($_POST['action'] == 'status') { echo ansi2html($session->exec('bash -c \'cd ' . $config['path'] . ' && ' . $gitstatus . "'")); + exit; } else if ($_POST['action'] == 'push') { $message = empty($_POST['message']) ? 'FTP' : str_replace(array('"', "'"), ' ', stripslashes($_POST['message'])); echo ansi2html($session->exec('bash -c \'cd ' . $config['path'] . ' && git add -A && git commit -m "' . $message . '" && git push && ' . $gitstatus . "'")); + exit; } else if ($_POST['action'] == 'pull') { echo ansi2html($session->exec('bash -c \'cd ' . $config['path'] . ' && git pull && ' . $gitstatus . "'")); + exit; + } else { + echo 'Unknown command ' . $_POST['action']; + exit; } + } else { + echo 'Permission denied, please try again.'; + exit; } } + +echo 'error'; diff --git a/config-sample.php b/config-sample.php index c3f4735..dcc76c3 100644 --- a/config-sample.php +++ b/config-sample.php @@ -5,6 +5,14 @@ // TRUE : Sécurité si vous executez Git Center sur un serveur GitLab define('ONGITLAB', false); +/* + * Dans le cas d'une connexion avec une clef RSA (clef privée) : + * -- Le mot de passe SSH (pass) est facultatif et sera utilisé en car de refus de connexion avec la clef + * -- Le keypass est le mot de passe de la clef (laissez vide ou omettez pas le champ si vous n'avez pas mis de keypass) + * -- Le key est votre clef privée qui peut être soit un chemin (absolu ou relatif) vers le fichier id_rsa soit LA FUCKING CLEF PRIVÉE EN DUR !!! + * ^ OUI ÇA FONCTIONNE OMGWTFBBQ11 + */ + // Définition de la forêt de serveurs $servers = array( 'Groupe de serveur 1' => array( @@ -29,17 +37,19 @@ $servers = array( 'host' => '192.168.1.30', 'port' => 22, 'user' => 'root', - 'pass' => 'root', + 'pass' => 'partoutatiss', 'path' => '/home/user/root' ) ), - 'Groupe de serveur 2' => array( + 'Groupe de serveur 2 conf RSA' => array( 'prod3' => array( 'title' => 'Production de la mort', 'host' => '192.168.1.40', 'port' => 22, 'user' => 'root', 'pass' => 'root', + 'key' => '/Users/tamere/.ssh/id_rsa', + 'keypass' => 'rootdelaclefrsa', 'path' => '/home/user/root' ), 'test3' => array( @@ -47,7 +57,33 @@ $servers = array( 'host' => '192.168.1.40', 'port' => 22, 'user' => 'user', - 'pass' => 'blbl', + 'key' => '-----BEGIN RSA PRIVATE KEY----- +MIIEpAIBAAKCAQEAw/scCsz9rtp+2VzUwpkdqNHPy6vqS72qvy3dt04U0rHj6NVv +/L+zF3M0EfULpNAB6D5XY35D854IKZ/Dwcp1/2xjPkLJ+XaLl38TUStLfMQA8EgR +EVzW5QrAte8xZOF35lyfoi5HBQay8R3d3SqIoRFzINEpWHtwlIHbf6CACQ1Rgx2J +gQo1/i8gu2xzp7T04cGSWguCEKbQsDqLTHNGYTDl2fTJki9b3NE6Fm+0/qp87pPq +YVNqapwPYlVDpmql4kcomPKnBzo3/ThFXeq5iwJMKwTgqnVUIttKTKJ1/HB83VPM +n/+FR+hwkcqtgSiPLI9ddtsRikO1auG8h1aB3wIDAQABAoIBAHgkSFyWri2y5HB7 +6DIji3sipDBHg6pK65GnnHPy+fDv/LePoMdg/XkytokLn8e5fHHTRd9IWH/QMVDT +ED6Mzyl2WKCicQ7tDUYiMMVhtTUXMzwZ8dyi/VoL7Xea2rztO4OM5I+XrxH1u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L2IDKjEIznGRIw386Cq2LsOmg== +-----END RSA PRIVATE KEY-----', 'path' => '/home/user/test' ), 'prod4' => array( @@ -55,7 +91,7 @@ $servers = array( 'host' => '192.168.1.50', 'port' => 22, 'user' => 'root', - 'pass' => 'root', + 'pass' => 'blbl', 'path' => '/home/user/root' ) ) diff --git a/js/app.js b/js/app.js index 1a1139c..cd305d2 100644 --- a/js/app.js +++ b/js/app.js @@ -32,7 +32,7 @@ function callRequest(action, section, message) { var splitLabel = xhr.responseText.split("\n").reverse(); label.classList.remove('label-warning'); - if (!splitLabel[1].match(/nothing to commit/) || xhr.responseText.match(/by [0-9]* commit/)) { + if ((typeof splitLabel[1] !== 'undefined' && !splitLabel[1].match(/nothing to commit/)) || xhr.responseText.match(/by [0-9]* commit/)) { label.classList.add('label-important'); label.innerHTML = 'Update needed'; } else {