コード例 #1
0
ファイル: MemoryData.php プロジェクト: ColinWaddell/CurrantPi
 private function prepareData()
 {
     /*
      * Check out this page to find out how to understand
      * the output of the free command:
      *   - http://www.linuxnix.com/find-ram-size-in-linuxunix/
      *
      * The code below pulls the relevant parts out of 'free'
      * and figures out the percentage used of each.
      *
      * $total_act is a little less than $mem_total as there's
      * some used up by the bootloader that's not available
      * to the system.
      */
     $mem_free = intval(shell_exec("free -m | awk '/buffers\\/cache/ {print \$3}'"));
     $mem_total = intval(shell_exec("free -m | awk '/Mem/ {print \$2}'"));
     $used_act = intval(shell_exec("free | awk '/buffers\\/cache/ {print \$3}'"));
     $free = intval(shell_exec("free | awk '/Mem/ {print \$4}'"));
     $buffers = intval(shell_exec("free | awk '/Mem/ {print \$6}'"));
     $cache = intval(shell_exec("free | awk '/Mem/ {print \$7}'"));
     $total_act = $used_act + $free + $buffers + $cache;
     $free_p = 100 * ($free / $total_act);
     $buffers_p = 100 * ($buffers / $total_act);
     $cache_p = 100 * ($cache / $total_act);
     $used_act_p = 100 * ($used_act / $total_act);
     // data object
     $data = (object) ['total' => (object) ['pretty' => StringHelpers::prettyMemory($mem_total), 'actual' => $total_act], 'used' => (object) ['pretty' => strval(round($used_act_p, 2)), 'percentage' => $used_act_p, 'actual' => $used_act], 'buffers' => (object) ['pretty' => strval(round($buffers_p, 2)), 'percentage' => $buffers_p, 'actual' => $buffers], 'cache' => (object) ['pretty' => strval(round($cache_p, 2)), 'percentage' => $cache_p, 'actual' => $cache], 'free' => (object) ['pretty' => strval(round($free_p, 2)), 'percentage' => $free_p, 'actual' => $free]];
     return $data;
 }
コード例 #2
0
 private function prepareData()
 {
     /*
      * The command uptime returns a bunch of information about how long
      * the system has been running and the load on the processor. Read
      * more about this information here
      *   - http://www.computerhope.com/unix/uptime.htm
      */
     $output = shell_exec('uptime');
     $loadavg = explode(' ', substr($output, strpos($output, 'load average:') + 14));
     // data object
     $data = new \stdClass();
     $data->one_min = StringHelpers::prettyLoadAverage($loadavg[0]);
     $data->five_mins = StringHelpers::prettyLoadAverage($loadavg[1]);
     $data->fifteen_mins = StringHelpers::prettyLoadAverage($loadavg[2]);
     return $data;
 }
コード例 #3
0
 private function prepareData()
 {
     /*
      * Using the onboard temperature sensor and the command 'uptime'
      * to pull in information about how hot the Raspberry Pi is and
      * how long it's been switched on for.
      */
     $output = shell_exec('cat /sys/class/thermal/thermal_zone0/temp');
     $temp = round($output / 1000, 1);
     $output = shell_exec('echo "$(</proc/uptime awk \'{print $1}\')"');
     $time_alive = StringHelpers::secondsToTime(intval($output));
     // data object
     $data = new \stdClass();
     $data->temperature = $temp;
     $data->uptime = $time_alive;
     return $data;
 }
コード例 #4
0
 private function prepareData()
 {
     /*
      * There is a custom script alongside this project called 'uptime'
      * which figures out the amount of data going through the network
      * in the past second. This script takes one second to execute so
      * will delay the loading of the page accordingly.
      *
      * Also using one of the scripts in lib/string_helpers.php to
      * print the network speed in either b/s, Kb/s or Gb/s.
      */
     $output = shell_exec('sh ./lib/transfer_rate.sh');
     $rates = explode(' ', $output);
     // data object
     $data = new \stdClass();
     $data->down = StringHelpers::prettyBaud($rates[0]);
     $data->up = StringHelpers::prettyBaud($rates[1]);
     return $data;
 }
コード例 #5
0
ファイル: class.htmlp.php プロジェクト: DartzIzBak/HTMLP
 /**
  * Get the next HTMLElement
  *
  * @param string $file The entire file content.
  * @param int $index The current position in our walker.
  * @param BaseElement $parent The parent of the next element.
  *
  * @return BaseElement
  */
 public function nextElement($file, &$index, $parent)
 {
     $string = new \StringHelpers();
     $string->set($file);
     $elements_name = '';
     $elements_text = '';
     $comment = false;
     $script_closed = true;
     $script_depth = 0;
     $is_alt_script = $is_inclusion = false;
     $thisElement = new BaseElement($this);
     $first_character = true;
     $single_line_element = false;
     while (false !== ($char = $string->charAt($index))) {
         if ($char == '{') {
             break;
         } elseif ($char == ';') {
             $single_line_element = true;
             break;
         }
         if ($first_character && $char == " ") {
             $index++;
             continue;
         } elseif ($first_character) {
             $first_character = false;
         }
         $elements_name .= $char;
         $index++;
     }
     $index++;
     if ($elements_name && $elements_name[strlen($elements_name) - 1] == ' ') {
         $elements_name = substr($elements_name, 0, strlen($elements_name) - 1);
     }
     $elements_true_name = $this->get_name_from_name($elements_name);
     $thisElement->set_type($elements_true_name);
     $thisElement->set_attributes($this->get_attributes_from_name($elements_name));
     $is_attribute = false;
     $is_style = false;
     switch ($elements_true_name) {
         case 'style':
             $is_style = true;
             $is_alt_script = true;
             break;
         case 'script':
             $is_alt_script = true;
             break;
         case 'pre':
             $is_alt_script = true;
             break;
         case 'import':
             $is_inclusion = true;
             $thisElement = new EmptyHE($this);
             break;
     }
     if (strlen($elements_true_name) <= 0) {
         return $this->document;
     }
     if ($elements_true_name[0] == '@') {
         $is_alt_script = true;
         $is_attribute = true;
     }
     while (($file[$index] != '}' || !$script_closed || $comment) && !$single_line_element) {
         if (!$is_alt_script) {
             if ($file[$index] == " " && !$comment || $file[$index] == "\t" || $file[$index] == "\r") {
                 # Skip any empty characters
             } elseif ($file[$index] == '"' && $file[$index - 1] != "\\" || $comment) {
                 if (!$comment && $file[$index] == '"') {
                     $comment = true;
                     $index++;
                 }
                 if ($comment && $file[$index] == '"' && $file[$index - 1] != "\\") {
                     $comment = false;
                     $index++;
                     if ($is_inclusion) {
                         $htmlp = new \htmlp\HTMLP();
                         if (file_exists($elements_text . '.template')) {
                             $htmlp->process($elements_text . '.template');
                             $thisElement->append_content($htmlp->get_render(), true);
                         } else {
                             $thisElement->append_content('File does not exist: ' . $elements_text . '.template', true);
                         }
                     } else {
                         $thisElement->append_content($elements_text, true);
                     }
                     $elements_text = '';
                     continue;
                 }
                 if ($file[$index] == '\\' && $file[$index - 1] != '\\') {
                     $index++;
                     continue;
                 }
                 $elements_text .= $file[$index];
             } else {
                 $this->nextElement($file, $index, $thisElement);
             }
         } else {
             $elements_text .= $file[$index];
             if ($file[$index] == '{') {
                 $script_depth++;
                 $script_closed = false;
             } elseif ($file[$index] == '}') {
                 $script_depth--;
                 if ($script_depth == 0) {
                     $script_closed = true;
                 }
             }
         }
         $index++;
     }
     if ($single_line_element) {
     } elseif ($is_attribute) {
         $attribute_name = substr($elements_true_name, 1);
         $line = preg_replace('/[\\t\\n]/', "", $elements_text);
         $script = trim($line);
         switch ($attribute_name) {
             case "style":
                 $parent->add_attribute($attribute_name, $script);
                 break;
             case "include":
                 $template_name = explode(' ', $elements_name);
                 $template_name = $template_name[1];
                 $element = new TemplateHE($this);
                 $element->template = $template_name;
                 $element->set_content($script);
                 $parent->add_child_element($element);
                 break;
             case "template":
                 global $htmlp_templates;
                 $template_name = explode(' ', $elements_name);
                 $template_name = $template_name[1];
                 $htmlp_templates[$template_name] = $script;
                 break;
             case "config":
                 $rules = CSSParser::Parse($script, true);
                 $this->config = array_merge($this->config, $rules);
                 $this->reloadConfig();
                 break;
             default:
                 //$parent->add_attribute($attribute_name, $script);
                 break;
         }
     } elseif ($is_alt_script) {
         global $emailprocessor;
         if ($is_style && $emailprocessor->isEnabled('styleHandling')) {
             $rules = CSSParser::Parse($elements_text, false);
             $emailprocessor->addRules($rules);
         } else {
             if ($elements_true_name != 'pre') {
                 $line = str_replace("\t", "", $elements_text);
                 $script = substr($line, 1 + ($line[1] == ' ' ? 1 : 0), strlen($line));
                 $thisElement->append_content($script);
                 $parent->add_child_element($thisElement);
             } else {
                 $script = $elements_text;
                 $thisElement->append_content($script);
                 $parent->add_child_element($thisElement);
             }
         }
     } else {
         $parent->add_child_element($thisElement);
     }
     $index++;
     return $this->document;
 }