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 )); ?>
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 47) Position 1 = 28, Position 2 = 30
Branch analysis from position: 28
2 jumps found. (Code = 43) Position 1 = 31, Position 2 = 34
Branch analysis from position: 31
2 jumps found. (Code = 47) Position 1 = 36, Position 2 = 38
Branch analysis from position: 36
2 jumps found. (Code = 47) Position 1 = 39, Position 2 = 41
Branch analysis from position: 39
2 jumps found. (Code = 43) Position 1 = 42, Position 2 = 74
Branch analysis from position: 42
2 jumps found. (Code = 43) Position 1 = 44, Position 2 = 47
Branch analysis from position: 44
2 jumps found. (Code = 43) Position 1 = 49, Position 2 = 51
Branch analysis from position: 49
1 jumps found. (Code = 42) Position 1 = 52
Branch analysis from position: 52
2 jumps found. (Code = 47) Position 1 = 54, Position 2 = 56
Branch analysis from position: 54
2 jumps found. (Code = 43) Position 1 = 57, Position 2 = 68
Branch analysis from position: 57
2 jumps found. (Code = 43) Position 1 = 62, Position 2 = 65
Branch analysis from position: 62
1 jumps found. (Code = 42) Position 1 = 68
Branch analysis from position: 68
2 jumps found. (Code = 46) Position 1 = 84, Position 2 = 86
Branch analysis from position: 84
2 jumps found. (Code = 43) Position 1 = 87, Position 2 = 98
Branch analysis from position: 87
1 jumps found. (Code = 42) Position 1 = 112
Branch analysis from position: 112
1 jumps found. (Code = 42) Position 1 = 118
Branch analysis from position: 118
2 jumps found. (Code = 44) Position 1 = 123, Position 2 = 114
Branch analysis from position: 123
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 114
2 jumps found. (Code = 44) Position 1 = 123, Position 2 = 114
Branch analysis from position: 123
Branch analysis from position: 114
Branch analysis from position: 98
1 jumps found. (Code = 42) Position 1 = 118
Branch analysis from position: 118
Branch analysis from position: 86
Branch analysis from position: 65
2 jumps found. (Code = 46) Position 1 = 84, Position 2 = 86
Branch analysis from position: 84
Branch analysis from position: 86
Branch analysis from position: 68
Branch analysis from position: 56
Branch analysis from position: 51
2 jumps found. (Code = 47) Position 1 = 54, Position 2 = 56
Branch analysis from position: 54
Branch analysis from position: 56
Branch analysis from position: 47
Branch analysis from position: 74
Branch analysis from position: 41
Branch analysis from position: 38
Branch analysis from position: 34
Branch analysis from position: 30
filename:       /in/g2NBl
function name:  (null)
number of ops:  133
compiled vars:  !0 = $config, !1 = $user, !2 = $password, !3 = $tools, !4 = $type, !5 = $tool, !6 = $argument, !7 = $server, !8 = $exec, !9 = $space, !10 = $host, !11 = $fp, !12 = $out
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     0  E >   INIT_FCALL                                               'header'
          1        SEND_VAL                                                 'Content-Type%3A+application%2Fjson'
          2        DO_ICALL                                                 
   29     3        INIT_FCALL                                               'parse_ini_file'
          4        SEND_VAL                                                 'config.ini.php'
          5        DO_ICALL                                         $14     
          6        ASSIGN                                                   !0, $14
   30     7        FETCH_DIM_R                                      ~16     !0, 'user'
          8        ASSIGN                                                   !1, ~16
   31     9        FETCH_DIM_R                                      ~18     !0, 'password'
         10        ASSIGN                                                   !2, ~18
   33    11        ASSIGN                                                   !3, <array>
   47    12        FETCH_R                      global              ~21     '_POST'
         13        FETCH_DIM_R                                      ~22     ~21, 'type'
         14        ASSIGN                                                   !4, ~22
   48    15        FETCH_DIM_R                                      ~24     !3, !4
         16        ASSIGN                                                   !5, ~24
   49    17        FETCH_R                      global              ~26     '_POST'
         18        FETCH_DIM_R                                      ~27     ~26, 'command'
         19        ASSIGN                                                   !6, ~27
   50    20        FETCH_R                      global              ~30     '_POST'
         21        FETCH_DIM_R                                      ~31     ~30, 'id'
         22        FETCH_DIM_R                                      ~29     !0, 'fqdn'
         23        FETCH_DIM_R                                      ~32     ~29, ~31
         24        ASSIGN                                                   !7, ~32
   51    25        ASSIGN                                                   !8, !5
   53    26        BOOL_NOT                                         ~35     !5
         27      > JMPNZ_EX                                         ~35     ~35, ->30
         28    >   BOOL_NOT                                         ~36     !7
         29        BOOL                                             ~35     ~36
         30    > > JMPZ                                                     ~35, ->34
   55    31    >   INIT_FCALL                                               'fail'
         32        SEND_VAL                                                 'Wrong+parameters.'
         33        DO_FCALL                                      0          
   58    34    >   IS_EQUAL                                         ~38     !4, 'ping'
         35      > JMPNZ_EX                                         ~38     ~38, ->38
         36    >   IS_EQUAL                                         ~39     !4, 'trace'
         37        BOOL                                             ~38     ~39
         38    > > JMPNZ_EX                                         ~38     ~38, ->41
         39    >   IS_EQUAL                                         ~40     !4, 'exactroute'
         40        BOOL                                             ~38     ~40
         41    > > JMPZ                                                     ~38, ->74
   60    42    >   ISSET_ISEMPTY_CV                                         !6
         43      > JMPZ                                                     ~41, ->47
   61    44    >   INIT_FCALL                                               'fail'
         45        SEND_VAL                                                 'Empty+parameter.'
         46        DO_FCALL                                      0          
   65    47    >   IS_EQUAL                                                 !4, 'exactroute'
         48      > JMPZ                                                     ~43, ->51
   66    49    >   ASSIGN                                                   !9, ''
         50      > JMP                                                      ->52
   68    51    >   ASSIGN                                                   !9, '+'
   72    52    >   IS_EQUAL                                         ~46     !4, 'ping'
         53      > JMPNZ_EX                                         ~46     ~46, ->56
         54    >   IS_EQUAL                                         ~47     !4, 'trace'
         55        BOOL                                             ~46     ~47
         56    > > JMPZ                                                     ~46, ->68
   74    57    >   INIT_FCALL                                               'gethostbynamel'
         58        SEND_VAR                                                 !6
         59        DO_ICALL                                         $48     
         60        ASSIGN                                                   !10, $48
   75    61      > JMPZ                                                     !10, ->65
   76    62    >   FETCH_DIM_R                                      ~50     !10, 0
         63        ASSIGN                                                   !6, ~50
         64      > JMP                                                      ->68
   78    65    >   INIT_FCALL                                               'fail'
         66        SEND_VAL                                                 'Wrong+hostname.'
         67        DO_FCALL                                      0          
   82    68    >   CONCAT                                           ~53     !5, !9
         69        INIT_FCALL                                               'escapeshellcmd'
         70        SEND_VAR                                                 !6
         71        DO_ICALL                                         $54     
         72        CONCAT                                           ~55     ~53, $54
         73        ASSIGN                                                   !8, ~55
   87    74    >   INIT_FCALL                                               'strtoupper'
         75        INIT_FCALL                                               'substr'
         76        SEND_VAL                                                 'Linux'
         77        SEND_VAL                                                 0
         78        SEND_VAL                                                 3
         79        DO_ICALL                                         $57     
         80        SEND_VAR                                                 $57
         81        DO_ICALL                                         $58     
         82        IS_NOT_IDENTICAL                                 ~59     $58, 'WIN'
         83      > JMPZ_EX                                          ~59     ~59, ->86
         84    >   ISSET_ISEMPTY_DIM_OBJ                         1  ~60     !0, 'password'
         85        BOOL                                             ~59     ~60
         86    > > JMPZ                                                     ~59, ->98
   89    87    >   INIT_FCALL                                               'popen'
         88        CONCAT                                           ~61     'ssh+-o+UserKnownHostsFile%3D%2Fdev%2Fnull+-o+StrictHostKeyChecking%3Dno+', !1
         89        CONCAT                                           ~62     ~61, '%40'
         90        CONCAT                                           ~63     ~62, !7
         91        CONCAT                                           ~64     ~63, '+'
         92        CONCAT                                           ~65     ~64, !8
         93        SEND_VAL                                                 ~65
         94        SEND_VAL                                                 'r'
         95        DO_ICALL                                         $66     
         96        ASSIGN                                                   !11, $66
         97      > JMP                                                      ->112
   92    98    >   INIT_FCALL                                               'popen'
         99        FETCH_DIM_R                                      ~68     !0, 'path'
        100        CONCAT                                           ~69     ~68, '+-ssh+-l+'
        101        CONCAT                                           ~70     ~69, !1
        102        CONCAT                                           ~71     ~70, '+-pw+'
        103        CONCAT                                           ~72     ~71, !2
        104        CONCAT                                           ~73     ~72, '+'
        105        CONCAT                                           ~74     ~73, !7
        106        CONCAT                                           ~75     ~74, '+'
        107        CONCAT                                           ~76     ~75, !8
        108        SEND_VAL                                                 ~76
        109        SEND_VAL                                                 'r'
        110        DO_ICALL                                         $77     
        111        ASSIGN                                                   !11, $77
   96   112    >   ASSIGN                                                   !12, null
   97   113      > JMP                                                      ->118
   98   114    >   INIT_FCALL                                               'fgets'
        115        SEND_VAR                                                 !11
        116        DO_ICALL                                         $80     
        117        ASSIGN_OP                                     8          !12, $80
   97   118    >   INIT_FCALL                                               'feof'
        119        SEND_VAR                                                 !11
        120        DO_ICALL                                         $82     
        121        BOOL_NOT                                         ~83     $82
        122      > JMPNZ                                                    ~83, ->114
  100   123    >   INIT_FCALL                                               'pclose'
        124        SEND_VAR                                                 !11
        125        DO_ICALL                                                 
  103   126        INIT_FCALL                                               'json_encode'
  104   127        INIT_ARRAY                                       ~85     !8, 'command'
  105   128        ADD_ARRAY_ELEMENT                                ~85     !12, 'result'
        129        SEND_VAL                                                 ~85
        130        DO_ICALL                                         $86     
        131        ECHO                                                     $86
  107   132      > RETURN                                                   1

Function fail:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 79) Position 1 = -2
filename:       /in/g2NBl
function name:  fail
number of ops:  8
compiled vars:  !0 = $why
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   22     0  E >   RECV                                             !0      
   23     1        INIT_FCALL                                               'json_encode'
   24     2        INIT_ARRAY                                       ~1      !0, 'error'
          3        SEND_VAL                                                 ~1
          4        DO_ICALL                                         $2      
          5        ECHO                                                     $2
   26     6      > EXIT                                                     
   27     7*     > RETURN                                                   null

End of function fail

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
163.02 ms | 1411 KiB | 38 Q