Example #1
0
function forgot_password()
{
    $email = filter_var($_POST["Email"], FILTER_SANITIZE_EMAIL);
    $target_id = WebUsers::getIdFromEmail($email);
    if ($target_id == "FALSE") {
        //the email address doesn't exist.
        $result['prevEmail'] = $email;
        $result['EMAIL_ERROR'] = 'TRUE';
        $result['no_visible_elements'] = 'TRUE';
        helpers::loadtemplate('forgot_password', $result);
        throw new SystemExit();
    }
    $webUser = new WebUsers($target_id);
    $target_username = $webUser->getUsername();
    $target_hashedPass = $webUser->getHashedPass();
    $hashed_key = hash('sha512', $target_hashedPass);
    if (isset($_COOKIE['Language'])) {
        $lang = $_COOKIE['Language'];
    } else {
        global $DEFAULT_LANGUAGE;
        $lang = $DEFAULT_LANGUAGE;
    }
    global $AMS_TRANS;
    $variables = parse_ini_file($AMS_TRANS . '/' . $lang . '.ini', true);
    $mailText = array();
    foreach ($variables['email'] as $key => $value) {
        $mailText[$key] = $value;
    }
    //create the reset url
    global $WEBPATH;
    $resetURL = $WEBPATH . "?page=reset_password&user="******"&email=" . $email . "&key=" . $hashed_key;
    //set email stuff
    $recipient = $email;
    $subject = $mailText['email_subject_forgot_password'];
    $body = $mailText['email_body_forgot_password_header'] . $resetURL . $mailText['email_body_forgot_password_footer'];
    Mail_Handler::send_mail($recipient, $subject, $body, NULL);
    $result['EMAIL_SUCCESS'] = 'TRUE';
    $result['prevEmail'] = $email;
    $result['no_visible_elements'] = 'TRUE';
    helpers::loadtemplate('forgot_password', $result);
    throw new SystemExit();
}
Example #2
0
 /**
  * Handles an incomming email
  * Read the content of one email by using imap's functionality. If a ticket id is found inside the message_id or else in the subject line, then a reply will be added
  * (if the email is not being sent from the authors email address it won't be added though and a warning will be sent to both parties).  If no ticket id is found, then a new
  * ticket will be created.
  * @param $mbox a mailbox object
  * @param $i the email's id in the mailbox (integer)
  * @param $group the group object that owns the inbox.
  * @return a string based on the found ticket i and timestamp (will be used to store a copy of the email locally)
  */
 function incoming_mail_handler($mbox, $i, $group)
 {
     global $MAIL_LOG_PATH;
     $header = imap_header($mbox, $i);
     $subject = self::decode_utf8($header->subject);
     $entire_email = imap_fetchheader($mbox, $i) . imap_body($mbox, $i);
     $subject = self::decode_utf8($header->subject);
     $to = $header->to[0]->mailbox;
     $from = $header->from[0]->mailbox . '@' . $header->from[0]->host;
     $fromEmail = $header->from[0]->mailbox . '@' . $header->from[0]->host;
     $txt = self::get_part($mbox, $i, "TEXT/PLAIN");
     //$html = self::get_part($mbox, $i, "TEXT/HTML");
     //get the id out of the email address of the person sending the email.
     if ($from !== NULL && !is_numeric($from)) {
         $from = Ticket_User::get_id_from_email($from);
     }
     //get ticket_id out of the message-id or else out of the subject line
     $ticket_id = 0;
     if (isset($header->references)) {
         $pieces = explode(".", $header->references);
         if ($pieces[0] == "<ams") {
             $ticket_id = $pieces[2];
         } else {
             $ticket_id = self::get_ticket_id_from_subject($subject);
         }
     } else {
         $ticket_id = self::get_ticket_id_from_subject($subject);
     }
     //if ticket id is found, that means it is a reply on an existing ticket
     if ($ticket_id && is_numeric($ticket_id) && $ticket_id > 0) {
         $ticket = new Ticket();
         $ticket->load_With_TId($ticket_id);
         //if email is sent from an existing email address in the db (else it will give an error while loading the user object)
         if ($from != "FALSE") {
             $user = new Ticket_User();
             $user->load_With_TUserId($from);
             //if user has access to it!
             if ((Ticket_User::isMod($user) or $ticket->getAuthor() == $user->getTUserId()) and $txt != "") {
                 Ticket::createReply($txt, $user->getTUserId(), $ticket->getTId(), 0);
                 error_log("Email found that is a reply to a ticket at:" . $group->getGroupEmail() . "\n", 3, $MAIL_LOG_PATH);
             } else {
                 //if user has no access to it
                 //Warn real ticket owner + person that send the mail
                 Mail_Handler::send_ticketing_mail($ticket->getAuthor(), $ticket, NULL, "WARNAUTHOR", $from);
                 Mail_Handler::send_ticketing_mail($from, $ticket, NULL, "WARNSENDER", NULL);
                 error_log("Email found that was a reply to a ticket, though send by another user to " . $group->getGroupEmail() . "\n", 3, $MAIL_LOG_PATH);
             }
         } else {
             //if a reply to a ticket is being sent by a non-user!
             //Warn real ticket owner + person that send the mail
             Mail_Handler::send_ticketing_mail($ticket->getAuthor(), $ticket, NULL, "WARNAUTHOR", $fromEmail);
             Mail_Handler::send_ticketing_mail($fromEmail, $ticket, NULL, "WARNUNKNOWNSENDER", NULL);
             error_log("Email found that was a reply to a ticket, though send by an unknown email address to " . $group->getGroupEmail() . "\n", 3, $MAIL_LOG_PATH);
         }
         return $ticket_id . "." . time();
     } else {
         if ($from != "FALSE") {
             //if ticket_id isn't found, create a new ticket!
             //if an existing email address mailed the ticket
             //if not default group, then forward it by giving the $group->getSGroupId's param
             $newTicketId = Ticket::create_Ticket($subject, $txt, 1, $from, $from, $group->getSGroupId());
             error_log("Email regarding new ticket found at:" . $group->getGroupEmail() . "\n", 3, $MAIL_LOG_PATH);
             return $newTicketId . "." . time();
         } else {
             //if it's a email that has nothing to do with ticketing, return 0;
             error_log("Email found that isn't a reply or new ticket, at:" . $group->getGroupEmail() . "\n", 3, $MAIL_LOG_PATH);
             return 0;
         }
     }
 }
Example #3
0
 /**
  * create a new reply for a ticket.
  * A reply will only be added if the content isn't empty and if the ticket isn't closed.
  * The ticket creator will be notified by email that someone else replied on his ticket.
  * @param $content the content of the reply
  * @param $author the author of the reply
  * @param $ticket_id the id of the ticket to which we want to add the reply.
  * @param $hidden boolean that specifies if the reply should only be shown to mods/admins or all users.
  */
 public static function createReply($content, $author, $ticket_id, $hidden)
 {
     //if not empty
     if (!(Trim($content) === '')) {
         $content = filter_var($content, FILTER_SANITIZE_STRING);
         $ticket = new Ticket();
         $ticket->load_With_TId($ticket_id);
         //if status is not closed
         if ($ticket->getStatus() != 3) {
             Ticket_Reply::createReply($content, $author, $ticket_id, $hidden, $ticket->getAuthor());
             //notify ticket author that a new reply is added!
             if ($ticket->getAuthor() != $author) {
                 Mail_Handler::send_ticketing_mail($ticket->getAuthor(), $ticket, $content, "REPLY", $ticket->getForwardedGroupId());
             }
         } else {
             //TODO: Show error message that ticket is closed
         }
     } else {
         //TODO: Show error content is empty
     }
 }
Example #4
0
<?php

/**
* This small piece of php code calls the cron() function of the Mail_Handler. 
* @author Daan Janssens, mentored by Matthew Lagoe
*/
require '../../config.php';
require_once $AMS_LIB . '/libinclude.php';
$mail_handler = new Mail_Handler();
$mail_handler->cron();