2012-06-04 16:58:40 +02:00
|
|
|
<?php
|
|
|
|
|
/*
|
|
|
|
|
FusionPBX
|
|
|
|
|
Version: MPL 1.1
|
|
|
|
|
|
|
|
|
|
The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
|
1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
|
the License. You may obtain a copy of the License at
|
|
|
|
|
http://www.mozilla.org/MPL/
|
|
|
|
|
|
|
|
|
|
Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
|
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
|
for the specific language governing rights and limitations under the
|
|
|
|
|
License.
|
|
|
|
|
|
|
|
|
|
The Original Code is FusionPBX
|
|
|
|
|
|
|
|
|
|
The Initial Developer of the Original Code is
|
|
|
|
|
Mark J Crane <markjcrane@fusionpbx.com>
|
2014-10-22 10:15:20 +02:00
|
|
|
Portions created by the Initial Developer are Copyright (C) 2008-2014
|
2012-06-04 16:58:40 +02:00
|
|
|
the Initial Developer. All Rights Reserved.
|
|
|
|
|
|
|
|
|
|
Contributor(s):
|
|
|
|
|
Mark J Crane <markjcrane@fusionpbx.com>
|
|
|
|
|
*/
|
|
|
|
|
require_once "root.php";
|
2013-07-06 08:03:27 +02:00
|
|
|
require_once "resources/require.php";
|
2013-07-06 07:50:55 +02:00
|
|
|
require_once "resources/check_auth.php";
|
2013-09-21 23:45:35 +02:00
|
|
|
if (permission_exists('service_view')) {
|
2012-06-04 16:58:40 +02:00
|
|
|
//access granted
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
echo "access denied";
|
|
|
|
|
exit;
|
|
|
|
|
}
|
2014-02-23 09:24:56 +01:00
|
|
|
|
|
|
|
|
//add multi-lingual support
|
2015-01-18 11:06:08 +01:00
|
|
|
$language = new text;
|
|
|
|
|
$text = $language->get();
|
2014-02-23 09:24:56 +01:00
|
|
|
|
2013-07-06 08:29:50 +02:00
|
|
|
require_once "resources/header.php";
|
2015-02-15 10:04:54 +01:00
|
|
|
$document['title'] = $text['title-services'];
|
2013-07-06 08:29:50 +02:00
|
|
|
require_once "resources/paging.php";
|
2012-06-04 16:58:40 +02:00
|
|
|
|
2014-10-22 10:15:20 +02:00
|
|
|
$order_by = check_str($_GET["order_by"]);
|
|
|
|
|
$order = check_str($_GET["order"]);
|
2012-06-04 16:58:40 +02:00
|
|
|
|
|
|
|
|
if (strlen($_GET["a"]) > 0) {
|
2014-10-22 10:15:20 +02:00
|
|
|
$service_uuid = check_str($_GET["id"]);
|
2012-11-24 03:28:56 +01:00
|
|
|
$sql = "select * from v_services ";
|
2012-06-04 16:58:40 +02:00
|
|
|
$sql .= "where service_uuid = '$service_uuid' ";
|
|
|
|
|
$prep_statement = $db->prepare(check_sql($sql));
|
|
|
|
|
$prep_statement->execute();
|
|
|
|
|
$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
|
|
|
|
|
foreach ($result as &$row) {
|
|
|
|
|
$domain_uuid = $row["domain_uuid"];
|
|
|
|
|
$service_name = $row["service_name"];
|
|
|
|
|
$service_type = $row["service_type"];
|
|
|
|
|
$service_data = $row["service_data"];
|
|
|
|
|
$service_cmd_start = $row["service_cmd_start"];
|
|
|
|
|
$service_cmd_stop = $row["service_cmd_stop"];
|
|
|
|
|
$service_description = $row["service_description"];
|
|
|
|
|
}
|
|
|
|
|
unset ($prep_statement);
|
|
|
|
|
|
|
|
|
|
if ($_GET["a"] == "stop") {
|
2014-02-23 09:24:56 +01:00
|
|
|
$_SESSION["message"] = $text['message-stopping'].': '.$service_name;
|
2012-06-04 16:58:40 +02:00
|
|
|
shell_exec($service_cmd_stop);
|
|
|
|
|
}
|
|
|
|
|
if ($_GET["a"] == "start") {
|
2014-02-23 09:24:56 +01:00
|
|
|
$_SESSION["message"] = $text['message-starting'].': '.$service_name;
|
2012-06-04 16:58:40 +02:00
|
|
|
shell_exec($service_cmd_start);
|
|
|
|
|
}
|
2014-02-23 09:24:56 +01:00
|
|
|
header("Location: services.php");
|
2012-06-04 16:58:40 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//check if a process is running
|
|
|
|
|
function is_process_running($pid) {
|
|
|
|
|
$status = shell_exec( 'ps -p ' . $pid );
|
|
|
|
|
$status_array = explode ("\n", $status);
|
|
|
|
|
if (strlen(trim($status_array[1])) > 0) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-15 09:46:20 +01:00
|
|
|
echo "<table width='100%' cellpadding='0' cellspacing='0' border='0'>\n";
|
2012-06-04 16:58:40 +02:00
|
|
|
echo "<tr>\n";
|
2015-02-15 10:04:54 +01:00
|
|
|
echo "<td width='50%' align='left' nowrap='nowrap'><b>".$text['header-services']."</b></td>\n";
|
2012-06-04 16:58:40 +02:00
|
|
|
echo "<td width='50%' align='right'> </td>\n";
|
|
|
|
|
echo "</tr>\n";
|
|
|
|
|
echo "<tr>\n";
|
|
|
|
|
echo "<td align='left' colspan='2'>\n";
|
2015-02-15 10:04:54 +01:00
|
|
|
echo $text['description-services']."<br /><br />\n";
|
2012-06-04 16:58:40 +02:00
|
|
|
echo "</td>\n";
|
|
|
|
|
echo "</tr>\n";
|
|
|
|
|
echo "</tr></table>\n";
|
|
|
|
|
|
2012-11-24 03:28:56 +01:00
|
|
|
$sql = "select * from v_services ";
|
2012-06-04 16:58:40 +02:00
|
|
|
if (strlen($order_by)> 0) { $sql .= "order by $order_by $order "; }
|
|
|
|
|
$prep_statement = $db->prepare(check_sql($sql));
|
|
|
|
|
$prep_statement->execute();
|
|
|
|
|
$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
|
|
|
|
|
$num_rows = count($result);
|
|
|
|
|
unset ($prep_statement, $result, $sql);
|
|
|
|
|
$rows_per_page = 10;
|
|
|
|
|
$param = "";
|
|
|
|
|
$page = $_GET['page'];
|
2014-02-23 09:24:56 +01:00
|
|
|
if (strlen($page) == 0) { $page = 0; $_GET['page'] = 0; }
|
|
|
|
|
list($paging_controls, $rows_per_page, $var_3) = paging($num_rows, $param, $rows_per_page);
|
|
|
|
|
$offset = $rows_per_page * $page;
|
2012-06-04 16:58:40 +02:00
|
|
|
|
2012-11-24 03:28:56 +01:00
|
|
|
$sql = "select * from v_services ";
|
2012-06-04 16:58:40 +02:00
|
|
|
if (strlen($order_by)> 0) { $sql .= "order by $order_by $order "; }
|
|
|
|
|
$sql .= " limit $rows_per_page offset $offset ";
|
|
|
|
|
$prep_statement = $db->prepare(check_sql($sql));
|
|
|
|
|
$prep_statement->execute();
|
|
|
|
|
$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
|
|
|
|
|
$result_count = count($result);
|
|
|
|
|
unset ($prep_statement, $sql);
|
|
|
|
|
|
|
|
|
|
$c = 0;
|
|
|
|
|
$row_style["0"] = "row_style0";
|
|
|
|
|
$row_style["1"] = "row_style1";
|
|
|
|
|
|
2014-06-22 06:53:29 +02:00
|
|
|
echo "<table class='tr_hover' width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
|
2012-06-04 16:58:40 +02:00
|
|
|
echo "<tr>\n";
|
2015-02-15 10:04:54 +01:00
|
|
|
echo th_order_by('service_name', $text['label-name'], $order_by, $order);
|
|
|
|
|
echo "<th>".$text['label-status']."</th>\n";
|
|
|
|
|
echo "<th>".$text['label-action']."</th>\n";
|
|
|
|
|
echo th_order_by('service_description', $text['label-description'], $order_by, $order);
|
2014-02-26 07:10:56 +01:00
|
|
|
echo "<td class='list_control_icons'>";
|
2013-09-21 23:45:35 +02:00
|
|
|
if (permission_exists('service_add')) {
|
2014-02-26 07:10:56 +01:00
|
|
|
echo "<a href='service_edit.php' alt='add'>$v_link_label_add</a>";
|
2012-06-04 16:58:40 +02:00
|
|
|
}
|
|
|
|
|
echo "</td>\n";
|
2014-06-22 06:53:29 +02:00
|
|
|
echo "</tr>\n";
|
2012-06-04 16:58:40 +02:00
|
|
|
|
2014-10-22 10:15:20 +02:00
|
|
|
if ($result_count > 0) {
|
2012-06-04 16:58:40 +02:00
|
|
|
foreach($result as $row) {
|
2014-06-22 06:53:29 +02:00
|
|
|
$tr_link = (permission_exists('service_edit')) ? "href='service_edit.php?id=".$row[service_uuid]."'" : null;
|
|
|
|
|
echo "<tr ".$tr_link.">\n";
|
2014-06-21 05:42:09 +02:00
|
|
|
echo " <td valign='top' class='".$row_style[$c]."'>";
|
|
|
|
|
if (permission_exists('service_edit')) {
|
|
|
|
|
echo "<a href='service_edit.php?id=".$row[service_uuid]."'>".$row[service_name]."</a>";
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
echo $row[service_name];
|
|
|
|
|
}
|
|
|
|
|
echo " </td>\n";
|
2012-06-04 16:58:40 +02:00
|
|
|
echo " <td valign='top' class='".$row_style[$c]."'>\n";
|
2014-10-22 10:15:20 +02:00
|
|
|
if ($row[service_type] == "pid" || $row[service_type] == "pid_file") {
|
|
|
|
|
$pid = file_get_contents($row[service_data]);
|
|
|
|
|
if (is_process_running($pid)) {
|
2015-02-15 10:04:54 +01:00
|
|
|
echo "<strong>".$text['label-running']."</strong>";
|
2014-10-22 10:15:20 +02:00
|
|
|
}
|
|
|
|
|
else {
|
2015-02-15 10:04:54 +01:00
|
|
|
echo "<strong>".$text['label-stopped']."</strong>";
|
2014-10-22 10:15:20 +02:00
|
|
|
}
|
2012-06-04 16:58:40 +02:00
|
|
|
}
|
2014-10-22 10:15:20 +02:00
|
|
|
if ($row[service_type] == "file") {
|
|
|
|
|
$service_data = $row[service_data];
|
|
|
|
|
if (file_exists($service_data)) {
|
2015-02-15 10:04:54 +01:00
|
|
|
echo "<strong>".$text['label-running']."</strong>";
|
2014-10-22 10:15:20 +02:00
|
|
|
}
|
|
|
|
|
else {
|
2015-02-15 10:04:54 +01:00
|
|
|
echo "<strong>".$text['label-stopped']."</strong>";
|
2014-10-22 10:15:20 +02:00
|
|
|
}
|
2012-06-04 16:58:40 +02:00
|
|
|
}
|
|
|
|
|
echo "</td>\n";
|
|
|
|
|
echo " <td valign='top' class='".$row_style[$c]."'>\n";
|
2014-10-22 10:15:20 +02:00
|
|
|
if ($row[service_type] == "pid" || $row[service_type] == "pid_file") {
|
|
|
|
|
if (is_process_running($pid)) {
|
2015-02-15 10:04:54 +01:00
|
|
|
echo " <a href='services.php?id=".$row[service_uuid]."&a=stop' alt='stop'>".$text['label-stop']."</a>";
|
2014-10-22 10:15:20 +02:00
|
|
|
}
|
|
|
|
|
else {
|
2015-02-15 10:04:54 +01:00
|
|
|
echo " <a href='services.php?id=".$row[service_uuid]."&a=start' alt='start'>".$text['label-start']."</a>";
|
2014-10-22 10:15:20 +02:00
|
|
|
}
|
2012-06-04 16:58:40 +02:00
|
|
|
}
|
2014-10-22 10:15:20 +02:00
|
|
|
if ($row[service_type] == "file") {
|
|
|
|
|
if (file_exists($service_data)) {
|
2015-02-15 10:04:54 +01:00
|
|
|
echo " <a href='services.php?id=".$row[service_uuid]."&a=stop' alt='stop'>".$text['label-stop']."</a>";
|
2014-10-22 10:15:20 +02:00
|
|
|
}
|
|
|
|
|
else {
|
2015-02-15 10:04:54 +01:00
|
|
|
echo " <a href='services.php?id=".$row[service_uuid]."&a=start' alt='start'>".$text['label-start']."</a>";
|
2014-10-22 10:15:20 +02:00
|
|
|
}
|
2012-06-04 16:58:40 +02:00
|
|
|
}
|
|
|
|
|
echo "</td>\n";
|
2014-06-21 05:42:09 +02:00
|
|
|
echo " <td valign='top' class='row_stylebg'>".$row[service_description]." </td>\n";
|
2014-02-26 07:10:56 +01:00
|
|
|
echo " <td class='list_control_icons'>";
|
2013-09-21 23:45:35 +02:00
|
|
|
if (permission_exists('service_edit')) {
|
2015-02-15 10:04:54 +01:00
|
|
|
echo "<a href='service_edit.php?id=".$row[service_uuid]."' alt='".$text['button-edit']."'>$v_link_label_edit</a>";
|
2012-06-04 16:58:40 +02:00
|
|
|
}
|
2013-09-21 23:45:35 +02:00
|
|
|
if (permission_exists('service_delete')) {
|
2015-02-15 10:04:54 +01:00
|
|
|
echo "<a href='service_delete.php?id=".$row[service_uuid]."' alt='".$text['button-delete']."' onclick=\"return confirm('".$text['confirm-delete']."')\">$v_link_label_delete</a>";
|
2012-06-04 16:58:40 +02:00
|
|
|
}
|
|
|
|
|
echo " </td>\n";
|
|
|
|
|
echo "</tr>\n";
|
|
|
|
|
if ($c==0) { $c=1; } else { $c=0; }
|
|
|
|
|
} //end foreach
|
|
|
|
|
unset($sql, $result, $row_count);
|
|
|
|
|
} //end if results
|
|
|
|
|
|
|
|
|
|
echo "<tr>\n";
|
|
|
|
|
echo "<td colspan='5' align='left'>\n";
|
|
|
|
|
echo " <table width='100%' cellpadding='0' cellspacing='0'>\n";
|
|
|
|
|
echo " <tr>\n";
|
|
|
|
|
echo " <td width='33.3%' nowrap> </td>\n";
|
|
|
|
|
echo " <td width='33.3%' align='center' nowrap>$paging_controls</td>\n";
|
2014-02-26 07:10:56 +01:00
|
|
|
echo " <td class='list_control_icons'>";
|
2013-09-21 23:45:35 +02:00
|
|
|
if (permission_exists('service_add')) {
|
2014-02-26 07:10:56 +01:00
|
|
|
echo "<a href='service_edit.php' alt='add'>$v_link_label_add</a>";
|
2012-06-04 16:58:40 +02:00
|
|
|
}
|
|
|
|
|
echo " </td>\n";
|
|
|
|
|
echo " </tr>\n";
|
|
|
|
|
echo " </table>\n";
|
|
|
|
|
echo "</td>\n";
|
|
|
|
|
echo "</tr>\n";
|
|
|
|
|
|
|
|
|
|
echo "</table>";
|
|
|
|
|
echo "<br><br>";
|
|
|
|
|
|
|
|
|
|
//include the footer
|
2013-07-06 08:29:50 +02:00
|
|
|
require_once "resources/footer.php";
|
2012-06-04 16:58:40 +02:00
|
|
|
|
|
|
|
|
?>
|