Exemplo n.º 1
0
 /**
  * create a new ticket user.
  * @param $extern_id the id of the user account in the www version (drupal,...)
  * @param $permission the permission that will be given to the user. 1=user, 2=mod, 3=admin
  */
 public static function createTicketUser($extern_id, $permission)
 {
     try {
         //make connection with and put into db
         $dbl = new DBLayer("lib");
         $dbl->insert("ticket_user", array('TUserId' => $extern_id, 'Permission' => $permission, 'ExternId' => $extern_id));
     } catch (PDOException $e) {
         //oh noooz...
         //error_log(print_r($e, true));
         //print_r($e);
         echo "Problem creating user in database!";
     }
 }
Exemplo n.º 2
0
 /**
  * send mail function that will add the email to the db.
  * this function is being used by the send_ticketing_mail() function. It adds the email as an entry to the `email` table in the database, which will be sent later on when we run the cron job.
  * @param $recipient if integer, then it refers to the id of the user to whom we want to mail, if it's a string(email-address) then we will use that.
  * @param $subject the subject of the email
  * @param $body the body of the email
  * @param $ticket_id the id of the ticket
  * @param $from the sending support_group's id (NULL in case the default group is sending))
  */
 public static function send_mail($recipient, $subject, $body, $ticket_id = 0, $from = NULL)
 {
     $id_user = NULL;
     if (is_numeric($recipient)) {
         $id_user = $recipient;
         $recipient = NULL;
     }
     $db = new DBLayer($db);
     $db->insert("email", array('Recipient' => $recipient, 'Subject' => $subject, 'Body' => $body, 'Status' => 'NEW', 'Attempts' => 0, 'Sender' => $from, 'UserId' => $id_user, 'MessageId' => 0, 'TicketId' => $ticket_id));
 }
Exemplo n.º 3
0
 /**
  * creates a new 'assigned' entry.
  * this method will use the object's attributes for creating a new 'assigned' entry in the database.
  */
 public function create()
 {
     $dbl = new DBLayer("lib");
     $dbl->insert("`assigned`", array('User' => $this->getUser(), 'Ticket' => $this->getTicket()));
 }
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
 /**
  * sets the shards email.
  * in case the shard is offline, the entry will be stored in the ams_querycache.
  * @param $user the usersname of the account of which we want to change the emailaddress.
  * @param $mail the new email address
  * @return ok if it worked, if the lib or shard is offline it will return liboffline or shardoffline.
  */
 protected static function setAmsEmail($user, $mail)
 {
     $values = array('Email' => $mail);
     try {
         //make connection with and put into shard db
         $dbs = new DBLayer("shard");
         $dbs->update("user", $values, "Login = '******'");
         return "ok";
     } catch (PDOException $e) {
         //oh noooz, the shard is offline! Put in query queue at ams_lib db!
         try {
             error_log($e);
             $dbl = new DBLayer("lib");
             $dbl->insert("ams_querycache", array("type" => "change_mail", "query" => json_encode(array($user, $mail)), "db" => "shard"));
             return "shardoffline";
         } catch (PDOException $e) {
             return "liboffline";
         }
     }
 }
Exemplo n.º 6
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.º 7
0
/**
 * Hook to store data to database which is sent as post
 * method from the forms in this plugin
 * It also calls the local hook
 */
function api_key_management_hook_store_db()
{
    global $var_set;
    global $API_key_management_return_set;
    // if the form been submited move forward
    if (@hook_validate($_POST['gen_key'])) {
        // local hook to validate the POST variables
        hook_variables();
        // if validation successfull move forward
        if ($API_key_management_return_set['gen_key_validate'] == 'true' && $_GET['plugin_action'] == 'generate_key') {
            // this part generated the access token
            include 'generate_key.php';
            $var_set['AccessToken'] = generate_key::randomToken(56, false, true, false);
            // database connection
            $db = new DBLayer('lib');
            // insert the form data to the database
            $db->insert('ams_api_keys', $var_set);
            // redirect to the the main page with success code
            // 1 refers to the successfull addition of key to the database
            header("Location: index.php?page=layout_plugin&&name=API_key_management&&success=1");
            throw new SystemExit();
        }
    }
}
Exemplo n.º 8
0
 /**
  * creates a new 'forwarded' entry.
  * this method will use the object's attributes for creating a new 'forwarded' entry in the database.
  */
 public function create()
 {
     $dbl = new DBLayer("lib");
     $dbl->insert("`forwarded`", array('Group' => $this->getGroup(), 'Ticket' => $this->getTicket()));
 }
Exemplo n.º 9
0
 /**
  * creates a ticket_Catergory in the DB.   
  * @param $name name we want to give to the new category.
  */
 public static function createTicketCategory($name)
 {
     $dbl = new DBLayer("lib");
     $dbl->insert("ticket_category", array('Name' => $name));
 }
Exemplo n.º 10
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.º 11
0
 /**
  * creates a new 'support_group' entry.
  * this method will use the object's attributes for creating a new 'support_group' entry in the database.
  */
 public function create()
 {
     $dbl = new DBLayer("lib");
     $dbl->insert("support_group", array('Name' => $this->getName(), 'Tag' => $this->getTag(), 'GroupEmail' => $this->getGroupEmail(), 'IMAP_MailServer' => $this->getIMAP_MailServer(), 'IMAP_Username' => $this->getIMAP_Username(), 'IMAP_Password' => $this->getIMAP_Password()));
 }
Exemplo n.º 12
0
 /**
  * creates a new 'ticket_info' entry.
  * this method will use the object's attributes for creating a new 'ticket_info' entry in the database.
  */
 public function create()
 {
     $dbl = new DBLayer("lib");
     $values = array('Ticket' => $this->getTicket(), 'ShardId' => $this->getShardId(), 'UserPosition' => $this->getUser_Position(), 'ViewPosition' => $this->getView_Position(), 'ClientVersion' => $this->getClient_Version(), 'PatchVersion' => $this->getPatch_Version(), 'ServerTick' => $this->getServer_Tick(), 'ConnectState' => $this->getConnect_State(), 'LocalAddress' => $this->getLocal_Address(), 'Memory' => $this->getMemory(), 'OS' => $this->getOS(), 'Processor' => $this->getProcessor(), 'CPUID' => $this->getCPUId(), 'CpuMask' => $this->getCpu_Mask(), 'HT' => $this->getHT(), 'NeL3D' => $this->getNel3D(), 'UserId' => $this->getUser_Id());
     $dbl->insert("ticket_info", $values);
 }
Exemplo n.º 13
0
 /**
  * create a new log entry.
  * It will check if the $TICKET_LOGGING global var is true, this var is used to turn logging on and off. In case it's on, the log message will be stored.
  * the action id and argument (which is -1 by default), will be json encoded and stored in the query field in the db.
  * @param $ticket_id the id of the ticket related to the new log entry
  * @param $author_id the id of the user that instantiated the logging.
  * @param $action the action id (see the list in the class description)
  * @param $arg argument for the action (default = -1)
  */
 public static function createLogEntry($ticket_id, $author_id, $action, $arg = -1)
 {
     global $TICKET_LOGGING;
     if ($TICKET_LOGGING) {
         $dbl = new DBLayer("lib");
         $values = array('Query' => json_encode(array($action, $arg)), 'Ticket' => $ticket_id, 'Author' => $author_id);
         $dbl->insert("ticket_log", $values, array('Timestamp' => 'now()'));
     }
 }
Exemplo n.º 14
0
 /**
  * creates a new 'in_support_group' entry.
  * this method will use the object's attributes for creating a new 'in_support_group' entry in the database.
  */
 public function create()
 {
     $dbl = new DBLayer("lib");
     $dbl->insert("`in_support_group`", array('User' => $this->user, 'Group' => $this->group));
 }