/dev/null', $output, $return); echo "\n"; } else if ($type === 'list') { exec('tuptime -l --csv 2> /dev/null', $output, $return); echo "
\n"; } else { exec('tuptime --csv 2> /dev/null', $output, $return); echo "
\n"; } } else { exec('tuptime --csv 2> /dev/null', $output, $return); echo "
\n"; } # Check right execution if ($return != 0) { echo "
- Error $return -
"; exit(1); } # Initialize empty array for the table $table = []; # Create table content based on execution output foreach ($output as $row) { $column = -1; // Column counter $tmprow = ''; // Temporary row store $row = str_getcsv($row); // Parse csv row into the array # Start row adding it into the array # For table type if ($type === 'table') { array_push($table, " "); } # For list type else if ($type === 'list') { if ( in_array('Startup', $row) && count($table) > 1 ) { array_push($table, " "); } } # For default type else { array_push($table, " "); } # Create the row content foreach ($row as $cell) { $column++; // Increment column counter $cell=htmlentities($cell); // Convert special chars to html # For table type if ($type === 'table') { $tmprow .= ""; } # For list type else if ($type === 'list') { # Match rows with different number of columns and # assign the right colspan to the right column number if ( in_array('Uptime', $row) || in_array('Downtime', $row) || in_array('Kernel', $row) ) { switch ($column) { case 1: $tmprow .= ""; continue 2; } } # Default row assignment $tmprow .= ""; } # For default type else { # Match rows with different number of columns and # assign the right colspan to the right column number if ( in_array('System uptime', $row) || in_array('System downtime', $row) || in_array('Largest uptime', $row) || in_array('Shortest uptime', $row) || in_array('Largest downtime', $row) || in_array('Shortest downtime', $row) || in_array('Current uptime', $row) ) { switch ($column) { case 1: case 3: $tmprow .= ""; continue 2; } } elseif ( in_array('System life', $row) || in_array('Average uptime', $row) || in_array('System kernels', $row) || in_array('...with kernel', $row) || in_array('Average downtime' , $row) ) { switch ($column) { case 1: $tmprow .= ""; continue 2; } } elseif ( in_array('System startups', $row) != in_array('until', $row) ) { switch ($column) { case 1: case 3: $tmprow .= ""; continue 2; case 4: case 5: continue 2; } } # Default row assignment $tmprow .= ""; } } array_push($table, "$tmprow"); // Add row into table array array_push($table, "\n"); // Add end of table row into array } # Print table content foreach ($table as $item) { echo $item; } ?>
$cell$cell$cell$cell$cell$cell$cell
/dev/null', $v_output); echo current($v_output) . "\n"; ?>