Subversion Repositories personal-webbase

Rev

Rev 6 | Blame | Compare with Previous | Last modification | View Log | RSS feed

  1. #!/usr/bin/env php
  2. <?php
  3.  
  4. /*
  5.  * Personal WebBase
  6.  * Copyright 2022 Daniel Marschall, ViaThinkSoft
  7.  *
  8.  * Licensed under the Apache License, Version 2.0 (the "License");
  9.  * you may not use this file except in compliance with the License.
  10.  * You may obtain a copy of the License at
  11.  *
  12.  *     http://www.apache.org/licenses/LICENSE-2.0
  13.  *
  14.  * Unless required by applicable law or agreed to in writing, software
  15.  * distributed under the License is distributed on an "AS IS" BASIS,
  16.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17.  * See the License for the specific language governing permissions and
  18.  * limitations under the License.
  19.  */
  20.  
  21. # Source:
  22. # https://svn.viathinksoft.com/cgi-bin/viewvc.cgi/vgwhois/trunk/maintenance/qa-monitor/syntax/global-syntax-check?revision=HEAD&view=markup
  23.  
  24. if (PHP_OS_FAMILY == 'Windows') {
  25.         // TODO: Adjust to your system settings
  26.         //chdir('C:\\php-8.0.3-nts-Win32-vs16-x64');
  27.         chdir('D:\\xampp\\php\\');
  28. }
  29.  
  30. error_reporting(E_ALL | E_NOTICE | E_STRICT | E_DEPRECATED);
  31.  
  32. //$silent = ($argc >= 2) && ($argv[1] == '--silent');
  33. $silent = true;
  34.  
  35. $files = array();
  36.  
  37. $rii = new RecursiveIteratorIterator(new RecursiveDirectoryIterator(dirname(__DIR__))); // dirname() to check the parent directory
  38. foreach ($rii as $file) {
  39.         $filename = $file->getPathname();
  40.         if (strpos($filename, DIRECTORY_SEPARATOR.'.') !== false) continue; # also hide ".dir" and ".file"
  41.        if (!file_exists($filename)) continue;
  42.         $files[] = $filename;
  43. }
  44.  
  45. $baddest = 0;
  46.  
  47. foreach ($files as $filename) {
  48.         $h = fopen($filename, 'r');
  49.         $headline = fgets($h);
  50.         fclose($h);
  51.  
  52.         // Personal WebBase only: Ignore embedded phpMyAdmin/Popper/webftp
  53.         if (preg_match('@modules'.preg_quote(DIRECTORY_SEPARATOR,'@').'([^/]+)'.preg_quote(DIRECTORY_SEPARATOR,'@').'system@ismU', $filename)) continue;
  54.         // End
  55.  
  56.         $scripttype = 'n/a';
  57.  
  58.         if (preg_match('@#!(.+)\s@U', $headline, $m)) {
  59.                 $interpreter = $m[1];
  60.  
  61.                 switch ($interpreter) {
  62.                         case '/usr/bin/env php':
  63.                         case '/usr/bin/php':
  64.                                 $scripttype = 'PHP';
  65.                                 break;
  66.                         case '/usr/bin/env perl':
  67.                         case '/usr/bin/perl':
  68.                                 $scripttype = 'Perl';
  69.                                 break;
  70.                 }
  71.         } else if (strpos($filename, '.php') !== false) {
  72.                 $scripttype = 'PHP';
  73.         } else if ((strpos($filename, '.pl') !== false) || (strpos($filename, '.pm') !== false)) {
  74.                 $scripttype = 'Perl';
  75.         }
  76.  
  77.         $cmd = '';
  78.         switch ($scripttype) {
  79.                 case 'PHP':
  80.                         $cmd = 'php -l '.escapeshellarg($filename);
  81.                         break;
  82.                 case 'Perl':
  83.                         $cmd = 'perl -Mstrict -Mdiagnostics -cw '.escapeshellarg($filename);
  84.                         break;
  85.         }
  86.  
  87.         if ($cmd) {
  88.                 $out = array();
  89.                 exec($cmd." 2>&1", $out, $code);
  90.  
  91.                 if ($code > $baddest) $baddest = $code;
  92.  
  93.                 if ($code != 0) {
  94.                         echo "($code) $filename: ".trim(implode("\n    ", $out))."\n";
  95.                 } else {
  96.                         if (!$silent) echo "OK: $filename\n";
  97.                 }
  98.         }
  99. }
  100.  
  101. echo "Done.\n";
  102.  
  103. exit($baddest);
  104.