2013-10-02 10:21:30 +00:00
|
|
|
<?php
|
|
|
|
|
2013-10-17 07:51:35 +00:00
|
|
|
ini_set('display_errors', true);
|
2013-10-16 19:16:17 +00:00
|
|
|
require_once 'config.php';
|
|
|
|
require_once 'utils.php';
|
2013-10-02 13:22:31 +00:00
|
|
|
require_once 'Net/SSH2.php';
|
2014-01-23 20:56:14 +00:00
|
|
|
require_once 'Crypt/RSA.php';
|
2014-07-15 06:56:55 +00:00
|
|
|
global $servers, $config;
|
2013-10-02 12:27:20 +00:00
|
|
|
|
|
|
|
if (!empty($_POST['section'])) {
|
|
|
|
foreach ($servers as $ssh) {
|
|
|
|
if (array_key_exists($_POST['section'], $ssh)) {
|
|
|
|
$config = $ssh[$_POST['section']];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!empty($_POST['action'])) {
|
2013-10-02 12:47:25 +00:00
|
|
|
$session = new Net_SSH2($config['host'], $config['port']);
|
2014-01-23 20:56:14 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
2014-07-15 06:56:55 +00:00
|
|
|
if (!$session->isConnected() && isset($config['pass'])) {
|
2014-01-23 20:56:14 +00:00
|
|
|
$session->login($config['user'], $config['pass']);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($session->isConnected()) {
|
2015-08-13 13:58:25 +00:00
|
|
|
$gitcommand = 'git --git-dir=' . $config['path'] . '/.git --work-tree=' . $config['path'];
|
2014-10-27 11:04:24 +00:00
|
|
|
|
2013-10-02 12:47:25 +00:00
|
|
|
if ($_POST['action'] == 'status') {
|
2015-02-03 15:47:23 +00:00
|
|
|
echo ansi2html($session->exec($gitcommand . ' fetch'));
|
|
|
|
echo ansi2html($session->exec($gitcommand . ' status'));
|
2014-01-23 20:56:14 +00:00
|
|
|
exit;
|
2014-04-14 13:02:53 +00:00
|
|
|
} else if (strpos($_POST['action'], 'push') !== false) {
|
|
|
|
if (strpos($_POST['action'], 'force') !== false) {
|
2015-02-03 15:47:23 +00:00
|
|
|
echo ansi2html($session->exec($gitcommand . ' push'));
|
|
|
|
echo ansi2html($session->exec($gitcommand . ' fetch'));
|
|
|
|
echo ansi2html($session->exec($gitcommand . ' status'));
|
2014-04-14 13:02:53 +00:00
|
|
|
if (!empty($config['after_push'])) {
|
2015-02-03 15:47:23 +00:00
|
|
|
echo ansi2html($session->exec($config['after_push']));
|
2014-04-14 13:02:53 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$message = empty($_POST['message']) ? 'FTP' : str_replace(array('"', "'"), ' ', stripslashes($_POST['message']));
|
2015-02-03 15:47:23 +00:00
|
|
|
echo ansi2html($session->exec($gitcommand . ' add -A'));
|
|
|
|
echo ansi2html($session->exec($gitcommand . ' commit -m "' . $message . '"'));
|
|
|
|
echo ansi2html($session->exec($gitcommand . ' push'));
|
|
|
|
echo ansi2html($session->exec($gitcommand . ' fetch'));
|
|
|
|
echo ansi2html($session->exec($gitcommand . ' status'));
|
2014-04-14 13:02:53 +00:00
|
|
|
if (!empty($config['after_push'])) {
|
2015-02-03 15:47:23 +00:00
|
|
|
echo ansi2html($session->exec($config['after_push']));
|
2014-04-14 13:02:53 +00:00
|
|
|
}
|
2014-04-07 07:58:06 +00:00
|
|
|
}
|
2014-01-23 20:56:14 +00:00
|
|
|
exit;
|
2013-10-02 12:47:25 +00:00
|
|
|
} else if ($_POST['action'] == 'pull') {
|
2015-02-03 15:47:23 +00:00
|
|
|
echo ansi2html($session->exec($gitcommand . ' pull'));
|
|
|
|
echo ansi2html($session->exec($gitcommand . ' fetch'));
|
|
|
|
echo ansi2html($session->exec($gitcommand . ' status'));
|
2014-04-07 07:58:06 +00:00
|
|
|
if (!empty($config['after_pull'])) {
|
2015-02-03 15:47:23 +00:00
|
|
|
echo ansi2html($session->exec($config['after_pull']));
|
2014-04-07 07:58:06 +00:00
|
|
|
}
|
2014-01-23 20:56:14 +00:00
|
|
|
exit;
|
|
|
|
} else {
|
|
|
|
echo 'Unknown command ' . $_POST['action'];
|
|
|
|
exit;
|
2013-10-02 12:47:25 +00:00
|
|
|
}
|
2014-01-23 20:56:14 +00:00
|
|
|
} else {
|
|
|
|
echo 'Permission denied, please try again.';
|
|
|
|
exit;
|
2013-10-02 12:27:20 +00:00
|
|
|
}
|
|
|
|
}
|
2014-01-23 20:56:14 +00:00
|
|
|
|
|
|
|
echo 'error';
|