2025-06-23 20:45:15 +02:00
< ? php global $session ;
2025-06-02 10:01:12 +02:00
/**
2025-06-23 20:45:15 +02:00
* Project : BeCast WebEngine - simple site engine
* File : / modules / chat / manage . apnl . php
2025-06-02 10:01:12 +02:00
*
* 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
*
2025-06-23 20:45:15 +02:00
* @ link http :// www . becast . at
* @ copyright 2010 - 2025 becast . at
2025-06-02 10:01:12 +02:00
* @ author Bernhard Jaud < bernhard at becast dot at >
2025-06-23 20:45:15 +02:00
* @ package BcWe module
2025-06-02 10:01:12 +02:00
* @ license http :// opensource . org / licenses / gpl - license . php GNU Public License
* @ version $Id $
2025-06-23 20:45:15 +02:00
*/
If ( ! defined ( " IN_BCWE_ADMIN " )) {
2025-06-02 10:01:12 +02:00
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 ();
2025-06-16 17:59:01 +02:00
if ( $istat [ 'status' ] == 2 ){
shell_exec ( " kill -9 " . $istat [ 'pid' ]);
2025-06-02 10:01:12 +02:00
sleep ( 5 );
2025-06-16 09:08:45 +02:00
shell_exec ( " sudo /bin/systemctl restart austria " );
2025-06-02 10:01:12 +02:00
} else {
2025-06-16 09:08:45 +02:00
shell_exec ( " sudo /bin/systemctl restart austria " );
2025-06-02 10:01:12 +02:00
}
$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 [ 'emergency' ])){
$istat = $this -> get_status ();
2025-06-16 17:59:01 +02:00
if ( $istat [ 'status' ] == 1 ){
shell_exec ( " sudo /bin/systemctl restart austria " );
} elseif ( $istat [ 'status' ] == 2 ){
shell_exec ( " kill -9 " . $istat [ 'pid' ]);
sleep ( 5 );
shell_exec ( " sudo /bin/systemctl restart austria " );
2025-06-02 10:01:12 +02:00
}
$panel -> admin_message ( " Triggered " , 'The Emergency Chatrestart has been triggered. 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 />' ;
2025-06-25 11:10:16 +02:00
$extra = " " ;
2025-06-02 10:01:12 +02:00
if ( $istat == 1 ){
$extra = 'disabled="disabled"' ;
}
$panel -> submit ( array ( 'name' => 'start' ), 'value="Start"' . $extra );
$panel -> submit ( array ( 'name' => 'emergency' ), 'value="Emergency Restart"' );
$panel -> formClose ();
}
}
function get_readable_status ( $status ){
global $db , $config , $cache , $log ;
2025-06-16 17:59:01 +02:00
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>' ;
2025-06-02 10:01:12 +02:00
} else {
return '<span style="color:red;">ALERT - Stopped</span>' ;
}
}
function get_status (){
2025-06-16 17:59:01 +02:00
$dat = '/bin/systemctl status austria|grep "Main PID"' ;
2025-06-02 10:01:12 +02:00
exec ( $dat , $cat );
2025-06-16 17:59:01 +02:00
$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 {
2025-06-02 10:01:12 +02:00
$psr = preg_split ( " / \ s/ " , $ps [ 0 ]);
$psr = $this -> removeEmptyValues ( $psr );
$status = $psr [ 2 ];
$status = substr ( $status , 0 , 1 );
2025-06-16 17:59:01 +02:00
if ( $status == " S " || $status == " R " ){
$r [ 'status' ] = 1 ;
} elseif ( $status == " Z " ){
$r [ 'status' ] = 2 ;
} else {
$r [ 'status' ] = 0 ;
}
2025-06-02 10:01:12 +02:00
}
2025-06-16 17:59:01 +02:00
return $r ;
2025-06-02 10:01:12 +02:00
}
function removeEmptyValues ( $ar )
{
$result = array ();
foreach ( $ar as $value ){
$value = trim ( $value );
if ( strlen ( $value ))
$result [] = $value ;
}
return $result ;
}
}
?>