From 0d169608878744e1b410891d74e516505120b519 Mon Sep 17 00:00:00 2001 From: jo Date: Fri, 29 Apr 2022 14:43:45 +0200 Subject: [PATCH] feat: remove php web installer --- .../load.php => application/check.php} | 0 legacy/application/configs/constants.php | 5 - .../airtime-setup/forms/database-settings.php | 49 --- .../airtime-setup/forms/finish-settings.php | 32 -- .../airtime-setup/forms/general-settings.php | 43 --- .../airtime-setup/forms/media-settings.php | 30 -- .../airtime-setup/forms/rabbitmq-settings.php | 77 ----- legacy/build/airtime-setup/setup-config.php | 60 ---- legacy/public/index.php | 18 +- legacy/public/install/clearstatcache.php | 6 - legacy/public/setup/database-setup.php | 293 ------------------ legacy/public/setup/general-setup.php | 90 ------ legacy/public/setup/media-setup.php | 136 -------- legacy/public/setup/rabbitmq-setup.php | 88 ------ legacy/public/setup/setup-functions.php | 143 --------- 15 files changed, 7 insertions(+), 1063 deletions(-) rename legacy/{build/airtime-setup/load.php => application/check.php} (100%) delete mode 100644 legacy/build/airtime-setup/forms/database-settings.php delete mode 100644 legacy/build/airtime-setup/forms/finish-settings.php delete mode 100644 legacy/build/airtime-setup/forms/general-settings.php delete mode 100644 legacy/build/airtime-setup/forms/media-settings.php delete mode 100644 legacy/build/airtime-setup/forms/rabbitmq-settings.php delete mode 100644 legacy/build/airtime-setup/setup-config.php delete mode 100644 legacy/public/install/clearstatcache.php delete mode 100644 legacy/public/setup/database-setup.php delete mode 100644 legacy/public/setup/general-setup.php delete mode 100644 legacy/public/setup/media-setup.php delete mode 100644 legacy/public/setup/rabbitmq-setup.php delete mode 100644 legacy/public/setup/setup-functions.php diff --git a/legacy/build/airtime-setup/load.php b/legacy/application/check.php similarity index 100% rename from legacy/build/airtime-setup/load.php rename to legacy/application/check.php diff --git a/legacy/application/configs/constants.php b/legacy/application/configs/constants.php index 5c66f51b4..4f0225fe7 100644 --- a/legacy/application/configs/constants.php +++ b/legacy/application/configs/constants.php @@ -4,7 +4,6 @@ define('ROOT_PATH', dirname(__DIR__, 2)); define('LIB_PATH', ROOT_PATH . '/library'); define('BUILD_PATH', ROOT_PATH . '/build'); -define('SETUP_PATH', BUILD_PATH . '/airtime-setup'); define('APPLICATION_PATH', ROOT_PATH . '/application'); define('CONFIG_PATH', APPLICATION_PATH . '/configs'); define('VENDOR_PATH', ROOT_PATH . '/vendor'); @@ -24,10 +23,6 @@ define('LIBRETIME_CONFIG_DIR', getenv('LIBRETIME_CONFIG_DIR') ?: '/etc/libretime define('LIBRETIME_CONF_DIR', LIBRETIME_CONFIG_DIR); // Deprecated define('LIBRETIME_CONFIG_FILEPATH', getenv('LIBRETIME_CONFIG_FILEPATH') ?: LIBRETIME_CONFIG_DIR . '/config.yml'); -// Installer -define('INSTALLER_CONFIG_FILEPATH', LIBRETIME_CONFIG_DIR . '/airtime.temp.conf'); -define('INSTALLER_DEFAULT_STORAGE_PATH', '/srv/airtime/stor'); - // Legacy constants define('PRODUCT_NAME', 'LibreTime'); define('PRODUCT_SITE_URL', 'http://libretime.org'); diff --git a/legacy/build/airtime-setup/forms/database-settings.php b/legacy/build/airtime-setup/forms/database-settings.php deleted file mode 100644 index 6263f7aea..000000000 --- a/legacy/build/airtime-setup/forms/database-settings.php +++ /dev/null @@ -1,49 +0,0 @@ - - -
-

Database Settings

- -

- Enter your Airtime database settings here. Empty or non-existent databases will be created and populated - if the given user has administrative permissions in postgres. -

-
- - - -
-
- - - -
-
- - - -
-
- - - -
- -
-

- This may take up to 30 seconds to complete! -

- -
-
- - diff --git a/legacy/build/airtime-setup/forms/finish-settings.php b/legacy/build/airtime-setup/forms/finish-settings.php deleted file mode 100644 index 2f119f1d1..000000000 --- a/legacy/build/airtime-setup/forms/finish-settings.php +++ /dev/null @@ -1,32 +0,0 @@ - - -
-

Manual Step: Start Libretime Services

- -

- Looks like you're almost done! As a final step, please run the following commands from the terminal: -

-
sudo systemctl start libretime-analyzer
-sudo systemctl start libretime-api
-sudo systemctl start libretime-celery
-sudo systemctl start libretime-liquidsoap
-sudo systemctl start libretime-playout
-

- Click "Done!" to bring up the Libretime configuration checklist; if your configuration is all green, - you're ready to get started with your personal Libretime station! -

-

- If you need to re-run the web installer, just remove . -

-
- -
-
- - diff --git a/legacy/build/airtime-setup/forms/general-settings.php b/legacy/build/airtime-setup/forms/general-settings.php deleted file mode 100644 index bee1708f9..000000000 --- a/legacy/build/airtime-setup/forms/general-settings.php +++ /dev/null @@ -1,43 +0,0 @@ - - -
-

General Settings

- -
-
- - - -
- -
-

- The CORS URL can be setup during install if you are accessing your LibreTime instance behind a Proxy. - This is common with docker setups. If you have a reverse proxy setup enter the URL below, otherwise you - can safely ignore this. Please enter one URL per line. Include the entire URL such as http://example.com - If you are reinstalling LibreTime on an existing setup you can ignore this as well, - the settings in your existing database will be retained unless you enter new values below. -

-
- - -
-
-
- - -
-
- - diff --git a/legacy/build/airtime-setup/forms/media-settings.php b/legacy/build/airtime-setup/forms/media-settings.php deleted file mode 100644 index ed668381d..000000000 --- a/legacy/build/airtime-setup/forms/media-settings.php +++ /dev/null @@ -1,30 +0,0 @@ - - -
-

Media Settings

- -

- Here you can set the default media storage directory for Airtime. If left blank, we'll create a new - directory located at for you. -

-
- - - - - Note that you need to enter the fully qualified path name! - -
- -
- - -
-
- - diff --git a/legacy/build/airtime-setup/forms/rabbitmq-settings.php b/legacy/build/airtime-setup/forms/rabbitmq-settings.php deleted file mode 100644 index 89dc2f74d..000000000 --- a/legacy/build/airtime-setup/forms/rabbitmq-settings.php +++ /dev/null @@ -1,77 +0,0 @@ - - -
-

RabbitMQ Settings

- -

- RabbitMQ is an AMQP-based messaging system used by Libretime. You should only edit these settings - if you have changed the defaults since running the installer, or if you've opted to install RabbitMQ manually. -

-

- In either case, we recommend that you change at least the default password provided - - you can do this by running the following line from the command line:
- sudo rabbitmqctl change_password <username> <newpassword>
- Notice: using special characters such as ! in your rabbitmq password will cause LibreTime to fail - to load properly after setup. Please use alphanumerical characters only. -

-
- Advanced
-
-
-
- - - -
-
- - - - - You probably want to change this! - -
-
- - - -
-
- - - -
-
- - - -
- -
-
- - -
-
- - diff --git a/legacy/build/airtime-setup/setup-config.php b/legacy/build/airtime-setup/setup-config.php deleted file mode 100644 index 87ad35a9c..000000000 --- a/legacy/build/airtime-setup/setup-config.php +++ /dev/null @@ -1,60 +0,0 @@ - - - - - - - - - - - - -
- - Step 1 of 5 -
- -
-
-
- -
-
- -
-
- -
-
- -
-
- -
-
-
- - - - diff --git a/legacy/public/index.php b/legacy/public/index.php index 3930ba7c2..735982c2b 100644 --- a/legacy/public/index.php +++ b/legacy/public/index.php @@ -2,6 +2,11 @@ require_once dirname(__DIR__) . '/application/preload.php'; +// Early exit if a configuration file does not exists! +if (!file_exists(LIBRETIME_CONFIG_FILEPATH)) { + exit("could not find a configuration file at '{$LIBRETIME_CONFIG_FILEPATH}', please make sure it is properly set!"); +} + $configRun = false; $extensions = get_loaded_extensions(); $airtimeSetup = false; @@ -40,7 +45,7 @@ if (!class_exists('Propel')) { exit('Error: Propel not found. Did you install Airtime\'s third-party dependencies with composer? (Check the README.)'); } -require_once SETUP_PATH . '/load.php'; +require_once APPLICATION_PATH . '/check.php'; // This allows us to pass ?config as a parameter to any page // and get to the config checklist. @@ -48,13 +53,4 @@ if (array_key_exists('config', $_GET)) { showConfigCheckPage(); } -// If a configuration file exists, forward to our boot script -if (file_exists(LIBRETIME_CONFIG_FILEPATH)) { - require_once APPLICATION_PATH . '/airtime-boot.php'; -} -// Otherwise, we'll need to run our configuration setup -else { - $airtimeSetup = true; - - require_once SETUP_PATH . '/setup-config.php'; -} +require_once APPLICATION_PATH . '/airtime-boot.php'; diff --git a/legacy/public/install/clearstatcache.php b/legacy/public/install/clearstatcache.php deleted file mode 100644 index a97ae567f..000000000 --- a/legacy/public/install/clearstatcache.php +++ /dev/null @@ -1,6 +0,0 @@ -value pairs for the config file - protected static $_properties; - - /** - * @var PDO - */ - public static $dbh; - - public function __construct($settings) - { - static::$_properties = [ - 'host' => $settings[self::DB_HOST], - 'name' => $settings[self::DB_NAME], - 'user' => $settings[self::DB_USER], - 'password' => $settings[self::DB_PASS], - ]; - } - - private function setNewDatabaseConnection($dbName) - { - self::$dbh = new PDO('pgsql:host=' . self::$_properties['host'] . ';dbname=' . $dbName . ';port=5432' - . ';user=' . self::$_properties['user'] . ';password=' . self::$_properties['password']); - $err = self::$dbh->errorInfo(); - if ($err[1] != null) { - throw new PDOException(); - } - } - - /** - * Runs various database checks against the given settings. If a database with the given name already exists, - * we attempt to install the Airtime schema. If not, we first check if the user can create databases, then try - * to create the database. If we encounter errors, the offending fields are returned in an array to the browser. - * - * @throws AirtimeDatabaseException - * - * @return array associative array containing a display message and fields with errors - */ - public function runSetup() - { - $this->writeToTemp(); - - try { - $this->setNewDatabaseConnection('postgres'); - if ($this->checkDatabaseExists()) { - $this->installDatabaseTables(); - } else { - $this->checkUserCanCreateDb(); - $this->createDatabase(); - $this->installDatabaseTables(); - } - } catch (PDOException $e) { - throw new AirtimeDatabaseException( - "Couldn't establish a connection to the database! " . - 'Please check your credentials and try again. ' - . 'PDO Exception: ' . $e->getMessage(), - [self::DB_NAME, self::DB_USER, self::DB_PASS] - ); - } - self::$dbh = null; - - return [ - 'message' => 'Airtime database was created successfully!', - 'errors' => [], - ]; - } - - private function installDatabaseTables() - { - $this->checkDatabaseEncoding(); - $this->setNewDatabaseConnection(self::$_properties['name']); - $this->checkSchemaExists(); - $this->createDatabaseTables(); - $this->updateIcecastPassword(); - $this->updateDjangoTables(); - } - - /** - * Check if the database settings and credentials given are valid. - * - * @return bool true if the database given exists and the user is valid and can access it - */ - private function checkDatabaseExists() - { - $statement = self::$dbh->prepare('SELECT datname FROM pg_database WHERE datname = :dbname'); - $statement->execute([':dbname' => self::$_properties['name']]); - $result = $statement->fetch(); - - return isset($result[0]); - } - - /** - * Check if the database schema has already been set up. - * - * @throws AirtimeDatabaseException - */ - private function checkSchemaExists() - { - $statement = self::$dbh->prepare("SELECT EXISTS (SELECT relname FROM pg_class WHERE relname='cc_files')"); - $statement->execute(); - $result = $statement->fetch(); - if (isset($result[0]) && $result[0] == 't') { - throw new AirtimeDatabaseException('Airtime is already installed in this database!', []); - } - } - - /** - * Check if the given user has access on the given host to create a new database. - * - * @throws AirtimeDatabaseException - */ - private function checkUserCanCreateDb() - { - $statement = self::$dbh->prepare("SELECT 1 FROM pg_roles WHERE rolname=:dbuser AND rolcreatedb='t'"); - $statement->execute([':dbuser' => self::$_properties['user']]); - $result = $statement->fetch(); - if (!isset($result[0])) { - throw new AirtimeDatabaseException( - 'No database ' . self::$_properties['name'] . " exists; user '" - . self::$_properties['user'] . "' does not have permission to " - . 'create databases on ' . self::$_properties['host'], - [self::DB_NAME, self::DB_USER, self::DB_PASS] - ); - } - } - - /** - * Creates the Airtime database using the given credentials. - * - * @throws AirtimeDatabaseException - */ - private function createDatabase() - { - $statement = self::$dbh->prepare('CREATE DATABASE ' . pg_escape_string(self::$_properties['name']) - . " WITH ENCODING 'UNICODE' TEMPLATE template0" - . ' OWNER ' . pg_escape_string(self::$_properties['user'])); - if (!$statement->execute()) { - throw new AirtimeDatabaseException( - 'There was an error creating the database!', - [self::DB_NAME] - ); - } - } - - /** - * Creates the Airtime database schema using the given credentials. - * - * @throws AirtimeDatabaseException - */ - private function createDatabaseTables() - { - $sqlDir = dirname(ROOT_PATH) . '/api/libretime_api/legacy/migrations/sql/'; - $files = ['schema.sql', 'data.sql']; - foreach ($files as $file) { - try { - $sql = file_get_contents($sqlDir . $file); - self::$dbh->exec($sql); - } catch (PDOException $e) { - echo $e->getMessage(); - - throw new AirtimeDatabaseException( - 'There was an error setting up the Airtime schema!: ' . $e->getMessage(), - [self::DB_NAME] - ); - } - } - } - - /** - * Checks whether the newly-created database's encoding was properly set to UTF8. - * - * @throws AirtimeDatabaseException - */ - private function checkDatabaseEncoding() - { - $statement = self::$dbh->prepare('SELECT pg_encoding_to_char(encoding) ' - . 'FROM pg_database WHERE datname = :dbname'); - $statement->execute([':dbname' => self::$_properties['name']]); - $encoding = $statement->fetch(); - if (!($encoding && $encoding[0] == 'UTF8')) { - throw new AirtimeDatabaseException( - 'The database was installed with an incorrect encoding type!', - [self::DB_NAME] - ); - } - } - - /** - * Updates the icecast password in the database based upon the temp file created during install. - * - * @throws AirtimeDatabaseException - */ - private function updateIcecastPassword() - { - if (!file_exists(LIBRETIME_CONF_DIR . '/icecast_pass')) { - throw new AirtimeDatabaseException('The Icecast Password file was not accessible', []); - } - $icecast_pass_txt = file(LIBRETIME_CONF_DIR . '/icecast_pass'); - $icecast_pass = $icecast_pass_txt[0]; - $icecast_pass = str_replace(PHP_EOL, '', $icecast_pass); - $statement = self::$dbh->prepare("UPDATE cc_stream_setting SET value = :icecastpass WHERE keyname = 's1_pass'"); - $statement->bindValue(':icecastpass', $icecast_pass, PDO::PARAM_STR); - - try { - $statement->execute(); - } catch (PDOException $ex) { - echo 'Error!: ' . $ex->getMessage() . '
'; - } - $statement = self::$dbh->prepare("UPDATE cc_stream_setting SET value = :icecastpass WHERE keyname = 's1_admin_pass'"); - $statement->bindValue(':icecastpass', $icecast_pass, PDO::PARAM_STR); - - try { - $statement->execute(); - } catch (PDOException $ex) { - echo 'Error!: ' . $ex->getMessage() . '
'; - } - $statement = self::$dbh->prepare("UPDATE cc_stream_setting SET value = :icecastpass WHERE keyname = 's2_pass'"); - $statement->bindValue(':icecastpass', $icecast_pass, PDO::PARAM_STR); - - try { - $statement->execute(); - } catch (PDOException $ex) { - echo 'Error!: ' . $ex->getMessage() . '
'; - } - $statement = self::$dbh->prepare("UPDATE cc_stream_setting SET value = :icecastpass WHERE keyname = 's2_admin_pass'"); - $statement->bindValue(':icecastpass', $icecast_pass, PDO::PARAM_STR); - - try { - $statement->execute(); - } catch (PDOException $ex) { - echo 'Error!: ' . $ex->getMessage() . '
'; - } - - $statement = self::$dbh->prepare("UPDATE cc_stream_setting SET value = :icecastpass WHERE keyname = 's3_pass'"); - $statement->bindValue(':icecastpass', $icecast_pass, PDO::PARAM_STR); - - try { - $statement->execute(); - } catch (PDOException $ex) { - echo 'Error!: ' . $ex->getMessage() . '
'; - } - $statement = self::$dbh->prepare("UPDATE cc_stream_setting SET value = :icecastpass WHERE keyname = 's3_admin_pass'"); - $statement->bindValue(':icecastpass', $icecast_pass, PDO::PARAM_STR); - - try { - $statement->execute(); - } catch (PDOException $ex) { - echo 'Error!: ' . $ex->getMessage() . '
'; - } - $statement = self::$dbh->prepare("UPDATE cc_stream_setting SET value = :icecastpass WHERE keyname = 's1_admin_pass'"); - $statement->bindValue(':icecastpass', $icecast_pass, PDO::PARAM_STR); - - try { - $statement->execute(); - } catch (PDOException $ex) { - echo 'Error!: ' . $ex->getMessage() . '
'; - } - $statement = self::$dbh->prepare("INSERT INTO cc_pref (keystr, valstr) VALUES ('default_icecast_password', :icecastpass )"); - $statement->bindValue(':icecastpass', $icecast_pass, PDO::PARAM_STR); - - try { - $statement->execute(); - } catch (PDOException $ex) { - echo 'Error!: ' . $ex->getMessage() . '
'; - } - } - - /** - * Updates the Django related tables for the API. - */ - private function updateDjangoTables() - { - shell_exec('DJANGO_SETTINGS_MODULE=libretime_api.settings.testing LIBRETIME_CONFIG_FILEPATH=' . INSTALLER_CONFIG_FILEPATH . ' libretime-api migrate'); - } -} diff --git a/legacy/public/setup/general-setup.php b/legacy/public/setup/general-setup.php deleted file mode 100644 index c8ffcc6bb..000000000 --- a/legacy/public/setup/general-setup.php +++ /dev/null @@ -1,90 +0,0 @@ -value pairs for the config file - protected static $_properties; - - // Constant form field names for passing errors back to the front-end - public const PUBLIC_URL = 'publicUrl'; - public const CORS_URL = 'corsUrl'; - - public static $cors_url; - - // Message and error fields to return to the front-end - public static $message; - public static $errors = []; - - public function __construct($settings) - { - self::$_properties = [ - 'api_key' => $this->generateRandomString(), - 'public_url' => $settings[self::PUBLIC_URL], - 'cors_url' => $settings[self::CORS_URL], - ]; - self::$cors_url = $settings[self::CORS_URL]; - } - - /** - * @return array associative array containing a display message and fields with errors - */ - public function runSetup() - { - // TODO Do we need to validate these settings? - - if (count(self::$errors) <= 0) { - $this->writeToTemp(); - } - if (strlen(self::$cors_url) == 0) { - } else { - $this->setupCorsUrl(); - } - - return [ - 'message' => self::$message, - 'errors' => self::$errors, - ]; - } - - /** - * If the user entered a CORS Url then add it to the system preferences - * TODO Make sure we check for existing CORS URLs and display them on initial form. - */ - public function setupCorsUrl() - { - try { - $_SERVER['LIBRETIME_CONFIG_FILEPATH'] = INSTALLER_CONFIG_FILEPATH; - Propel::init(PROPEL_CONFIG_FILEPATH); - $con = Propel::getConnection(); - } catch (Exception $e) { - self::$message = "Failed to insert Cors URL; database isn't configured properly!"; - self::$errors[] = self::CORS_URL; - - return; - } - - $this->runCorsUrlQuery($con); - } - - public function runCorsUrlQuery($con) - { - try { - Application_Model_Preference::SetAllowedCorsUrls(self::$cors_url); - Propel::close(); - } catch (Exception $e) { - self::$message = 'Failed to insert ' . self::$cors_url . ' into cc_pref' . $e; - self::$errors[] = self::CORS_URL; - } - } -} diff --git a/legacy/public/setup/media-setup.php b/legacy/public/setup/media-setup.php deleted file mode 100644 index 06b6ca31a..000000000 --- a/legacy/public/setup/media-setup.php +++ /dev/null @@ -1,136 +0,0 @@ -setupMusicDirectory(); - } else { - self::$message = 'Invalid path!'; - self::$errors[] = self::MEDIA_FOLDER; - } - - // Finalize and move installer config file to libretime config file - if (file_exists(LIBRETIME_CONFIG_DIR)) { - if (!$this->moveAirtimeConfig()) { - self::$message = 'Error moving or deleting the installer config!'; - self::$errors[] = 'ERR'; - } - - /* - * If we're upgrading from an old Airtime instance (pre-2.5.2) we rename their old - * config.yml to config.yml.tmp during the setup process. Now that we're done, - * we can rename it to config.yml.bak to avoid confusion. - */ - $fileName = LIBRETIME_CONFIG_FILEPATH; - $tmpFile = $fileName . '.tmp'; - $bakFile = $fileName . '.bak'; - if (file_exists($tmpFile)) { - rename($tmpFile, $bakFile); - } - } else { - self::$message = "Failed to move config.yml; /etc/libretime doesn't exist!"; - self::$errors[] = 'ERR'; - } - - return [ - 'message' => self::$message, - 'errors' => self::$errors, - ]; - } - - /** - * Moves /tmp/airtime.temp.conf to /etc/libretime/config.yml and then removes it to complete setup. - * - * @return bool false if either of the copy or removal operations fail - */ - public function moveAirtimeConfig() - { - return copy(INSTALLER_CONFIG_FILEPATH, LIBRETIME_CONFIG_FILEPATH) - && unlink(INSTALLER_CONFIG_FILEPATH); - } - - /** - * Add the given directory to cc_music_dirs - * TODO Should we check for an existing entry in cc_music_dirs? - */ - public function setupMusicDirectory() - { - try { - $_SERVER['LIBRETIME_CONFIG_FILEPATH'] = INSTALLER_CONFIG_FILEPATH; - Propel::init(PROPEL_CONFIG_FILEPATH); - $con = Propel::getConnection(); - } catch (Exception $e) { - self::$message = "Failed to insert media folder; database isn't configured properly!"; - self::$errors[] = self::MEDIA_FOLDER; - - return; - } - - $this->runMusicDirsQuery($con); - } - - public function runMusicDirsQuery($con) - { - try { - if ($this->checkMusicDirectoryExists($con)) { - $dir = CcMusicDirsQuery::create()->findPk(1, $con); - } else { - $dir = new CcMusicDirs(); - } - - $dir->setDirectory(self::$path) - ->setType('stor') - ->save(); - self::$message = 'Successfully set up media folder!'; - Propel::close(); - unset($_SERVER['AIRTIME_CONF']); - } catch (Exception $e) { - self::$message = 'Failed to insert ' . self::$path . ' into cc_music_dirs'; - self::$errors[] = self::MEDIA_FOLDER; - } - } - - public function checkMusicDirectoryExists($con) - { - $entry = CcMusicDirsQuery::create()->findPk(1, $con); - - return isset($entry) && $entry; - } -} diff --git a/legacy/public/setup/rabbitmq-setup.php b/legacy/public/setup/rabbitmq-setup.php deleted file mode 100644 index 8336434fc..000000000 --- a/legacy/public/setup/rabbitmq-setup.php +++ /dev/null @@ -1,88 +0,0 @@ -value pairs for config.yml - protected static $_properties; - - // Constant form field names for passing errors back to the front-end - public const RMQ_USER = 'rmqUser'; - public const RMQ_PASS = 'rmqPass'; - public const RMQ_PORT = 'rmqPort'; - public const RMQ_HOST = 'rmqHost'; - public const RMQ_VHOST = 'rmqVHost'; - - // Message and error fields to return to the front-end - public static $message; - public static $errors = []; - - public function __construct($settings) - { - static::$_properties = [ - 'host' => $settings[self::RMQ_HOST], - 'port' => $settings[self::RMQ_PORT], - 'user' => $settings[self::RMQ_USER], - 'password' => $settings[self::RMQ_PASS], - 'vhost' => $settings[self::RMQ_VHOST], - ]; - } - - /** - * @return array associative array containing a display message and fields with errors - */ - public function runSetup() - { - try { - if ($this->checkRMQConnection()) { - self::$message = 'Connection successful!'; - } else { - $this->identifyRMQConnectionError(); - } - } catch (Exception $e) { - $this->identifyRMQConnectionError(); - } - - return [ - 'message' => self::$message, - 'errors' => self::$errors, - ]; - } - - public function checkRMQConnection() - { - $conn = new \PhpAmqpLib\Connection\AMQPStreamConnection( - self::$_properties['host'], - self::$_properties['port'], - self::$_properties['user'], - self::$_properties['password'], - self::$_properties['vhost'] - ); - $this->writeToTemp(); - - return isset($conn); - } - - public function identifyRMQConnectionError() - { - // It's impossible to identify errors coming out of amqp.inc without a major - // rewrite, so for now just tell the user ALL THE THINGS went wrong - self::$message = _("Couldn't connect to RabbitMQ server! Please check if the server " - . 'is running and your credentials are correct.'); - self::$errors[] = self::RMQ_USER; - self::$errors[] = self::RMQ_PASS; - self::$errors[] = self::RMQ_HOST; - self::$errors[] = self::RMQ_PORT; - self::$errors[] = self::RMQ_VHOST; - } -} diff --git a/legacy/public/setup/setup-functions.php b/legacy/public/setup/setup-functions.php deleted file mode 100644 index 50edc1764..000000000 --- a/legacy/public/setup/setup-functions.php +++ /dev/null @@ -1,143 +0,0 @@ -value pairs for config.yml. - * - * @var array - */ - protected static $_properties; - - abstract public function __construct($settings); - - abstract public function runSetup(); - - /** - * Write new property values to a given section in airtime.temp.conf. - */ - protected function writeToTemp() - { - if (!file_exists(INSTALLER_CONFIG_FILEPATH)) { - copy(SAMPLE_CONFIG_FILEPATH, INSTALLER_CONFIG_FILEPATH); - } - // Logging::info(CONFIG_TEMP_FILEPATH); - $this->_write(INSTALLER_CONFIG_FILEPATH); - } - - protected function _write($filePath) - { - $file = file($filePath); - $fileOutput = ''; - - $inSection = false; - - foreach ($file as $line) { - if (strpos($line, static::$_section) !== false) { - $inSection = true; - } elseif (strpos($line, '[') !== false) { - $inSection = false; - } - - if (substr(trim($line), 0, 1) == '#') { - /* Workaround to strip comments from config.yml. - * We need to do this because python's ConfigObj and PHP - * have different (and equally strict) rules about comment - * characters in configuration files. - */ - } elseif ($inSection) { - $key = trim(@substr($line, 0, strpos($line, '='))); - $fileOutput .= $key && isset(static::$_properties[$key]) ? - $key . ' = ' . static::$_properties[$key] . "\n" : $line; - } else { - $fileOutput .= $line; - } - } - - file_put_contents($filePath, $fileOutput); - } - - /** - * Generates a random string. - * - * @param int $p_len - * length of the output string - * @param string $p_chars - * characters to use in the output string - * - * @return string the generated random string - */ - protected function generateRandomString($p_len = 20, $p_chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789') - { - $string = ''; - for ($i = 0; $i < $p_len; ++$i) { - $pos = random_int(0, strlen($p_chars) - 1); - $string .= $p_chars[$pos]; - } - - return $string; - } -} - -/** - * Class AirtimeDatabaseException. - * - * @author sourcefabric - * - * Exception class for database setup errors - */ -class AirtimeDatabaseException extends Exception -{ - protected $message = 'Unknown Airtime database exception'; - protected $errors = []; - - public function __construct($message = null, $errors = [], $code = 0, Exception $previous = null) - { - parent::__construct($message, $code, $previous); - $this->errors = $errors; - } - - public function getErrorFields() - { - return $this->errors; - } -} - -// Import Setup subclasses -require_once 'database-setup.php'; - -require_once 'rabbitmq-setup.php'; - -require_once 'general-setup.php'; - -require_once 'media-setup.php'; - -// If config.yml exists, we shouldn't be here -if (!file_exists('/etc/libretime/config.yml')) { - if (isset($_GET['obj']) && $objType = $_GET['obj']) { - $obj = new $objType($_POST); - if ($obj instanceof Setup) { - try { - $response = $obj->runSetup(); - } catch (AirtimeDatabaseException $e) { - $response = [ - 'message' => $e->getMessage(), - 'errors' => $e->getErrorFields(), - ]; - } - - echo json_encode($response); - } - } -}