2010-09-20 07:41:43 +00:00
|
|
|
<?php
|
2010-11-17 18:53:40 +00:00
|
|
|
require_once "functions.php";
|
|
|
|
require_once "jsonwrapper.php";
|
|
|
|
|
|
|
|
$query = '';
|
|
|
|
$output = '';
|
|
|
|
$temp = '';
|
|
|
|
$pythonProcess = '';
|
2011-09-12 14:24:09 +00:00
|
|
|
if (!isAuthenticated()) {
|
|
|
|
echo ("Please login before continuing!");
|
2010-11-17 18:53:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$query = 's=' . $_POST['s'] . '&w=' . $_POST['w'] . '&h=' . $_POST['h'];
|
2011-09-12 14:24:09 +00:00
|
|
|
if (isset($_POST['q'])) {
|
2010-11-17 18:53:40 +00:00
|
|
|
$query .= '&q=1';
|
2011-09-12 14:24:09 +00:00
|
|
|
} else {
|
2010-11-17 18:53:40 +00:00
|
|
|
$query .= '&q=0';
|
|
|
|
}
|
|
|
|
|
2011-09-12 14:24:09 +00:00
|
|
|
if (isset($_POST['f'])) {
|
2010-11-17 18:53:40 +00:00
|
|
|
$pythonProcess = exec('ps -aef | grep -v grep | grep ajaxterm.py');
|
2011-09-12 14:24:09 +00:00
|
|
|
if ('' == $pythonProcess) {
|
2010-11-17 18:53:40 +00:00
|
|
|
exec('nohup ' . dirname(__FILE__) . '/ajaxterm/ajaxterm.py >/dev/null 2>&1 &');
|
2010-09-20 07:41:43 +00:00
|
|
|
}
|
2010-11-17 18:53:40 +00:00
|
|
|
sleep(1);
|
|
|
|
|
|
|
|
$temp = $query . '&k=' . urlencode($_SESSION["username"] . "\r");
|
|
|
|
$output = rconsSynchronise($temp);
|
2011-09-12 14:24:09 +00:00
|
|
|
if (0 < substr_count($output, 'error')) {
|
2010-11-17 18:53:40 +00:00
|
|
|
echo json_encode(array('err'=>$output));
|
|
|
|
exit;
|
2010-09-20 07:41:43 +00:00
|
|
|
}
|
2010-11-17 18:53:40 +00:00
|
|
|
sleep(1);
|
2010-09-20 07:41:43 +00:00
|
|
|
|
2010-11-17 18:53:40 +00:00
|
|
|
$temp = $query . '&k=' . urlencode(getpassword() . "\r");
|
|
|
|
$output = rconsSynchronise($temp);
|
2011-09-12 14:24:09 +00:00
|
|
|
if (0 < substr_count($output, 'error')) {
|
2010-11-17 18:53:40 +00:00
|
|
|
echo json_encode(array('err'=>$output));
|
|
|
|
exit;
|
2010-09-20 07:41:43 +00:00
|
|
|
}
|
2010-11-17 18:53:40 +00:00
|
|
|
sleep(1);
|
2010-09-20 07:41:43 +00:00
|
|
|
|
2010-11-17 18:53:40 +00:00
|
|
|
$temp = $query . '&c=1&k=' . urlencode('rcons ' . $_POST['s'] . "\r");
|
2011-09-12 14:24:09 +00:00
|
|
|
} else {
|
2010-11-17 18:53:40 +00:00
|
|
|
$temp = $query . '&c=1&k=' . urlencode($_POST['k']);
|
|
|
|
}
|
2011-04-15 20:46:23 +00:00
|
|
|
|
2010-11-17 18:53:40 +00:00
|
|
|
$output = rconsSynchronise($temp);
|
2011-09-12 14:24:09 +00:00
|
|
|
if (0 < substr_count($output, 'error')) {
|
2010-11-17 18:53:40 +00:00
|
|
|
echo (array('err'=>$output));
|
2011-09-12 14:24:09 +00:00
|
|
|
} else {
|
2010-11-17 18:53:40 +00:00
|
|
|
$xml = simplexml_load_string($output);
|
2011-09-12 14:24:09 +00:00
|
|
|
if ('pre' == $xml->getName()) {
|
2010-11-17 18:53:40 +00:00
|
|
|
$output = $xml->asXML();
|
|
|
|
$output = preg_replace('/'. chr(160) . '/', ' ', $output);
|
|
|
|
|
|
|
|
echo json_encode(array('term'=>$output));
|
2011-09-12 14:24:09 +00:00
|
|
|
} else {
|
2010-11-17 18:53:40 +00:00
|
|
|
echo json_encode(array('nc'=>'nc'));
|
|
|
|
}
|
|
|
|
}
|
2010-09-20 07:41:43 +00:00
|
|
|
|
2011-09-12 14:24:09 +00:00
|
|
|
function rconsSynchronise($parameter) {
|
2010-09-20 07:41:43 +00:00
|
|
|
$flag = false;
|
|
|
|
$return = "";
|
|
|
|
$out = "";
|
|
|
|
$fp = fsockopen("127.0.0.1", 8022, $errno, $errstr, 30);
|
|
|
|
if (!$fp) {
|
2010-11-17 18:53:40 +00:00
|
|
|
return "<error>$errstr($errno)</error>";
|
2010-09-20 07:41:43 +00:00
|
|
|
}
|
2010-11-17 18:53:40 +00:00
|
|
|
|
2010-09-20 07:41:43 +00:00
|
|
|
$out = "GET /u?$parameter HTTP/1.1\r\nHost: 127.0.0.1:8022\r\nConnection: Close\r\n\r\n";
|
2010-11-17 18:53:40 +00:00
|
|
|
|
2010-09-20 07:41:43 +00:00
|
|
|
fwrite($fp, $out);
|
2011-09-12 14:24:09 +00:00
|
|
|
while (!feof($fp)) {
|
2010-11-17 18:53:40 +00:00
|
|
|
$line = fgets($fp,1024);
|
2011-09-12 14:24:09 +00:00
|
|
|
if (0 == strlen($line)) {
|
2010-11-17 18:53:40 +00:00
|
|
|
continue;
|
|
|
|
}
|
2012-05-01 23:43:11 +00:00
|
|
|
|
2011-09-12 14:24:09 +00:00
|
|
|
if ('<' == substr($line, 0, 1)) {
|
2010-11-17 18:53:40 +00:00
|
|
|
$flag = true;
|
|
|
|
$return .= $line;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-05-01 23:43:11 +00:00
|
|
|
|
2011-09-12 14:24:09 +00:00
|
|
|
if ($flag) {
|
|
|
|
while (!feof($fp)) {
|
2010-11-17 18:53:40 +00:00
|
|
|
$return .= fgets($fp, 1024);
|
|
|
|
}
|
|
|
|
}
|
2010-09-20 07:41:43 +00:00
|
|
|
|
2010-11-17 18:53:40 +00:00
|
|
|
return ($return);
|
2010-09-20 07:41:43 +00:00
|
|
|
}
|
|
|
|
?>
|