2025-06-02 10:01:12 +02:00
< ? php
/**
* Project : astat - simple site engine
* File : / modules / mybb / admin . 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 . astat . org SVN : $URL $
* @ copyright 2010 becast . at
* @ author Bernhard Jaud < bernhard at becast dot at >
* @ package astat module
* @ license http :// opensource . org / licenses / gpl - license . php GNU Public License
* @ version $Id $
*/
If ( ! defined ( " in_BL_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 ();
2025-06-16 09:08:45 +02:00
exec ( '/bin/systemctl status austria|grep running' , $cat );
2025-06-02 10:01:12 +02:00
$cat = trim ( $cat [ 0 ]);
if ( $istat == 2 && $cat != " not " ){
shell_exec ( " kill -9 " . $cat );
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 ();
if ( $istat == 1 ){
shell_exec ( " sudo /sbin/restart topia " );
} elseif ( $istat == 2 ){
shell_exec ( " sudo /sbin/restart topia " );
}
$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 />' ;
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 ;
if ( $status == 1 ){
exec ( '/sbin/status topia|awk \'{ print $4}\'' , $cat );
$cat = trim ( $cat [ 0 ]);
return '<span style="color:green;">OK - Running - Process ID: ' . $cat . '</span>' ;
} elseif ( $status == 2 ){
exec ( '/sbin/status topia|awk \'{ print $4}\'' , $cat );
$cat = trim ( $cat [ 0 ]);
return '<span style="color:red;">ALERT - Zombie - Process ID: ' . $cat . '</span>' ;
} else {
return '<span style="color:red;">ALERT - Stopped</span>' ;
}
}
function get_status (){
global $db , $config , $cache , $log ;
$dat = " /sbin/status topia|awk ' { print $ 4}' " ;
exec ( $dat , $cat );
$cat = trim ( $cat [ 0 ]);
if ( $cat != 'not' ){
exec ( " ps ax|grep " . $cat . " |grep -v grep " , $ps );
$psr = preg_split ( " / \ s/ " , $ps [ 0 ]);
$psr = $this -> removeEmptyValues ( $psr );
$status = $psr [ 2 ];
$status = substr ( $status , 0 , 1 );
if ( $status == " S " || $status == " R " ){
return 1 ;
} elseif ( $status == " Z " ){
return 2 ;
} else {
return 0 ;
}
} else {
return 0 ;
}
}
function removeEmptyValues ( $ar )
{
$result = array ();
foreach ( $ar as $value ){
$value = trim ( $value );
if ( strlen ( $value ))
$result [] = $value ;
}
return $result ;
}
}
?>