/** * Initialise the driver. * * Expects options containing a key 'SQL_DRIVER' with constructor values from dibi::connect() * * Example: * "SQL_DRIVER" => Array( * 'driver' => 'sqlite', * 'file' => "./server/ajxp.db" * ) * * Example 2: * "SQL_DRIVER" => Array( * 'driver' => 'mysql', * 'host' => 'localhost', * 'username' => 'root', * 'password' => '***', * 'database' => 'dbname' * ) * * @see AbstractConfDriver#init($options) */ public function init($options) { parent::init($options); $this->sqlDriver = AJXP_Utils::cleanDibiDriverParameters($options["SQL_DRIVER"]); try { if (!dibi::isConnected()) { dibi::connect($this->sqlDriver); } if (AJXP_SERVER_DEBUG && AJXP_VERSION_DB != "##DB_VERSION##") { $res = dibi::query("select MAX(db_build) from [ajxp_version]"); if (!empty($res)) { $dbVersion = intval($res->fetchSingle()); $current = intval(AJXP_VERSION_DB); if ($dbVersion > 0 && $dbVersion < $current) { // We need to upgrade now! error_log("[Pydio] DB Upgrade Required! You may encounter strange issues. Make sure to manually apply the DB update."); $this->logError("[DB]", "DB Upgrade Required! You may encounter strange issues. Make sure to manually apply the DB update."); } } } } catch (DibiException $e) { //throw $e; echo get_class($e), ': ', $e->getMessage(), "\n"; exit(1); } }
public function init($options) { parent::init($options); $this->sqlDriver = AJXP_Utils::cleanDibiDriverParameters($options["SQL_DRIVER"]); try { if (!dibi::isConnected()) { dibi::connect($this->sqlDriver); } } catch (DibiException $e) { echo get_class($e), ': ', $e->getMessage(), "\n"; exit(1); } }
/** * Initialize the driver. * * Gives the driver a chance to set up it's connection / file resource etc.. * * @param Array $options array of options specific to the logger driver. * @access public */ public function init($options) { parent::init($options); $this->sqlDriver = AJXP_Utils::cleanDibiDriverParameters($options["SQL_DRIVER"]); try { if (!dibi::isConnected()) { dibi::connect($this->sqlDriver); } } catch (DibiException $e) { echo get_class($e), ': ', $e->getMessage(), "\n"; exit(1); } $this->queries = AJXP_Utils::loadSerialFile($this->getBaseDir() . "/queries.json", false, "json"); }
/** * @param array $connectionParams */ public static function init(array $connectionParams) { if (!dibi::isConnected()) { try { $connection = dibi::connect(array('driver' => $connectionParams['driver'], 'host' => $connectionParams['host'], 'dsn' => 'mysql:host=' . $connectionParams['host'] . ';dbname=' . $connectionParams['db'] . '', 'persistent' => true, 'username' => $connectionParams['user'], 'password' => $connectionParams['pass'], 'database' => $connectionParams['db'], 'charset' => isset($connectionParams['charset']) ? $connectionParams['charset'] : 'utf8', 'result' => array('detectTypes' => true, 'formatDate' => "Y-m-d", 'formatDateTime' => 'Y-m-d H:i:s'), 'profiler' => array('run' => true), 'flags' => MYSQLI_CLIENT_COMPRESS)); $panel = new Dibi\Bridges\Tracy\Panel(); $panel->register($connection); } catch (DibiException $e) { dd($e->getMessage()); $view = Core_View::getInstance(); $view->setLayoutFile('$maintenance/db_connect.phtml'); $view->displayLayout(); die; } } }
/** * @param AJXP_Node $oldNode * @param AJXP_Node $newNode * @param bool $copy */ public function updateNodesIndex($oldNode = null, $newNode = null, $copy = false) { if (!dibi::isConnected()) { dibi::connect($this->sqlDriver); } //$this->logInfo("Syncable index", array($oldNode == null?'null':$oldNode->getUrl(), $newNode == null?'null':$newNode->getUrl())); try { if ($newNode != null && $this->excludeNode($newNode)) { // CREATE if ($oldNode == null) { AJXP_Logger::debug("Ignoring " . $newNode->getUrl() . " for indexation"); return; } else { AJXP_Logger::debug("Target node is excluded, see it as a deletion: " . $newNode->getUrl()); $newNode = null; } } if ($newNode == null) { $repoId = $this->computeIdentifier($oldNode->getRepository(), $oldNode->getUser()); // DELETE $this->logDebug('DELETE', $oldNode->getUrl()); dibi::query("DELETE FROM [ajxp_index] WHERE [node_path] LIKE %like~ AND [repository_identifier] = %s", SystemTextEncoding::toUTF8($oldNode->getPath()), $repoId); } else { if ($oldNode == null || $copy) { // CREATE $stat = stat($newNode->getUrl()); $newNode->setLeaf(!($stat['mode'] & 040000)); $this->logDebug('INSERT', $newNode->getUrl()); dibi::query("INSERT INTO [ajxp_index]", array("node_path" => SystemTextEncoding::toUTF8($newNode->getPath()), "bytesize" => $stat["size"], "mtime" => $stat["mtime"], "md5" => $newNode->isLeaf() ? md5_file($newNode->getUrl()) : "directory", "repository_identifier" => $repoId = $this->computeIdentifier($newNode->getRepository(), $newNode->getUser()))); } else { $repoId = $this->computeIdentifier($oldNode->getRepository(), $oldNode->getUser()); if ($oldNode->getPath() == $newNode->getPath()) { // CONTENT CHANGE clearstatcache(); $stat = stat($newNode->getUrl()); $this->logDebug("Content changed", "current stat size is : " . $stat["size"]); $this->logDebug('UPDATE CONTENT', $newNode->getUrl()); dibi::query("UPDATE [ajxp_index] SET ", array("bytesize" => $stat["size"], "mtime" => $stat["mtime"], "md5" => md5_file($newNode->getUrl())), "WHERE [node_path] = %s AND [repository_identifier] = %s", SystemTextEncoding::toUTF8($oldNode->getPath()), $repoId); try { $rowCount = dibi::getAffectedRows(); if ($rowCount === 0) { $this->logError(__FUNCTION__, "There was an update event on a non-indexed node (" . $newNode->getPath() . "), creating index entry!"); $this->updateNodesIndex(null, $newNode, false); } } catch (Exception $e) { } } else { // PATH CHANGE ONLY $newNode->loadNodeInfo(); if ($newNode->isLeaf()) { $this->logDebug('UPDATE LEAF PATH', $newNode->getUrl()); dibi::query("UPDATE [ajxp_index] SET ", array("node_path" => SystemTextEncoding::toUTF8($newNode->getPath())), "WHERE [node_path] = %s AND [repository_identifier] = %s", SystemTextEncoding::toUTF8($oldNode->getPath()), $repoId); try { $rowCount = dibi::getAffectedRows(); if ($rowCount === 0) { $this->logError(__FUNCTION__, "There was an update event on a non-indexed node (" . $newNode->getPath() . "), creating index entry!"); $this->updateNodesIndex(null, $newNode, false); } } catch (Exception $e) { } } else { $this->logDebug('UPDATE FOLDER PATH', $newNode->getUrl()); dibi::query("UPDATE [ajxp_index] SET [node_path]=REPLACE( REPLACE(CONCAT('\$\$\$',[node_path]), CONCAT('\$\$\$', %s), CONCAT('\$\$\$', %s)) , '\$\$\$', '') ", $oldNode->getPath(), $newNode->getPath(), "WHERE [node_path] LIKE %like~ AND [repository_identifier] = %s", SystemTextEncoding::toUTF8($oldNode->getPath()), $repoId); try { $rowCount = dibi::getAffectedRows(); if ($rowCount === 0) { $this->logError(__FUNCTION__, "There was an update event on a non-indexed folder (" . $newNode->getPath() . "), relaunching a recursive indexation!"); AJXP_Controller::findActionAndApply("index", array("file" => $newNode->getPath()), array()); } } catch (Exception $e) { } } } } } } catch (Exception $e) { AJXP_Logger::error("[meta.syncable]", "Exception", $e->getTraceAsString()); AJXP_Logger::error("[meta.syncable]", "Indexation", $e->getMessage()); } }
public function updateMetaObject($repositoryId, $oldPath, $newPath = null, $copy = false) { if ($this->sqlDriver["password"] == "XXXX") { return array(); } if (!dibi::isConnected()) { dibi::connect($this->sqlDriver); } if ($oldPath != null && $newPath == null) { // DELETE dibi::query("DELETE FROM [ajxp_feed] WHERE [repository_id]=%s and [index_path] LIKE %like~", $repositoryId, $oldPath); } else { if ($oldPath != null && $newPath != null) { // MOVE or COPY if ($copy) { // ?? Do we want to duplicate metadata? } else { $starter = "__START__"; dibi::query("UPDATE [ajxp_feed] SET [index_path] = CONCAT(%s, [index_path]) WHERE [index_path] LIKE %s AND [repository_id]=%s", $starter, $oldPath . "%", $repositoryId); dibi::query("UPDATE [ajxp_feed] SET [index_path] = REPLACE([index_path], %s, %s) WHERE [index_path] LIKE %s AND [repository_id]=%s", $starter . $oldPath, $starter . $newPath, $starter . $oldPath . "%", $repositoryId); dibi::query("UPDATE [ajxp_feed] SET [index_path] = REPLACE([index_path], %s, %s) WHERE [index_path] LIKE %s AND [repository_id]=%s", $starter, '', $starter . $newPath . "%", $repositoryId); } } } }
public function processNotification(AJXP_Notification &$notification) { // Inserting the node information. try { $notification->getNode()->loadNodeInfo(); } catch (Exception $e) { // Do nothing } $userExist = AuthService::userExists($notification->getTarget()); if ($userExist === true) { $userObject = ConfService::getConfStorageImpl()->createUserObject($notification->getTarget()); } else { $messages = ConfService::getMessages(); throw new AJXP_Exception($messages['core.mailer.2']); } if ($userObject->mergedRole->filterParameterValue("core.mailer", "NOTIFICATIONS_EMAIL_GET", AJXP_REPO_SCOPE_ALL, "true") !== "true") { // User does not want to receive any emails. return; } $notification_email = $userObject->mergedRole->filterParameterValue("core.mailer", "NOTIFICATIONS_EMAIL", AJXP_REPO_SCOPE_ALL, ""); $arrayRecipients = array(); $mainRecipient = $userObject->mergedRole->filterParameterValue("core.conf", "email", AJXP_REPO_SCOPE_ALL, ""); $useHtml = $userObject->mergedRole->filterParameterValue("core.mailer", "NOTIFICATIONS_EMAIL_SEND_HTML", AJXP_REPO_SCOPE_ALL, "true") === "true" ? 1 : 0; if (!empty($mainRecipient)) { $arrayRecipients[] = $mainRecipient; } $additionalRecipients = array_map("trim", explode(',', $notification_email)); foreach ($additionalRecipients as $addR) { if (!empty($addR)) { $arrayRecipients[] = $addR; } } if ($this->pluginConf["MAILER_ACTIVATE_QUEUE"] && count($arrayRecipients)) { $frequencyType = $userObject->mergedRole->filterParameterValue("core.mailer", "NOTIFICATIONS_EMAIL_FREQUENCY", AJXP_REPO_SCOPE_ALL, "M"); $frequencyDetail = $userObject->mergedRole->filterParameterValue("core.mailer", "NOTIFICATIONS_EMAIL_FREQUENCY_USER", AJXP_REPO_SCOPE_ALL, "5"); $nextFrequency = $this->computeEmailSendDate($frequencyType, $frequencyDetail); if (!empty($nextFrequency)) { if (!dibi::isConnected()) { dibi::connect($this->getDibiDriver()); } foreach ($arrayRecipients as $recipient) { try { dibi::query("INSERT INTO [ajxp_mail_queue] ([recipient],[url],[date_event],[notification_object],[html]) VALUES (%s,%s,%s,%bin,%i) ", $recipient, $notification->getNode()->getUrl(), $nextFrequency, serialize($notification), $useHtml); } catch (Exception $e) { $this->logError("[mailer]", $e->getMessage()); } } } else { $this->logError("[mailer]", "Could not determine email frequency from {$frequencyType} / {$frequencyDetail} for send email to user " . $userObject->getId()); } } else { $mailer = AJXP_PluginsService::getInstance()->getActivePluginsForType("mailer", true); if ($mailer !== false) { try { $mailer->sendMail(array($notification->getTarget()), $notification->getDescriptionShort(), $notification->getDescriptionLong(), $notification->getAuthor(), $notification->getMainLink(), $useHtml); } catch (Exception $e) { throw new AJXP_Exception($e->getMessage()); } } } }
/** * @param string $channel Name of the persistant queue to create * @param object $message Message to send * @return mixed */ public function publishWorkerMessage($channel, $message) { if (!dibi::isConnected()) { dibi::connect($this->sqlDriver); } $castType = "UNSIGNED"; if ($this->sqlDriver["driver"] == "postgre") { $castType = "INTEGER"; } $r = dibi::query("SELECT MAX( CAST( [object_id] AS " . $castType . " ) ) FROM [ajxp_simple_store] WHERE [store_id]=%s", "queues.{$channel}"); $index = $r->fetchSingle(); if ($index == null) { $index = 1; } else { $index = intval($index) + 1; } $values = array("store_id" => "queues.{$channel}", "object_id" => $index, "serialized_data" => serialize($message)); dibi::query("INSERT INTO [ajxp_simple_store] ([object_id],[store_id],[serialized_data],[binary_data],[related_object_id]) VALUES (%s,%s,%bin,%bin,%s)", $values["object_id"], $values["store_id"], $values["serialized_data"], $values["binary_data"], $values["related_object_id"]); }
<?php require_once __DIR__ . '/vendors/dibi.min.php'; require_once __DIR__ . '/../config.php'; require_once __DIR__ . '/classes/ConfigSet.php'; require_once __DIR__ . '/classes/Analytics.php'; require_once __DIR__ . '/classes/ListMenu.php'; require_once __DIR__ . '/classes/TemplateVars.php'; require_once __DIR__ . '/classes/Database.php'; require_once __DIR__ . '/classes/Table.php'; require_once __DIR__ . '/functions.php'; if (!dibi::isConnected()) { try { dibi::connect(array('driver' => 'mysqli', 'host' => DB_HOST, 'username' => DB_USER, 'password' => DB_PASS, 'database' => DB_NAME, 'charset' => 'utf8')); } catch (DibiException $e) { die("Error: " . $e->getMessage()); } } session_start(); // Check for a ban. if (dibi::fetchSingle("SELECT 1 FROM bans WHERE ip=%s", $_SERVER['REMOTE_ADDR'])) { die("<h2>YOU ARE BANNED SON</h2>"); } // Check for IP whitelist if (dibi::fetchSingle("SELECT 1 FROM whitelist WHERE ip=%s", $_SERVER['REMOTE_ADDR'])) { $_SESSION['whitelisted'] = true; } $configs = ConfigSet::getInstance(); $analytics = new Analytics(); $analytics->logAccess();