Ajout de l'Ajax
This commit is contained in:
parent
d001b21ef7
commit
5add4907e1
29
ajax.php
29
ajax.php
@ -1,3 +1,30 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
echo json_encode(array('section' => $_POST['section'], 'pre' => 'Woooohou !'));
|
require_once 'config/config.php';
|
||||||
|
global $servers;
|
||||||
|
|
||||||
|
if (!empty($_POST['section'])) {
|
||||||
|
foreach ($servers as $ssh) {
|
||||||
|
if (array_key_exists($_POST['section'], $ssh)) {
|
||||||
|
$config = $ssh[$_POST['section']];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($_POST['action'])) {
|
||||||
|
$session = ssh2_connect($config['host'], $config['port']);
|
||||||
|
ssh2_auth_password($session, $config['user'], $config['pass']);
|
||||||
|
if ($_POST['action'] == 'status') {
|
||||||
|
$output = ssh2_exec($session, 'cd ' . $config['path'] . ' && git fetch && git status');
|
||||||
|
} else if ($_POST['action'] == 'push') {
|
||||||
|
$message = empty($_POST['message']) ? 'FTP' : $_POST['message'];
|
||||||
|
$output = ssh2_exec($session, 'cd ' . $config['path'] . ' && git add -A && git commit -m "' . $message . '" && git push');
|
||||||
|
} else if ($_POST['action'] == 'pull') {
|
||||||
|
$output = ssh2_exec($session, 'cd ' . $config['path'] . ' && git pull');
|
||||||
|
}
|
||||||
|
|
||||||
|
$pre = stream_get_contents($output);
|
||||||
|
}
|
||||||
|
|
||||||
|
echo json_encode(array('pre' => $pre));
|
||||||
|
@ -11,7 +11,7 @@ function callRequest(section) {
|
|||||||
var xhr = new XMLHttpRequest();
|
var xhr = new XMLHttpRequest();
|
||||||
xhr.open('POST', 'ajax.php');
|
xhr.open('POST', 'ajax.php');
|
||||||
xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
|
xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
|
||||||
xhr.send('section=' + section);
|
xhr.send('action=status§ion=' + section);
|
||||||
xhr.onreadystatechange = function() {
|
xhr.onreadystatechange = function() {
|
||||||
if (xhr.readyState === 4 && (xhr.status === 200 || xhr.status === 0)) {
|
if (xhr.readyState === 4 && (xhr.status === 200 || xhr.status === 0)) {
|
||||||
var data = JSON.parse(xhr.responseText);
|
var data = JSON.parse(xhr.responseText);
|
||||||
|
Loading…
Reference in New Issue
Block a user