public function __construct($email, $package_version, $install_seq_id, $install_id) { $this->report_parameters['email'] = $email; $this->report_parameters['client_type'] = 'PHP CLI'; $this->report_parameters['server_ip'] = null; $this->report_parameters['host_name'] = null; $this->report_parameters['operating_system'] = php_uname('s'); $this->report_parameters['os_disribution'] = OsUtils::getOsLsb(); $this->report_parameters['architecture'] = php_uname('m'); $this->report_parameters['php_version'] = phpversion(); $this->report_parameters['package_version'] = $package_version; $this->report_parameters['install_id'] = $install_id; $this->report_parameters['install_seq_id'] = $install_seq_id; }
function logMessage($level, $message, $new_line = true) { global $logFile, $logPrintLevel; if (!isset($logFile)) { return; } $message = str_replace("\\n", PHP_EOL, $message); $message = str_replace("\\t", "\t", $message); $logLine = date(L_DATE_FORMAT) . ' ' . $level . ' ' . $message . PHP_EOL; OsUtils::appendFile($logFile, $logLine); // print to screen according to log level if ($level === L_USER && $logPrintLevel >= 0 || $level === L_ERROR && $logPrintLevel >= 1 || $level === L_WARNING && $logPrintLevel >= 2 || $level === L_INFO && $logPrintLevel >= 3) { echo $message; if ($new_line) { echo PHP_EOL; } } }
public function getApplicationInput() { $httpd_bin_found = OsUtils::findBinary(array('apachectl', 'apache2ctl')); if (!empty($httpd_bin_found)) { $httpd_bin_message = "The following apachectl script has been detected: {$httpd_bin_found}. Do you want to use this script to run your Kaltura application? Leave empty to use or provide a pathname to an alternative apachectl script on your server."; $httpd_error_message = "Invalid pathname for apachectl script, leave empty to use {$httpd_bin_found} or enter an alternative apachectl path"; } else { $httpd_bin_message = "Installation could not automatically detect any apachectl script. Please provide a pathname to the apachectl script on your server."; $httpd_error_message = "Invalid pathname for apachectl script, please enter the apachectl pathname again"; } $php_bin_found = OsUtils::findBinary('php'); if (!empty($php_bin_found)) { $php_bin_message = "The following PHP binary has been detected: {$php_bin_found}. Do you want to use this script to run your Kaltura application? Leave empty to use or provide a pathname to an alternative PHP binary on your server."; $php_error_message = "Invalid pathname for PHP binary, leave empty to use {$php_bin_found} or enter an alternative PHP path"; } else { $php_bin_message = "Installation could not automatically detect any PHP binary. Please provide a pathname to the PHP binary on your server."; $php_error_message = "Invalid pathname for PHP binary, please enter the PHP pathname again"; } logMessage(L_USER, "Please provide the following information:"); echo PHP_EOL; $this->getInput('HTTPD_BIN', $httpd_bin_message, $httpd_error_message, InputValidator::createFileValidator(), $httpd_bin_found); $this->getInput('PHP_BIN', $php_bin_message, $php_error_message, InputValidator::createFileValidator(), $php_bin_found); $this->getInput('BASE_DIR', "Full target directory path for Kaltura application (leave empty for /opt/kaltura)", "Target directory must be a valid directory path, please enter again", InputValidator::createDirectoryValidator(), '/opt/kaltura'); $this->getInput('KALTURA_FULL_VIRTUAL_HOST_NAME', "Please enter the domain name/virtual hostname that will be used for the Kaltura server (without http://)", 'Must be a valid hostname or ip, please enter again', InputValidator::createHostValidator(), null); $this->getInput('ADMIN_CONSOLE_ADMIN_MAIL', "Your primary system administrator email address", "Email must be in a valid email format, please enter again", InputValidator::createEmailValidator(false), null); $this->getInput('ADMIN_CONSOLE_PASSWORD', "The password you want to set for your primary administrator", "Password should not be empty and should not contain whitespaces, please enter again", InputValidator::createNoWhitespaceValidator(), null); $this->getInput('DB1_HOST', "Database host (leave empty for 'localhost')", "Must be a valid hostname or ip, please enter again (leave empty for 'localhost')", InputValidator::createHostValidator(), 'localhost'); $this->getInput('DB1_PORT', "Database port (leave empty for '3306')", "Must be a valid port (1-65535), please enter again (leave empty for '3306')", InputValidator::createRangeValidator(1, 65535), '3306'); $this->set('DB1_NAME', 'kaltura'); // currently we do not support getting the DB name from the user because of the DWH implementation $this->getInput('DB1_USER', "Database username (with create & write privileges)", "Database username cannot be empty, please enter again", InputValidator::createNonEmptyValidator(), null); $this->getInput('DB1_PASS', "Database password (leave empty for no password)", null, null, null); $this->getInput('XYMON_URL', "The URL to your xymon/hobbit monitoring location. Xymon is an optional installation. Leave empty to set manually later\nExamples:\nhttp://www.xymondomain.com/xymon/\nhttp://www.xymondomain.com/hobbit/", null, null, null); $this->saveInput(); }
public static function findBinary($file_name) { if (!is_array($file_name)) { $file_name = array($file_name); } foreach ($file_name as $file) { $which_path = OsUtils::executeReturnOutput("which {$file}"); if (isset($which_path[0]) && trim($which_path[0]) != '' && substr($which_path[0], 0, 1) == "/") { return $which_path[0]; } } return null; }
public function install($app, $db_params) { logMessage(L_USER, sprintf("Copying application files to %s", $app->get('BASE_DIR'))); if (!OsUtils::fullCopy('package/app/', $app->get('BASE_DIR'))) { return "Failed to copy application files to target directory"; } $os_name = OsUtils::getOsName(); $architecture = OsUtils::getSystemArchitecture(); logMessage(L_USER, "Copying binaries for {$os_name} {$architecture}"); if (!OsUtils::fullCopy("package/bin/{$os_name}/{$architecture}", $app->get('BIN_DIR'))) { return "Failed to copy binaris for {$os_name} {$architecture}"; } logMessage(L_USER, "Replacing configuration tokens in files"); foreach ($this->install_config['token_files'] as $file) { $replace_file = $app->replaceTokensInString($file); if (!$app->replaceTokensInFile($replace_file)) { return "Failed to replace tokens in {$replace_file}"; } } logMessage(L_USER, "Changing permissions of directories and files"); foreach ($this->install_config['chmod_items'] as $item) { $chmod_item = $app->replaceTokensInString($item); if (!OsUtils::chmod($chmod_item)) { return "Failed to change permissions for {$chmod_item}"; } } $sql_files = parse_ini_file($app->get('BASE_DIR') . APP_SQL_DIR . 'create_kaltura_db.ini', true); logMessage(L_USER, sprintf("Creating and initializing '%s' database", $app->get('DB1_NAME'))); if (!DatabaseUtils::createDb($db_params, $app->get('DB1_NAME'))) { return "Failed to create '" . $app->get('DB1_NAME') . "' database"; } foreach ($sql_files['kaltura']['sql'] as $sql) { $sql_file = $app->get('BASE_DIR') . APP_SQL_DIR . $sql; if (!DatabaseUtils::runScript($sql_file, $db_params, $app->get('DB1_NAME'))) { return "Failed running database script {$sql_file}"; } } logMessage(L_USER, sprintf("Creating and initializing '%s' database", $app->get('DB_STATS_NAME'))); if (!DatabaseUtils::createDb($db_params, $app->get('DB_STATS_NAME'))) { return "Failed to create '" . $app->get('DB_STATS_NAME') . "' database"; } foreach ($sql_files['stats']['sql'] as $sql) { $sql_file = $app->get('BASE_DIR') . APP_SQL_DIR . $sql; if (!DatabaseUtils::runScript($sql_file, $db_params, $app->get('DB_STATS_NAME'))) { return "Failed running database script {$sql_file}"; } } logMessage(L_USER, "Creating data warehouse"); if (!OsUtils::execute(sprintf("%s/ddl/dwh_ddl_install.sh -h %s -P %s -u %s -p %s -d %s ", $app->get('DWH_DIR'), $app->get('DB1_HOST'), $app->get('DB1_PORT'), $app->get('DWH_USER'), $app->get('DWH_PASS'), $app->get('DWH_DIR')))) { return "Failed running data warehouse initialization script"; } logMessage(L_USER, "Creating Dynamic Enums"); if (OsUtils::execute(sprintf("%s %s/deployment/base/scripts/installPlugins.php", $app->get('PHP_BIN'), $app->get('APP_DIR')))) { logMessage(L_INFO, "Dynamic Enums created"); } else { return "Failed to create dynamic enums"; } logMessage(L_USER, "Configure sphinx"); if (OsUtils::execute(sprintf("%s %s/deployment/base/scripts/configureSphinx.php", $app->get('PHP_BIN'), $app->get('APP_DIR')))) { logMessage(L_INFO, "sphinx configuration file (kaltura.conf) created"); } else { return "Failed to create sphinx configuration file (kaltura.conf)"; } logMessage(L_USER, "Running the sphinx search deamon"); !OsUtils::executeInBackground($app->get('APP_DIR') . '/plugins/sphinx_search/scripts/watch.daemon.sh -u root'); logMessage(L_USER, "Creating system symbolic links"); foreach ($this->install_config['symlinks'] as $slink) { $link_items = explode(SYMLINK_SEPARATOR, $app->replaceTokensInString($slink)); if (symlink($link_items[0], $link_items[1])) { logMessage(L_INFO, "Created symbolic link {$link_items['0']} -> {$link_items['1']}"); } else { return sprintf("Failed to create symblic link from %s to %s", $link_items[0], $link_items[1]); } } if (strcasecmp($app->get('KALTURA_VERSION_TYPE'), K_CE_TYPE) == 0) { $app->simMafteach(); } logMessage(L_USER, "Deploying uiconfs in order to configure the application"); foreach ($this->install_config['uiconfs'] as $uiconfapp) { $to_deploy = $app->replaceTokensInString($uiconfapp); if (OsUtils::execute(sprintf("%s %s/deployment/uiconf/deploy.php --disableUrlHashing=true --ini=%s", $app->get('PHP_BIN'), $app->get('APP_DIR'), $to_deploy))) { logMessage(L_INFO, "Deployed uiconf {$to_deploy}"); } else { return "Failed to deploy uiconf {$to_deploy}"; } } logMessage(L_USER, "Deploying uiconfs in order to configure the application"); foreach ($this->install_config['uiconfs_2'] as $uiconfapp) { $to_deploy = $app->replaceTokensInString($uiconfapp); if (OsUtils::execute(sprintf("%s %s/deployment/uiconf/deploy_v2.php --ini=%s", $app->get('PHP_BIN'), $app->get('APP_DIR'), $to_deploy))) { logMessage(L_INFO, "Deployed uiconf {$to_deploy}"); } else { return "Failed to deploy uiconf {$to_deploy}"; } } logMessage(L_USER, "Creating the uninstaller"); if (!OsUtils::fullCopy('installer/uninstall.php', $app->get('BASE_DIR') . "/uninstaller/")) { return "Failed to create the uninstaller"; } $app->saveUninstallerConfig($this->install_config['symlinks']); logMessage(L_USER, "Running the batch manager"); if (!OsUtils::execute($app->get('APP_DIR') . '/scripts/serviceBatchMgr.sh start')) { return "Failed running the btach manager"; } return null; }
private function copyTemplateFileIfNeeded($file) { $return_file = $file; // Replacement in a template file, first copy to a non .template file if (strpos($file, TEMPLATE_FILE) !== false) { $return_file = str_replace(TEMPLATE_FILE, "", $file); logMessage(L_INFO, "{$file} token file contains " . TEMPLATE_FILE); OsUtils::fullCopy($file, $return_file); } return $return_file; }
public function getApplicationInput() { $httpd_bin_found = OsUtils::findBinary(array('apachectl', 'apache2ctl')); if (!empty($httpd_bin_found)) { $httpd_bin_message = "The following apachectl script has been detected: {$httpd_bin_found}. Do you want to use this script to run your Kaltura application? Leave empty to use or provide a pathname to an alternative apachectl script on your server."; $httpd_error_message = "Invalid pathname for apachectl script, leave empty to use {$httpd_bin_found} or enter an alternative apachectl path"; } else { $httpd_bin_message = "Installation could not automatically detect any apachectl script. Please provide a pathname to the apachectl script on your server."; $httpd_error_message = "Invalid pathname for apachectl script, please enter the apachectl pathname again"; } $php_bin_found = OsUtils::findBinary('php'); if (!empty($php_bin_found)) { $php_bin_message = "The following PHP binary has been detected: {$php_bin_found}. Do you want to use this script to run your Kaltura application? Leave empty to use or provide a pathname to an alternative PHP binary on your server."; $php_error_message = "Invalid pathname for PHP binary, leave empty to use {$php_bin_found} or enter an alternative PHP path"; } else { $php_bin_message = "Installation could not automatically detect any PHP binary. Please provide a pathname to the PHP binary on your server."; $php_error_message = "Invalid pathname for PHP binary, please enter the PHP pathname again"; } logMessage(L_USER, "Please provide the following information:"); echo PHP_EOL; $this->set('HTTPD_BIN', $httpd_bin_found); $this->set('PHP_BIN', $php_bin_found); $this->getInput('TIME_ZONE', "Default time zone for Kaltura application (leave empty to use system timezone: " . date_default_timezone_get() . " )", "Timezone must be a valid timezone, please enter again", InputValidator::createTimezoneValidator(), date_default_timezone_get()); $this->getInput('BASE_DIR', "Full target directory path for Kaltura application (leave empty for /opt/kaltura)", "Target directory must be a valid directory path, please enter again", InputValidator::createDirectoryValidator(), '/opt/kaltura'); $this->getInput('KALTURA_FULL_VIRTUAL_HOST_NAME', "Please enter the domain name/virtual hostname that will be used for the Kaltura server (without http://)", 'Must be a valid hostname or ip, please enter again', InputValidator::createHostValidator(), null); $this->getInput('DB1_HOST', "Database host (leave empty for 'localhost')", "Must be a valid hostname or ip, please enter again (leave empty for 'localhost')", InputValidator::createHostValidator(), 'localhost'); $this->getInput('DB1_PORT', "Database port (leave empty for '3306')", "Must be a valid port (1-65535), please enter again (leave empty for '3306')", InputValidator::createRangeValidator(1, 65535), '3306'); $this->set('DB1_NAME', 'kaltura'); // currently we do not support getting the DB name from the user because of the DWH implementation $this->getInput('DB1_USER', "Database username (with create & write privileges)", "Database username cannot be empty, please enter again", InputValidator::createNonEmptyValidator(), null); $this->getInput('DB1_PASS', "Database password (leave empty for no password)", null, null, null); if ((strcasecmp($this->get('DB1_HOST'), 'localhost') === 0 || strcasecmp($this->get('DB1_HOST'), '127.0.0.1') === 0) && empty($this->user_input['DB1_PASS'])) { $this->getInput('DB1_SET_PASSWORD', "Empty password is not secure. Would you like to set password now? (Y/n)", "Input is not valid", InputValidator::createYesNoValidator(), "yes"); if (strcasecmp($this->get('DB1_SET_PASSWORD'), 'y') === 0 || strcasecmp($this->get('DB1_SET_PASSWORD'), 'yes') === 0) { $user = $this->get('DB1_USER'); $newPassword = ''; $continue = true; while ($continue) { $this->getInput('DB1_NEW_PASSWORD', "Enter new password", "Password cannot be empty, please enter again", InputValidator::createNonEmptyValidator(), null); $this->getInput('DB1_NEW_PASSWORD_CONFIRM', "Confirm new password", "Password cannot be empty, please enter again", InputValidator::createNonEmptyValidator(), null); if ($this->get('DB1_NEW_PASSWORD') === $this->get('DB1_NEW_PASSWORD_CONFIRM')) { $newPassword = $this->get('DB1_NEW_PASSWORD'); $continue = false; } else { echo "The passwords that you entered do not match."; echo PHP_EOL; } $this->unsetInput('DB1_NEW_PASSWORD'); $this->unsetInput('DB1_NEW_PASSWORD_CONFIRM'); } shell_exec("sudo mysqladmin -u {$user} password '{$newPassword}'"); $this->set('DB1_PASS', $newPassword); } $this->unsetInput('DB1_SET_PASSWORD'); } $this->getInput('DB1_CREATE_NEW_DB', "Would you like to create a new kaltura database or use an existing one? (Y/n)", "Input is not valid", InputValidator::createYesNoValidator(), "yes"); $this->set('XYMON_URL', null); $this->getInput('RED5_INSTALL', "Would you like to install Red5 on this machine? Server needs it for web camera recording support. (Y/n)", "Please input yes/no.", InputValidator::createYesNoValidator(), "yes"); $this->getInput('SPHINX_DB_HOST', "Sphinx host (leave empty if Sphinx is running on this machine).", null, InputValidator::createHostValidator(), '127.0.0.1'); $this->getInput('WORK_MODE', "Work mode - enter http/https (http)", "Input is not valid", InputValidator::createWorkModeValidator(), 'http'); $this->getInput('ADMIN_CONSOLE_ADMIN_MAIL', "Your primary system administrator email address", "Email must be in a valid email format, please enter again", InputValidator::createEmailValidator(false), null); $this->getInput('ADMIN_CONSOLE_PASSWORD', "The password you want to set for your primary administrator", "Password should not be empty and should not contain whitespaces, please enter again", InputValidator::createNoWhitespaceValidator(), null); $this->saveInput(); }
private function installRed5($app) { if (!$app->get('RED5_INSTALL')) { return; } OsUtils::execute("dos2unix " . $app->get('BIN_DIR') . "/red5/red5"); OsUtils::execute("ln -s " . $app->get('BIN_DIR') . "/red5/red5 /etc/init.d/red5"); OsUtils::execute("/etc/init.d/red5 start"); OsUtils::executeInBackground('chkconfig red5 on'); //Replace rtmp_url parameter in the local.ini configuration file $location = $app->get('APP_DIR') . "/configurations/local.ini"; $localValues = parse_ini_file($location, true); $localValues['rtmp_url'] = 'rtmp://' . $app->get('BASE_HOST_NO_PORT') . '/oflaDemo'; OsUtils::writeToIniFile($location, $localValues); //url-managers.ini change $location = $app->get('APP_DIR') . "/configurations/url_managers.ini"; $urlManagersValues = parse_ini_file($location); $red5Addition = array('class' => 'kLocalPathUrlManager'); $urlManagersValues[$app->get('BASE_HOST_NO_PORT')] = $red5Addition; OsUtils::writeToIniFile($location, $urlManagersValues); OsUtils::execute("mv " . $app->get('BIN_DIR') . "/red5/webapps/oflaDemo/streams " . $app->get('BIN_DIR') . "/red5/webapps/oflaDemo/streams_x"); OsUtils::execute("ln -s " . $app->get('WEB_DIR') . "/content/webcam " . $app->get('BIN_DIR') . "/red5/webapps/oflaDemo/streams"); OsUtils::execute("ln -s " . $app->get('WEB_DIR') . "/content " . $app->get('BIN_DIR') . "/red5/webapps/oflaDemo/streams"); }
public function installRed5($app) { OsUtils::execute("dos2unix " . $app->get('BIN_DIR') . "/red5/red5"); OsUtils::execute("ln -s " . $app->get('BIN_DIR') . "/red5/red5 /etc/init.d/red5"); OsUtils::execute("/etc/init.d/red5 start"); OsUtils::executeInBackground('chkconfig red5 on'); //Replace rtmp_url parameter in the local.ini configuration file $location = $app->get('APP_DIR') . "/configurations/local.ini"; $localValues = parse_ini_file($location, true); $localValues['rtmp_url'] = 'rtmp://' . $app->get('KALTURA_VIRTUAL_HOST_NAME') . '/oflaDemo'; OsUtils::writeToIniFile($location, $localValues); //url-managers.ini change $location = $app->get('APP_DIR') . "/configurations/url_managers.ini"; $urlManagersValues = parse_ini_file($location); $red5Addition = array('class' => 'kLocalPathUrlManager'); $urlManagersValues[$app->get('ENVIRONMENT_NAME')] = $red5Addition; OsUtils::writeToIniFile($location, $urlManagersValues); //Retrieve KCW uiconf ids $uiconfIds = $this->extractKCWUiconfIds($app); logMessage(L_USER, "If you are insterested in recording entries from webcam, please adjust the RTMP server URL in each of the following uiConfs:\r\n" . implode("\r\n", $uiconfIds)); logMessage(L_USER, "By replacing 'rtmp://yoursite.com/oflaDemo' with 'rtmp://" . $app->get('ENVIRONMENT_NAME') . "/oflaDemo"); OsUtils::execute("mv " . $app->get('BIN_DIR') . "/red5/webapps/oflaDemo/streams " . $app->get('BIN_DIR') . "/red5/webapps/oflaDemo/streams_x"); OsUtils::execute("ln -s " . $app->get('WEB_DIR') . "/content/webcam " . $app->get('BIN_DIR') . "/red5/webapps/oflaDemo/streams"); OsUtils::execute("ln -s " . $app->get('WEB_DIR') . "/content " . $app->get('BIN_DIR') . "/red5/webapps/oflaDemo/streams"); }
logMessage(L_USER, 'restart cron'); if (!OsUtils::execute("/etc/init.d/crond restart")) { echo "Failed restart cron"; return "\nFailed cron\n"; } logMessage(L_USER, 'chmod'); if (!OsUtils::execute("chmod 700 /etc/cron.d")) { echo "Failed chmod"; return "\nFailed chmod\n"; } //logMessage(L_USER, 'chmod'); //if (!OsUtils::execute("chmod 700 /etc/rc.d/init.d")) { // echo "Failed chmod"; // return "\nFailed chmod\n"; //} $kalturaProcesses = implode(OsUtils::executeReturnOutput("ps -ef | grep kaltura")); logMessage(L_USER, 'ps -ef | grep kaltura: ' . $kalturaProcesses); $processFound = strstr($kalturaProcesses, 'searchd --config'); if (!$processFound) { echo 'ERROR: searchd is not running'; } $processFound = strstr($kalturaProcesses, 'KGenericBatchMgr.class.php'); if (!$processFound) { echo 'ERROR: batch is not running'; } $processFound = strstr($kalturaProcesses, 'watch.daemon.sh'); if (!$processFound) { echo 'ERROR: watch daemon is not running'; } $processFound = strstr($kalturaProcesses, 'populateFromLog.php'); if (!$processFound) {
public static function getCurrentDir() { if (OsUtils::getOsName() === self::LINUX_OS) { return exec('pwd'); } return dirname(__FILE__); }
} $app->set('REPORT_ADMIN_EMAIL', ""); $app->set('TRACK_KDPWRAPPER', 'false'); $app->set('USAGE_TRACKING_OPTIN', 'false'); // set to replace passwords on first activiation if this installation is preinstalled $app->set('REPLACE_PASSWORDS', $app->get('KALTURA_PREINSTALLED')); // allow ui conf tab only for CE installation if (strcasecmp($app->get('KALTURA_VERSION_TYPE'), K_TM_TYPE) !== 0) { $app->set('UICONF_TAB_ACCESS', 'SYSTEM_ADMIN_BATCH_CONTROL'); } // verify that the installation can continue //if (!OsUtils::verifyRootUser()) { // installationFailed("Installation cannot continue, you must have root privileges to continue with the installation process.", // null, null); //} if (!OsUtils::verifyOS()) { installationFailed("Installation cannot continue, Kaltura platform can only be installed on Linux OS at this time.", null, null); } if (!extension_loaded('mysqli')) { installationFailed("You must have PHP mysqli extension loaded to continue with the installation.", null, null); } // get the user input if needed if ($user->isInputLoaded()) { logMessage(L_USER, "Skipping user input, previous installation input will be used."); } else { $user->getApplicationInput(); } // get from kConf.php the latest versions of kmc , clipapp and HTML5 $kconf = file_get_contents("package/app/app/configurations/base.ini"); $latestVersions = array(); $latestVersions["KMC_VERSION"] = getVersionFromKconf($kconf, "kmc_version");