148 lines
4.8 KiB
PHP
148 lines
4.8 KiB
PHP
<?php global $session;
|
|
/**
|
|
* Project: BeCast WebEngine - simple site engine
|
|
* File: /modules/chat/manage.apnl.php
|
|
*
|
|
* This library is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
* License as published by the Free Software Foundation; either
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
*
|
|
* This library is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
* Lesser General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
* License along with this library; if not, write to the Free Software
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
*
|
|
* @link http://www.becast.at
|
|
* @copyright 2010-2025 becast.at
|
|
* @author Bernhard Jaud <bernhard at becast dot at>
|
|
* @package BcWe module
|
|
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
|
|
* @version $Id$
|
|
*/
|
|
If (!defined("IN_BCWE_ADMIN")) {
|
|
die("Dieses Script kann nicht ausserhalb des Frameworks laufen!");
|
|
}
|
|
$session->page_begin("chat_admin", True);
|
|
|
|
class manage_chat_panel extends admin_module{
|
|
|
|
function output(){
|
|
global $config, $db,$panel, $cache, $session;
|
|
if(isset($_POST['start'])){
|
|
$istat = $this->get_status();
|
|
if($istat['status']==2){
|
|
shell_exec("kill -9 ".$istat['pid']);
|
|
sleep(5);
|
|
shell_exec("sudo /bin/systemctl restart funchat");
|
|
}else{
|
|
shell_exec("sudo /bin/systemctl restart funchat");
|
|
}
|
|
$panel->admin_message("Triggered", 'The Chatstart has been triggered. please refresh the page to see if it was successful.',TRUE,"manage_chat");
|
|
}elseif(isset($_POST['restart'])){
|
|
$istat = $this->get_status();
|
|
if($istat['status']==1){
|
|
$this->sendRPC("restart");
|
|
}elseif($istat['status']==2){
|
|
shell_exec("kill -9 ".$istat['pid']);
|
|
sleep(5);
|
|
shell_exec("sudo /bin/systemctl restart funchat");
|
|
}
|
|
$panel->admin_message("Triggered", 'The Emergency Chatrestart has been triggered. please refresh the page to see if it was successful.',TRUE,"manage_chat");
|
|
}elseif(isset($_POST['stop'])){
|
|
$istat = $this->get_status();
|
|
if($istat['status']==1){
|
|
$this->sendRPC("stop");
|
|
}
|
|
$panel->admin_message("Triggered", 'The Chat has been stopped. please refresh the page to see if it was successful.',TRUE,"manage_chat");
|
|
}else{
|
|
$count=false;
|
|
$panel->title="Manage Chat";
|
|
$panel->form(array('action'=>$config['path'].'/admin/index.php?panel=manage_chat'));
|
|
|
|
$panel->content.='<h3>Status:</h3>';
|
|
$istat = $this->get_status();
|
|
$status = $this->get_readable_status($istat);
|
|
|
|
$panel->content.=$status.'<br />';
|
|
$extra = "";
|
|
$extrastop = "";
|
|
if($istat==1){
|
|
$extra='disabled="disabled"';
|
|
}elseif($istat==0){
|
|
$extrastop='disabled="disabled"';
|
|
}
|
|
$panel->submit(array('name'=>'start'),'value="Start"'.$extra);
|
|
$panel->submit(array('name'=>'restart'),'value="Restart"');
|
|
$panel->submit(array('name'=>'stop'),'value="Stop"'.$extrastop);
|
|
$panel->formClose();
|
|
}
|
|
}
|
|
|
|
function get_readable_status($status){
|
|
global $db, $config, $cache, $log;
|
|
if($status['status']==1){
|
|
return '<span style="color:green;">OK - Running - Process ID: '.$status['pid'].'</span>';
|
|
}elseif($status['status']==2){
|
|
return '<span style="color:red;">ALERT - Zombie - Process ID: '.$status['pid'].'</span>';
|
|
}else{
|
|
return '<span style="color:red;">ALERT - Stopped</span>';
|
|
}
|
|
}
|
|
|
|
function get_status(){
|
|
$dat='/bin/systemctl status funchat|grep "Main PID"';
|
|
exec($dat,$cat);
|
|
$data = explode(" ",$cat[0]);
|
|
$r['pid'] = $data[5];
|
|
exec("ps ax|grep ".$r['pid']."|grep -v grep",$ps);
|
|
if(empty($ps)){
|
|
$r['status'] = 0;
|
|
} else {
|
|
$psr = preg_split("/\s/", $ps[0]);
|
|
$psr = $this->removeEmptyValues($psr);
|
|
$status = $psr[2];
|
|
$status=substr($status, 0, 1);
|
|
if($status=="S"||$status=="R"){
|
|
$r['status'] = 1;
|
|
}elseif($status=="Z"){
|
|
$r['status'] = 2;
|
|
}else{
|
|
$r['status'] = 0;
|
|
}
|
|
}
|
|
return $r;
|
|
}
|
|
|
|
function sendRPC($type){
|
|
global $config;
|
|
$ch = curl_init();
|
|
// setze die URL und andere Optionen
|
|
curl_setopt($ch, CURLOPT_URL, 'https://chat.funch.at/rpc?secret='.$config['chatsecret'].'&task='.$type);
|
|
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
|
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
|
|
curl_setopt($ch, CURLOPT_HEADER, false);
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
curl_setopt($ch, CURLOPT_TIMEOUT, 3);
|
|
curl_exec($ch);
|
|
curl_close($ch);
|
|
}
|
|
|
|
function removeEmptyValues($ar)
|
|
{
|
|
$result = array();
|
|
|
|
foreach($ar as $value){
|
|
$value = trim($value);
|
|
if (strlen($value))
|
|
$result[] = $value;
|
|
}
|
|
|
|
return $result;
|
|
}
|
|
}
|
|
?>
|