Add ability to reload one or more services
This commit is contained in:
@@ -180,8 +180,7 @@ class services {
|
|||||||
if (is_array($uuids) && @sizeof($uuids) != 0) {
|
if (is_array($uuids) && @sizeof($uuids) != 0) {
|
||||||
$sql = "select ".$this->name."_uuid as uuid, ".$this->toggle_field." as toggle from v_".$this->table." ";
|
$sql = "select ".$this->name."_uuid as uuid, ".$this->toggle_field." as toggle from v_".$this->table." ";
|
||||||
$sql .= "where ".$this->name."_uuid in (".implode(', ', $uuids).") ";
|
$sql .= "where ".$this->name."_uuid in (".implode(', ', $uuids).") ";
|
||||||
$database = new database;
|
$rows = $this->database->select($sql, $parameters, 'all');
|
||||||
$rows = $database->select($sql, $parameters, 'all');
|
|
||||||
if (is_array($rows) && @sizeof($rows) != 0) {
|
if (is_array($rows) && @sizeof($rows) != 0) {
|
||||||
foreach ($rows as $row) {
|
foreach ($rows as $row) {
|
||||||
$states[$row['uuid']] = $row['toggle'];
|
$states[$row['uuid']] = $row['toggle'];
|
||||||
@@ -214,6 +213,71 @@ class services {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reload the state of a service without restarting it
|
||||||
|
*
|
||||||
|
* @param array $records An array of services to reload, where each ID is an associative array
|
||||||
|
* containing 'uuid' and 'checked' keys. The 'checked' value indicates
|
||||||
|
* whether the corresponding checkbox was checked to reload the service.
|
||||||
|
*
|
||||||
|
* @return void No return value;
|
||||||
|
*/
|
||||||
|
public function reload($records) {
|
||||||
|
// Permission not found
|
||||||
|
if (!permission_exists($this->name.'_edit')) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add multi-lingual support
|
||||||
|
$language = new text;
|
||||||
|
$text = $language->get();
|
||||||
|
|
||||||
|
// Validate the token
|
||||||
|
$token = new token;
|
||||||
|
if (!$token->validate($_SERVER['PHP_SELF'])) {
|
||||||
|
message::add($text['message-invalid_token'],'negative');
|
||||||
|
header('Location: '.$this->location);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
// reloaad the checked services
|
||||||
|
if (is_array($records) && @sizeof($records) != 0) {
|
||||||
|
// Get current reload state
|
||||||
|
foreach($records as $record) {
|
||||||
|
if ($record['checked'] == 'true' && is_uuid($record['uuid'])) {
|
||||||
|
$uuids[] = "'".$record['uuid']."'";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Reload the selected services
|
||||||
|
if (is_array($uuids) && @sizeof($uuids) != 0) {
|
||||||
|
$sql = "select service_name as name from v_".$this->table." ";
|
||||||
|
$sql .= "where ".$this->name."_uuid in (".implode(', ', $uuids).") ";
|
||||||
|
$rows = $this->database->select($sql, $parameters, 'all');
|
||||||
|
if (is_array($rows) && @sizeof($rows) != 0) {
|
||||||
|
foreach ($rows as $row) {
|
||||||
|
$service_name = $row['name'];
|
||||||
|
$service_class_name = $row['name'].'_service';
|
||||||
|
if (class_exists($service_class_name)) {
|
||||||
|
if (method_exists($service_class_name, 'send_reload')) {
|
||||||
|
// Reload the service
|
||||||
|
$service_class_name::send_reload();
|
||||||
|
|
||||||
|
// Add the service to an array
|
||||||
|
$services[] = $service_name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// The list of services that were reloaded
|
||||||
|
$service_list = implode("<br />", $services);
|
||||||
|
|
||||||
|
// Set the message
|
||||||
|
message::add($text['message-reload']."<br />".$service_list);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the list of services
|
* Get the list of services
|
||||||
*
|
*
|
||||||
@@ -254,7 +318,7 @@ class services {
|
|||||||
$services[$i]['etime'] = $service_status['etime'];
|
$services[$i]['etime'] = $service_status['etime'];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Increment
|
// Increment
|
||||||
$i++;
|
$i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -296,7 +360,7 @@ class services {
|
|||||||
$services[$i]['etime'] = $service_status['etime'];
|
$services[$i]['etime'] = $service_status['etime'];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Increment
|
// Increment
|
||||||
$i++;
|
$i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -354,7 +418,7 @@ class services {
|
|||||||
foreach ($service_array as $service) {
|
foreach ($service_array as $service) {
|
||||||
// Sanitize the service name
|
// Sanitize the service name
|
||||||
$service_name = preg_replace('/[^a-zA-Z0-9_-]/', '', $service['name']);
|
$service_name = preg_replace('/[^a-zA-Z0-9_-]/', '', $service['name']);
|
||||||
|
|
||||||
// Built the array to save to the database
|
// Built the array to save to the database
|
||||||
if (!is_array($service_array) || !in_array($service_name, $service_names)) {
|
if (!is_array($service_array) || !in_array($service_name, $service_names)) {
|
||||||
// Get the category
|
// Get the category
|
||||||
|
|||||||
@@ -50,7 +50,15 @@
|
|||||||
|
|
||||||
// process the http post data by action
|
// process the http post data by action
|
||||||
if (!empty($action) && !empty($services) && is_array($services) && @sizeof($services) != 0) {
|
if (!empty($action) && !empty($services) && is_array($services) && @sizeof($services) != 0) {
|
||||||
|
|
||||||
|
// send the array to the database class
|
||||||
switch ($action) {
|
switch ($action) {
|
||||||
|
case 'reload':
|
||||||
|
if (permission_exists('service_edit')) {
|
||||||
|
$obj = new services;
|
||||||
|
$obj->reload($services);
|
||||||
|
}
|
||||||
|
break;
|
||||||
case 'toggle':
|
case 'toggle':
|
||||||
if (permission_exists('service_edit')) {
|
if (permission_exists('service_edit')) {
|
||||||
$obj = new services;
|
$obj = new services;
|
||||||
@@ -157,6 +165,9 @@
|
|||||||
echo "<div class='action_bar' id='action_bar'>\n";
|
echo "<div class='action_bar' id='action_bar'>\n";
|
||||||
echo " <div class='heading'><b>".$text['title-services']."</b><div class='count'>".$num_rows."</div></div>\n";
|
echo " <div class='heading'><b>".$text['title-services']."</b><div class='count'>".$num_rows."</div></div>\n";
|
||||||
echo " <div class='actions'>\n";
|
echo " <div class='actions'>\n";
|
||||||
|
if (permission_exists('service_edit') && $services) {
|
||||||
|
echo button::create(['type'=>'button','label'=>$text['button-reload'],'icon'=>$_SESSION['theme']['button_icon_reload'],'id'=>'btn_reload','name'=>'btn_reload','style'=>'display:none;','onclick'=>"modal_open('modal-reload','btn_reload');"]);
|
||||||
|
}
|
||||||
if (permission_exists('service_edit') && $services) {
|
if (permission_exists('service_edit') && $services) {
|
||||||
echo button::create(['type'=>'button','label'=>$text['button-toggle'],'icon'=>$_SESSION['theme']['button_icon_toggle'],'id'=>'btn_toggle','name'=>'btn_toggle','style'=>'display:none;','onclick'=>"modal_open('modal-toggle','btn_toggle');"]);
|
echo button::create(['type'=>'button','label'=>$text['button-toggle'],'icon'=>$_SESSION['theme']['button_icon_toggle'],'id'=>'btn_toggle','name'=>'btn_toggle','style'=>'display:none;','onclick'=>"modal_open('modal-toggle','btn_toggle');"]);
|
||||||
}
|
}
|
||||||
@@ -177,6 +188,9 @@
|
|||||||
if (permission_exists('service_add') && $services) {
|
if (permission_exists('service_add') && $services) {
|
||||||
echo modal::create(['id'=>'modal-copy','type'=>'copy','actions'=>button::create(['type'=>'button','label'=>$text['button-continue'],'icon'=>'check','id'=>'btn_copy','style'=>'float: right; margin-left: 15px;','collapse'=>'never','onclick'=>"modal_close(); list_action_set('copy'); list_form_submit('form_list');"])]);
|
echo modal::create(['id'=>'modal-copy','type'=>'copy','actions'=>button::create(['type'=>'button','label'=>$text['button-continue'],'icon'=>'check','id'=>'btn_copy','style'=>'float: right; margin-left: 15px;','collapse'=>'never','onclick'=>"modal_close(); list_action_set('copy'); list_form_submit('form_list');"])]);
|
||||||
}
|
}
|
||||||
|
if (permission_exists('service_edit') && $services) {
|
||||||
|
echo modal::create(['id'=>'modal-reload','type'=>'reload','actions'=>button::create(['type'=>'button','label'=>$text['button-continue'],'icon'=>'check','id'=>'btn_reload','style'=>'float: right; margin-left: 15px;','collapse'=>'never','onclick'=>"modal_close(); list_action_set('reload'); list_form_submit('form_list');"])]);
|
||||||
|
}
|
||||||
if (permission_exists('service_edit') && $services) {
|
if (permission_exists('service_edit') && $services) {
|
||||||
echo modal::create(['id'=>'modal-toggle','type'=>'toggle','actions'=>button::create(['type'=>'button','label'=>$text['button-continue'],'icon'=>'check','id'=>'btn_toggle','style'=>'float: right; margin-left: 15px;','collapse'=>'never','onclick'=>"modal_close(); list_action_set('toggle'); list_form_submit('form_list');"])]);
|
echo modal::create(['id'=>'modal-toggle','type'=>'toggle','actions'=>button::create(['type'=>'button','label'=>$text['button-continue'],'icon'=>'check','id'=>'btn_toggle','style'=>'float: right; margin-left: 15px;','collapse'=>'never','onclick'=>"modal_close(); list_action_set('toggle'); list_form_submit('form_list');"])]);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user