Current File : //etc/sentora/panel/modules/logviewer/code/controller.ext.php |
<?php
/**
*
* Apache Log Viewer for ZPanel 10.1.0
* Version : 101
* Author : Aderemi Adewale (modpluz @ ZPanel Forums)
* Email : goremmy@gmail.com
*/
class module_controller {
static $logfile;
static $error;
static $ok;
static $FromLine;
static $ToLine;
/**
* The 'worker' methods.
*/
/* Load CSS and JS files */
static function getInit() {
global $controller;
$line = '<link rel="stylesheet" type="text/css" href="modules/' . $controller->GetControllerRequest('URL', 'module') . '/assets/logviewer.css">';
$line .= '<script type="text/javascript" src="modules/' . $controller->GetControllerRequest('URL', 'module') . '/assets/logviewer.js"></script>';
return $line;
}
static function gethelpicon()
{
global $zdbh;
global $controller;
$temp=$controller->GetControllerRequest('URL','module') ;
$val = '/assets/one.txt';
$val1 = '/modules/';
$name=file_get_contents("modules/$temp/assets/helpicon.txt");
return $name;
}
static function getCSFR_Tag() {
return runtime_csfr::Token();
}
static function getModuleName() {
$module_name = ui_module::GetModuleName();
return $module_name;
}
static function getModuleIcon() {
global $controller;
// Check if the current userland theme has a module icon override
if(trim(strtolower(ui_template::GetUserTemplate()))=="zentora-master")
{
$mod_dir=$controller->GetControllerRequest('URL', 'module') ;
if (file_exists('etc/styles/' . ui_template::GetUserTemplate() . '/img/style/' . $mod_dir . '.jpg'))
return './etc/styles/' . ui_template::GetUserTemplate() . '/img/style/' . $mod_dir . '.jpg';
else
$module_icon = "/modules/" . $controller->GetControllerRequest('URL', 'module') . "/assets/icon.png";
return $module_icon;
}else
{
$module_icon = "/modules/" . $controller->GetControllerRequest('URL', 'module') . "/assets/icon.png";
return $module_icon;
}
}
static function getModuleDesc() {
$message = ui_language::translate(ui_module::GetModuleDescription());
return $message;
}
static function getDomains(){
global $zdbh,$controller;
$currentuser = ctrl_users::GetUserDetail();
$formvars = $controller->GetAllControllerRequests('FORM');
$sql = "SELECT vh_directory_vc,vh_name_vc,vh_id_pk FROM x_vhosts WHERE vh_acc_fk=:user_id AND vh_deleted_ts IS NULL AND vh_type_in IN (1,2) ORDER BY vh_name_vc ASC";
$bindArray = array(':user_id' => $currentuser['userid']);
$zdbh->bindQuery($sql, $bindArray);
$rows = $zdbh->returnRows();
if (count($rows) > 0) {
$res = array();
foreach($rows as $row) {
$selected_yn = '';
if(isset($formvars['domain_id'])){
$selected_yn = ($formvars['domain_id'] == $row['vh_id_pk']) ? 'selected="selected"':'';
}
array_push($res, array(
'selected' => $selected_yn,
'name' => $row['vh_name_vc'],
'id' => $row['vh_id_pk'],
));
}
return $res;
} else {
return false;
}
}
static function getErrorTypes(){
global $controller;
$formvars = $controller->GetAllControllerRequests('FORM');
$error_types = array(1=>'Access Logs', 2=>'Error Logs');
$res = array();
foreach($error_types as $row_idx=>$row){
$selected_yn = '';
if(isset($formvars['log_type_id'])){
$selected_yn = ($formvars['log_type_id'] == $row_idx) ? 'selected="selected"':'';
}
array_push($res, array(
'id' => $row_idx,
'name' => $row,
'selected' => $selected_yn,
));
}
return $res;
}
static function getErrorType(){
global $controller;
$formvars = $controller->GetAllControllerRequests('FORM');
$log_type = '';
if(isset($formvars['log_type_id']) && (int) $formvars['log_type_id']){
if($formvars['log_type_id'] == 1){
$log_type = ui_language::translate("Access Logs");
} elseif($formvars['log_type_id'] == 2){
$log_type = ui_language::translate("Error Logs");
}
}
return $log_type;
}
static function getisDisplayLogs(){
global $controller;
$urlvars = $controller->GetAllControllerRequests('URL');
$formvars = $controller->GetAllControllerRequests('FORM');
if((isset($urlvars['action']) && $urlvars['action'] == 'DisplayLogs')){
return true;
}
return false;
}
static function doDisplayLogs(){
global $controller, $zdbh;
$formvars = $controller->GetAllControllerRequests('FORM');
self::$logfile = '';
runtime_csfr::Protect();
if((int) $formvars['domain_id'] && (int) $formvars['log_type_id']){
$currentuser = ctrl_users::GetUserDetail();
$log_dir = ctrl_options::GetSystemOption('hosted_dir').'domains/' . $currentuser['username'];
$log_dir = str_replace('hostdata', 'logs', $log_dir);
$log_dir = fs_director::ConvertSlashes($log_dir);
if(is_dir($log_dir)){
$sql = "SELECT vh_name_vc FROM x_vhosts
WHERE vh_id_pk=:vh_id AND vh_acc_fk=:uid AND vh_deleted_ts IS NULL";
$bindArray = array(':vh_id' => (int)$formvars['domain_id'], ':uid' => $currentuser['userid']);
$zdbh->bindQuery($sql, $bindArray);
$domain_info = $zdbh->returnRow();
if($formvars['log_type_id'] == 1){
$log_file = 'access.log';
} elseif($formvars['log_type_id'] == 2){
$log_file = 'error.log';
}
if(!isset($log_file) || !$domain_info['vh_name_vc']){
self::$error['no_log_exist'] = true;
return false;
}
$log_path = $log_dir.'/'.$domain_info['vh_name_vc'].'-'.$log_file;
$log_path = fs_director::ConvertSlashes($log_path);
if(!is_file($log_path)){
self::$error['no_log_exist'] = true;
return false;
}
self::$logfile = $log_path;
self::$ok = true;
return true;
} else {
self::$error['no_log_exist'] = true;
return false;
}
} else {
self::$error = true;
return false;
}
}
static function getLogFile()
{
if(isset(self::$logfile) && self::$logfile != ''){
/* $log_output = '';
$log_content = file(self::$logfile);
if(is_array($log_content) && count($log_content) > 1){
foreach($log_content as $log){
$log_output .= $log.'<br><br>';
}
} else {
$log_output = ui_language::translate("There are no log items to display.");
}
return $log_output; */
$log_content="<pre>";
$to_line=shell_exec("wc -l ".self::$logfile." | cut -d ' ' -f1");
$from_line = $to_line - 100;
self::$FromLine = $from_line;
self::$ToLine = $to_line;
$log_content.= shell_exec("awk 'NR >= $from_line && NR <= $to_line' ".self::$logfile);
$log_content.="</pre>";
if($log_content=="<pre></pre>")
$log_content = ui_language::translate("There are no log items to display.");
return $log_content;
}
return false;
}
static function getFromLine()
{
return self::$FromLine;
}
static function getToLine()
{
return self::$ToLine;
}
static function getLogFileName()
{
return self::$logfile;
}
static function doAnotherSetLogs()
{
global $controller;
$FromLine = $controller->GetControllerRequest('FORM', 'FromLine');
$ToLine = $controller->GetControllerRequest('FORM', 'ToLine');
$LogFile = $controller->GetControllerRequest('FORM', 'LogFile');
if($FromLine < 0)
{
echo "All logs has been completed.";exit;
}
$log_content="<pre>";
$log_content.=shell_exec("awk 'NR >= $FromLine && NR <= $ToLine' $LogFile");
$log_content.="</pre>";
echo $log_content;exit;
}
static function getResult() {
if (isset(self::$error['no_log_exist']) && !fs_director::CheckForEmptyValue(self::$error['no_log_exist'])) {
return ui_sysmessage::shout(ui_language::translate("Unable to locate log file for the selected domain."), "zannounceerror");
}
if (!fs_director::CheckForEmptyValue(self::$error)) {
return ui_sysmessage::shout(ui_language::translate("An error has occurred while executing your request, please check your input and try again."), "zannounceerror");
}
return;
}
/**
* Webinterface sudo methods.
*/
}
?>