function addInputValue($value, $col) { $value = removeNewLines($value); ?> <script type="text/javascript"> document.getElementById('<?php echo $col; ?> ').value = '<?php echo addslashes($value); ?> '; </script> <?php }
$networkInterface = removeNewLines(shell_exec(preg_replace("/\r|\n/", "", "ip route get 8.8.8.8 | grep dev | awk -F'dev' '{ print \$2 }' | awk '{ print \$1 }'"))); $config = ['apache2' => ['accessLog' => '/var/log/apache2/access.log', 'parseString' => '%h %l %u %t "%r" %>s %O "%{Referer}i" \\"%{User-Agent}i"'], 'nginx' => ['accessLog' => '/var/log/nginx/access.log', 'parseString' => '%h %l %u %t "%r" %>s %O "%{Referer}i" \\"%{User-Agent}i"'], 'system' => ['ubuntu' => ['memory' => ['free' => "free -b | awk '/cache:/ { print \$4 }'", 'total' => "free -b | awk '/Mem:/ { print \$2 }'"], 'bandwidth' => ['out' => "cat /sys/class/net/" . $networkInterface . "/statistics/tx_bytes", 'in' => "cat /sys/class/net/" . $networkInterface . "/statistics/rx_bytes"], 'cpuCoreCount' => "grep 'model name' /proc/cpuinfo | wc -l", 'activeSsh' => 'users | wc -w', 'uptime' => "awk '{print \$1}' /proc/uptime"], 'centos7' => ['memory' => ['free' => "free -b | awk '/cache:/ { print \$7 }'", 'total' => "free -b | awk '/Mem:/ { print \$2 }'"], 'bandwidth' => ['out' => "cat /sys/class/net/" . $networkInterface . "/statistics/tx_bytes", 'in' => "cat /sys/class/net/" . $networkInterface . "/statistics/rx_bytes"], 'cpuCoreCount' => "grep 'model name' /proc/cpuinfo | wc -l", 'activeSsh' => 'users | wc -w', 'uptime' => "awk '{print \$1}' /proc/uptime"]]]; $os = getLinuxDistro(); $webserver = getWebServer(); try { $payload = []; $payload['parseString'] = $config[$webserver]['parseString']; $payload['memory'] = ['free' => removeNewLines(shell_exec($config['system'][$os]['memory']['free'])), 'total' => removeNewLines(shell_exec($config['system'][$os]['memory']['total']))]; $payload['disk'] = ['free' => disk_free_space('/'), 'total' => disk_total_space('/')]; $payload['bandwidth'] = ['out' => (int) shell_exec($config['system'][$os]['bandwidth']['out']), 'in' => (int) shell_exec($config['system'][$os]['bandwidth']['in'])]; $cpuLoad = sys_getloadavg()[0]; $cpuCoreCount = shell_exec($config['system'][$os]['cpuCoreCount']); $payload['cpu'] = ['1minAverage' => $cpuLoad / $cpuCoreCount * 100]; $payload['accessLog'] = file($config[$webserver]['accessLog'], FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); $payload['hostname'] = gethostname(); $payload['activeSsh'] = removeNewLines(shell_exec($config['system'][$os]['activeSsh'])); $payload['uptime'] = ceil(shell_exec($config['system'][$os]['uptime'])); file_put_contents($config[$webserver]['accessLog'], ''); } catch (Exception $e) { print 'Whoops! Something went wrong...' . PHP_EOL; $payload['errors'] = $e; print print_r($payload['errors'], 1); file_put_contents($config[$webserver]['accessLog'], ''); } $curl = curl_init($host); function removeNewLines($str) { return trim(preg_replace('/\\s\\s+/', ' ', $str)); } // Thanks to this guy on StackOverflow! :) // http://stackoverflow.com/a/16338644
function setTranslation($string) { return preg_replace_callback('/_e\\("([^\\"\\"]+)"\\)/', function ($m) { return '_e("' . addslashes(removeNewLines(T_gettext(stripslashes($m[1])))) . '")'; }, $string); }
function textForTable($values, $fieldname) { $f = $this->fieldByName($fieldname); $value = $values[$this->realField($fieldname)]; if ($f->getType() == 'multiselect') { $values = explode(',', $value); $opts = $f->getOptions(); foreach ($values as $k => $v) { $values[$k] = @$opts[$v]; } $value = implode(',', $values); } if ($f->getType() == 'dropdown') { $opts = $f->getOptions(); $value = @$opts[$value]; } $limite = config_item('yupii_show_ellipsis_for_text_longer_than'); $limite = ifSet($limite, 30); $this->load->helper('text'); $value = removeNewLines(character_limiter(strip_tags(addslashes($value)), $limite)); return $value; }