diff --git a/.travis.yml b/.travis.yml index 67778c0d..8ae12401 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,8 @@ language: php php: - - 7.1 - 7.2 + - 7.3 script: - ./vendor/bin/phpunit --configuration phpunit.xml diff --git a/include/xmlWrite.php b/include/xmlWrite.php index 116e0836..95e0797f 100644 --- a/include/xmlWrite.php +++ b/include/xmlWrite.php @@ -18,7 +18,7 @@ * along with stk-addons. If not, see . */ -function generateNewsXML() +function generateNewsXML($assets_xml_location, $assets_xml_path) { $writer = new XMLWriter(); @@ -45,8 +45,17 @@ function generateNewsXML() // Reference assets.xml $writer->startElement('include'); - $writer->writeAttribute('file', ASSETS_XML_LOCATION); - $writer->writeAttribute('mtime', FileSystem::fileModificationTime(ASSETS_XML_PATH, false)); + $writer->writeAttribute('file', $assets_xml_location); + + try + { + $modification_time = FileSystem::fileModificationTime($assets_xml_path, false); + } + catch (FileSystemException $e) + { + $modification_time = 0; + } + $writer->writeAttribute('mtime', $modification_time); $writer->endElement(); // Refresh dynamic news entries @@ -80,7 +89,7 @@ function generateNewsXML() return $return; } -function generateAssetXML() +function generateAssetXML($download_location) { // Define addon types $addon_types = ['kart', 'track', 'arena']; @@ -168,7 +177,7 @@ function generateAssetXML() $writer->startElement($type); $writer->writeAttribute('id', $addon['id']); $writer->writeAttribute('name', $addon['name']); - $writer->writeAttribute('file', DOWNLOAD_LOCATION . $relative_path); + $writer->writeAttribute('file', $download_location . $relative_path); $writer->writeAttribute('date', strtotime($addon['date'])); $writer->writeAttribute('uploader', $addon['username']); $writer->writeAttribute('designer', $addon['designer']); @@ -182,7 +191,7 @@ function generateAssetXML() $image_path = File::getFromID($addon['image_id'])->getPath(); if (FileSystem::exists(UP_PATH . $image_path)) { - $writer->writeAttribute('image', DOWNLOAD_LOCATION . $image_path); + $writer->writeAttribute('image', $download_location . $image_path); } } catch (FileException $e) @@ -200,7 +209,7 @@ function generateAssetXML() $icon_path = File::getFromID($icon_id)->getPath(); if (FileSystem::exists(UP_PATH . $icon_path)) { - $writer->writeAttribute('icon', DOWNLOAD_LOCATION . $icon_path); + $writer->writeAttribute('icon', $download_location . $icon_path); } } catch (FileException $e) @@ -477,18 +486,29 @@ function generateAssetXML() function writeNewsXML() { - $newsxml = generateNewsXML(); - FileSystem::filePutContents(NEWS_XML_PATH, str_replace("http://addons.supertuxkart.net/dl/", "https://online.supertuxkart.net/dl/", $newsxml)); - return FileSystem::filePutContents(OLD_NEWS_XML_PATH, $newsxml); + $news_xml = generateNewsXML(OLD_ASSETS_XML_LOCATION, OLD_NEWS_XML_LOCATION); + + // Write new xml file + FileSystem::filePutContents( + NEWS_XML_PATH, + str_replace(OLD_DOWNLOAD_LOCATION, DOWNLOAD_LOCATION, $news_xml) + ); + + + return FileSystem::filePutContents(OLD_NEWS_XML_PATH, $news_xml); } function writeAssetXML() { - $assetxml = generateAssetXML(); - FileSystem::filePutContents(ASSETS_XML_PATH, str_replace("http://addons.supertuxkart.net/dl/", "https://online.supertuxkart.net/dl/", $assetxml)); - $count = FileSystem::filePutContents(OLD_ASSETS_XML_PATH, $assetxml); - //$count += File::write(ASSETS2_XML_PATH, generateAssetXML2()); - return $count; + $asset_xml = generateAssetXML(OLD_DOWNLOAD_LOCATION); + + // Write new xml file + FileSystem::filePutContents( + ASSETS_XML_PATH, + str_replace(OLD_DOWNLOAD_LOCATION, DOWNLOAD_LOCATION, $asset_xml) + ); + + return FileSystem::filePutContents(OLD_ASSETS_XML_PATH, $asset_xml); } function writeXML() diff --git a/install/config.EXAMPLE.php b/install/config.EXAMPLE.php index 493e179b..ea646d0d 100755 --- a/install/config.EXAMPLE.php +++ b/install/config.EXAMPLE.php @@ -1,6 +1,6 @@ pushHandler(new \Whoops\Handler\PrettyPageHandler); diff --git a/phpcs/ruleset.xml b/phpcs/ruleset.xml index 79d1ab90..8bc9d302 100644 --- a/phpcs/ruleset.xml +++ b/phpcs/ruleset.xml @@ -37,10 +37,10 @@ - - - - + + + + diff --git a/phpstan/config.example_install_for_phpstan.php b/phpstan/config.example_install_for_phpstan.php index cd0d4fb1..646d9c48 100644 --- a/phpstan/config.example_install_for_phpstan.php +++ b/phpstan/config.example_install_for_phpstan.php @@ -19,8 +19,17 @@ */ declare(strict_types=1); -// Make sure that this does not end with a trailing slash, and does not have a prefix in front -const DOMAIN_NAME = 'online.supertuxkart.net'; +// useful for phpunit testing +if (!defined('TEST_MODE')) define('TEST_MODE', false); +// useful for cron jobs +if (!defined('CRON_MODE')) define('CRON_MODE', false); +// useful for the API +if (!defined('API_MODE')) define('API_MODE', false); +// useful for to know if downloading file +if (!defined('DOWNLOAD_MODE')) define('DOWNLOAD_MODE', false); + +// Check if we are in CLI mode +define('CLI_MODE', php_sapi_name() == "cli"); // WARNING!!!! turn OFF in the production server. // Enable this when you want detailed debugging output. @@ -37,6 +46,21 @@ // Indicate if the certificate is signed by an authority const IS_SSL_CERTIFICATE_VALID = false; +// Do you prefer https? +const PREFER_SSL = true; + + +// Redirect access from web browser to secure server +// NOTE: Do not redirect API requests or download requests as Old STK versions can't handle proper certificates +const REDIRECT_TO_HTTPS_SERVER_NAME = false; +const STK_HTTPS_SERVER_NAME = "https://online.supertuxkart.net"; +if (!API_MODE && !DOWNLOAD_MODE && REDIRECT_TO_HTTPS_SERVER_NAME) +{ + header("Location: " . STK_HTTPS_SERVER_NAME . $_SERVER['REQUEST_URI'], true, 307); + exit; +} + + // set default values ini_set('html_errors', 'On'); if (DEBUG_MODE) @@ -51,14 +75,29 @@ ini_set('display_errors', "false"); } -// useful for phpunit testing -if (!defined('TEST_MODE')) define('TEST_MODE', true); -// useful for cron jobs -if (!defined('CRON_MODE')) define('CRON_MODE', false); -// useful for the API -if (!defined('API_MODE')) define('API_MODE', false); +if (empty($_SERVER['SERVER_NAME']) || empty($_SERVER['SERVER_PORT'])) +{ + // NOTE: We can't access the server name variable in cron mode + // Make sure that this does not end with a trailing slash, and does not have a prefix in front + $DOMAIN_NAME = 'stk-addons.localhost'; +} +else +{ + $DOMAIN_NAME = $_SERVER['SERVER_NAME'] . (!in_array($_SERVER['SERVER_PORT'], ['80', '443'], true) ? ':' . $_SERVER['SERVER_PORT'] : ''); +} + + +// +// Cron constants +// + +// After how many days should we delete the verification emails +const CRON_DAILY_VERIFICATION_DAYS = 1; + +// // Paths on the local filesystem +// const DS = DIRECTORY_SEPARATOR; const ROOT_PATH = __DIR__ . DS; const INCLUDE_PATH = ROOT_PATH . 'include' . DS; @@ -72,33 +111,48 @@ const CACHE_PATH = ASSETS_PATH . 'cache' . DS; // cache for images/html/template const FONTS_PATH = ASSETS_PATH . 'fonts' . DS; +// For old server, http only const OLD_NEWS_XML_PATH = UP_PATH . 'xml' . DS . 'news.xml'; -const NEWS_XML_PATH = UP_PATH . 'xml' . DS . 'online_news.xml'; const OLD_ASSETS_XML_PATH = UP_PATH . 'xml' . DS . 'assets.xml'; + +// For new online server, https only +const NEWS_XML_PATH = UP_PATH . 'xml' . DS . 'online_news.xml'; const ASSETS_XML_PATH = UP_PATH . 'xml' . DS . 'online_assets.xml'; -const ASSETS2_XML_PATH = UP_PATH . 'xml' . DS . 'assets2.xml'; +// // Location urls -if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on') +// +define('ROOT_LOCATION_UNSECURE', 'http://' . $DOMAIN_NAME . '/'); +if ((PREFER_SSL && IS_SSL_CERTIFICATE_VALID) || (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on')) { - define('ROOT_LOCATION', 'https://' . DOMAIN_NAME . '/'); + define('ROOT_LOCATION', 'https://' . $DOMAIN_NAME . '/'); } else { - define('ROOT_LOCATION', 'http://' . DOMAIN_NAME . '/'); + define('ROOT_LOCATION', ROOT_LOCATION_UNSECURE); } -const DOWNLOAD_LOCATION = ROOT_LOCATION . 'dl/'; +// Change this if you want downloads to be from another server +const OLD_DOWNLOAD_LOCATION_ROOT_SERVER = "http://addons.supertuxkart.net/"; +const DOWNLOAD_LOCATION_ROOT_SERVER = ROOT_LOCATION; + +// Old version, http only +const OLD_DOWNLOAD_LOCATION = OLD_DOWNLOAD_LOCATION_ROOT_SERVER . 'dl/'; +const OLD_DOWNLOAD_XML_LOCATION = OLD_DOWNLOAD_LOCATION . 'xml/'; +const OLD_ASSETS_XML_LOCATION = OLD_DOWNLOAD_XML_LOCATION . 'assets.xml'; +const OLD_NEWS_XML_LOCATION = OLD_DOWNLOAD_XML_LOCATION . 'news.xml'; + +// New version, https only +const DOWNLOAD_LOCATION = DOWNLOAD_LOCATION_ROOT_SERVER . 'dl/'; const DOWNLOAD_XML_LOCATION = DOWNLOAD_LOCATION . 'xml/'; -const DOWNLOAD_ASSETS_LOCATION = DOWNLOAD_LOCATION; -const NEWS_XM_LOCATION = DOWNLOAD_XML_LOCATION . 'news.xml'; -const ASSETS_XML_LOCATION = DOWNLOAD_XML_LOCATION . 'assets.xml'; -const ASSETS2_XML_LOCATION = DOWNLOAD_XML_LOCATION . 'assets.xml'; +const ASSETS_XML_LOCATION = DOWNLOAD_XML_LOCATION . 'online_assets.xml'; +const NEWS_XML_LOCATION = DOWNLOAD_XML_LOCATION . 'online_news.xml'; + const BUGS_LOCATION = ROOT_LOCATION . 'bugs/'; const STATS_LOCATION = ROOT_LOCATION . 'stats/'; const ASSETS_LOCATION = ROOT_LOCATION . 'assets/'; const CACHE_LOCATION = ASSETS_LOCATION . 'cache/'; -const LIBS_LOCATION = ASSETS_LOCATION . 'libs/'; +const LIBS_LOCATION = ASSETS_LOCATION . 'libs/@bower_components/'; const IMG_LOCATION = ASSETS_LOCATION . 'img/'; const JS_LOCATION = ASSETS_LOCATION . 'js/'; const CSS_LOCATION = ASSETS_LOCATION . 'css/'; diff --git a/tools/cli.php b/tools/cli.php old mode 100644 new mode 100755 index ea339881..51ab63f5 --- a/tools/cli.php +++ b/tools/cli.php @@ -28,6 +28,8 @@ // Prevent against disaster!!! error_reporting(E_ALL); +ini_set('display_errors', "On"); +ini_set('html_errors', "Off"); function exception_error_handler($severity, $message, $file, $line) { throw new ErrorException($message, 0, $severity, $file, $line); diff --git a/tools/convert-db-v2-to-v3.php b/tools/convert-db-v2-to-v3.php old mode 100644 new mode 100755 diff --git a/tools/dev-precommit.sh b/tools/dev-precommit.sh new file mode 100755 index 00000000..c245408b --- /dev/null +++ b/tools/dev-precommit.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash +composer phpcs +composer phpstan diff --git a/generate_xml.php b/tools/generate-xml.php old mode 100644 new mode 100755 similarity index 56% rename from generate_xml.php rename to tools/generate-xml.php index 9988bb69..94155cfe --- a/generate_xml.php +++ b/tools/generate-xml.php @@ -1,7 +1,7 @@ - * + * copyright 2011 Stephen Just + * 2015 - 2016 Daniel Butum * This file is part of stk-addons. * * stk-addons is free software: you can redistribute it and/or modify @@ -17,11 +17,22 @@ * You should have received a copy of the GNU General Public License * along with stk-addons. If not, see . */ +declare(strict_types=1); -require_once(__DIR__ . DIRECTORY_SEPARATOR . "config.php"); +// Useful CLI interface for the addons +if (php_sapi_name() !== "cli") + exit("Not in CLI Mode"); + +require_once(dirname(__DIR__) . DIRECTORY_SEPARATOR . "config.php"); + +// Prevent against disaster!!! +error_reporting(E_ALL); +ini_set('display_errors', "On"); +ini_set('html_errors', "Off"); -$xml = writeAssetXML(); -echo 'Asset xml written: ' . $xml . ' bytes
'; $xml = writeNewsXML(); -echo 'News xml written: ' . $xml . ' bytes
'; +echo 'News xml written: ' . $xml . ' bytes' . PHP_EOL; + +$xml = writeAssetXML(); +echo 'Asset xml written: ' . $xml . ' bytes' . PHP_EOL; diff --git a/tools/get-achievements.php b/tools/get-achievements.php old mode 100644 new mode 100755