3v4l.org

run code in 300+ PHP versions simultaneously
<?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 8.3.0 - 8.3.4
Warning: parse_ini_file(): open_basedir restriction in effect. File(config.ini.php) is not within the allowed path(s): (/tmp:/in:/etc) in /in/g2NBl on line 29 Warning: parse_ini_file(config.ini.php): Failed to open stream: Operation not permitted in /in/g2NBl on line 29 Warning: Trying to access array offset on false in /in/g2NBl on line 30 Warning: Trying to access array offset on false in /in/g2NBl on line 31 Warning: Undefined array key "type" in /in/g2NBl on line 47 Warning: Undefined array key "" in /in/g2NBl on line 48 Warning: Undefined array key "command" in /in/g2NBl on line 49 Warning: Undefined array key "id" in /in/g2NBl on line 50 Warning: Trying to access array offset on false in /in/g2NBl on line 50 Warning: Trying to access array offset on null in /in/g2NBl on line 50 {"error":"Wrong parameters."}
Output for 8.0.0 - 8.0.12, 8.0.14 - 8.0.30, 8.1.0 - 8.1.27, 8.2.0 - 8.2.17
Warning: parse_ini_file(): open_basedir restriction in effect. File(config.ini.php) is not within the allowed path(s): (/tmp:/in:/etc) in /in/g2NBl on line 29 Warning: parse_ini_file(config.ini.php): Failed to open stream: Operation not permitted in /in/g2NBl on line 29 Warning: Trying to access array offset on value of type bool in /in/g2NBl on line 30 Warning: Trying to access array offset on value of type bool in /in/g2NBl on line 31 Warning: Undefined array key "type" in /in/g2NBl on line 47 Warning: Undefined array key "" in /in/g2NBl on line 48 Warning: Undefined array key "command" in /in/g2NBl on line 49 Warning: Undefined array key "id" in /in/g2NBl on line 50 Warning: Trying to access array offset on value of type bool in /in/g2NBl on line 50 Warning: Trying to access array offset on value of type null in /in/g2NBl on line 50 {"error":"Wrong parameters."}
Output for 8.0.13
Warning: parse_ini_file(config.ini.php): Failed to open stream: No such file or directory in /in/g2NBl on line 29 Warning: Trying to access array offset on value of type bool in /in/g2NBl on line 30 Warning: Trying to access array offset on value of type bool in /in/g2NBl on line 31 Warning: Undefined array key "type" in /in/g2NBl on line 47 Warning: Undefined array key "" in /in/g2NBl on line 48 Warning: Undefined array key "command" in /in/g2NBl on line 49 Warning: Undefined array key "id" in /in/g2NBl on line 50 Warning: Trying to access array offset on value of type bool in /in/g2NBl on line 50 Warning: Trying to access array offset on value of type null in /in/g2NBl on line 50 {"error":"Wrong parameters."}
Output for 7.4.33
Warning: parse_ini_file(config.ini.php): failed to open stream: No such file or directory in /in/g2NBl on line 29 Notice: Trying to access array offset on value of type bool in /in/g2NBl on line 30 Notice: Trying to access array offset on value of type bool 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: Trying to access array offset on value of type bool in /in/g2NBl on line 50 Notice: Trying to access array offset on value of type null in /in/g2NBl on line 50 {"error":"Wrong parameters."}
Output for 7.4.0 - 7.4.25, 7.4.27 - 7.4.32
Warning: parse_ini_file(): open_basedir restriction in effect. File(config.ini.php) is not within the allowed path(s): (/tmp:/in:/etc) in /in/g2NBl on line 29 Warning: parse_ini_file(config.ini.php): failed to open stream: Operation not permitted in /in/g2NBl on line 29 Notice: Trying to access array offset on value of type bool in /in/g2NBl on line 30 Notice: Trying to access array offset on value of type bool 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: Trying to access array offset on value of type bool in /in/g2NBl on line 50 Notice: Trying to access array offset on value of type null in /in/g2NBl on line 50 {"error":"Wrong parameters."}
Output for 7.3.32 - 7.3.33, 7.4.26
Warning: parse_ini_file(config.ini.php): failed to open stream: No such file or directory in /in/g2NBl on line 29 {"error":"Wrong parameters."}
Output for 7.2.29 - 7.2.33, 7.3.12 - 7.3.31
Warning: parse_ini_file(): open_basedir restriction in effect. File(config.ini.php) is not within the allowed path(s): (/tmp:/in:/etc) in /in/g2NBl on line 29 Warning: parse_ini_file(config.ini.php): failed to open stream: Operation not permitted 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 7.1.20, 7.2.6
Warning: parse_ini_file(): open_basedir restriction in effect. File(config.ini.php) is not within the allowed path(s): (/tmp:/in) in /in/g2NBl on line 29 Warning: parse_ini_file(config.ini.php): failed to open stream: Operation not permitted 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.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.7
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.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.0.5, 5.1.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.3.11, 4.4.0 - 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

preferences:
243.08 ms | 402 KiB | 348 Q