/** * This function is used in deleting plugins. * It removes the plugin from the codebase as well as * from the Database. When user request to delete a plugin * id of that plugin is sent in $_GET global variable. * * @author Shubham Meena, mentored by Matthew Lagoe */ function delete_plugin() { // if logged in if (WebUsers::isLoggedIn()) { if (isset($_GET['id'])) { // id of plugin to delete after filtering $id = filter_var($_GET['id'], FILTER_SANITIZE_FULL_SPECIAL_CHARS); $db = new DBLayer('lib'); $sth = $db->selectWithParameter("FileName", "plugins", array('id' => $id), "Id=:id"); $name = $sth->fetch(); if (is_dir("{$name['FileName']}")) { // removing plugin directory from the code base if (Plugincache::rrmdir("{$name['FileName']}")) { $db->delete('plugins', array('id' => $id), "Id=:id"); //if result successfull redirect and show success message header("Cache-Control: max-age=1"); header("Location: index.php?page=plugins&result=2"); throw new SystemExit(); } else { // if result unsuccessfull redirect and show error message header("Cache-Control: max-age=1"); header("Location: index.php?page=plugins&result=0"); throw new SystemExit(); } } } else { // if result unsuccessfull redirect and show error message header("Cache-Control: max-age=1"); header("Location: index.php?page=plugins&result=0"); throw new SystemExit(); } } }
/** * creates permissions in the shard db for a user. * incase the shard is offline it will place it in the ams_querycache. * @param $pvalues with username */ public static function createPermissions($pvalues) { try { $values = array('username' => $pvalues[0]); $dbs = new DBLayer("shard"); $sth = $dbs->selectWithParameter("UId", "user", $values, "Login= :username"); $result = $sth->fetchAll(); $dbl = new DBLayer("lib"); $UId = $result['0']['UId']; $statement = $dbl->execute("SELECT * FROM `settings` WHERE `Setting` = :setting", array('setting' => 'Domain_Auto_Add')); $json = $statement->fetch(); $json = json_decode($json['Value'], true); $db = new DBLayer('shard'); // get all domains $statement = $db->executeWithoutParams("SELECT * FROM domain"); $rows = $statement->fetchAll(); //error_log(print_r($rows,true)); //error_log(print_r($result,true)); //error_log(print_r($json,true)); foreach ($json as $key => $value) { //error_log(print_r($key,true)); //error_log(print_r($value,true)); $ins_values = array('UId' => $UId, 'DomainId' => $key, 'AccessPrivilege' => $value['1']); error_log(print_r($ins_values, true)); $dbs = new DBLayer("shard"); $dbs->insert("permission", $ins_values); } } catch (PDOException $e) { //oh noooz, the shard is offline! Put it in query queue at ams_lib db! $dbl = new DBLayer("lib"); $dbl->insert("ams_querycache", array("type" => "createPermissions", "query" => json_encode(array($pvalues[0])), "db" => "shard")); } return true; }
/** * Function to check for the update of a plugin already exists * * @param $pluginId id of the plugin for which update is available * @param $updatePath path of the new update * @return boolean True if update already exists else False * */ function PluginUpdateExists($pluginId, $updatePath) { $db = new DBLayer('lib'); $sth = $db->selectWithParameter("UpdatePath", "updates", array('pluginid' => $pluginId), "PluginId=:pluginid"); $row = $sth->fetch(); if ($updatePath == $row['UpdatePath']) { return true; } else { rmdir($row['UpdatePath']); return false; } }
/** * Global Hook to load the data from db and set it * into the global array to return it to the template */ function api_key_management_hook_load_db() { global $var_set; global $API_key_management_return_set; $dbl = new DBLayer("lib"); if (isset($_SESSION['user'])) { // returns the registered keys $sth = $dbl->select('ams_api_keys', array('user' => $_SESSION['user']), 'User = :user'); $row = $sth->fetchAll(); $API_key_management_return_set['api_keys'] = $row; // fetch the character from the array to compare $com = array_column($API_key_management_return_set['api_keys'], 'UserCharacter'); // returns the characters with respect to the user id in the ring_tool->characters try { $dbl = new DBLayer('ring'); $sth = $dbl->selectWithParameter('char_name', 'characters', array(), '1'); $row = $sth->fetch(); // loop through the character list and remove the character if already have an api key $API_key_management_return_set['characters'] = array_diff($row, $com); } catch (PDOException $e) { error_log($e->getMessage()); } } }
/** * Function provides list of active plugins * * @return list of active plugins */ public static function activePlugins() { $db = new DBLayer('lib'); $sth = $db->selectWithParameter('Id', 'plugins', array('status' => 1), 'Status=:status'); $row = $sth->fetchAll(); return $row; }
/** * performs the actions listed in the querycache. * All entries in the querycache will be read and performed depending on their type. * This is done because the shard could have been offline and we want changes made on the website (which is still online) to eventually hit the shard. * These changes are: createPermissions, createUser, change_pass, change_mail */ public static function syncdata($display = false) { if (function_exists('pcntl_fork')) { $pid = pcntl_fork(); } global $AMS_TMPDIR; $pidfile = $AMS_TMPDIR . '/ams_cron_pid'; if (isset($pid) and function_exists('pcntl_fork')) { // We're the main process. } else { $pid = getmypid(); if (Sync::check_for_pid(@file_get_contents($pidfile))) { $file = fopen($pidfile, 'w+'); if (!$file) { echo $pidfile . ' is not writeable.'; error_log($pidfile . ' is not writeable.'); throw new SystemExit(); } fwrite($file, $pid); fclose($file); try { $dbl = new DBLayer("lib"); $statement = $dbl->executeWithoutParams("SELECT * FROM ams_querycache"); $rows = $statement->fetchAll(); foreach ($rows as $record) { $db = new DBLayer($record['db']); switch ($record['type']) { case 'createPermissions': $decode = json_decode($record['query']); $values = array('username' => $decode[0]); //make connection with and put into shard db & delete from the lib $sth = $db->selectWithParameter("UId", "user", $values, "Login= :username"); $result = $sth->fetchAll(); /*foreach ($result as $UId) { $ins_values = array('UId' => $UId['UId']); $ins_values['ClientApplication'] = "r2"; $ins_values['AccessPrivilege'] = "OPEN"; $db->insert("permission", $ins_values); $ins_values['ClientApplication'] = 'ryzom_open'; $db->insert("permission",$ins_values); }*/ // FIXME: GARBAGE break; case 'change_pass': $decode = json_decode($record['query']); $values = array('Password' => $decode[1]); //make connection with and put into shard db & delete from the lib $db->update("user", $values, "Login = '******'0']}'"); break; case 'change_mail': $decode = json_decode($record['query']); $values = array('Email' => $decode[1]); //make connection with and put into shard db & delete from the lib $db->update("user", $values, "Login = '******'0']}'"); break; case 'createUser': $decode = json_decode($record['query']); $values = array('Login' => $decode[0], 'Password' => $decode[1], 'Email' => $decode[2]); //make connection with and put into shard db & delete from the lib $db->insert("user", $values); break; } $dbl->delete("ams_querycache", array('SID' => $record['SID']), "SID=:SID"); } if ($display == true) { print 'Syncing completed'; } } catch (PDOException $e) { if ($display == true) { print 'Something went wrong! The shard is probably still offline!'; print_r($e); } } unlink($pidfile); } } }
/** * Global Hook to return global variables which contains * the content to use in the smarty templates extracted from * the database * * @return $achievements_return_set global array returns the template data */ function achievements_hook_get_db() { global $achievements_return_set; if (isset($_SESSION['user'])) { $db = new DBLayer('lib'); // getting content for selecting characters $sth = $db->selectWithParameter('UserCharacter', 'ams_api_keys', array('User' => $_SESSION['user']), 'User = :User'); $row = $sth->fetch(); $achievements_return_set['Character'] = $row; } }