public static function saveBootstrapConf($jsonData)
 {
     $jsonPath = self::_getBootstrapFilePath();
     if (file_exists($jsonPath)) {
         copy($jsonPath, $jsonPath . ".bak");
     }
     AJXP_Utils::saveSerialFile($jsonPath, $jsonData, true, false, "json", true);
 }
 public function __destruct()
 {
     if (isset($this->channels) && is_array($this->channels)) {
         foreach ($this->channels as $channelName => $data) {
             if (is_array($data)) {
                 AJXP_Utils::saveSerialFile($this->getPluginWorkDir() . "/queues/channel-{$channelName}", $data);
             }
         }
     }
 }
 function deleteUser($login)
 {
     $users = $this->listUsers();
     if (is_array($users) && array_key_exists($login, $users)) {
         unset($users[$login]);
         AJXP_Utils::saveSerialFile($this->usersSerFile, $users);
     }
 }
 public function handleTasks($action, $httpVars, $fileVars)
 {
     $tasks = AJXP_Utils::loadSerialFile($this->getDbFile(), false, "json");
     switch ($action) {
         case "scheduler_addTask":
             if (isset($httpVars["task_id"])) {
                 foreach ($tasks as $index => $task) {
                     if ($task["task_id"] == $httpVars["task_id"]) {
                         $data = $task;
                         $theIndex = $index;
                     }
                 }
             }
             if (!isset($theIndex)) {
                 $data = array();
                 $data["task_id"] = substr(md5(time()), 0, 16);
             }
             $data["label"] = $httpVars["label"];
             $data["schedule"] = $httpVars["schedule"];
             $data["action_name"] = $httpVars["action_name"];
             $data["repository_id"] = $httpVars["repository_id"];
             $i = 1;
             while (array_key_exists("repository_id_" . $i, $httpVars)) {
                 $data["repository_id"] .= "," . $httpVars["repository_id_" . $i];
                 $i++;
             }
             $data["user_id"] = $httpVars["user_id"];
             $data["PARAMS"] = array();
             if (!empty($httpVars["param_name"]) && !empty($httpVars["param_value"])) {
                 $data["PARAMS"][$httpVars["param_name"]] = $httpVars["param_value"];
             }
             foreach ($httpVars as $key => $value) {
                 if (preg_match('/^param_name_/', $key)) {
                     $paramIndex = str_replace("param_name_", "", $key);
                     if (preg_match('/ajxptype/', $paramIndex)) {
                         continue;
                     }
                     if (preg_match('/replication/', $paramIndex)) {
                         continue;
                     }
                     if (isset($httpVars["param_value_" . $paramIndex])) {
                         $data["PARAMS"][$value] = $httpVars["param_value_" . $paramIndex];
                     }
                 }
             }
             if (isset($theIndex)) {
                 $tasks[$theIndex] = $data;
             } else {
                 $tasks[] = $data;
             }
             AJXP_Utils::saveSerialFile($this->getDbFile(), $tasks, true, false, "json");
             AJXP_XMLWriter::header();
             AJXP_XMLWriter::sendMessage("Successfully added/edited task", null);
             AJXP_XMLWriter::reloadDataNode();
             AJXP_XMLWriter::close();
             break;
         case "scheduler_removeTask":
             $this->removeTask($httpVars["task_id"]);
             AJXP_XMLWriter::header();
             AJXP_XMLWriter::sendMessage("Successfully removed task", null);
             AJXP_XMLWriter::reloadDataNode();
             AJXP_XMLWriter::close();
             break;
         case "scheduler_loadTask":
             $found = false;
             foreach ($tasks as $task) {
                 if ($task["task_id"] == $httpVars["task_id"]) {
                     $index = 0;
                     $found = true;
                     foreach ($task["PARAMS"] as $pName => $pValue) {
                         if ($index == 0) {
                             $task["param_name"] = $pName;
                             $task["param_value"] = $pValue;
                         } else {
                             $task["param_name_" . $index] = $pName;
                             $task["param_value_" . $index] = $pValue;
                         }
                         $index++;
                     }
                     unset($task["PARAMS"]);
                     if (strpos($task["repository_id"], ",") !== false) {
                         $ids = explode(",", $task["repository_id"]);
                         $task["repository_id"] = $ids[0];
                         for ($i = 1; $i < count($ids); $i++) {
                             $task["repository_id_" . $i] = $ids[$i];
                         }
                     }
                     break;
                 }
             }
             if ($found) {
                 HTMLWriter::charsetHeader("application/json");
                 echo json_encode($task);
             }
             break;
         default:
             break;
     }
     //var_dump($tasks);
 }
 /**
  * Create or update the bootstrap json file.
  * @param Array $data Parsed result of the installer form
  * @return array 2 entries array containing the new Conf Driver (0) and Auth Driver (1)
  * @throws Exception
  */
 public function createBootstrapConf($data)
 {
     // Create a custom bootstrap.json file
     $coreConf = array();
     $coreAuth = array();
     $coreCache = array();
     $this->_loadPluginConfig("core.conf", $coreConf);
     $this->_loadPluginConfig("core.auth", $coreAuth);
     $this->_loadPluginConfig("core.cache", $coreCache);
     if (!isset($coreConf["UNIQUE_INSTANCE_CONFIG"])) {
         $coreConf["UNIQUE_INSTANCE_CONFIG"] = array();
     }
     if (!isset($coreAuth["MASTER_INSTANCE_CONFIG"])) {
         $coreAuth["MASTER_INSTANCE_CONFIG"] = array();
     }
     if (!isset($coreCache["UNIQUE_INSTANCE_CONFIG"])) {
         $coreCache["UNIQUE_INSTANCE_CONFIG"] = array();
     }
     $coreConf["AJXP_CLI_SECRET_KEY"] = AJXP_Utils::generateRandomString(24, true);
     // REWRITE BOOTSTRAP.JSON
     $coreConf["DIBI_PRECONFIGURATION"] = $data["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")));
     $coreCache["UNIQUE_INSTANCE_CONFIG"] = array_merge($coreCache["UNIQUE_INSTANCE_CONFIG"], array());
     // DETECT REQUIRED SQL TABLES AND INSTALL THEM
     $registry = AJXP_PluginsService::getInstance()->getDetectedPlugins();
     $driverData = array("SQL_DRIVER" => $data["db_type"]);
     foreach ($registry as $type => $plugins) {
         foreach ($plugins as $plugObject) {
             if ($plugObject instanceof SqlTableProvider) {
                 $plugObject->installSQLTables($driverData);
             }
         }
     }
     $oldBoot = $this->getPluginWorkDir(true) . "/bootstrap.json";
     if (is_file($oldBoot)) {
         copy($oldBoot, $oldBoot . ".bak");
         unlink($oldBoot);
     }
     $newBootstrap = array("core.conf" => $coreConf, "core.auth" => $coreAuth, "core.cache" => $coreCache);
     AJXP_Utils::saveSerialFile($oldBoot, $newBootstrap, true, false, "json", true);
     // Write new bootstrap and reload conf plugin!
     $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");
     $newCachePlugin = ConfService::instanciatePluginFromGlobalParams($coreCache["UNIQUE_INSTANCE_CONFIG"], "AbstractCacheDriver");
     $sqlPlugs = array("core.notifications/UNIQUE_FEED_INSTANCE" => "feed.sql", "core.log/UNIQUE_PLUGIN_INSTANCE" => "log.sql", "core.mq/UNIQUE_MS_INSTANCE" => "mq.sql");
     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);
     }
     return array($newConfigPlugin, $newAuthPlugin, $newCachePlugin);
 }
 function saveTemporaryData($key, $value)
 {
     $fastCheck = $this->storage->getOption("FAST_CHECKS");
     $fastCheck = $fastCheck == "true" || $fastCheck == true;
     return AJXP_Utils::saveSerialFile($this->storage->getOption("USERS_DIRPATH") . "/" . $this->getId() . "/" . $key . ".ser", $value, !$fastCheck);
 }
 /**
  * Save Temporary Data.
  * Implementation uses serialised files because of the overhead incurred with a full db implementation.
  *
  * @param $key String key of data to save.
  * @param $value Value to save
  */
 public function saveTemporaryData($key, $value)
 {
     $dirPath = $this->storage->getOption("USERS_DIRPATH");
     if ($dirPath == "") {
         $dirPath = AJXP_INSTALL_PATH . "/data/users";
         AJXP_Logger::info(__CLASS__, "setTemporaryData", array("Warning" => "The conf.sql driver is missing a mandatory option USERS_DIRPATH!"));
     }
     $id = AuthService::ignoreUserCase() ? strtolower($this->getId()) : $this->getId();
     AJXP_Utils::saveSerialFile($dirPath . "/" . $id . "/temp-" . $key . ".ser", $value);
 }
 public function storeToPluginQueriesCache($key, $value)
 {
     if (AJXP_SKIP_CACHE) {
         return;
     }
     $test = AJXP_Utils::loadSerialFile(AJXP_PLUGINS_QUERIES_CACHE);
     if (!is_array($test)) {
         $test = array();
     }
     $test[$key] = $value;
     AJXP_Utils::saveSerialFile(AJXP_PLUGINS_QUERIES_CACHE, $test);
 }
 public function setTokens($oauth_tokens)
 {
     $repositoryId = $this->repository->getId();
     if (AuthService::usersEnabled()) {
         $userId = AuthService::getLoggedUser()->getId();
     } else {
         $userId = "shared";
     }
     return AJXP_Utils::saveSerialFile(AJXP_DATA_PATH . "/plugins/access.dropbox/" . $repositoryId . "_" . $userId . "_tokens", $oauth_tokens, true);
 }
 /**
  * Delete a repository, given its unique ID.
  *
  * @param String $repositoryId
  */
 function deleteRepository($repositoryId)
 {
     $repositories = AJXP_Utils::loadSerialFile($this->repoSerialFile);
     $newList = array();
     foreach ($repositories as $repo) {
         if ($repo->getUniqueId() != $repositoryId) {
             $newList[$repo->getUniqueId()] = $repo;
         }
     }
     AJXP_Utils::saveSerialFile($this->repoSerialFile, $newList);
 }
示例#11
0
 /**
  * Save Temporary Data.
  * Implementation uses serialised files because of the overhead incurred with a full db implementation.
  * 
  * @param $key String key of data to save.
  * @param $value Value to save
  * @return null (AJXP_Utils::saveSerialFile() returns nothing)
  */
 function saveTemporaryData($key, $value)
 {
     return AJXP_Utils::saveSerialFile(INSTALL_PATH . "/server/users/" . $this->getId() . "-temp-" . $key . ".ser", $value);
 }
示例#12
0
 function saveTemporaryData($key, $value)
 {
     return AJXP_Utils::saveSerialFile($this->storage->getOption("USERS_DIRPATH") . "/" . $this->getId() . "/" . $key . ".ser", $value);
 }
 private static function saveCounters($counters)
 {
     self::$counters = $counters;
     AJXP_Utils::saveSerialFile(PUBLIC_DOWNLOAD_FOLDER . "/.ajxp_publiclet_counters.ser", $counters, false);
 }
 function setTokens($repositoryId, $oauth_tokens)
 {
     return AJXP_Utils::saveSerialFile(AJXP_DATA_PATH . "/plugins/access.dropbox/" . $repositoryId . "_tokens", $oauth_tokens, true);
 }
 /**
  * Save the plugins order in a cache
  *
  * @param array $sortedPlugins
  * @return bool|void
  */
 private function cachePlugSort($sortedPlugins)
 {
     if (!AJXP_PLUGINS_CACHE_FILE) {
         return false;
     }
     $indexes = array();
     $i = 0;
     foreach ($sortedPlugins as $plugin) {
         $indexes[$i] = $plugin->getId();
         $i++;
     }
     AJXP_Utils::saveSerialFile(AJXP_PLUGINS_CACHE_FILE, $indexes, false, true);
 }
示例#16
0
 /**
  * @param String $pluginId
  * @param String $options
  */
 public function _savePluginConfig($pluginId, $options)
 {
     $jsonPath = $this->getPluginWorkDir(true) . "/bootstrap.json";
     $jsonData = AJXP_Utils::loadSerialFile($jsonPath, false, "json");
     if (!is_array($jsonData)) {
         $jsonData = array();
     }
     $jsonData[$pluginId] = $options;
     if ($pluginId == "core.conf" || $pluginId == "core.auth") {
         $testKey = $pluginId == "core.conf" ? "UNIQUE_INSTANCE_CONFIG" : "MASTER_INSTANCE_CONFIG";
         $current = array();
         $this->_loadPluginConfig($pluginId, $current);
         if (isset($current[$testKey]["instance_name"]) && $current[$testKey]["instance_name"] != $options[$testKey]["instance_name"]) {
             $forceDisconnexion = $pluginId;
         }
     }
     if (file_exists($jsonPath)) {
         copy($jsonPath, $jsonPath . ".bak");
     }
     AJXP_Utils::saveSerialFile($jsonPath, $jsonData, true, false, "json", true);
     if (isset($forceDisconnexion)) {
         if ($pluginId == "core.conf") {
             // DISCONNECT
             AuthService::disconnect();
         } else {
             if ($pluginId == "core.auth") {
                 // DELETE admin_counted file and DISCONNECT
                 @unlink(AJXP_CACHE_DIR . "/admin_counted");
             }
         }
     }
 }
 /**
  * Serial specific method : indexes repositories by slugs, for better performances
  */
 function updateAliasesIndex($repositoryId, $repositorySlug)
 {
     $data = AJXP_Utils::loadSerialFile($this->aliasesIndexFile);
     $byId = array_flip($data);
     $byId[$repositoryId] = $repositorySlug;
     AJXP_Utils::saveSerialFile($this->aliasesIndexFile, array_flip($byId));
 }
示例#18
0
 public function deleteUser($login)
 {
     if (AuthService::ignoreUserCase()) {
         $login = strtolower($login);
     }
     $users = $this->_listAllUsers();
     if (is_array($users) && array_key_exists($login, $users)) {
         unset($users[$login]);
         AJXP_Utils::saveSerialFile($this->usersSerFile, $users);
     }
 }
 public function saveTemporaryData($key, $value)
 {
     $fastCheck = $this->storage->getOption("FAST_CHECKS");
     $fastCheck = $fastCheck == "true" || $fastCheck == true;
     AJXP_Utils::saveSerialFile($this->getStoragePath() . "/" . $key . ".ser", $value, !$fastCheck);
 }
示例#20
0
 /**
  * @abstract
  * @param String $keyType
  * @param String $expiration
  * @return null
  */
 public function pruneTemporaryKeys($keyType, $expiration)
 {
     $storage = $this->getPluginWorkDir() . "/temporary_keys";
     $list = AJXP_Utils::loadSerialFile($storage, false, "ser");
     foreach ($list as $type => &$keys) {
         foreach ($keys as $key => $data) {
             if ($data["date"] < time() - $expiration * 60) {
                 unset($keys[$key]);
             }
         }
         if (count($keys) == 0) {
             unset($list[$type]);
         }
     }
     AJXP_Utils::saveSerialFile($storage, $list);
 }
 /**
  * Save Temporary Data.
  * Implementation uses serialised files because of the overhead incurred with a full db implementation.
  * 
  * @param $key String key of data to save.
  * @param $value Value to save
  * @return null (AJXP_Utils::saveSerialFile() returns nothing)
  */
 function saveTemporaryData($key, $value)
 {
     $dirPath = $this->storage->getOption("USERS_DIRPATH");
     if ($dirPath == "") {
         $dirPath = AJXP_INSTALL_PATH . "/data/users";
         AJXP_Logger::logAction("setTemporaryData", array("Warning" => "The conf.sql driver is missing a mandatory option USERS_DIRPATH!"));
     }
     return AJXP_Utils::saveSerialFile($dirPath . "/" . $this->getId() . "-temp-" . $key . ".ser", $value);
 }