3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php /* MikroGlass - Mikrotik looking glass. For the web. Copyright (C) 2013 Tom Hetmer (http://tom.hetmer.cz) This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ header('Content-Type: application/json'); function fail($why) { echo json_encode(array( 'error' => $why )); exit(); } $config = parse_ini_file("config.ini.php"); $user = $config['user']; $password = $config['password']; $tools = array( 'ping' => '/ping count=4', 'trace' => '/tool traceroute duration=3 use-dns=yes', 'exactroute' => '/ip r pr de where dst-address=', 'ipv4-route-info' => '/ip route print', 'ipv6-route-info' => '/ipv6 route print', 'bgp-peer' => '/routing bgp peer print', //Commented out by default to disallow any chance for users to see BGP peer password details etc //'bgp-status' => '/routing bgp peer print status', 'ospf-neighbor' => '/routing ospf neigh print', 'v4-neighbor' => '/ip neigh pr de', 'v6-neighbor' => '/ipv6 neigh pr', ); $type = $_POST['type']; // type of command (ping, trace, ..) $tool = $tools[$type]; // command syntax $argument = $_POST['command']; // user's argument $server = $config['fqdn'][$_POST['id']];// resolve FQDN host $exec = $tool; // simple commands execute immediately if (!$tool || !$server) { // Does not match our tool or server arrays. fail('Wrong parameters.'); } if ($type == 'ping' || $type == 'trace' || $type == 'exactroute') { // We need argument for these tools if (empty($argument)) { fail('Empty parameter.'); } // BGP route can't have space if ($type == 'exactroute') { $space = ''; } else { $space = ' '; } // Need to sanitize hostname if ($type == 'ping' || $type == 'trace') { // Always returns safely with IP, even for IPs $host = gethostbynamel($argument); if($host) { $argument = $host[0]; } else { fail('Wrong hostname.'); } } $exec = $tool . $space . escapeshellcmd($argument); } // Can't really ssh with passwords // Key auth works. if (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN' && empty($config['password'])) { // Linux, no password/keys, let's ssh $fp = popen('ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no ' . $user . '@' . $server . ' ' . $exec, 'r'); } else { // Putty Link fallback (Linux, Windows) $fp = popen($config['path'] . ' -ssh -l ' . $user . ' -pw ' . $password . ' ' . $server . ' ' . $exec, 'r'); } // Handle stream $out = null; while (!feof($fp)) { $out .= fgets($fp); } pclose($fp); // Return result and our command for display echo json_encode(array( 'command' => $exec, 'result' => $out )); ?>
Output for 5.3.0 - 5.6.28, 7.0.0 - 7.1.0
Warning: parse_ini_file(config.ini.php): failed to open stream: No such file or directory in /in/g2NBl on line 29 Notice: Undefined index: type in /in/g2NBl on line 47 Notice: Undefined index: in /in/g2NBl on line 48 Notice: Undefined index: command in /in/g2NBl on line 49 Notice: Undefined index: id in /in/g2NBl on line 50 {"error":"Wrong parameters."}
Output for hhvm-3.10.0 - 3.12.0
Warning: No such file or directory in /in/g2NBl on line 29 Notice: Undefined index: type in /in/g2NBl on line 47 Notice: Undefined index: in /in/g2NBl on line 48 Notice: Undefined index: command in /in/g2NBl on line 49 Notice: Undefined index: id in /in/g2NBl on line 50 {"error":"Wrong parameters."}
Output for 5.2.7 - 5.2.17
Warning: parse_ini_file(config.ini.php): failed to open stream: No such file or directory in /in/g2NBl on line 29 Notice: Undefined index: type in /in/g2NBl on line 47 Notice: Undefined index: in /in/g2NBl on line 48 Notice: Undefined index: command in /in/g2NBl on line 49 Notice: Undefined index: id in /in/g2NBl on line 50 {"error":"Wrong parameters."}
Output for 5.2.0 - 5.2.6
Warning: parse_ini_file(config.ini.php): failed to open stream: No such file or directory in /in/g2NBl on line 29 Notice: Undefined index: user in /in/g2NBl on line 30 Notice: Undefined index: password in /in/g2NBl on line 31 Notice: Undefined index: type in /in/g2NBl on line 47 Notice: Undefined index: in /in/g2NBl on line 48 Notice: Undefined index: command in /in/g2NBl on line 49 Notice: Undefined index: id in /in/g2NBl on line 50 Notice: Undefined index: fqdn in /in/g2NBl on line 50 {"error":"Wrong parameters."}
Output for 5.0.0 - 5.1.6
Warning: parse_ini_file(config.ini.php): failed to open stream: No such file or directory in /in/g2NBl on line 29 Notice: Undefined index: user in /in/g2NBl on line 30 Notice: Undefined index: password in /in/g2NBl on line 31 Notice: Undefined index: type in /in/g2NBl on line 47 Notice: Undefined index: in /in/g2NBl on line 48 Notice: Undefined index: command in /in/g2NBl on line 49 Notice: Undefined index: id in /in/g2NBl on line 50 Notice: Undefined index: fqdn in /in/g2NBl on line 50 Fatal error: Call to undefined function json_encode() in /in/g2NBl on line 23
Process exited with code 255.
Output for 4.4.5 - 4.4.9
Warning: parse_ini_file(): Cannot open 'config.ini.php' for reading in /in/g2NBl on line 29 Notice: Undefined index: type in /in/g2NBl on line 47 Notice: Undefined index: in /in/g2NBl on line 48 Notice: Undefined index: command in /in/g2NBl on line 49 Notice: Undefined index: id in /in/g2NBl on line 50 Fatal error: Call to undefined function: json_encode() in /in/g2NBl on line 23
Process exited with code 255.
Output for 4.3.2 - 4.4.4
Warning: parse_ini_file(): Cannot open 'config.ini.php' for reading in /in/g2NBl on line 29 Notice: Undefined index: type in /in/g2NBl on line 47 Notice: Undefined index: in /in/g2NBl on line 48 Notice: Undefined index: command in /in/g2NBl on line 49 Notice: Undefined index: id in /in/g2NBl on line 50 Fatal error: Call to undefined function: json_encode() in /in/g2NBl on line 23
Process exited with code 255.
Output for 4.3.0 - 4.3.1
Warning: parse_ini_file() [http://www.php.net/function.parse-ini-file]: Cannot open 'config.ini.php' for reading in /in/g2NBl on line 29 Notice: Undefined index: type in /in/g2NBl on line 47 Notice: Undefined index: in /in/g2NBl on line 48 Notice: Undefined index: command in /in/g2NBl on line 49 Notice: Undefined index: id in /in/g2NBl on line 50 Fatal error: Call to undefined function: json_encode() in /in/g2NBl on line 23