Example #1
0
 function controlServicio($sServicio, $sAccion)
 {
     $oPalo = new paloSantoSysInfo();
     $flag = 0;
     $acciones = array('processcontrol_start' => 'start', 'processcontrol_restart' => 'restart', 'processcontrol_stop' => 'stop', 'processcontrol_activate' => 'on', 'processcontrol_deactivate' => 'off');
     $servicios = array('Asterisk' => 'asterisk', 'OpenFire' => 'openfire', 'Hylafax' => 'hylafax', 'Postfix' => 'postfix', 'MySQL' => 'mysqld', 'Apache' => 'httpd', 'Dialer' => 'elastixdialer');
     if (!in_array($sServicio, array_keys($servicios))) {
         return FALSE;
     }
     if (!in_array($sAccion, array_keys($acciones))) {
         return FALSE;
     }
     $output = $retval = NULL;
     if ($sAccion == "processcontrol_deactivate" || $sAccion == "processcontrol_activate") {
         //  exec('sudo -u root chkconfig --level 3 '.escapeshellarg($servicios[$sServicio]).' '.escapeshellarg($acciones[$sAccion]),$output,$retval);
         exec('/usr/bin/elastix-helper rchkconfig --level 3 ' . escapeshellarg($servicios[$sServicio]) . ' ' . escapeshellarg($acciones[$sAccion]), $output, $retval);
         $arrServices = $oPalo->getStatusServices();
         if ($arrServices[$sServicio]["status_service"] == "Shutdown" && $sAccion == "processcontrol_activate" || $arrServices[$sServicio]["status_service"] == "OK" && $sAccion == "processcontrol_deactivate") {
             $sAccion = $sAccion == "processcontrol_deactivate" ? 'processcontrol_stop' : 'processcontrol_start';
         } else {
             $flag = 1;
         }
     }
     if ($flag != 1) {
         exec('sudo -u root service generic-cloexec ' . $servicios[$sServicio] . ' ' . $acciones[$sAccion] . ' 1>/dev/null 2>/dev/null');
     }
     return TRUE;
 }
 function getDataApplet_SystemResources()
 {
     $oPalo = new paloSantoSysInfo();
     $fastgauge = $this->_getFastGraphics();
     $cpu_a = $oPalo->obtener_muestra_actividad_cpu();
     $cpuinfo = $oPalo->getCPUInfo();
     $speed = number_format($cpuinfo['CpuMHz'], 2) . " MHz";
     $cpu_info = $cpuinfo['CpuModel'];
     $meminfo = $oPalo->getMemInfo();
     //MEMORY USAGE
     $fraction_mem_used = ($meminfo['MemTotal'] - $meminfo['MemFree'] - $meminfo['Cached'] - $meminfo['MemBuffers']) / $meminfo['MemTotal'];
     $mem_usage_val = number_format(100.0 * $fraction_mem_used, 1);
     $mem_usage = $fastgauge ? $this->_htmlgauge($fraction_mem_used, 140, 140) : $this->genericImage('rbgauge', array('percent' => $fraction_mem_used, 'size' => '140,140'), null, null);
     $inf2 = number_format($meminfo['MemTotal'] / 1024, 2) . " Mb";
     //SWAP USAGE
     $fraction_swap_used = ($meminfo['SwapTotal'] - $meminfo['SwapFree']) / $meminfo['SwapTotal'];
     $swap_usage_val = number_format(100.0 * $fraction_swap_used, 1);
     $swap_usage = $fastgauge ? $this->_htmlgauge($fraction_swap_used, 140, 140) : $this->genericImage('rbgauge', array('percent' => $fraction_swap_used, 'size' => '140,140'), null, null);
     $inf3 = number_format($meminfo['SwapTotal'] / 1024, 2) . " Mb";
     //UPTIME
     $upfields = array();
     $up = $oPalo->getUptime();
     // Segundos de actividad desde arranque
     $upfields[] = $up % 60;
     $up = ($up - $upfields[0]) / 60;
     $upfields[] = $up % 60;
     $up = ($up - $upfields[1]) / 60;
     $upfields[] = $up % 24;
     $up = ($up - $upfields[2]) / 24;
     $upfields[] = $up;
     $uptime = $upfields[1] . ' ' . _tr('minute(s)');
     if ($upfields[2] > 0) {
         $uptime = $upfields[2] . ' ' . _tr('hour(s)') . ' ' . $uptime;
     }
     if ($upfields[3] > 0) {
         $uptime = $upfields[3] . ' ' . _tr('day(s)') . ' ' . $uptime;
     }
     usleep(200000);
     $cpu_b = $oPalo->obtener_muestra_actividad_cpu();
     $cpu_percent = calcular_carga_cpu_intervalo($cpu_a, $cpu_b);
     $cpu_usage = $fastgauge ? $this->_htmlgauge($cpu_percent, 140, 140) : $this->genericImage('rbgauge', array('percent' => $cpu_percent, 'size' => '140,140'), null, null);
     $inf1 = number_format($cpu_percent * 100.0, 1);
     $html = "<div style='height:165px; position:relative; text-align:center;'>\n                          <div style='width:155px; float:left; position: relative;'>\n                                {$cpu_usage}\n                                <div class=\"neo-applet-sys-gauge-percent\">{$inf1}%</div><div>" . _tr('CPU') . "</div>\n                          </div>\n                          <div style='width:154px; float:left; position: relative;'>\n                                {$mem_usage}\n                                <div class=\"neo-applet-sys-gauge-percent\">{$mem_usage_val}%</div><div>" . _tr('RAM') . "</div>\n                          </div>\n                          <div style='width:155px; float:right; position: relative;'>\n                                {$swap_usage}\n                          <div class=\"neo-applet-sys-gauge-percent\">{$swap_usage_val}%</div><div>" . _tr('SWAP') . "</div>\n                          </div>\n                        </div>\n                        <div class='neo-divisor'></div>\n                        <div class=neo-applet-tline>\n                          <div class='neo-applet-titem'><strong>" . _tr('CPU Info') . ":</strong></div>\n                          <div class='neo-applet-tdesc'>{$cpu_info}</div>\n                        </div>\n                        <div class=neo-applet-tline>\n                          <div class='neo-applet-titem'><strong>" . _tr('Uptime') . ":</strong></div>\n                          <div class='neo-applet-tdesc'>{$uptime}</div>\n                        </div>\n                        <div class='neo-applet-tline'>\n                          <div class='neo-applet-titem'><strong>" . _tr('CPU Speed') . ":</strong></div>\n                          <div class='neo-applet-tdesc'>{$speed}</div>\n                        </div>\n                        <div class='neo-applet-tline'>\n                          <div class='neo-applet-titem'><strong>" . _tr('Memory usage') . ":</strong></div>\n                          <div class='neo-applet-tdesc'>RAM: {$inf2} SWAP: {$inf3}</div>\n                        </div>";
     return $html;
 }