示例#1
0
 /**
  * Wrapper for creating a support group.
  * It will check if the support group doesn't exist yet, if the tag or name already exists then NAME_TAKEN  or TAG_TAKEN will be returned.
  * If the name is bigger than 20 characters or smaller than 4 and the tag greater than 7 or smaller than 2 a SIZE_ERROR will be returned.
  * Else it will return SUCCESS
  * @return a string that specifies if it was a success or not (SUCCESS, SIZE_ERROR, NAME_TAKEN or TAG_TAKEN )
  */
 public static function createSupportGroup($name, $tag, $groupemail, $imap_mailserver, $imap_username, $imap_password)
 {
     //error_log( "Error at line " . __LINE__ . " in file " . __FILE__);
     if (strlen($name) <= 21 && strlen($name) >= 4 && strlen($tag) <= 8 && strlen($tag) >= 2) {
         $notExists = self::supportGroup_EntryNotExists($name, $tag);
         //error_log( "Error at line " . __LINE__ . " in file " . __FILE__);
         if ($notExists == "SUCCESS") {
             $sGroup = new self();
             $values = array('Name' => $name, 'Tag' => $tag, 'GroupEmail' => $groupemail, 'IMAP_MailServer' => $imap_mailserver, 'IMAP_Username' => $imap_username, 'IMAP_Password' => $imap_password);
             $sGroup->setName($values['Name']);
             $sGroup->setTag($values['Tag']);
             $sGroup->setGroupEmail($values['GroupEmail']);
             $sGroup->setIMAP_MailServer($values['IMAP_MailServer']);
             $sGroup->setIMAP_Username($values['IMAP_Username']);
             //encrypt password!
             global $cfg;
             $crypter = new MyCrypt($cfg['crypt']);
             $enc_password = $crypter->encrypt($values['IMAP_Password']);
             $sGroup->setIMAP_Password($enc_password);
             $sGroup->create();
             //error_log( "Error at line " . __LINE__ . " in file " . __FILE__);
         } else {
             //error_log( "Error at line " . __LINE__ . " in file " . __FILE__);
             //return NAME_TAKEN  or TAG_TAKEN
             return $notExists;
         }
     } else {
         //error_log( "Error at line " . __LINE__ . " in file " . __FILE__);
         //RETURN ERROR that indicates SIZE
         return "SIZE_ERROR";
     }
 }
示例#2
0
 public function doLoginAction()
 {
     $rsa = new MyCrypt();
     $email = $this->request->getPost('email');
     $password = $this->request->getPost('password');
     var_dump($email, $password, $rsa->decrypt($email), $rsa->decrypt($password));
     die;
 }
/**
* This function is beign used to modify the email related to a support group.
* It will first check if the user who executed this function is an admin. If this is not the case the page will be redirected to an error page.
* the new email will be validated and in case it's valid we'll add it to the db. Before adding it, we will encrypt the password by using the MyCrypt class. Afterwards the password gets
* updated and the page redirected again.
* @author Daan Janssens, mentored by Matthew Lagoe
*/
function modify_email_of_sgroup()
{
    global $INGAME_WEBPATH;
    global $WEBPATH;
    if (WebUsers::isLoggedIn()) {
        //check if user is an admin
        if (Ticket_User::isAdmin(unserialize($_SESSION['ticket_user'])) && isset($_POST['target_id'])) {
            $sgroupid = filter_var($_POST['target_id'], FILTER_SANITIZE_NUMBER_INT);
            $group = Support_Group::getGroup($sgroupid);
            $groupemail = filter_var($_POST['GroupEmail'], FILTER_SANITIZE_STRING);
            if (Users::validEmail($groupemail) || $groupemail == "") {
                $password = filter_var($_POST['IMAP_Password'], FILTER_SANITIZE_STRING);
                $group->setGroupEmail($groupemail);
                $group->setIMAP_MailServer(filter_var($_POST['IMAP_MailServer'], FILTER_SANITIZE_STRING));
                $group->setIMAP_Username(filter_var($_POST['IMAP_Username'], FILTER_SANITIZE_STRING));
                //encrypt password!
                global $cfg;
                $crypter = new MyCrypt($cfg['crypt']);
                $enc_password = $crypter->encrypt($password);
                $group->setIMAP_Password($enc_password);
                $group->update();
                $result['RESULT_OF_MODIFYING'] = "SUCCESS";
                if ($password == "") {
                    $result['RESULT_OF_MODIFYING'] = "NO_PASSWORD";
                }
            } else {
                $result['RESULT_OF_MODIFYING'] = "EMAIL_NOT_VALID";
            }
            $result['permission'] = unserialize($_SESSION['ticket_user'])->getPermission();
            $result['no_visible_elements'] = 'FALSE';
            $result['username'] = $_SESSION['user'];
            //global $SITEBASE;
            //require_once($SITEBASE . 'inc/show_sgroup.php');
            //$result= array_merge($result, show_sgroup());
            //helpers :: loadtemplate( 'show_sgroup', $result);
            header("Cache-Control: max-age=1");
            if (Helpers::check_if_game_client()) {
                header("Location: " . $INGAME_WEBPATH . "?page=show_sgroup&id=" . $sgroupid);
            } else {
                header("Location: " . $WEBPATH . "?page=show_sgroup&id=" . $sgroupid);
            }
            throw new SystemExit();
        } else {
            //ERROR: No access!
            $_SESSION['error_code'] = "403";
            header("Cache-Control: max-age=1");
            header("Location: index.php?page=error");
            throw new SystemExit();
        }
    } else {
        //ERROR: not logged in!
        header("Cache-Control: max-age=1");
        header("Location: index.php");
        throw new SystemExit();
    }
}
示例#4
0
 /**
  * the cron funtion (workhorse of the mailing system).
  * The cron job will create a child process, which will first send the emails that are in the email table in the database, we use some kind of semaphore (a temp file) to make sure that
  * if the cron job is called multiple times, it wont email those mails multiple times. After this, we will read the mail inboxes of the support groups and the default group using IMAP
  * and we will add new tickets or new replies according to the incoming emails.
  */
 function cron()
 {
     global $cfg;
     global $MAIL_LOG_PATH;
     $default_groupemail = $cfg['mail']['default_groupemail'];
     $default_groupname = $cfg['mail']['default_groupname'];
     /*
             $inbox_host = $cfg['mail']['host'];
             $oms_reply_to = "Ryzom Ticketing Support <ticketing@".$inbox_host.">";*/
     global $MAIL_DIR;
     error_log("========================================================\n", 3, $MAIL_LOG_PATH);
     error_log("mailing cron Job started at: " . Helpers::outputTime(time(), 0) . "\n", 3, $MAIL_LOG_PATH);
     //creates child process
     $pid = self::mail_fork();
     $pidfile = '/tmp/ams_cron_email_pid';
     if ($pid) {
         // We're the parent process, do nothing!
         //INFO: if $pid =
         //-1: "Could not fork!\n";
         // 0: "In child!\n";
         //>0: "In parent!\n";
     } else {
         //deliver new mail
         //make db connection here because the children have to make the connection.
         $this->db = new DBLayer("lib");
         //if $pidfile doesn't exist yet, then start sending the mails that are in the db.
         if (!file_exists($pidfile)) {
             //create the file and write the child processes id in it!
             $pid = getmypid();
             $file = fopen($pidfile, 'w');
             fwrite($file, $pid);
             fclose($file);
             //select all new & failed emails & try to send them
             //$emails = db_query("select * from email where status = 'NEW' or status = 'FAILED'");
             $statement = $this->db->select("email", array(null), "Status = 'NEW' or Status = 'FAILED'");
             $emails = $statement->fetchAll();
             foreach ($emails as $email) {
                 $message_id = self::new_message_id($email['TicketId']);
                 //if recipient isn't given, then use the email of the id_user instead!
                 if (!$email['Recipient']) {
                     $email['Recipient'] = Ticket_User::get_email_by_user_id($email['UserId']);
                 }
                 //create sending email adres based on the $sender id which refers to the department id
                 if ($email['Sender'] == NULL) {
                     $from = $default_groupname . " <" . $default_groupemail . ">";
                 } else {
                     $group = Support_Group::getGroup($email['Sender']);
                     $from = $group->getName() . " <" . $group->getGroupEmail() . ">";
                 }
                 $headers = "From: {$from}\r\n" . "Message-ID: " . $message_id;
                 if (mail($email['Recipient'], $email['Subject'], $email['Body'], $headers)) {
                     $status = "DELIVERED";
                     error_log("Emailed {$email['Recipient']}\n", 3, $MAIL_LOG_PATH);
                 } else {
                     $status = "FAILED";
                     error_log("Email to {$email['Recipient']} failed\n", 3, $MAIL_LOG_PATH);
                 }
                 //change the status of the emails.
                 $this->db->execute('update email set Status = ?, MessageId = ?, Attempts = Attempts + 1 where MailId = ?', array($status, $message_id, $email['MailId']));
             }
             unlink($pidfile);
         }
         // Check mail
         $sGroups = Support_Group::getGroups();
         //decrypt passwords in the db!
         $crypter = new MyCrypt($cfg['crypt']);
         foreach ($sGroups as $group) {
             $group->setIMAP_Password($crypter->decrypt($group->getIMAP_Password()));
         }
         $defaultGroup = new Support_Group();
         $defaultGroup->setSGroupId(0);
         $defaultGroup->setGroupEmail($default_groupemail);
         $defaultGroup->setIMAP_MailServer($cfg['mail']['default_mailserver']);
         $defaultGroup->setIMAP_Username($cfg['mail']['default_username']);
         $defaultGroup->setIMAP_Password($cfg['mail']['default_password']);
         //add default group to the list
         $sGroups[] = $defaultGroup;
         foreach ($sGroups as $group) {
             //check if group has mailing stuff filled in!
             if ($group->getGroupEmail() != "" && $group->getIMAP_MailServer() != "" && $group->getIMAP_Username() != "" && $group->getIMAP_Password() != "") {
                 $mbox = imap_open($group->getIMAP_MailServer(), $group->getIMAP_Username(), $group->getIMAP_Password()) or die('Cannot connect to mail server: ' . imap_last_error());
                 $message_count = imap_num_msg($mbox);
                 for ($i = 1; $i <= $message_count; ++$i) {
                     //return task ID
                     $tkey = self::incoming_mail_handler($mbox, $i, $group);
                     if ($tkey) {
                         //base file on Ticket + timestamp
                         $file = fopen($MAIL_DIR . "/ticket" . $tkey, 'w');
                         error_log("Email was written to " . $MAIL_DIR . "/ticket" . $tkey . "\n", 3, $MAIL_LOG_PATH);
                         fwrite($file, imap_fetchheader($mbox, $i) . imap_body($mbox, $i));
                         fclose($file);
                         //mark message $i of $mbox for deletion!
                         imap_delete($mbox, $i);
                     }
                 }
                 //delete marked messages
                 imap_expunge($mbox);
                 imap_close($mbox);
             }
         }
         error_log("Child Cron job finished at " . Helpers::outputTime(time(), 0) . "\n", 3, $MAIL_LOG_PATH);
         error_log("========================================================\n", 3, $MAIL_LOG_PATH);
     }
 }