From cf922ce9361bb3b328d66bb545000dcb41b0984d Mon Sep 17 00:00:00 2001 From: Erreur32 Date: Tue, 8 Aug 2017 18:30:38 +0200 Subject: [PATCH] modif text --- bin/motds32 | 3 +- ssl-check.sh | 236 +++++++++++ vpsinfo.php | 1154 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 1392 insertions(+), 1 deletion(-) create mode 100755 ssl-check.sh create mode 100755 vpsinfo.php diff --git a/bin/motds32 b/bin/motds32 index 85a3548..57fe21c 100755 --- a/bin/motds32 +++ b/bin/motds32 @@ -595,7 +595,7 @@ esac gen_mount_point_table # Create e-mail REPORT header -REPORT="System report\n=============\nHost: ${HOSTNAME}\nDate: $(date)\n" +REPORT="MOTDs32 System report\n=============\nHost: ${HOSTNAME}\nDate: $(date)\n (You can change and set this report alarm in /etc/motds32/motds32.conf)" # Get disk statistics disk @@ -658,6 +658,7 @@ fi test -e /proc/uptime && cut -d '.' -f 1 < /proc/uptime > $STATS_DIR/uptime + # Removing temporary files rm -f ${COLL_PROC} ${COLL_PROC}.tmp rm -f ${COLL_MEM} ${COLL_MEM}.tmp diff --git a/ssl-check.sh b/ssl-check.sh new file mode 100755 index 0000000..e545cdc --- /dev/null +++ b/ssl-check.sh @@ -0,0 +1,236 @@ +#!/bin/bash + +usage() +{ +cat <&2 + echo "see --help for usage" + exit 1 + ;; + esac + shift +done + +CheckLocalCert() +{ + openssl x509 -in $crt -noout $opt +} + +CheckRemoteCert() +{ + echo | + openssl s_client $servername -connect $host:$port 2>/dev/null | + openssl x509 -noout $opt +} + +if [ -z "$(type -t FormatOutput)" ]; then + FormatOutput() { cat; } +fi + +if [ -z "$opt" ]; then + opt="-text -certopt no_header,no_version,no_serial,no_signame,no_pubkey,no_sigdump,no_aux" +fi + +if [ -z "$source" ]; then + echo "ERROR: missing certificate source." + echo "Provide one via '--file' or '--host' arguments." + echo "See '--help' for examples." + exit 1 +fi + +if [ "$source" == "local" ]; then + [ -n "$DEBUG" ] && echo "DEBUG: certificate source is local file" + if [ -z "$crt" ]; then + echo "ERROR: missing certificate file" + exit 1 + fi + [ -n "$DEBUG" ] && echo + CheckLocalCert | FormatOutput +fi + +if [ "$source" == "remote" ]; then + [ -n "$DEBUG" ] && echo "DEBUG: certificate source is remote host" + if [ -z "$host" ]; then + echo "ERROR: missing remote host value." + echo "Provide one via '--host' argument" + exit 1 + fi + if [ -z "$port" ]; then + [ -n "$DEBUG" ] && echo "DEBUG: defaulting to 443 for port." + port="443" + fi + [ -n "$DEBUG" ] && echo + CheckRemoteCert | FormatOutput +fi + + diff --git a/vpsinfo.php b/vpsinfo.php new file mode 100755 index 0000000..45f5a1f --- /dev/null +++ b/vpsinfo.php @@ -0,0 +1,1154 @@ +&1"; + $mysql_com2 = "./mysqlreport --all --tab --user $my_user --password $my_pass --no-mycnf"; + +} +$allps_com = "ps -e | awk '{ print $4;}' | uniq"; + +// GET and POST requests to this page ----------------------------------------- + +// 'Sample current traffic' (vnstat): + +if ($_GET["traffic"]) { + $io = trim(`vnstat -tr | grep --after-context=3 Traffic`); + echo "\n\n
$io
\n\n"; + exit; +} + +// 'Ports List': + +if ($_GET["showports"]) { + $porttext = "Port What Is It? +---- ----------------------- + 21 FTP server + 25 Exim - SMTP + 53 Bind nameserver + 80 Apache webserver + 110 POP mail server + 143 IMAP mail server + 443 Secure Apache webserver + 465 Secure SMTP + 993 Secure IMAP +2082 cPanel +2083 Secure cPanel (https) +2086 WHM +2087 Secure WHM (https) +2095 Webmail +2096 Secure webmail (https) +3306 MySQL +8888 Secure shell - SSHD"; + echo "\n\n
$porttext
\n\n"; + exit; +} + +// Show logged-in shell users: + +if ($_GET["users"]) { + $users = trim(`w`); + echo "\n\n
Logged-in Users\n---------------\n$users
\n\n"; + exit; +} + +// Whois lookup: + +if ($_POST['whois']) { + $whois = trim($_POST['whois']); +} +elseif ($_GET['whois']) { + $whois = trim($_GET['whois']); +} +if ($whois) { + $whois = preg_replace("/[^a-z0-9-.]/", "", $whois); + $lookup = `whois $whois`; + echo "\n\n
$lookup
\n\n"; + exit; +} + +// ls -al /tmp: + +if ($_GET['lsal']) { + $lsout = "Command: ls -al /tmp\n\n"; + $lsout .= `ls -al /tmp`; + echo "\n\n
$lsout
\n\n"; + exit; +} + +// ps -aux (and mem): + +if ($_GET['psaux']) { + $psout = "Command: ps -aux\n\n"; + $psout .= `ps -aux`; + $psout = str_replace("<","<",$psout); + echo "\n\n
$psout
\n\n"; + exit; +} + +if ($_GET['psmem']) { + $psout = "Command: ps -auxh --sort=size | tac\n\n"; + $psout .= "USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND\n"; + $psout .= `ps -auxh --sort=size | tac`; + $psout = str_replace("<","<",$psout); + echo "\n\n
$psout
\n\n"; + exit; +} + +// Command windows: + +if ($_GET['cmd']) { + $cmd = $_GET['cmd']; + if ($cmd == "top") { + $out = trim(`top -n 1 -b`); + $meta = ""; + } + elseif ($cmd == "vpsstat") { + list($out,$opages,$ppages) = vpsstat(); + $meta = ""; + } + elseif ($cmd == "netstat") { + $out = netstat($netstat_com); + $meta = ""; + $buttons = "\n"; + $title = "netstat -nt (TCP connections)"; + } + elseif ($cmd == "netstat2") { + $out = trim(`netstat -ntl`); + $meta = ""; + $buttons = "\n"; + $title = "netstat -ntl (listening TCP ports)"; + } + elseif ($cmd == "mytop") { + $out = trim(`$mysql_com`); + $meta = ""; + } + elseif ($cmd == "mysqlreport") { + $out = trim(`$mysql_com2`); + $out = str_replace('_','-',$out); + $meta = ""; + } + elseif ($cmd == "vnstat") { + $out = trim(`vnstat`); + $meta = ""; + } + elseif ($cmd == "vnstat2") { + $out = trim(`vnstat -d`); + $meta = ""; + $title = "vnstat -d"; + } + elseif ($cmd == "vnstat3") { + $out = trim(`vnstat -m`); + $meta = ""; + $title = "vnstat -m"; + } + elseif ($cmd == "vnstat4") { + $out = trim(`vnstat -tr | grep --after-context=3 Traffic`); + $meta = ""; + $title = "vnstat -tr"; + } + + $reload = "$scriptname?cmd=$cmd"; + if (stristr($cmd,"vnstat")) { + $buttons = " + + + +"; + } + else { + $buttons .= " "; + } + if (!$title) { + $title = $cmd; + } + poppage($cmd,$out,$meta,$reload,$shorttime,$buttons,$title); + exit; +} + +// Run the commands now (except vnstat & mysql) ------------------------------- + +$top = trim(`$top_com`); +$hostname = trim(`hostname`); +$netstat = netstat($netstat_com); +$pstree = trim(`$pstree_com`); +$df_full = trim(`$df_com`); +$tmp_full = trim(`$tmp_com`); +$allps = trim(`$allps_com`); + +// Clean up / prep output ----------------------------------------------------- + +$netstat = preg_replace("/ {1,99}\n/", "\n", $netstat); +$tmp_full = preg_replace("/ {1,99}/", "\n", $tmp_full); + +// df - Disk Usage: + +$lines = explode("\n", $df_full); +for ($i=0; $i 90) { + $allfs .= "$mnt $parts[4]$actual, "; + } + else { + $allfs .= "$mnt $parts[4]$actual, "; + } + } + } + $prev = $parts[0];; +} +if (substr($allfs, -7) == ", ") { + $allfs = substr($allfs, 0, -7); +} + +// Other summary stats: + +$num_mysql = substr_count($pstree,'mysqld'); +$num_httpd = substr_count($pstree,'httpd'); +$num_tcp = substr_count($netstat,'tcp'); + +//Main page buttons: + +// Box buttons to command windows: +$topcmdlink = " + "; +$vpscmdlink = " + "; +$netcmdlink = " + "; + +if ($mysql_mon == 1) + $mycmdlink = " + "; +elseif ($mysql_mon == 2) + $mycmdlink = " + "; + +$vncmdlink = " + "; + +// Button for 'ls -al /tmp': +$lsal = "\n"; + +// Button for 'ps -aux': +$psaux = "\n"; + +// Button for 'ps -aux --sort=size | tac' :) +$psmem = "\n"; + +// Buttons for vnstat: +$vn_sampl = ""; +$vn_days = ""; +$vn_mons = ""; + +// Buttons for netstat: +$netstat_ntl = ""; +$portslink = ""; + +// Button for mysqlreport: +$mysqlrep_det = ""; + +// Auto-refresh meta tag: + +if ($refresh) { + if ($refresh < 1) { + $refresh = 1; + } + $refresh = ($refresh * 60); + $meta_refresh = "\n"; +} + +// Load bar indicators: + +$pattern = "/^.*\b(average)\b.*$/mi"; +preg_match($pattern, $top, $hits); +$loadline = $hits[0]; + +$load_bits = explode("average:",$loadline); +$load_parts = explode(",",$load_bits[1]); +$load1 = trim($load_parts[0]); +$loadlabel1 = $load1; +$load5 = trim($load_parts[1]); +$loadlabel5 = $load5; +$load15 = trim($load_parts[2]); +$loadlabel15 = $load15; + +if ($load1 > 10) { + $load1 = 10; +} +if ($load5 > 10) { + $load5 = 10; +} +if ($load15 > 10) { + $load15 = 10; +} + +if ($load1 > 1) { + $load1_width = round(($load1 - 1) * 22.22); + $bgcolor1 = "#82826E"; + $fgcolor1 = "#CC0000"; +} +else { + $load1_width = round($load1 * 200); + $bgcolor1 = "#222222"; + $fgcolor1 = "#82826E"; +} +if ($load5 > 1) { + $load5_width = round(($load5 - 1) * 22.22); + $bgcolor5 = "#82826E"; + $fgcolor5 = "#CC0000"; +} +else { + $load5_width = round($load5 * 200); + $bgcolor5 = "#222222"; + $fgcolor5 = "#82826E"; +} +if ($load15 > 1) { + $load15_width = round(($load15 - 1) * 22.22); + $bgcolor15 = "#82826E"; + $fgcolor15 = "#CC0000"; +} +else { + $load15_width = round($load15 * 200); + $bgcolor15 = "#222222"; + $fgcolor15 = "#82826E"; +} + +// If users, hyperlink 'User(s)' in top display: + +if (!stristr($top,"0 users,")) { + $top = preg_replace("/(user|users),/", "$1,", $top); +} + +// Mytop/mysqlreport and vnstat ------------------------------------------------ +// Run or produce a useful message if not installed. + +if ($mysql_mon == 1) { + exec("which mytop",$output,$return); + if ($return == 1) { + $mysql = "\n\nMytop is not installed. See the mytop website for information.\n\n"; + $mycmdlink = ""; + $mysql_head = ""; + } + elseif ($return == 0) { + $mysql = trim(`$mysql_com`); + $pattern = "/^.*\bQueries\b.*$/mi"; + preg_match($pattern, $mysql, $hits); + $queryline = trim($hits[0]); + $my_parts = explode(" ",$queryline); + } + $mysql_div = "
$mycmdlink
mytop
$mysql
\n"; +} +elseif ($mysql_mon == 2) { + if (file_exists('mysqlreport') && is_executable('mysqlreport')) { + $mysql = trim(`$mysql_com`); + if (stristr($mysql,'uptime')) { + // Get total queries for topbar display + $parts = explode("_\n",$mysql); + $parts = explode("\n",$parts[2]); + $qline = preg_replace("/ {1,99}/", "|", $parts[0]); + $my_parts = explode('|',$qline); + // The 'Full report' button + $full_report = "\n
$mysqlrep_det
"; + // Change underscores to dashes for readability + $mysql = str_replace('_','-',$mysql); + } + elseif (stristr($mysql,'Access denied for user')) { + $mysql = "\n\nThe mysqlreport script was denied access to mysql. Check that the mysql username +& password (in the vpsinfo configuration) are valid.\n\n"; + $mycmdlink = ''; + } + elseif (stristr($mysql,'bad interpreter')) { + $mysql = "\n\nThe mysqlreport script encountered a problem -- the first line does not have the +correct path for perl on your system.\n\n"; + $mycmdlink = ''; + } + else { + $mysql = "\n\nAn unknown error occurred with the mysqlreport script.\n\n"; + $mycmdlink = ''; + } + } + elseif (file_exists('mysqlreport')) { + $mysql = "\n\nThe mysqlreport script could not be executed. Check the file ownership & permissions.\n\n"; + $mycmdlink = ''; + } + else { + $mysql = "\n\nThe mysqlreport script was not found.\n +You need to get it from http://hackmysql.com/mysqlreport, store it in the same +directory as vpsinfo, and set correct ownership & permissions.\n\n"; + $mycmdlink = ''; + } + $mysql_div = "
$mycmdlink
mysqlreport
+
$mysql
$full_report\n"; +} + +if ($my_parts) { + if (is_numeric($my_parts[1])) { + $mysql_queries = round($my_parts[1]); + $mysql_units = ""; + } + else { + $mysql_units = strtoupper(substr($my_parts[1],-1)); + if ($mysql_units == "M") { + $mysql_queries = round(substr($my_parts[1],0,-1),2); + } + if ($mysql_units == "K") { + $mysql_queries = round(substr($my_parts[1],0,-1)); + } + } + $mysql_head = "
mysql queries
$mysql_queries $mysql_units
"; +} + +if ($vnstat) { + exec("which vnstat",$output,$return); + if ($return == 1) { + $vnstat = "\n\nVnstat is not installed. See the vnstat website for information.\n\n"; + $vncmdlink=''; $vn_sampl=''; $vn_days=''; $vn_mons=''; + $vnstat_div = "
vnstat
$vnstat
"; + } + elseif ($return == 0) { + $vnstat = trim(`$vnstat_com`); + $pattern = "/^.*\btoday\b.*$/mi"; + preg_match_all($pattern, $vnstat, $hits); + $todayline = $hits[0][0]; + $today = explode("|",$todayline); + $today_mb = str_replace(" MB","",$today[2]); + $today_mb = trim($today_mb); + if (stristr($today_mb,",")) { + $today_mb = str_replace(",","",$today_mb); + } + $today_mb = round($today_mb); + if ($today_mb > 999) { + $bw_today = round(($today_mb / 1024),1); + $bw_units = "GB"; + } + else { + $bw_today = $today_mb; + $bw_units = "MB"; + } + if ($today_mb > $bw_alert) { + $bw_today = "$bw_today"; + } + $vnstat_head = "
transfer today
$bw_today $bw_units
+ "; + $vnstat_div = "
$vncmdlink
vnstat
$vnstat
+
$vn_sampl $vn_days $vn_mons
"; + } +} +// vpsstat-like processing of user_beancounters or RAM & swap ----------------- + +list($vpsstat,$mem1,$mem1_units,$mem1_label,$mem1_tip,$mem2,$mem2_units,$mem2_label,$mem2_tip) = vpsstat(); +if ($vpsstat) { + $vpsstat_div = "
$vpscmdlink
vpsstat
$vpsstat
\n"; +} + +// Process/daemon monitor ----------------------------------------------------- + +$allprocs = explode(" ", $processes); +foreach ($allprocs as $proc) { + $proc = trim($proc); + if (stristr($allps,$proc)) { + $tcpstatus .= " $proc  "; + } + else { + $tcpstatus .= " $proc  "; + } +} + +// FUNCTIONS ================================================================== + +function netstat($netstat_com) { + $out = trim(`$netstat_com`); + $out = str_replace(" Address","_Address",$out); + $lines = explode("\n",$out); + for ($i=0; $i 0) { + $line = preg_replace("/ {1,99}/", "|", $lines[$i]); + $line = str_replace("::ffff:","",$line); + $parts = explode("|",$line); + $col_0 = str_pad($parts[0], 5, " ", STR_PAD_RIGHT); + $col_1 = str_pad($parts[1], 6, " ", STR_PAD_LEFT); + $col_2 = str_pad($parts[2], 6, " ", STR_PAD_LEFT); + $col_3 = str_pad($parts[3], 23, " ", STR_PAD_RIGHT); + if (stristr($parts[4],":")) { + $col_4_parts = explode(":",$parts[4]); + $ip_str = $col_4_parts[0]; + } + $col_4 = str_pad($parts[4], 23, " ", STR_PAD_RIGHT); + if ($ip_str) { + $link = "$ip_str"; + $col_4 = str_replace($ip_str,$link,$col_4); + } + $col_5 = $parts[5]; + $cols = $col_0." ".$col_1." ".$col_2." ".$col_3." ".$col_4." ".$col_5; + } + else { + $cols = $lines[$i]; + } + $all .= "\n" . $cols; + } + $all = str_replace("_Address"," Address",$all); + return $all; +} +function poppage($cmd,$out,$meta,$reload,$shorttime,$buttons,$title) { + echo " + + + + $cmd + $meta + + + + + +
$title @ $shorttime
+
$buttons
+
$out
+ + \n"; +} + +function vpsstat() { + $rawbeans = `/bin/beanc 2> /dev/null`; + if (!$rawbeans) { + if (file_exists('/proc/user_beancounters')) { + $rawbeans = `cat /proc/user_beancounters 2> /dev/null`; + } + else { + $ded=TRUE; + } + } + if ($rawbeans) { + $lines = explode("\n", $rawbeans); + for ($i=0; $i $bar) { + $mem1 = "$mem1"; + } + $mem1_label = "oomguarpages"; + $oomg_per = round($mem1 / $bar * 100); + $mem1_tip = "title='oomguarpages is guaranteed memory; you are using $oomg_per% of your quota'"; + $mem1_units = "MB"; + } + else { + $lim = round($line_parts[5] / 256) . " MB"; + $mem2 = round($cur); + $mem2_label = "privvmpages"; + $pmg_per = round($mem2 / $lim * 100); + $mem2_tip = "title='privvmpages is burstable memory; you are using $pmg_per% of your limit'"; + $mem2_units = "MB"; + } + } + else { + $cur = $line_parts[2]; + $rec = $line_parts[3]; + $bar = "n/a"; + $lim = $line_parts[5]; + } + $beans .= str_pad($line_parts[1],12) . str_pad($cur, 12, " ", STR_PAD_LEFT) .str_pad($rec, 12, " ", STR_PAD_LEFT) . str_pad($bar, 12, " ", STR_PAD_LEFT) . str_pad($lim, 12, " ", STR_PAD_LEFT) . str_pad($line_parts[6], 12, " ", STR_PAD_LEFT) . "\n"; + } + } + $parts = explode("\n",$beans); + $vpsstat = "Resource Current Recent Max Barrier Limit Failures\n"; + $vpsstat .= "------------ ---------- ---------- ---------- ---------- ----------\n"; + $vpsstat .= "$parts[2]\n$parts[0]\n$parts[1]\n$parts[3]\n$parts[4]\n$parts[5]"; + } + if (!$vpsstat && $ded==FALSE) { + $vpsstat = "\n +It seems you're running Virtuozzo 3 or OpenVZ. In order to read the VPS stats +(beancounters) you need a small 'helper' app. To install it do the following at +a shell prompt as root: + +[root@vps] wget http://www.labradordata.ca/downloads/install_beanc.sh +[root@vps] sh install_beanc.sh\n\n"; + } + elseif ($ded==TRUE) { + $free = `free`; + if ($free) { + $pattern = "/^.*\bMem\b.*$/mi"; + preg_match($pattern, $free, $hits); + $memline = $hits[0]; + $memline = preg_replace("/ {1,99}/", "|", $memline); + $parts = explode("|",$memline); + $kbytes = $parts[3]; + $mbytes = round($kbytes / 1024); + if ($mbytes > 999) { + $mem1 = round(($mbytes / 1024),1); + $mem1_units = "GB"; + } + else { + $mem1 = $mbytes; + $mem1_units = "MB"; + } + $mem1_label = "free RAM"; + $mem1_tip = "title='amount of free memory'"; + $pattern = "/^.*\bSwap\b.*$/mi"; + preg_match($pattern, $free, $hits); + $memline = $hits[0]; + $memline = preg_replace("/ {1,99}/", "|", $memline); + $parts = explode("|",$memline); + $kbytes = $parts[2]; + $mbytes = round($kbytes / 1024); + if ($mbytes > 999) { + $mem2 = round(($mbytes / 1024),1); + $mem2_units = "GB"; + } + else { + $mem2 = $mbytes; + $mem2_units = "MB"; + } + $mem2_label = "swap used"; + $mem2_tip = "title='amount of swap space currently used'"; + } + } + return array($vpsstat,$mem1,$mem1_units,$mem1_label,$mem1_tip,$mem2,$mem2_units,$mem2_label,$mem2_tip); +} + +$mtime = explode (" ", microtime()); +$tend = $mtime[0] + $mtime[1]; +$totaltime = round(($tend - $tstart),4); +$pagegen = "page generated in $totaltime sec."; + +// MAIN PAGE OUTPUT =========================================================== + +if ($gzip) { + ini_set('zlib.output_compression_level', 1); + ob_start("ob_gzhandler"); +} +header("Cache-Control: no-cache, must-revalidate"); +header('Pragma: no-cache'); +?> + + + + + +<?=$hostname?> : vpsinfo + + + + + + + + + +
+ + + + + + +
Disk Usage:
+ + + + + + + + + + + + + + +
+ + + + + + + + + + + + + +
 
+
+
 
+
+
 
+
+
 
+
+
 
+
+
 
+
+
+
>
>
tcp conn
apache thds
mysql thds
 
+ +
+ + + + + + + + + + + +
 
top
+
+ + +
+
Whois:
+ +
pstree
+
ls -a /tmp
Ignoring PHP session files (sess_*)
+
+ + + + +