From ea5a06643abd2d75492226fee54a42645623cf41 Mon Sep 17 00:00:00 2001
From: Christian Boltz
+
+
+
+
+ vBulletin Server Test Script
+
vBulletin Website
+
+vBulletin 5 should run on your system without any errors
+
+options(MYSQLI_OPT_LOCAL_INFILE, false);
+
+ if (mysqli_connect_errno())
+ {
+ $db_connection_error = mysqli_connect_error();
+ return false;
+ }
+ return $obj;
+ }
+}
+
+function test_ini_set($setting, $value)
+{
+ $result = @ini_set($setting, $value);
+ if ($result === false OR $result === null)
+ {
+ return false;
+ }
+ else
+ {
+ return $result;
+ }
+}
+
+//initalise variables dont want any XSS in our test script :)
+$versions = array();
+
+$required_versions = array(
+ 'PHP' => '7.2.0',
+ 'MySQL' => '5.5.8'
+);
+
+if (!empty($_GET['help']))
+{
+ $tested = false;
+
+ $type = strtolower($_GET['help']);
+ $help = array();
+ $help['php'] = 'Your PHP Version is too low to support vBulletin 5, you must at least upgrade to ' . $required_versions['PHP'];
+ $help['mysql'] = 'Your MySQL version is too low to support vBulletin 5, you must at least upgrade to ' . $required_versions['MySQL'];
+ $help['pcre'] = 'vBulletin requires PCRE to be enabled in PHP, ask your host to enable this in php.ini';
+ $help['open_basedir'] = 'You may experience problems with uploading files to vBulletin';
+ $help['curl'] = 'The cUrl extension is needed for many features that gather data from the internet';
+ $help['json'] = 'The JSON extension is required to support vBulletin 5';
+ $help['gzip'] = 'vBulletin uses GZIP to compress pages, though this is not essential for operation';
+ $help['mysql_perms'] = 'vBulletin requires that the mysql username has create, select, update, insert, ' .
+ 'delete, alter and drop privledges, contact your host and ask them to adjust these privledges.';
+ $help['xml'] = 'XML is required as a major component of vBulletin for data storage of languages, settings and templates.';
+ $help['gd'] = 'GD functions are used to produce images, this includes features such as thumbnails and image verification on registration';
+ $help['iconv'] = 'Iconv is used to handle different character encodings. Either the Multibyte String ' .
+ 'or iconv modules are required to properly handle character encodings. Multibyte String is preferred.';
+ $help['mbstring'] = 'Multibyte String is used to handle different character encodings. Either the Multibyte String ' .
+ 'or iconv modules are required to properly handle character encodings. Multibyte String is preferred.';
+ $help['pcre.backtrack_limit'] = 'PHP 5.2.0 and above imposes a limit on PCRE code that we are unable to work-around on this server. ' .
+ 'Ask your host to add the following to php.ini:
+pcre.backtrack_limit = -1
';
+ $help['pcre.utf8'] = 'PCRE with utf8 support is recommended';
+ $help['mysql.utf8mb4'] = 'The utf8mb4 character set allows extended (up to four byte) utf8 characters. Requires MySql 5.5.3 or greater.';
+
+ echo ' ';
+ echo '' . htmlspecialchars($type) . ' Help ';
+}
+elseif (empty($_POST['server']) or empty($_POST['user']) or empty($_POST['db']))
+{
+ $tested = false;
+
+ echo '' . $help["$type"] . ' ';
+ echo '';
+}
+else
+{
+ $tested = true;
+
+ /**
+ * Define the tests
+ */
+
+ // modules
+ // modulename => 'represtative function' or array('function1', 'function2'). There should also be a "help"
+ // entry for every module
+ $required_modules = array(
+ 'PCRE' => 'preg_replace',
+ 'XML' => 'xml_set_element_handler',
+ 'curl' => 'curl_init',
+ 'json' => 'json_encode'
+ );
+
+ $recommended_modules = array(
+ 'GZIP' => array('crc32', 'gzcompress'),
+ 'GD' => 'imagecreatetruecolor',
+ 'iconv' => 'iconv',
+ 'mbstring' => 'mb_convert_encoding'
+ );
+
+ //'feature' => test query. Will check if query produces an error, but not
+ //what it returns
+ $mysql_perms = array(
+ 'create' => 'CREATE TABLE vb3_test (test int(10) unsigned NOT NULL)',
+ 'alter' => 'ALTER TABLE vb3_test CHANGE test test VARCHAR(254) NOT NULL',
+ 'insert' => 'INSERT INTO vb3_test (test) VALUES (\'abcd\')',
+ 'update' => 'UPDATE vb3_test SET test=123 WHERE test=\'abcd\'',
+ 'select' => 'SELECT * FROM vb3_test WHERE test=123',
+ 'delete' => 'DELETE FROM vb3_test WHERE test=123',
+ 'drop' => 'DROP TABLE vb3_test'
+ );
+
+ //either a query string (check for error) or an anonymous function that
+ //takes the mysqli object as a parameter. Always fails when the db connection
+ //does not exist (function will not be called).
+ $mysql_recommended = array(
+ 'mysql.utf8mb4' => function($db)
+ {
+ $result = $db->query("SHOW CHARACTER SET LIKE 'utf8mb4'");
+ return ($result->num_rows > 0);
+ },
+ );
+
+ $required_tests = array();
+
+ $recommended_tests = array(
+ 'open_basedir' => function()
+ {
+ return (get_cfg_var('open_basedir') == '');
+ },
+ 'pcre.backtrack_limit' => function()
+ {
+ return (!test_ini_set('pcre.backtrack_limit', -1) === false);
+ },
+ 'pcre.utf8support' => function()
+ {
+ return (@preg_match('/\p{L}/u', 'a') == 1);
+ },
+ );
+
+
+ /**
+ * Run the tests
+ */
+
+ class vB_TestObserver
+ {
+ private $results = array();
+ private $failures = 0;
+
+ public function getFailureCount()
+ {
+ return $this->failures;
+ }
+
+ public function getResults()
+ {
+ return $this->results;
+ }
+
+ public function logTest($name, $result)
+ {
+ $this->results[$name] = (bool) $result;
+ if(!$result)
+ {
+ $this->failures++;
+ }
+ }
+ }
+
+ $requiredResults = new vB_TestObserver();
+ $recommendedResults = new vB_TestObserver();
+ $mysqlResults = new vB_TestObserver();
+
+ //PHP
+ $versions['PHP'] = phpversion();
+
+ $db = DB::fetch_db($_POST['server'], $_POST['user'], $_POST['pass'], $_POST['db']);
+ //MySQL
+ if(!$db)
+ {
+ //if we don't this this, then then it will be set by the version test.
+ $requiredResults->logTest('MySQL', false);
+ }
+ else
+ {
+ $vquery = $db->query('SELECT VERSION() AS version');
+ $mysql = $vquery->fetch_array();
+ $versions['MySQL'] = $mysql['version'];
+ }
+
+ //check mysql permissions
+ foreach($mysql_perms AS $feature => $query)
+ {
+ $mysqlResults->logTest($feature, ($db AND $db->query($query)));
+ }
+
+ foreach($mysql_recommended AS $feature => $query)
+ {
+ if(!$db)
+ {
+ $result = false;
+ }
+ else if (is_callable($query))
+ {
+ $result = $query($db);
+ }
+ else
+ {
+ $result = (bool) $db->query($query);
+ }
+
+ $recommendedResults->logTest($feature, $result);
+ }
+
+
+ if ($db)
+ {
+ $db->close();
+ }
+
+ //check versions -- if we don't set the version of something, we skip the check
+ //(presumably this means we couldn't look it up and there is another error that covers
+ //that such as the database.
+ foreach($versions as $feature => $version)
+ {
+ $requiredResults->logTest($feature, !version_compare($version, $required_versions[$feature], '<'));
+ }
+
+ function check_modules($modules, $observer)
+ {
+ //check modules.
+ foreach ($modules AS $module => $function)
+ {
+ $test_function = $function;
+ if (!is_array($function))
+ {
+ $test_function = array($test_function);
+ }
+
+ $pass = true;
+ foreach($test_function AS $check)
+ {
+ if (!function_exists($check))
+ {
+ $pass = false;
+ }
+ }
+
+ $observer->logTest($module, $pass);
+ }
+ }
+
+ check_modules($required_modules, $requiredResults);
+ check_modules($recommended_modules, $recommendedResults);
+
+ foreach($required_tests AS $name => $function)
+ {
+ $requiredResults->logTest($name, $function());
+ }
+
+ foreach($recommended_tests AS $name => $function)
+ {
+ $recommendedResults->logTest($name, $function());
+ }
+
+ //translate to the previos vars for display -- should eventually rewrite that
+ //part as well.
+ $e_test = $requiredResults->getResults();
+ $mysql = $mysqlResults->getResults();
+ $test = $recommendedResults->getResults();
+
+ //a bit of a hack to handle previous behavior. This doesn't
+ //fit into our nice little formal setup.
+ //not sure why we set the version only if GD passes.
+ if ($test['GD'])
+ {
+ $versions['GD'] = '2.x';
+ }
+
+ $e_error = $requiredResults->getFailureCount() + $mysqlResults->getFailureCount();
+ $error = $recommendedResults->getFailureCount();
+
+ echo 'MySQL Information ';
+ foreach ($e_test AS $type => $result) {
+ echo 'Essential vBulletin Requirements ';
+ echo ' ';
+ }
+ if ($db_connection_error)
+ {
+ echo '' . $type . ' ';
+ echo ' ' . (!isset($versions["$type"]) ? '' : $versions["$type"]) . ' ';
+ echo ' ' . iif($result, 'Pass', 'Fail') . ' ';
+ echo '';
+ echo ' ';
+ }
+ echo 'Database Connection Error: ' . htmlspecialchars($db_connection_error) . ' ';
+ echo ' ';
+ foreach ($mysql AS $type => $result) {
+ echo 'MySQL Permission Requirements ';
+ echo ' ';
+ }
+
+ echo '' . $type . ' ';
+ echo ' ' . iif($result, 'Pass', 'Fail') . ' ';
+ echo ' ';
+ foreach ($test AS $type => $result) {
+ echo 'Recommended Settings (Optional) ';
+ echo ' ';
+ }
+
+ echo '' . $type . ' ';
+ echo ' ' . (!isset($versions["$type"]) ? '' : $versions["$type"]) . ' ';
+ echo ' ' . iif($result, 'Pass', 'Fail') . ' ';
+ echo ' ';
+
+}
+
+?>
+Overall Result: ' . iif($e_error, 'Fail', 'Pass') . '
vBulletin 5 should run on your system though there may be reduced functionality, click the link(s) above for more information
'; + } + else + { + echo 'vBulletin5 will not run on your system, please click the link(s) above for more information.
'; + } + } +/*======================================================================*\ +|| #################################################################### +|| # CVS: $RCSfile$ - $Revision: 105451 $ +|| #################################################################### +\*======================================================================*/ +?> + + diff --git a/salt/profile/vbulletin/init.sls b/salt/profile/vbulletin/init.sls new file mode 100644 index 0000000..350b17f --- /dev/null +++ b/salt/profile/vbulletin/init.sls @@ -0,0 +1,13 @@ +# NOTE: +# The vb5 binaries must be uploaded to the target host, and made available at +# +# /root/vb5_connect.zip +# +# before running state.apply + +include: + - profile.vbulletin.php-fpm +{% if salt['file.file_exists']('/root/vb5_connect.zip') %} + - profile.vbulletin.setup + - profile.vbulletin.tools +{% endif %} diff --git a/salt/profile/vbulletin/php-fpm.sls b/salt/profile/vbulletin/php-fpm.sls new file mode 100644 index 0000000..b856755 --- /dev/null +++ b/salt/profile/vbulletin/php-fpm.sls @@ -0,0 +1,34 @@ +/etc/php7/fpm/php.ini: + file.managed: + - contents: + - memory_limit = 192M + - opcache.enable=1 + - opcache.interned_strings_buffer=8 + - opcache.max_accelerated_files=10000 + - opcache.memory_consumption=128 + - opcache.save_comments=1 + - opcache.revalidate_freq=1 + +/etc/php7/fpm/php-fpm.conf: + file.managed: + - contents: + - pid = run/php-fpm.pid + - error_log = syslog + - syslog.ident = fpm + - log_level = notice + - include=/etc/php7/fpm/php-fpm.d/*.conf + +/etc/php7/fpm/php-fpm.d/forums.conf: + file.managed: + - source: salt://profile/vbulletin/files/fpm-listener.conf + - template: jinja + - context: + name: forums + user: nginx + +php-fpm: + service.running: + - enable: True + - watch: + - file: /etc/php7/fpm/* + diff --git a/salt/profile/vbulletin/setup.sls b/salt/profile/vbulletin/setup.sls new file mode 100644 index 0000000..a2cae5c --- /dev/null +++ b/salt/profile/vbulletin/setup.sls @@ -0,0 +1,57 @@ +/srv/www/vhosts/forums: + file.directory: + - user: root + - group: nginx + - dir_mode: 750 + - makedirs: True + archive.extracted: + - source: /root/vb5_connect.zip + - keep_source: False + - enforce_toplevel: False + - trim_output: True + +/srv/www/vhosts/forums/htdocs: + file.copy: + - source: /srv/www/vhosts/forums/upload + - preserve: True + - user: root + - group: nginx + - mode: 644 + +/srv/www/vhosts/forums/htdocs/.htaccess: + file.rename: + - source: /srv/www/vhosts/forums/htdocs/htaccess.txt + +/srv/www/vhosts/forums/htdocs/config.php: + file.rename: + - source: /srv/www/vhosts/forums/htdocs/config.php.bkp + +/srv/www/vhosts/forums/htdocs/core/includes/config.php: + file.rename: + - source: /srv/www/vhosts/forums/htdocs/core/includes/config.php.new + +{% for key1, values in pillar.vbulletin.config.items() %} +{% for key2, value in values.items() %} + +configure vBulletin {{key1}}-{{key2}}: + file.line: + - name: /srv/www/vhosts/forums/htdocs/core/includes/config.php + - match: "^(// )?\\$config\\['{{key1}}']\\['{{key2}}']" + - content: "$config['{{key1}}']['{{key2}}'] = '{{value}}';" + - mode: replace + +{% endfor %} +{% endfor %} + +/srv/www/vhosts/forums/htdocs/core/includes/md5_sums_vbulletin.php: + file.managed: + - mode: 444 + - create: no + - replace: no + +/srv/www/vhosts/forums/htdocs/core/cache/css: + file.directory: + - user: nginx + - recurse: + - user + diff --git a/salt/profile/vbulletin/tools.sls b/salt/profile/vbulletin/tools.sls new file mode 100644 index 0000000..a6199a5 --- /dev/null +++ b/salt/profile/vbulletin/tools.sls @@ -0,0 +1,36 @@ +# NB: do not enable these tools in production + +{% set tools = salt['pillar.get']('vbulletin:tools', False) %} + +{% if tools %} +/srv/www/vhosts/forums/htdocs/vb_test.php: + file.managed: + - source: salt://profile/vbulletin/files/vb_test.php +{% else %} + file.absent +{% endif %} + +{% if tools %} +/srv/www/vhosts/forums/htdocs/info.php: + file.managed: + - contents: "" +{% else %} + file.absent +{% endif %} + +{% if tools %} +/srv/www/vhosts/forums/db-tweak.sql: + file.managed: + - source: salt://profile/vbulletin/files/db-tweak.sql + - template: jinja + - defaults: + host: {{ pillar.vbulletin.config.MasterServer.servername }} + username: {{ pillar.vbulletin.config.MasterServer.username }} + password: {{ pillar.vbulletin.config.MasterServer.password }} + bburl: {{ grains.weburls[0] ~ '/forum' }} + frontendurl: {{ grains.weburls[0] }} +{% else %} + file.absent +{% endif %} + + diff --git a/salt/role/web_forum.sls b/salt/role/web_forum.sls new file mode 100644 index 0000000..4db44b7 --- /dev/null +++ b/salt/role/web_forum.sls @@ -0,0 +1,3 @@ +include: + - profile.web.server.nginx + - profile.vbulletin