/**
  * Transmit to the ajxp_conf load_plugin_manifest action
  * @param $action
  * @param $httpVars
  * @param $fileVars
  */
 public function applyInstallerForm($action, $httpVars, $fileVars)
 {
     $data = array();
     AJXP_Utils::parseStandardFormParameters($httpVars, $data, null, "");
     // Create a custom bootstrap.json file
     $coreConf = array();
     $coreAuth = array();
     $this->_loadPluginConfig("core.conf", $coreConf);
     $this->_loadPluginConfig("core.auth", $coreAuth);
     if (!isset($coreConf["UNIQUE_INSTANCE_CONFIG"])) {
         $coreConf["UNIQUE_INSTANCE_CONFIG"] = array();
     }
     if (!isset($coreAuth["MASTER_INSTANCE_CONFIG"])) {
         $coreAuth["MASTER_INSTANCE_CONFIG"] = array();
     }
     $coreConf["AJXP_CLI_SECRET_KEY"] = AJXP_Utils::generateRandomString(24, true);
     $storageType = $data["STORAGE_TYPE"]["type"];
     if ($storageType == "db") {
         // REWRITE BOOTSTRAP.JSON
         $coreConf["DIBI_PRECONFIGURATION"] = $data["STORAGE_TYPE"]["db_type"];
         if (isset($coreConf["DIBI_PRECONFIGURATION"]["sqlite3_driver"])) {
             $dbFile = AJXP_VarsFilter::filter($coreConf["DIBI_PRECONFIGURATION"]["sqlite3_database"]);
             if (!file_exists(dirname($dbFile))) {
                 mkdir(dirname($dbFile), 0755, true);
             }
         }
         $coreConf["UNIQUE_INSTANCE_CONFIG"] = array_merge($coreConf["UNIQUE_INSTANCE_CONFIG"], array("instance_name" => "conf.sql", "group_switch_value" => "conf.sql", "SQL_DRIVER" => array("core_driver" => "core", "group_switch_value" => "core")));
         $coreAuth["MASTER_INSTANCE_CONFIG"] = array_merge($coreAuth["MASTER_INSTANCE_CONFIG"], array("instance_name" => "auth.sql", "group_switch_value" => "auth.sql", "SQL_DRIVER" => array("core_driver" => "core", "group_switch_value" => "core")));
         // INSTALL ALL SQL TABLES
         $sqlPlugs = array("conf.sql", "auth.sql", "feed.sql", "log.sql", "meta.syncable");
         foreach ($sqlPlugs as $plugId) {
             $plug = AJXP_PluginsService::findPluginById($plugId);
             $plug->installSQLTables(array("SQL_DRIVER" => $data["STORAGE_TYPE"]["db_type"]));
         }
     } else {
         $coreConf["UNIQUE_INSTANCE_CONFIG"] = array_merge($coreConf["UNIQUE_INSTANCE_CONFIG"], array("instance_name" => "conf.serial", "group_switch_value" => "conf.serial"));
         $coreAuth["MASTER_INSTANCE_CONFIG"] = array_merge($coreAuth["MASTER_INSTANCE_CONFIG"], array("instance_name" => "auth.serial", "group_switch_value" => "auth.serial"));
     }
     $oldBoot = $this->getPluginWorkDir(true) . "/bootstrap.json";
     if (is_file($oldBoot)) {
         copy($oldBoot, $oldBoot . ".bak");
         unlink($oldBoot);
     }
     $newBootstrap = array("core.conf" => $coreConf, "core.auth" => $coreAuth);
     AJXP_Utils::saveSerialFile($oldBoot, $newBootstrap, true, false, "json", true);
     // Write new bootstrap and reload conf plugin!
     if ($storageType == "db") {
         $coreConf["UNIQUE_INSTANCE_CONFIG"]["SQL_DRIVER"] = $coreConf["DIBI_PRECONFIGURATION"];
         $coreAuth["MASTER_INSTANCE_CONFIG"]["SQL_DRIVER"] = $coreConf["DIBI_PRECONFIGURATION"];
     }
     $newConfigPlugin = ConfService::instanciatePluginFromGlobalParams($coreConf["UNIQUE_INSTANCE_CONFIG"], "AbstractConfDriver");
     $newAuthPlugin = ConfService::instanciatePluginFromGlobalParams($coreAuth["MASTER_INSTANCE_CONFIG"], "AbstractAuthDriver");
     if ($data["ENCODING"] != (defined('AJXP_LOCALE') ? AJXP_LOCALE : SystemTextEncoding::getEncoding())) {
         file_put_contents($this->getPluginWorkDir() . "/encoding.php", "<?php \$ROOT_ENCODING='" . $data["ENCODING"] . "';");
     }
     $tpl = file_get_contents($this->getBaseDir() . "/htaccess.tpl");
     if (!empty($data["SERVER_URI"]) && $data["SERVER_URI"] != "/") {
         $htContent = str_replace('${APPLICATION_ROOT}', $data["SERVER_URI"], $tpl);
     } else {
         $htContent = str_replace('${APPLICATION_ROOT}/', "/", $tpl);
         $htContent = str_replace('${APPLICATION_ROOT}', "/", $htContent);
     }
     if (is_writeable(AJXP_INSTALL_PATH . "/.htaccess")) {
         file_put_contents(AJXP_INSTALL_PATH . "/.htaccess", $htContent);
     } else {
         $htAccessToUpdate = AJXP_INSTALL_PATH . "/.htaccess";
     }
     if ($storageType == "db") {
         $sqlPlugs = array("core.notifications/UNIQUE_FEED_INSTANCE" => "feed.sql", "core.log/UNIQUE_PLUGIN_INSTANCE" => "log.sql", "core.mq/UNIQUE_MS_INSTANCE" => "mq.sql");
         $data["ENABLE_NOTIF"] = $data["STORAGE_TYPE"]["notifications"];
     }
     // Prepare plugins configs
     $direct = array("APPLICATION_TITLE" => "core.ajaxplorer/APPLICATION_TITLE", "APPLICATION_LANGUAGE" => "core.ajaxplorer/DEFAULT_LANGUAGE", "ENABLE_NOTIF" => "core.notifications/USER_EVENTS", "APPLICATION_WELCOME" => "gui.ajax/CUSTOM_WELCOME_MESSAGE");
     $mailerEnabled = $data["MAILER_ENABLE"]["status"];
     if ($mailerEnabled == "yes") {
         // Enable core.mailer
         $data["MAILER_SYSTEM"] = $data["MAILER_ENABLE"]["MAILER_SYSTEM"];
         $data["MAILER_ADMIN"] = $data["MAILER_ENABLE"]["MAILER_ADMIN"];
         $direct = array_merge($direct, array("MAILER_SYSTEM" => "mailer.phpmailer-lite/MAILER", "MAILER_ADMIN" => "core.mailer/FROM"));
     }
     foreach ($direct as $key => $value) {
         list($pluginId, $param) = explode("/", $value);
         $options = array();
         $newConfigPlugin->_loadPluginConfig($pluginId, $options);
         $options[$param] = $data[$key];
         $newConfigPlugin->_savePluginConfig($pluginId, $options);
     }
     if (isset($sqlPlugs)) {
         foreach ($sqlPlugs as $core => $value) {
             list($pluginId, $param) = explode("/", $core);
             $options = array();
             $newConfigPlugin->_loadPluginConfig($pluginId, $options);
             $options[$param] = array("instance_name" => $value, "group_switch_value" => $value, "SQL_DRIVER" => array("core_driver" => "core", "group_switch_value" => "core"));
             $newConfigPlugin->_savePluginConfig($pluginId, $options);
         }
     }
     ConfService::setTmpStorageImplementations($newConfigPlugin, $newAuthPlugin);
     require_once $newConfigPlugin->getUserClassFileName();
     $adminLogin = AJXP_Utils::sanitize($data["ADMIN_USER_LOGIN"], AJXP_SANITIZE_EMAILCHARS);
     $adminName = $data["ADMIN_USER_NAME"];
     $adminPass = $data["ADMIN_USER_PASS"];
     $adminPass2 = $data["ADMIN_USER_PASS2"];
     AuthService::createUser($adminLogin, $adminPass, true);
     $uObj = $newConfigPlugin->createUserObject($adminLogin);
     if (isset($data["MAILER_ADMIN"])) {
         $uObj->personalRole->setParameterValue("core.conf", "email", $data["MAILER_ADMIN"]);
     }
     $uObj->personalRole->setParameterValue("core.conf", "USER_DISPLAY_NAME", $adminName);
     $uObj->personalRole->setAcl('ajxp_conf', 'rw');
     AuthService::updateRole($uObj->personalRole);
     $loginP = "USER_LOGIN";
     $i = 0;
     while (isset($data[$loginP]) && !empty($data[$loginP])) {
         $pass = $data[str_replace("_LOGIN", "_PASS", $loginP)];
         $pass2 = $data[str_replace("_LOGIN", "_PASS2", $loginP)];
         $name = $data[str_replace("_LOGIN", "_NAME", $loginP)];
         $mail = $data[str_replace("_LOGIN", "_MAIL", $loginP)];
         $saniLogin = AJXP_Utils::sanitize($data[$loginP], AJXP_SANITIZE_EMAILCHARS);
         AuthService::createUser($saniLogin, $pass);
         $uObj = $newConfigPlugin->createUserObject($saniLogin);
         $uObj->personalRole->setParameterValue("core.conf", "email", $mail);
         $uObj->personalRole->setParameterValue("core.conf", "USER_DISPLAY_NAME", $name);
         AuthService::updateRole($uObj->personalRole);
         $i++;
         $loginP = "USER_LOGIN_" . $i;
     }
     AJXP_PluginsService::clearPluginsCache();
     AJXP_Utils::setApplicationFirstRunPassed();
     if (isset($htAccessToUpdate)) {
         HTMLWriter::charsetHeader("application/json");
         echo json_encode(array('file' => $htAccessToUpdate, 'content' => $htContent));
     } else {
         session_destroy();
         HTMLWriter::charsetHeader("text/plain");
         echo 'OK';
     }
 }
 /**
  * Send output to the user.
  * @param String $htAccessToUpdate file path
  * @param String $htContent file content
  */
 public function sendInstallResult($htAccessToUpdate, $htContent)
 {
     ConfService::clearAllCaches();
     AJXP_Utils::setApplicationFirstRunPassed();
     if ($htAccessToUpdate != null) {
         HTMLWriter::charsetHeader("application/json");
         echo json_encode(array('file' => $htAccessToUpdate, 'content' => $htContent));
     } else {
         session_destroy();
         HTMLWriter::charsetHeader("text/plain");
         echo 'OK';
     }
 }
Beispiel #3
0
 /**
  * Transmit to the ajxp_conf load_plugin_manifest action
  * @param $action
  * @param $httpVars
  * @param $fileVars
  */
 public function applyInstallerForm($action, $httpVars, $fileVars)
 {
     $data = array();
     AJXP_Utils::parseStandardFormParameters($httpVars, $data, null, "");
     // Create a custom bootstrap.json file
     $coreConf = array();
     $coreAuth = array();
     $this->_loadPluginConfig("core.conf", $coreConf);
     $this->_loadPluginConfig("core.auth", $coreAuth);
     if (!isset($coreConf["UNIQUE_INSTANCE_CONFIG"])) {
         $coreConf["UNIQUE_INSTANCE_CONFIG"] = array();
     }
     if (!isset($coreAuth["MASTER_INSTANCE_CONFIG"])) {
         $coreAuth["MASTER_INSTANCE_CONFIG"] = array();
     }
     $storageType = $data["STORAGE_TYPE"]["type"];
     $coreConfLIVECONFIG = array();
     if ($storageType == "db") {
         // REWRITE BOOTSTRAP.JSON
         $coreConf["DIBI_PRECONFIGURATION"] = $data["STORAGE_TYPE"]["db_type"];
         if (isset($coreConf["DIBI_PRECONFIGURATION"]["sqlite3_driver"])) {
             $dbFile = AJXP_VarsFilter::filter($coreConf["DIBI_PRECONFIGURATION"]["sqlite3_database"]);
             if (!file_exists(dirname($dbFile))) {
                 mkdir(dirname($dbFile), 0755, true);
             }
         }
         $coreConf["UNIQUE_INSTANCE_CONFIG"] = array_merge($coreConf["UNIQUE_INSTANCE_CONFIG"], array("instance_name" => "conf.sql", "group_switch_value" => "conf.sql", "SQL_DRIVER" => array("core_driver" => "core", "group_switch_value" => "core")));
         $coreAuth["MASTER_INSTANCE_CONFIG"] = array_merge($coreAuth["MASTER_INSTANCE_CONFIG"], array("instance_name" => "auth.sql", "group_switch_value" => "auth.sql", "SQL_DRIVER" => array("core_driver" => "core", "group_switch_value" => "core")));
         // INSTALL ALL SQL TABLES
         $sqlPlugs = array("conf.sql", "auth.sql", "feed.sql", "log.sql", "mq.sql");
         foreach ($sqlPlugs as $plugId) {
             $plug = AJXP_PluginsService::findPluginById($plugId);
             $plug->installSQLTables(array("SQL_DRIVER" => $data["STORAGE_TYPE"]["db_type"]));
         }
     } else {
         $coreConf["UNIQUE_INSTANCE_CONFIG"] = array_merge($coreConf["UNIQUE_INSTANCE_CONFIG"], array("instance_name" => "conf.serial", "group_switch_value" => "conf.serial"));
         $coreAuth["MASTER_INSTANCE_CONFIG"] = array_merge($coreAuth["MASTER_INSTANCE_CONFIG"], array("instance_name" => "auth.serial", "group_switch_value" => "auth.serial"));
     }
     $oldBoot = $this->getPluginWorkDir(true) . "/bootstrap.json";
     if (is_file($oldBoot)) {
         copy($oldBoot, $oldBoot . ".bak");
         unlink($oldBoot);
     }
     $newBootstrap = array("core.conf" => $coreConf, "core.auth" => $coreAuth);
     AJXP_Utils::saveSerialFile($oldBoot, $newBootstrap, true, false, "json", true);
     // Write new bootstrap and reload conf plugin!
     if ($storageType == "db") {
         $coreConf["UNIQUE_INSTANCE_CONFIG"]["SQL_DRIVER"] = $coreConf["DIBI_PRECONFIGURATION"];
         $coreAuth["MASTER_INSTANCE_CONFIG"]["SQL_DRIVER"] = $coreConf["DIBI_PRECONFIGURATION"];
     }
     $newConfigPlugin = ConfService::instanciatePluginFromGlobalParams($coreConf["UNIQUE_INSTANCE_CONFIG"], "AbstractConfDriver");
     $newAuthPlugin = ConfService::instanciatePluginFromGlobalParams($coreAuth["MASTER_INSTANCE_CONFIG"], "AbstractAuthDriver");
     if ($storageType == "db") {
         $sqlPlugs = array("core.notifications/UNIQUE_FEED_INSTANCE" => "feed.sql", "core.log/UNIQUE_PLUGIN_INSTANCE" => "log.sql", "core.mq/UNIQUE_MS_INSTANCE" => "mq.sql");
         $data["ENABLE_NOTIF"] = $data["STORAGE_TYPE"]["notifications"];
     }
     // Prepare plugins configs
     $direct = array("APPLICATION_TITLE" => "core.ajaxplorer/APPLICATION_TITLE", "APPLICATION_LANGUAGE" => "core.ajaxplorer/DEFAULT_LANGUAGE", "ENABLE_NOTIF" => "core.notifications/USER_EVENTS", "APPLICATION_WELCOME" => "gui.ajax/CUSTOM_WELCOME_MESSAGE");
     $mailerEnabled = $data["MAILER_ENABLE"]["status"];
     if ($mailerEnabled == "yes") {
         // Enable core.mailer
         $data["MAILER_SYSTEM"] = $data["MAILER_ENABLE"]["MAILER_SYSTEM"];
         $data["MAILER_ADMIN"] = $data["MAILER_ENABLE"]["MAILER_ADMIN"];
         $direct = array_merge($direct, array("MAILER_SYSTEM" => "mailer.phpmailer-lite/MAILER", "MAILER_ADMIN" => "core.mailer/FROM"));
     }
     foreach ($direct as $key => $value) {
         list($pluginId, $param) = explode("/", $value);
         $options = array();
         $newConfigPlugin->_loadPluginConfig($pluginId, $options);
         $options[$param] = $data[$key];
         $newConfigPlugin->_savePluginConfig($pluginId, $options);
     }
     if (isset($sqlPlugs)) {
         foreach ($sqlPlugs as $core => $value) {
             list($pluginId, $param) = explode("/", $core);
             $options = array();
             $newConfigPlugin->_loadPluginConfig($pluginId, $options);
             $options[$param] = array("instance_name" => $value, "group_switch_value" => $value, "SQL_DRIVER" => array("core_driver" => "core", "group_switch_value" => "core"));
             $newConfigPlugin->_savePluginConfig($pluginId, $options);
         }
     }
     ConfService::setTmpStorageImplementations($newConfigPlugin, $newAuthPlugin);
     require_once $newConfigPlugin->getUserClassFileName();
     $adminLogin = AJXP_Utils::sanitize($data["ADMIN_USER_LOGIN"], AJXP_SANITIZE_EMAILCHARS);
     $adminName = $data["ADMIN_USER_NAME"];
     $adminPass = $data["ADMIN_USER_PASS"];
     $adminPass2 = $data["ADMIN_USER_PASS2"];
     AuthService::createUser($adminLogin, $adminPass, true);
     $uObj = $newConfigPlugin->createUserObject($adminLogin);
     if (isset($data["MAILER_ADMIN"])) {
         $uObj->personalRole->setParameterValue("core.conf", "email", $data["MAILER_ADMIN"]);
     }
     $uObj->personalRole->setParameterValue("core.conf", "USER_DISPLAY_NAME", $adminName);
     AuthService::updateRole($uObj->personalRole);
     $loginP = "USER_LOGIN";
     $i = 0;
     while (isset($data[$loginP]) && !empty($data[$loginP])) {
         $pass = $data[str_replace("_LOGIN", "_PASS", $loginP)];
         $pass2 = $data[str_replace("_LOGIN", "_PASS2", $loginP)];
         $name = $data[str_replace("_LOGIN", "_NAME", $loginP)];
         $mail = $data[str_replace("_LOGIN", "_MAIL", $loginP)];
         $saniLogin = AJXP_Utils::sanitize($data[$loginP], AJXP_SANITIZE_EMAILCHARS);
         AuthService::createUser($saniLogin, $pass);
         $uObj = $newConfigPlugin->createUserObject($saniLogin);
         $uObj->personalRole->setParameterValue("core.conf", "email", $mail);
         $uObj->personalRole->setParameterValue("core.conf", "USER_DISPLAY_NAME", $name);
         AuthService::updateRole($uObj->personalRole);
         $i++;
         $loginP = "USER_LOGIN_" . $i;
     }
     @unlink(AJXP_PLUGINS_CACHE_FILE);
     @unlink(AJXP_PLUGINS_REQUIRES_FILE);
     @unlink(AJXP_PLUGINS_MESSAGES_FILE);
     AJXP_Utils::setApplicationFirstRunPassed();
     session_destroy();
     echo 'OK';
 }