Beispiel #1
0
 /**
  * Run the tests in this collection
  *
  * @access 	public
  * @return 	void
  */
 public function run()
 {
     $test_methods = get_class_methods($this);
     if (!is_array($this->validator->package_files) || !sizeof($this->validator->package_files)) {
         return;
     }
     foreach ($this->validator->package_files as $package_file) {
         // only test language files
         /*if (!preg_match($package_file, '#language/.+\.php#'))
         		{
         			continue;
         		}*/
         if (mpv::check_unwanted($package_file)) {
             continue;
         }
         $this->failed_tests = array();
         $this->file_name = $package_file;
         $this->file_contents = file_get_contents($this->validator->temp_dir . $package_file);
         $this->file_contents_file = file($this->validator->temp_dir . $package_file);
         foreach ($test_methods as $method) {
             if (substr($method, 0, 5) == 'test_') {
                 if (!$this->{$method}() || $this->terminate) {
                     $this->failed_tests[] = substr($method, 5);
                 }
                 if ($this->terminate) {
                     unset($this->file_contents, $this->file_contents_file);
                     return;
                 }
             }
         }
         unset($this->file_contents, $this->file_contents_file);
     }
 }
Beispiel #2
0
 /**
  * Run the tests in this collection
  *
  * @access 	public
  * @return 	void
  */
 public function run()
 {
     $test_methods = get_class_methods($this);
     if (!is_array($this->validator->package_files) || !sizeof($this->validator->package_files)) {
         return;
     }
     foreach ($this->validator->package_files as $package_file) {
         $this->file_name = $package_file;
         if (mpv::check_unwanted($package_file)) {
             continue;
         }
         // Only test PHP files
         // We also check files that should be binary, but arent.
         // Maybe there is php in that?
         if (in_array(substr($package_file, -3), array('.md', 'txt', 'tml', 'htm', 'tpl', 'xsl', 'xml', 'css', '.js', 'sql', 'ess')) || $this->check_binary($this->validator->temp_dir . $package_file)) {
             continue;
         }
         $this->failed_tests = array();
         $this->file_contents = file_get_contents($this->validator->temp_dir . $package_file);
         $this->file_contents_file = file($this->validator->temp_dir . $package_file);
         unset($content);
         foreach ($test_methods as $method) {
             if (substr($method, 0, 5) == 'test_') {
                 if (!$this->{$method}() || $this->terminate) {
                     $this->failed_tests[] = substr($method, 5);
                 }
                 if ($this->terminate) {
                     unset($this->file_contents, $this->file_contents_file);
                     return;
                 }
             }
         }
         unset($this->file_contents, $this->file_contents_file);
     }
 }
Beispiel #3
0
 /**
  * Run the tests in this collection
  *
  * @access 	public
  * @return 	void
  */
 public function run()
 {
     // Make sure these tests are enabled in MPV.
     // These tests are for security reasons disabled by default.
     // Only enable these tests if you know what you do and
     // if this MPV install isnt public usable.
     // These tests are NOT enabled at the online MPV at phpBB.com
     // if you want to use these tests you need to install MPV
     // locally.
     // If you use these tests is it at your own risk.
     if (mpv::$exec_php !== mpv::EXEC_PHP) {
         return;
     }
     $test_methods = get_class_methods($this);
     if (!is_array($this->validator->package_files) || !sizeof($this->validator->package_files)) {
         return;
     }
     foreach ($this->validator->package_files as $package_file) {
         if (mpv::check_unwanted($package_file)) {
             continue;
         }
         $this->file_name = $package_file;
         // Only test PHP files
         if (substr($package_file, -3) !== 'php') {
             continue;
         }
         $this->failed_tests = array();
         $this->file_contents = file_get_contents($this->validator->temp_dir . $package_file);
         $this->file_contents_file = file($this->validator->temp_dir . $package_file);
         unset($content);
         foreach ($test_methods as $method) {
             if (substr($method, 0, 5) == 'test_') {
                 if (!$this->{$method}() || $this->terminate) {
                     $this->failed_tests[] = substr($method, 5);
                 }
                 if ($this->terminate) {
                     unset($this->file_contents, $this->file_contents_file);
                     return;
                 }
             }
         }
         unset($this->file_contents, $this->file_contents_file);
     }
 }
Beispiel #4
0
 /**
  * Run the tests in this collection
  *
  * @access 	public
  * @return 	void
  */
 public function run()
 {
     $test_methods = get_class_methods($this);
     $files = array();
     if (is_array($this->validator->package_files)) {
         $files = array_merge($files, $this->validator->package_files);
     }
     if (is_array($this->validator->modx_files)) {
         $files = array_merge($files, $this->validator->modx_files);
     }
     foreach ($files as $package_file) {
         if (mpv::check_unwanted($package_file)) {
             continue;
         }
         // Only test html, php, xml files
         if (!in_array(strrchr($package_file, '.'), array('.php', '.xml', '.html'))) {
             continue;
         }
         $this->failed_tests = array();
         $this->file_name = $package_file;
         $this->file_contents = file_get_contents($this->validator->temp_dir . $package_file);
         $this->file_contents_file = file($this->validator->temp_dir . $package_file);
         foreach ($test_methods as $method) {
             if (substr($method, 0, 5) == 'test_') {
                 if (!$this->{$method}() || $this->terminate) {
                     $this->failed_tests[] = substr($method, 5);
                 }
                 if ($this->terminate) {
                     unset($this->file_contents, $this->file_contents_file);
                     return;
                 }
             }
         }
         unset($this->file_contents, $this->file_contents_file);
     }
 }
Beispiel #5
0
Datei: mpv.php Projekt: phpbb/mpv
 /**
  * Validate a given package
  *
  * @access	public
  * @param	string		Path to MOD package (.zip)
  * @return	void
  */
 public function validate($package)
 {
     global $root_path, $phpEx, $lang;
     // Clear some data
     $this->errors = array();
     $this->message = '';
     $this->zip_file = $package;
     $this->message .= sprintf($lang['VALIDATING_ZIP'], $this->orig_package_name) . "\n\n";
     $this->push_error(self::ERROR_NOTICE, 'GENERAL_NOTICE');
     // Add a general notice about possible wrong fails.
     // First see if the package actually exists
     if (!file_exists($package)) {
         $this->push_error(self::ERROR_FAIL, 'PACKAGE_NOT_EXISTS', __FILE__, $package);
         $this->cleanup();
         return;
     }
     $this->temp_dir = $root_path . 'store/temp/mpv_' . md5(uniqid(time())) . '/';
     mkdir($this->temp_dir, 0777, true);
     if (defined('MPV_DEBUG') && MPV_DEBUG) {
         $type = '';
         switch ($this->unzip_type) {
             case self::UNZIP_EXEC:
                 $type = $lang['TYPE_EXEC'];
                 break;
             case self::UNZIP_PHP:
                 $type = $lang['TYPE_PHP'];
                 break;
             case self::UNZIP_PHPBB:
                 $type = $lang['TYPE_PHPBB'];
                 break;
             default:
                 $this->push_error(self::ERROR_FAIL, 'INVALID_ZIP_METHOD', __FILE__, $this->zip_type);
                 $this->cleanup();
                 return;
         }
         $this->push_error(self::ERROR_INFO, 'ZIP_METHOD', __FILE__, $this->unzip_type, $type);
     }
     if ($this->unzip_type == self::UNZIP_EXEC) {
         $basename = basename($package);
         copy($package, $this->temp_dir . $basename);
         // Unzip it.
         exec('cd ' . escapeshellarg($this->temp_dir) . ' && unzip ' . escapeshellarg($basename));
     } else {
         if ($this->unzip_type == self::UNZIP_PHP) {
             $zip = new ZipArchive();
             if ($zip->open($package) === true) {
                 if (!$zip->extractTo($this->temp_dir)) {
                     $zip->close();
                     $this->push_error(self::ERROR_FAIL, 'UNABLE_EXTRACT_PHP', __FILE__, $package);
                     $this->cleanup();
                     return;
                 }
                 $zip->close();
             } else {
                 $this->push_error(self::ERROR_FAIL, 'UNABLE_OPEN_PHP', __FILE__, $package);
                 $this->cleanup();
                 return;
             }
         } else {
             if ($this->unzip_type == self::UNZIP_PHPBB) {
                 if (!class_exists('compress_zip')) {
                     include $root_path . 'includes/functions_compress.' . $phpEx;
                 }
                 // Next, try to unzip it
                 $compress = new compress_zip('r', $package);
                 $compress->extract($this->temp_dir);
             } else {
                 $this->push_error(self::ERROR_FAIL, 'INVALID_ZIP_METHOD', __FILE__, $this->unzip_type);
                 $this->cleanup();
                 return;
             }
         }
     }
     $file_exists = 0;
     $dir_exists = 0;
     if ($dh = opendir($this->temp_dir)) {
         while (false !== ($file = readdir($dh))) {
             if ($file == '.' || $file == '..') {
                 continue;
             }
             if (is_dir($this->temp_dir . $file)) {
                 $dir_exists++;
                 $dir = $file;
             }
             if (is_file($this->temp_dir . $file) && $file != $package) {
                 $file_exists++;
             }
         }
         closedir($dh);
     }
     if (!$file_exists && $dir_exists) {
         self::$mod_dir = $dir;
     }
     foreach (self::dir_files($this->temp_dir, '', true) as $file) {
         $this->package_files[] = $file;
         $ext = substr(strrchr($file, '.'), 1);
         if ($ext == 'xsl') {
             $this->xsl_files[] = $file;
         } else {
             if ($ext == 'xml') {
                 $raw_xml = file_get_contents($this->temp_dir . $file);
                 if (strpos($raw_xml, '<mod xmlns:xsi=') !== false || strpos($raw_xml, '<mod xmlns=') !== false) {
                     $modx_file = $file;
                     $this->error = array();
                     set_error_handler(array($this, 'internal_error'));
                     $tmp = cortex_xml::load_file($this->temp_dir . $file);
                     restore_error_handler();
                     if ($this->error || !$tmp) {
                         foreach ($this->error as $error) {
                             $this->push_error(self::ERROR_FAIL, 'MPV_XML_ERROR', $file, $error);
                         }
                     } else {
                         $this->modx_files[$modx_file] = $tmp;
                     }
                 }
                 unset($raw_xml);
             }
         }
     }
     // Run the tests
     foreach ($this->test_collections as $collection) {
         $collection->run();
     }
     // Now get rid of $this->temp_dir
     $this->cleanup();
 }
Beispiel #6
0
Datei: cli.php Projekt: phpbb/mpv
*
* @package mpv
* @version $Id$
* @copyright (c) 2010 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
*
*/
if (php_sapi_name() != 'cli') {
    die('Please run this from the command line.');
}
if (!isset($argv[1])) {
    die("Usage: mpv my-mod.zip\n");
}
if (!file_exists($argv[1])) {
    die("Error: file {$argv[1]} not found\n");
}
$phpEx = substr(strrchr(__FILE__, '.'), 1);
$root_path = './';
// Will define all needed things.
require './mpv_config.' . $phpEx;
if (version_compare(PHP_VERSION, '5.2.0', '<')) {
    die($lang['MIN_PHP']);
}
require './includes/functions_mpv.' . $phpEx;
require './includes/mpv.' . $phpEx;
error_reporting(E_ALL);
$mpv = new mpv(null, mpv::UNZIP_PREFERENCE, false);
$mpv->output_type = mpv::OUTPUT_TEXT;
mpv::$exec_php = mpv::EXEC_PHP;
$mpv->validate($argv[1]);
print $lang['VALIDATION_RESULTS'] . "\n\n" . $mpv;
Beispiel #7
0
 /**
  * Test to see if prosilver.xml or english.xml exisits.
  *
  * @return bool
  * @access private
  */
 protected function test_prosilver_english()
 {
     $return = true;
     foreach ($this->validator->package_files as $filename) {
         if (mpv::check_unwanted($filename)) {
             continue;
         }
         $file = strtolower(basename($filename));
         if ($file == 'prosilver.xml' || strpos($file, 'prosilver') !== false && strpos($file, '.xml') !== false) {
             $this->push_error(mpv::ERROR_FAIL, 'PROSILVER_NO_MAIN_MODX', null, array($filename));
             $return = false;
         }
         if ($file == 'en.xml' || strpos($file, 'english') !== false && strpos($file, '.xml') !== false) {
             $this->push_error(mpv::ERROR_FAIL, 'ENGLISH_NO_MAIN_MODX', null, array($filename));
             $return = false;
         }
     }
     return $return;
 }
Beispiel #8
0
 /**
  * Test the phpBB version
  */
 protected function test_phpbb_version()
 {
     $return = true;
     $phpbb_version = $this->modx_object->get_by_name('target-version', true);
     //If we're only going to be local then we get the version from the config file
     $current_phpbb_version = mpv::get_current_version('phpbb');
     if (!is_object($phpbb_version)) {
         $this->push_error(mpv::ERROR_FAIL, 'TARGET_VERSION_NOT_FOUND');
         $return = false;
     } else {
         if (version_compare(strtolower(trim($phpbb_version->value)), strtolower($current_phpbb_version), '<')) {
             if (mpv::$mod_dir . '/' . basename($this->modx_filename) == $this->modx_filename) {
                 $this->push_error(mpv::ERROR_FAIL, 'NOT_LATEST_PHPBB', array($phpbb_version->value, $current_phpbb_version));
             } else {
                 $this->push_error(mpv::ERROR_WARNING, 'NOT_LATEST_PHPBB', array($phpbb_version->value, $current_phpbb_version));
             }
             $return = false;
         }
     }
     return $return;
 }
Beispiel #9
0
*
*/
$phpEx = substr(strrchr(__FILE__, '.'), 1);
$root_path = './';
// Will define all needed things.
require './mpv_config.' . $phpEx;
if (version_compare(PHP_VERSION, '5.2.0', '<')) {
    die($lang['MIN_PHP']);
}
require './includes/functions_mpv.' . $phpEx;
require './includes/mpv.' . $phpEx;
//Override HTML format
define('HTML_FORMAT', true);
register_shutdown_function('end_output');
error_reporting(E_ALL);
$mpv = new mpv(null, mpv::UNZIP_PREFERENCE, false);
$mpv->output_type = HTML_FORMAT ? mpv::OUTPUT_HTML : mpv::OUTPUT_BBCODE;
mpv::$exec_php = mpv::EXEC_PHP;
$mpv->validate('./test-file.zip');
if (HTML_HEADERS) {
    print '<!DOCTYPE html>';
    print '<html>
	<head>
	<title>' . $lang['TITLE'] . '</title>
    <link rel="stylesheet" href="style.css">
	</head>
	<body>';
}
print '<div class="wrapper">';
print '<header>';
print '<h2>' . $lang['VALIDATION_RESULTS'] . "</h2><br /></header>";