Exemplo n.º 1
0
/**
 * 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();
        }
    }
}
Exemplo n.º 2
0
/**
 * This function is used in installing updates for plugins.
 * It takes id of the plugin whose update is available using
 * $_GET global variable and then extract the update details
 * from db and then install it in the plugin.
 *
 * @author Shubham Meena, mentored by Matthew Lagoe
 */
function update_plugin()
{
    // if logged in
    if (WebUsers::isLoggedIn()) {
        if (isset($_GET['id'])) {
            // id of plugin to update
            $id = filter_var($_GET['id'], FILTER_SANITIZE_FULL_SPECIAL_CHARS);
            $db = new DBLayer('lib');
            $sth = $db->executeWithoutParams("SELECT * FROM plugins INNER JOIN updates ON plugins.Id=updates.PluginId Where plugins.Id={$id}");
            $row = $sth->fetch();
            // replacing update in the  database
            Plugincache::rrmdir($row['FileName']);
            Plugincache::zipExtraction($row['UpdatePath'], rtrim($row['FileName'], strtolower($row['Name'])));
            $db->update("plugins", array('Info' => $row['UpdateInfo']), "Id={$row['Id']}");
            // deleting the previous update
            $db->delete("updates", array('id' => $row['s.no']), "s.no=:id");
            // if update is installed succesffully redirect to show success message
            header("Cache-Control: max-age=1");
            header("Location: index.php?page=plugins&result=8");
            throw new SystemExit();
        }
    }
}
Exemplo n.º 3
0
 /**
  * deletes an existing 'assigned' entry.
  * this method will use the object's attributes for deleting an existing 'assigned' entry in the database.
  */
 public function delete()
 {
     $dbl = new DBLayer("lib");
     $dbl->delete("`assigned`", array('user_id' => $this->getUser(), 'ticket_id' => $this->getTicket()), "`User` = :user_id and `Ticket` = :ticket_id");
 }
Exemplo n.º 4
0
 /**
  * function that creates a ticket Attachment.
  */
 public static function add_Attachment($TId, $filename, $author, $tempFile)
 {
     global $FILE_STORAGE_PATH;
     $length = mt_rand(20, 25);
     $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ$-_.+!*\'(),';
     $randomString = '';
     for ($i = 0; $i < $length; $i++) {
         $randomString .= $characters[rand(0, strlen($characters) - 1)];
     }
     $targetFile = $FILE_STORAGE_PATH . $randomString . "/" . $filename;
     if (file_exists($targetFile)) {
         return self::add_Attachment($TId, $filename, $author, $tempFile);
     }
     $ticket = new Ticket();
     $ticket->load_With_TId($TId);
     //create the attachment!
     try {
         $dbl = new DBLayer("lib");
         $dbl->insert("`ticket_attachments`", array('ticket_TId' => $TId, 'Filename' => $filename, 'Filesize' => filesize($tempFile), 'Uploader' => $author, 'Path' => $randomString . "/" . $filename));
     } catch (Exception $e) {
         return $false;
     }
     mkdir($FILE_STORAGE_PATH . $randomString);
     $return = move_uploaded_file($tempFile, $targetFile);
     if ($return == false) {
         $dbl->delete("`ticket_attachments`", array('Path' => $randomString . "/" . $filename), "`Path` = :Path");
     }
     //write a log entry
     Ticket_Log::createLogEntry($TId, $author, 10);
     return $return;
 }
Exemplo n.º 5
0
/**
 * function to check for updates or
 * if the same plugin already exists
 * also, if the update founds ,check for the UpdateInfo in the .info file.
 * Update is saved in the temp directory with pluginName_version.zip
 *
 * @param  $fileName file which is uploaded in .zip extension
 * @param  $findPath where we have to look for the installed plugins
 * @param  $tempFile path for the temporary file
 * @param  $tempPath path where we have to store the update
 * @return 2 if plugin already exists and update not found
 * @return 3 if update info tag not found in .info file
 */
function checkForUpdate($fileName, $findPath, $tempFile, $tempPath)
{
    // check for plugin if exists
    $file = scandir($findPath);
    foreach ($file as $key => $value) {
        if (strcmp($value, $fileName) == 0) {
            if (!file_exists($tempPath . "/test")) {
                mkdir($tempPath . "/test");
            }
            // extracting the update
            if (zipExtraction($tempFile, $tempPath . "/test/")) {
                $result = readPluginFile(".info", $tempPath . "/test/" . $fileName);
                // check for the version for the plugin
                $db = new DBLayer("lib");
                $sth = $db->select("plugins", array('Name' => $result['PluginName']), "Name = :Name");
                $info = $sth->fetch();
                $info['Info'] = json_decode($info['Info']);
                // the two versions from main plugin and the updated part
                $new_version = explode('.', $result['Version']);
                $pre_version = explode('.', $info['Info']->Version);
                // For all plugins we have used semantic versioning
                // Format: X.Y.Z ,X->Major, Y->Minor, Z->Patch
                // change in the X Y & Z values refer the type of change in the plugin.
                // for initial development only Minor an Patch MUST be 0.
                // if there is bug fix then there MUST be an increment in the Z value.
                // if there is change in the functionality or addition of new functionality
                // then there MUST be an increment in the Y value.
                // When there is increment in the X value , Y and Z MUST be 0.
                // comparing if there is some change
                if (!array_diff($new_version, $pre_version)) {
                    // removing the uploaded file
                    Plugincache::rrmdir($tempPath . "/test/" . $fileName);
                    return '2';
                    //plugin already exists
                } else {
                    // check for update info if exists
                    if (!array_key_exists('UpdateInfo', $result)) {
                        return '3';
                        //update info tag not found
                    } else {
                        // check if update already exists
                        if (pluginUpdateExists($info['Id'], $tempPath . "/" . trim($fileName, ".zip") . "_" . $result['Version'] . ".zip")) {
                            echo "Update already exists";
                            throw new SystemExit();
                        } else {
                            // removing the preivous update
                            $dbr = new DBLayer("lib");
                            $dbr->delete("updates", array('id' => $info['Id']), "PluginId=:id");
                            // storing update in the temp directory
                            // format of update save
                            if (move_uploaded_file($tempFile, $tempPath . "/" . trim($fileName, ".zip") . "_" . $result['Version'] . ".zip")) {
                                // setting update information in the database
                                $update['PluginId'] = $info['Id'];
                                $update['UpdatePath'] = $tempPath . "/" . trim($fileName, ".zip") . "_" . $result['Version'] . ".zip";
                                $update['UpdateInfo'] = json_encode($result);
                                $dbr->insert("updates", $update);
                                header("Cache-Control: max-age=1");
                                header("Location: index.php?page=plugins&result=7");
                                throw new SystemExit();
                            }
                        }
                    }
                }
            }
        }
    }
}
Exemplo n.º 6
0
/**
 * Global Hook to update or delete the data from db
 */
function api_key_management_hook_update_db()
{
    global $var_set;
    global $API_key_management_return_set;
    $db = new DBLayer('lib');
    if (isset($_GET['delete_id'])) {
        // removes the registered key using get variable which contains the id of the registered key
        $db->delete('ams_api_keys', array('SNo' => $_GET['delete_id']), 'SNo = :SNo');
        // redirecting to the API_key_management plugins template with success code
        // 2 refers to the succssfull delete condition
        header("Location: index.php?page=layout_plugin&&name=API_key_management&&success=2");
        throw new SystemExit();
    }
}
Exemplo n.º 7
0
 /**
  * deletes an existing 'forwarded' entry.
  * this method will use the object's attributes for deleting an existing 'forwarded' entry in the database.
  */
 public function delete()
 {
     $dbl = new DBLayer("lib");
     $dbl->delete("`forwarded`", array('group_id' => $this->getGroup(), 'ticket_id' => $this->getTicket(), "`Group` = :group_id and `Ticket` = :ticket_id"));
 }
Exemplo n.º 8
0
 /**
  * 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);
         }
     }
 }
Exemplo n.º 9
0
 /**
  * deletes an existing 'support_group' entry.
  * this method will use the object's attributes for deleting an existing 'support_group' entry in the database.
  */
 public function delete()
 {
     $dbl = new DBLayer("lib");
     $dbl->delete("`support_group`", array('id' => $this->getSGroupId()), "`SGroupId` = :id");
 }
Exemplo n.º 10
0
 /**
  * deletes an existing 'in_support_group' entry.
  * this method will use the object's attributes for deleting an existing 'in_support_group' entry in the database.
  */
 public function delete()
 {
     $dbl = new DBLayer("lib");
     $dbl->delete("`in_support_group`", array('user_id' => $this->getUser(), 'group_id' => $this->getGroup()), "`User` = :user_id and `Group` = :group_id");
 }