"Fossies" - the Fresh Open Source Software Archive

Member "openlitespeed-1.6.6/dist/admin/html.open/view/ajax_data.php" (22 Jan 2020, 7890 Bytes) of package /linux/www/openlitespeed-1.6.6.src.tgz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) PHP source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "ajax_data.php" see the Fossies "Dox" file reference documentation.

    1 <?php
    2 
    3 if ( $_GET['id'] == 'pid_load' ) {
    4     // do not update timeout stamp
    5     define('NO_UPDATE_ACCESS', 1) ;
    6 }
    7 
    8 require_once('inc/auth.php') ;
    9 
   10 function ajax_pid_load()
   11 {
   12     $data = array( 'pid' => Service::ServiceData(SInfo::DATA_PID),
   13         'serverload' => implode(', ', sys_getloadavg()) ) ;
   14     echo json_encode($data) ;
   15 }
   16 
   17 function ajax_dashstat()
   18 {
   19     $d = RealTimeStats::GetDashPlot() ;
   20     echo json_encode($d) ;
   21 }
   22 
   23 function ajax_plotstat()
   24 {
   25     $stat = RealTimeStats::GetPlotStats() ;
   26 
   27     $d = $stat->GetServerData() ;
   28     $vhd = $stat->GetVHData() ;
   29 
   30     $s = '{"serv":' . json_encode($d) ;
   31 
   32     foreach ( $vhd as $vn => $vh ) {
   33         unset($vh['ea']) ;
   34         $s .= ', "' . $vn . '":' . json_encode($vh) ;
   35     }
   36 
   37     $s .= '}' ;
   38 
   39     echo $s ;
   40 }
   41 
   42 function ajax_vhstat()
   43 {
   44     $stat = RealTimeStats::GetVHStats() ;
   45     $vhd = $stat->GetVHData() ;
   46 
   47     $vbody = '' ;
   48     $ebody = '' ;
   49     $td = '</td><td>' ;
   50 
   51     foreach ( $vhd as $vn => $vh ) {
   52         $vbody .= '<tr><td><span class="btn btn-default btn-xs txt-color-blueLight" data-lstmonitor="vh">
   53                 <i class="fa fa-stethoscope"></i></span></td><td class="lst-vhname">' . $vn
   54                 . $td . $vh[RealTimeStats::FLD_VH_REQ_PROCESSING]
   55                 . $td . $vh[RealTimeStats::FLD_VH_REQ_PER_SEC]
   56                 . $td . $vh[RealTimeStats::FLD_VH_TOT_REQS]
   57                 . $td . $vh[RealTimeStats::FLD_VH_EAP_COUNT]
   58                 . $td . $vh[RealTimeStats::FLD_VH_EAP_INUSE]
   59                 . $td . $vh[RealTimeStats::FLD_VH_EAP_IDLE]
   60                 . $td . $vh[RealTimeStats::FLD_VH_EAP_WAITQUE]
   61                 . $td . $vh[RealTimeStats::FLD_VH_EAP_REQ_PER_SEC]
   62                 . "</td></tr>" ;
   63 
   64         if ( isset($vh['ea']) && count($vh['ea']) > 0 ) {
   65             foreach ( $vh['ea'] as $appname => $ea ) {
   66                 $ebody .= '<tr><td>' . $vn
   67                         . $td . $ea[RealTimeStats::FLD_EA_TYPE]
   68                         . $td . $appname
   69                         . $td . $ea[RealTimeStats::FLD_EA_CMAXCONN]
   70                         . $td . $ea[RealTimeStats::FLD_EA_EMAXCONN]
   71                         . $td . $ea[RealTimeStats::FLD_EA_POOL_SIZE]
   72                         . $td . $ea[RealTimeStats::FLD_EA_INUSE_CONN]
   73                         . $td . $ea[RealTimeStats::FLD_EA_IDLE_CONN]
   74                         . $td . $ea[RealTimeStats::FLD_EA_WAITQUE_DEPTH]
   75                         . $td . $ea[RealTimeStats::FLD_EA_REQ_PER_SEC]
   76                         . $td . $ea[RealTimeStats::FLD_EA_TOT_REQS]
   77                         . "</td></tr>" ;
   78             }
   79         }
   80     }
   81     $data = array( 'vbody' => $vbody, 'ebody' => $ebody ) ;
   82 
   83     echo json_encode($data) ;
   84 }
   85 
   86 function ajax_dashstatus()
   87 {
   88     $sinfo = Service::ServiceData(SInfo::DATA_Status_LV) ;
   89     $listeners = $sinfo->Get(SInfo::FLD_Listener) ;
   90 
   91     $body = '' ;
   92     $running = 0 ;
   93     $broken = '' ;
   94     foreach ( $listeners as $lname => $l ) {
   95         $body .= '<tr><td class="' ;
   96         if ( isset($l['addr']) ) {
   97             $body .= 'success"><i class="fa fa-link"></i>' ;
   98             $running ++ ;
   99             $addr = $l['addr'] ;
  100         }
  101         else {
  102             $body .= 'danger"><i class="fa fa-unlink"></i>' ;
  103             $broken ++ ;
  104             $addr = $l['daddr'] ;
  105         }
  106         $body .= '</td><td>' . $lname . ' </td><td>' . $addr
  107                 . '</td></tr>' . "\n" ;
  108     }
  109 
  110     $vhosts = $sinfo->Get(SInfo::FLD_VHosts) ;
  111     $vrunning = 0 ;
  112     $vdisabled = '' ;
  113     $verrors = '' ;
  114 
  115     $vbody = '' ;
  116 
  117     $note_stopped = DMsg::ALbl('service_stopped') ;
  118     $note_running = DMsg::ALbl('service_running') ;
  119     $note_suspendvh = DMsg::ALbl('service_suspendvh') ;
  120     $note_enablevh = DMsg::ALbl('service_enablevh') ;
  121     $note_disabled = DMsg::ALbl('service_disabled') ;
  122 
  123     foreach ( $vhosts as $vn => $vh ) {
  124         $vbody .= '<tr data-vn="' . $vn . '"><td>' ;
  125 
  126         if ( $vh['running'] == -1 ) {
  127             $verrors ++ ;
  128             $vbody .= '<span class="text-danger" title="' . $note_stopped . '"><i class="fa fa-ban"></i></span> ' ;
  129             $actions = '' ;
  130         }
  131         elseif ( $vh['running'] == 1 ) {
  132             $vrunning ++ ;
  133             $vbody .= '<span class="text-success" title="' . $note_running . '"><i class="fa fa-rocket"></i></span> ' ;
  134             $actions = '<a class="btn btn-warning btn-xs" data-action="lstvhcontrol" data-lstact="disable" title="'
  135                     . $note_suspendvh . '"><i class="fa fa-pause"></i></a>' ;
  136         }
  137         else {
  138             $vdisabled ++ ;
  139             $vbody .= '<span class="text-warning" title="' . $note_disabled . '"><i class="fa fa-stop"></i></span> ' ;
  140             $actions = '<a class="btn btn-success btn-xs"  data-action="lstvhcontrol" data-lstact="enable" title="'
  141                     . $note_enablevh . '"><i class="fa fa-play"></i></a>' ;
  142         }
  143         $vbody .= '</td><td>' . htmlspecialchars(wordwrap($vn, 40, "\n", true)) . '</td><td>' ;
  144         if ( isset($vh['templ']) )
  145             $vbody .= $vh['templ'] ;
  146         $vbody .= '</td><td>' ;
  147         if ( isset($vh['domains']) ) {
  148             $vbody .= htmlspecialchars(wordwrap(implode("\n", array_keys($vh['domains'])), 60, "\n", true)) ;
  149         }
  150         $vbody .= '</td><td>' ;
  151         $vbody .= $actions ;
  152         $vbody .= '</td></tr>' ;
  153     }
  154 
  155     $res = array( 'l_running' => $running,
  156         'l_broken' => $broken,
  157         'v_running' => $vrunning,
  158         'v_disabled' => $vdisabled,
  159         'v_err' => $verrors,
  160         'l_body' => $body,
  161         'v_body' => $vbody
  162             ) ;
  163 
  164     echo json_encode($res) ;
  165 }
  166 
  167 function ajax_dashlog()
  168 {
  169     $logfilter = Service::ServiceData(SInfo::DATA_DASH_LOG) ;
  170     $debug = Service::ServiceData(SInfo::DATA_DEBUGLOG_STATE) ;
  171 
  172     $res = array( 'debuglog' => $debug,
  173         'logfound' => $logfilter->Get(LogFilter::FLD_TOTALFOUND),
  174         'logfoundmesg' => $logfilter->Get(LogFilter::FLD_OUTMESG),
  175         'log_body' => $logfilter->GetLogOutput() ) ;
  176     echo json_encode($res) ;
  177 }
  178 
  179 function ajax_viewlog()
  180 {
  181     $logfilter = Service::ServiceData(SInfo::DATA_VIEW_LOG) ;
  182 
  183     $res = array( 'logfound' => $logfilter->Get(LogFilter::FLD_TOTALFOUND),
  184         'logfoundmesg' => $logfilter->Get(LogFilter::FLD_OUTMESG),
  185         'cur_log_file' => $logfilter->Get(LogFilter::FLD_LOGFILE),
  186         'cur_log_size' => $logfilter->Get(LogFilter::FLD_FILE_SIZE),
  187         'sellevel' => $logfilter->Get(LogFilter::FLD_LEVEL),
  188         'startpos' => $logfilter->Get(LogFilter::FLD_FROMPOS),
  189         'blksize' => $logfilter->Get(LogFilter::FLD_BLKSIZE),
  190         'log_body' => $logfilter->GetLogOutput() ) ;
  191 
  192     echo json_encode($res) ;
  193 }
  194 
  195 function ajax_downloadlog()
  196 {
  197     $file = UIBase::GrabGoodInput('get', 'filename') ;
  198 
  199     if ( file_exists($file) ) {
  200         if ( ob_get_level() ) {
  201             ob_end_clean() ;
  202         }
  203         header('Content-Description: File Transfer') ;
  204         header('Content-Type: application/octet-stream') ;
  205         header('Content-Disposition: attachment; filename=' . basename($file)) ;
  206         header('Expires: 0') ;
  207         header('Cache-Control: must-revalidate') ;
  208         header('Pragma: public') ;
  209         header('Content-Length: ' . filesize($file)) ;
  210         readfile($file) ;
  211         exit ;
  212     }
  213     else {
  214         error_log("download log $file not exist") ;
  215     }
  216 }
  217 
  218 function ajax_buildprogress()
  219 {
  220     $progress_file = $_SESSION['progress_file'] ;
  221     $log_file = $_SESSION['log_file'] ;
  222 
  223     echo file_get_contents($progress_file) ;
  224 
  225     echo "\n**LOG_DETAIL** retrieved from $log_file\n" ;
  226     echo file_get_contents($log_file) ;
  227 }
  228 
  229 $id = UIBase::GrabGoodInput('get', 'id') ;
  230 $supported = array( 'dashstat', 'plotstat', 'vhstat', 'dashstatus', 'pid_load',
  231     'dashlog', 'viewlog', 'downloadlog', 'buildprogress' ) ;
  232 
  233 if ( in_array($id, $supported) ) {
  234     $func = "ajax_$id" ;
  235     $func() ;
  236 }
  237 else {
  238     error_log("invalid action ajax_data id = $id") ;
  239 }
  240