Exemplo n.º 1
0
 /**
  * show tooltip for user notification informations
  *
  * @param $type integer : user type
  * @param $canedit boolean : can edit ?
  *
  * @return nothing display
  **/
 function showUsersAssociated($type, $canedit)
 {
     global $CFG_GLPI, $LANG;
     $showuserlink = 0;
     if (haveRight('user', 'r')) {
         $showuserlink = 2;
     }
     $usericon = self::getActorIcon('user', $type);
     $user = new User();
     if (isset($this->users[$type]) && count($this->users[$type])) {
         foreach ($this->users[$type] as $k => $d) {
             $save_showuserlink = $showuserlink;
             echo "{$usericon} ";
             if ($k) {
                 $userdata = getUserName($k, $showuserlink);
             } else {
                 $email = $d['alternative_email'];
                 $userdata = "<a href='mailto:{$email}'>{$email}</a>";
                 $showuserlink = false;
             }
             if ($showuserlink) {
                 echo $userdata['name'] . "&nbsp;" . showToolTip($userdata["comment"], array('link' => $userdata["link"], 'display' => false));
             } else {
                 echo $userdata;
             }
             if ($CFG_GLPI['use_mailing']) {
                 $text = $LANG['job'][19] . "&nbsp;:&nbsp;" . Dropdown::getYesNo($d['use_notification']) . '<br>';
                 if ($d['use_notification']) {
                     $uemail = $d['alternative_email'];
                     if (empty($uemail) && $user->getFromDB($d['users_id'])) {
                         $uemail = $user->getField('email');
                     }
                     $text .= $LANG['mailing'][118] . "&nbsp;:&nbsp;" . $uemail;
                     if (!NotificationMail::isUserAddressValid($uemail)) {
                         $text .= "<span class='red'>" . $LANG['mailing'][110] . "</span>";
                     }
                 }
                 echo "&nbsp;";
                 if ($canedit || $d['users_id'] == getLoginUserID()) {
                     $opt = array('img' => $CFG_GLPI['root_doc'] . '/pics/edit.png', 'popup' => 'edit_user_notification&amp;id=' . $d['id']);
                     showToolTip($text, $opt);
                 }
             }
             if ($canedit) {
                 echo "&nbsp;<a href='" . $CFG_GLPI["root_doc"] . "/front/ticket.form.php?delete_user=delete_user&amp;id=" . $d['id'] . "&amp;tickets_id=" . $this->fields['id'] . "' title=\"" . $LANG['buttons'][6] . "\">\n                     <img src='" . $CFG_GLPI["root_doc"] . "/pics/delete.png'\n                     alt=\"" . $LANG['buttons'][6] . "\" title=\"" . $LANG['buttons'][6] . "\"></a>";
             }
             echo "<br>";
             $showuserlink = $save_showuserlink;
         }
     }
 }
Exemplo n.º 2
0
 /**
  * Try to get login of external auth method
  *
  * @param $authtype external auth type (default 0)
  *
  * @return boolean : user login success
  **/
 function getAlternateAuthSystemsUserLogin($authtype = 0)
 {
     global $CFG_GLPI;
     switch ($authtype) {
         case self::CAS:
             include GLPI_PHPCAS;
             phpCAS::client(CAS_VERSION_2_0, $CFG_GLPI["cas_host"], intval($CFG_GLPI["cas_port"]), $CFG_GLPI["cas_uri"], false);
             // no SSL validation for the CAS server
             phpCAS::setNoCasServerValidation();
             // force CAS authentication
             phpCAS::forceAuthentication();
             $this->user->fields['name'] = phpCAS::getUser();
             return true;
         case self::EXTERNAL:
             $ssovariable = Dropdown::getDropdownName('glpi_ssovariables', $CFG_GLPI["ssovariables_id"]);
             $login_string = '';
             // MoYo : checking REQUEST create a security hole for me !
             if (isset($_SERVER[$ssovariable])) {
                 $login_string = $_SERVER[$ssovariable];
             }
             //             else {
             //                $login_string = $_REQUEST[$ssovariable];
             //             }
             $login = $login_string;
             $pos = stripos($login_string, "\\");
             if (!$pos === false) {
                 $login = substr($login_string, $pos + 1);
             }
             if ($CFG_GLPI['existing_auth_server_field_clean_domain']) {
                 $pos = stripos($login, "@");
                 if (!$pos === false) {
                     $login = substr($login, 0, $pos);
                 }
             }
             if (self::isValidLogin($login)) {
                 $this->user->fields['name'] = $login;
                 // Get data from SSO if defined
                 $ret = $this->user->getFromSSO();
                 if (!$ret) {
                     return false;
                 }
                 return true;
             }
             break;
         case self::X509:
             // From eGroupWare  http://www.egroupware.org
             // an X.509 subject looks like:
             // CN=john.doe/OU=Department/O=Company/C=xx/Email=john@comapy.tld/L=City/
             $sslattribs = explode('/', $_SERVER['SSL_CLIENT_S_DN']);
             while ($sslattrib = next($sslattribs)) {
                 list($key, $val) = explode('=', $sslattrib);
                 $sslattributes[$key] = $val;
             }
             if (isset($sslattributes[$CFG_GLPI["x509_email_field"]]) && NotificationMail::isUserAddressValid($sslattributes[$CFG_GLPI["x509_email_field"]]) && self::isValidLogin($sslattributes[$CFG_GLPI["x509_email_field"]])) {
                 $restrict = false;
                 $CFG_GLPI["x509_ou_restrict"] = trim($CFG_GLPI["x509_ou_restrict"]);
                 if (!empty($CFG_GLPI["x509_ou_restrict"])) {
                     $split = explode('$', $CFG_GLPI["x509_ou_restrict"]);
                     if (!in_array($sslattributes['OU'], $split)) {
                         $restrict = true;
                     }
                 }
                 $CFG_GLPI["x509_o_restrict"] = trim($CFG_GLPI["x509_o_restrict"]);
                 if (!empty($CFG_GLPI["x509_o_restrict"])) {
                     $split = explode('$', $CFG_GLPI["x509_o_restrict"]);
                     if (!in_array($sslattributes['O'], $split)) {
                         $restrict = true;
                     }
                 }
                 $CFG_GLPI["x509_cn_restrict"] = trim($CFG_GLPI["x509_cn_restrict"]);
                 if (!empty($CFG_GLPI["x509_cn_restrict"])) {
                     $split = explode('$', $CFG_GLPI["x509_cn_restrict"]);
                     if (!in_array($sslattributes['CN'], $split)) {
                         $restrict = true;
                     }
                 }
                 if (!$restrict) {
                     $this->user->fields['name'] = $sslattributes[$CFG_GLPI["x509_email_field"]];
                     // Can do other things if need : only add it here
                     $this->user->fields['email'] = $this->user->fields['name'];
                     return true;
                 }
             }
             break;
     }
     return false;
 }
 function prepareInputForAdd($input)
 {
     global $LANG;
     if (isset($input["passwd"])) {
         if (empty($input["passwd"])) {
             unset($input["passwd"]);
         } else {
             $input["passwd"] = encrypt(stripslashes($input["passwd"]), GLPIKEY);
         }
     }
     if (isset($input['mail_server']) && !empty($input['mail_server'])) {
         $input["host"] = constructMailServerConfig($input);
     }
     if (!NotificationMail::isUserAddressValid($input['name'])) {
         addMessageAfterRedirect($LANG['mailing'][111] . ' : ' . $LANG['mailing'][110], false, ERROR);
     }
     return $input;
 }
Exemplo n.º 4
0
 echo __('Email followup') . '&nbsp;';
 $default_notif = true;
 if (isset($_POST['use_notification'][$user_index])) {
     $default_notif = $_POST['use_notification'][$user_index];
 }
 if (isset($_POST['alternative_email'][$user_index]) && !empty($_POST['alternative_email'][$user_index]) && empty($default_email)) {
     if (NotificationMail::isUserAddressValid($_POST['alternative_email'][$user_index])) {
         $default_email = $_POST['alternative_email'][$user_index];
     } else {
         throw new \RuntimeException('Invalid email provided!');
     }
 }
 $rand = Dropdown::showYesNo($_POST['field'] . '[use_notification][]', $default_notif);
 $email_string = '';
 // Only one email
 if (count($emails) == 1 && !empty($default_email) && NotificationMail::isUserAddressValid($default_email[$user_index])) {
     $email_string = $default_email[$user_index];
     // Clean alternative email
     echo "<input type='hidden' size='25' name='" . $_POST['field'] . "[alternative_email][]'\n             value=''>";
 } else {
     if (count($emails) > 1) {
         // Several emails : select in the list
         $emailtab = array();
         foreach ($emails as $new_email) {
             if ($new_email != $default_email) {
                 $emailtab[$new_email] = $new_email;
             } else {
                 $emailtab[''] = $new_email;
             }
         }
         $email_string = Dropdown::showFromArray($_POST['field'] . "[alternative_email][]", $emailtab, array('value' => '', 'display' => false));
Exemplo n.º 5
0
 /**
  * Try to get login of external auth method
  *
  * @param $authtype extenral auth type
  *
  * @return boolean : user login success
  **/
 function getAlternateAuthSystemsUserLogin($authtype = 0)
 {
     global $CFG_GLPI;
     switch ($authtype) {
         case self::CAS:
             include GLPI_PHPCAS;
             phpCAS::client(CAS_VERSION_2_0, $CFG_GLPI["cas_host"], intval($CFG_GLPI["cas_port"]), $CFG_GLPI["cas_uri"], false);
             // no SSL validation for the CAS server
             phpCAS::setNoCasServerValidation();
             // force CAS authentication
             phpCAS::forceAuthentication();
             $this->user->fields['name'] = phpCAS::getUser();
             return true;
         case self::EXTERNAL:
             $login_string = $_SERVER[$CFG_GLPI["existing_auth_server_field"]];
             $login = $login_string;
             $pos = stripos($login_string, "\\");
             if (!$pos === false) {
                 $login = substr($login_string, $pos + 1);
             }
             if ($CFG_GLPI['existing_auth_server_field_clean_domain']) {
                 $pos = stripos($login, "@");
                 if (!$pos === false) {
                     $login = substr($login, 0, $pos);
                 }
             }
             if (isValidLogin($login)) {
                 $this->user->fields['name'] = $login;
                 return true;
             }
             break;
         case self::X509:
             // From eGroupWare  http://www.egroupware.org
             // an X.509 subject looks like:
             // CN=john.doe/OU=Department/O=Company/C=xx/Email=john@comapy.tld/L=City/
             $sslattribs = explode('/', $_SERVER['SSL_CLIENT_S_DN']);
             while ($sslattrib = next($sslattribs)) {
                 list($key, $val) = explode('=', $sslattrib);
                 $sslattributes[$key] = $val;
             }
             if (isset($sslattributes[$CFG_GLPI["x509_email_field"]]) && NotificationMail::isUserAddressValid($sslattributes[$CFG_GLPI["x509_email_field"]]) && isValidLogin($sslattributes[$CFG_GLPI["x509_email_field"]])) {
                 $this->user->fields['name'] = $sslattributes[$CFG_GLPI["x509_email_field"]];
                 // Can do other things if need : only add it here
                 $this->user->fields['email'] = $this->user->fields['name'];
                 return true;
             }
             break;
     }
     return false;
 }
 function showFormMailServerConfig()
 {
     global $CFG_GLPI;
     echo "<form action='" . Toolbox::getItemTypeFormURL(__CLASS__) . "' method='post'>";
     echo "<div>";
     echo "<table class='tab_cadre_fixe'>";
     echo "<input type='hidden' name='id' value='1'>";
     echo "<tr class='tab_bg_1'><th colspan='4'>" . _n('Notification', 'Notifications', 2) . "</th></tr>";
     echo "<tr class='tab_bg_2'><td>" . __('Enable followup via email') . "</td><td>";
     Dropdown::showYesNo("use_mailing", $CFG_GLPI["use_mailing"]);
     echo "</td>";
     if ($CFG_GLPI['use_mailing']) {
         echo "<td colspan='2'></td></tr>";
         echo "<tr class='tab_bg_2'>";
         echo "<td>" . __('Administrator email') . "</td>";
         echo "<td><input type='text' name='admin_email' size='40' value='" . $CFG_GLPI["admin_email"] . "'>";
         if (!NotificationMail::isUserAddressValid($CFG_GLPI["admin_email"])) {
             echo "<span class='red'>&nbsp;" . __('Invalid email address') . "</span>";
         }
         echo "</td>";
         echo "<td >" . __('Administrator name') . "</td>";
         echo "<td><input type='text' name='admin_email_name' size='40' value='" . $CFG_GLPI["admin_email_name"] . "'>";
         echo " </td></tr>";
         echo "<tr class='tab_bg_2'>";
         echo "<td >" . __('Administrator reply-to email (if needed)') . "</td>";
         echo "<td><input type='text' name='admin_reply' size='40' value='" . $CFG_GLPI["admin_reply"] . "'>";
         if (!NotificationMail::isUserAddressValid($CFG_GLPI["admin_reply"])) {
             echo "<span class='red'>&nbsp;" . __('Invalid email address') . "</span>";
         }
         echo " </td>";
         echo "<td >" . __('Response address (if needed)') . "</td>";
         echo "<td><input type='text' name='admin_reply_name' size='40' value='" . $CFG_GLPI["admin_reply_name"] . "'>";
         echo " </td></tr>";
         if (!function_exists('mail')) {
             echo "<tr class='tab_bg_2'><td class='center' colspan='2'>";
             echo "<span class='red'>" . __('The PHP mail function is unknown or is not activated on your system.') . "</span><br>" . __('The use of a SMTP is needed.') . "</td></tr>";
         }
         echo "<tr class='tab_bg_2'>";
         echo "<td>" . __('Email signature') . "</td>";
         echo "<td colspan='3'><textarea cols='60' rows='3' name='mailing_signature'>" . $CFG_GLPI["mailing_signature"] . "</textarea></td></tr>";
         echo "<tr class='tab_bg_1'><th colspan='4'>" . __('Mail server') . "</th></tr>";
         echo "<tr class='tab_bg_2'><td>" . __('Way of sending emails') . "</td><td>";
         $mail_methods = array(MAIL_MAIL => __('PHP'), MAIL_SMTP => __('SMTP'), MAIL_SMTPSSL => __('SMTP+SSL'), MAIL_SMTPTLS => __('SMTP+TLS'));
         Dropdown::showFromArray("smtp_mode", $mail_methods, array('value' => $CFG_GLPI["smtp_mode"]));
         echo "</td><td colspan='2'>&nbsp;</td>";
         echo "</tr>";
         echo "<tr class='tab_bg_2'><td >" . __('SMTP host') . "</td>";
         echo "<td><input type='text' name='smtp_host' size='40' value='" . $CFG_GLPI["smtp_host"] . "'>";
         echo "</td>";
         echo "<td >" . __('SMTP login (optional)') . "</td>";
         echo "<td><input type='text' name='smtp_username' size='40' value='" . $CFG_GLPI["smtp_username"] . "'></td></tr>";
         //TRANS: SMTP port
         echo "<tr class='tab_bg_2'><td >" . __('Port') . "</td>";
         echo "<td><input type='text' name='smtp_port' size='5' value='" . $CFG_GLPI["smtp_port"] . "'>";
         echo "</td>";
         echo "<td >" . __('SMTP password (optional)') . "</td>";
         echo "<td><input type='password' name='smtp_passwd' size='40' value='' autocomplete='off'>";
         echo "<br><input type='checkbox' name='_blank_smtp_passwd'>&nbsp;" . __('Clear');
         echo "</td></tr>";
     } else {
         echo "<td colspan='2'></td></tr>";
     }
     $options['candel'] = false;
     if ($CFG_GLPI['use_mailing']) {
         $options['addbuttons'] = array('test_smtp_send' => __('Send a test email to the administrator'));
     }
     $this->showFormButtons($options);
 }
Exemplo n.º 7
0
 /**
  * Assign and actor in a ticket for an authenticated user
  *
  * @param $params    array of options (ticket, id2name)
  * @param $protocol        the communication protocol used
  *
  * @return array of hashtable as glpi.getTicket
  **/
 static function methodsetTicketAssign($params, $protocol)
 {
     global $DB, $CFG_GLPI;
     if (isset($params['help'])) {
         return array('ticket' => 'integer,mandatory', 'user' => 'integer,optional', 'supplier' => 'integer,optional', 'group' => 'integer,optional', 'user_email' => 'string,optional', 'use_email_notification' => 'bool,optional', 'help' => 'bool,optional');
     }
     if (!Session::getLoginUserID()) {
         return self::Error($protocol, WEBSERVICES_ERROR_NOTAUTHENTICATED);
     }
     if (!Session::haveRight("assign_ticket", "1")) {
         return self::Error($protocol, WEBSERVICES_ERROR_NOTALLOWED);
     }
     if (!isset($params['user']) && !isset($params['group']) && !isset($params['supplier'])) {
         return self::Error($protocol, WEBSERVICES_ERROR_MISSINGPARAMETER, '', 'user or group or supplier');
     }
     $ticket = new Ticket();
     if (!isset($params['ticket'])) {
         return self::Error($protocol, WEBSERVICES_ERROR_MISSINGPARAMETER, '', 'ticket');
     }
     if (!is_numeric($params['ticket'])) {
         return self::Error($protocol, WEBSERVICES_ERROR_BADPARAMETER, '', 'ticket=' . $params['ticket']);
     }
     if (!$ticket->can($params['ticket'], 'r')) {
         return self::Error($protocol, WEBSERVICES_ERROR_NOTFOUND);
     }
     if (!$ticket->getFromDB($params['ticket'])) {
         return self::Error($protocol, WEBSERVICES_ERROR_NOTFOUND, '', 'ticket');
     }
     $ticket_user = new Ticket_User();
     $user = array('tickets_id' => $params['ticket'], 'type' => CommonITILActor::ASSIGN);
     // technician : optionnal,  default = none
     if (isset($params['user'])) {
         if (!is_numeric($params['user'])) {
             return self::Error($protocol, WEBSERVICES_ERROR_BADPARAMETER, '', 'user');
         }
         $user['users_id'] = $params['user'];
         if ($ticket->getFromDB($params['ticket'])) {
             $entity = $ticket->getField('entities_id');
         }
         if (!$ticket_user->can(-1, 'w', $user) || !self::checkUserRights($params['user'], "own_ticket", 1, $entity)) {
             return self::Error($protocol, WEBSERVICES_ERROR_NOTALLOWED);
         }
         if ($ticket->isUser(CommonITILActor::ASSIGN, $user['users_id'])) {
             return self::Error($protocol, WEBSERVICES_ERROR_FAILED, '', 'User already assign for this ticket');
         }
         if (isset($params['user_email'])) {
             if (!NotificationMail::isUserAddressValid($params['user_email'])) {
                 return self::Error($protocol, WEBSERVICES_ERROR_BADPARAMETER, '', 'user_email');
             }
             $user['alternative_email'] = $params['user_email'];
             $user['use_notification'] = 1;
         } else {
             if (isset($params['use_email_notification']) && $params['use_email_notification']) {
                 $user['_additional_assigns'][] = array('users_id' => $params['user'], 'use_notification' => 1);
             } else {
                 if (isset($params['use_email_notification']) && !$params['use_email_notification']) {
                     $user['_additional_assigns'][] = array('users_id' => $params['user'], 'use_notification' => 0);
                 }
             }
         }
         if (!$ticket_user->add($user)) {
             return self::Error($protocol, WEBSERVICES_ERROR_FAILED, '', 'user not assign');
         }
     }
     // group (technicians group) : optionnal,  default = none
     $group_ticket = new Group_Ticket();
     $group = array('tickets_id' => $params['ticket'], 'type' => CommonITILActor::ASSIGN);
     if (isset($params['group'])) {
         if (!is_numeric($params['group'])) {
             return self::Error($protocol, WEBSERVICES_ERROR_BADPARAMETER, '', 'group');
         }
         $group['groups_id'] = $params['group'];
         if (!$group_ticket->can(-1, 'w', $group)) {
             return self::Error($protocol, WEBSERVICES_ERROR_NOTALLOWED);
         }
         if ($ticket->isGroup(CommonITILActor::ASSIGN, $params['group'])) {
             return self::Error($protocol, WEBSERVICES_ERROR_FAILED, '', 'Group already assign for this ticket');
         }
         if (!$group_ticket->add($group)) {
             return self::Error($protocol, WEBSERVICES_ERROR_FAILED, '', 'group not assign');
         }
     }
     // supplier to assign : optionnal,  default = none
     $supplier_ticket = new Supplier_Ticket();
     $supplier = array('tickets_id' => $params['ticket'], 'type' => CommonITILActor::ASSIGN);
     if (isset($params['supplier'])) {
         if (!is_numeric($params['supplier'])) {
             return self::Error($protocol, WEBSERVICES_ERROR_BADPARAMETER, '', 'supplier');
         }
         $supplier['suppliers_id'] = $params['supplier'];
         if (!$supplier_ticket->can(-1, 'w', $supplier)) {
             return self::Error($protocol, WEBSERVICES_ERROR_NOTALLOWED);
         }
         if ($ticket->isSupplier(CommonITILActor::ASSIGN, $params['supplier'])) {
             return self::Error($protocol, WEBSERVICES_ERROR_FAILED, '', 'Supplier already assign for this ticket');
         }
         if (!$supplier_ticket->add($supplier)) {
             return self::Error($protocol, WEBSERVICES_ERROR_FAILED, '', 'supplier not assign');
         }
     }
     return self::methodGetTicket(array('ticket' => $params['ticket']), $protocol);
     return self::Error($protocol, WEBSERVICES_ERROR_FAILED, '', self::getDisplayError());
 }
 /**
  * show tooltip for user notification information
  *
  * @param $type      integer  user type
  * @param $canedit   boolean  can edit ?
  * @param $options   array    options for default values ($options of showForm)
  *
  * @return nothing display
  **/
 function showUsersAssociated($type, $canedit, array $options = array())
 {
     global $CFG_GLPI;
     $showuserlink = 0;
     if (User::canView()) {
         $showuserlink = 2;
     }
     $usericon = self::getActorIcon('user', $type);
     $user = new User();
     $linkuser = new $this->userlinkclass();
     $itemtype = $this->getType();
     $typename = self::getActorFieldNameType($type);
     $candelete = true;
     $mandatory = '';
     // For ticket templates : mandatories
     if ($itemtype == 'Ticket' && isset($options['_tickettemplate'])) {
         $mandatory = $options['_tickettemplate']->getMandatoryMark("_users_id_" . $typename);
         if ($options['_tickettemplate']->isMandatoryField("_users_id_" . $typename) && isset($this->users[$type]) && count($this->users[$type]) == 1) {
             $candelete = false;
         }
     }
     if (isset($this->users[$type]) && count($this->users[$type])) {
         foreach ($this->users[$type] as $d) {
             $k = $d['users_id'];
             echo "{$mandatory}{$usericon}&nbsp;";
             if ($k) {
                 $userdata = getUserName($k, 2);
             } else {
                 $email = $d['alternative_email'];
                 $userdata = "<a href='mailto:{$email}'>{$email}</a>";
             }
             if ($k) {
                 $param = array('display' => false);
                 if ($showuserlink) {
                     $param['link'] = $userdata["link"];
                 }
                 echo $userdata['name'] . "&nbsp;" . Html::showToolTip($userdata["comment"], $param);
             } else {
                 echo $userdata;
             }
             if ($CFG_GLPI['use_mailing']) {
                 $text = __('Email followup') . "&nbsp;" . Dropdown::getYesNo($d['use_notification']) . '<br>';
                 if ($d['use_notification']) {
                     $uemail = $d['alternative_email'];
                     if (empty($uemail) && $user->getFromDB($d['users_id'])) {
                         $uemail = $user->getDefaultEmail();
                     }
                     $text .= sprintf(__('%1$s: %2$s'), __('Email'), $uemail);
                     if (!NotificationMail::isUserAddressValid($uemail)) {
                         $text .= "&nbsp;<span class='red'>" . __('Invalid email address') . "</span>";
                     }
                 }
                 echo "&nbsp;";
                 if ($canedit || $d['users_id'] == Session::getLoginUserID()) {
                     $opt = array('img' => $CFG_GLPI['root_doc'] . '/pics/edit.png', 'popup' => $linkuser->getFormURL() . "?id=" . $d['id']);
                     Html::showToolTip($text, $opt);
                 }
             }
             if ($canedit && $candelete) {
                 echo "&nbsp;";
                 Html::showSimpleForm($linkuser->getFormURL(), 'delete', _x('button', 'Delete permanently'), array('id' => $d['id']), $CFG_GLPI["root_doc"] . "/pics/delete.png");
             }
             echo "<br>";
         }
     }
 }
 function getOldAssignTechnicianAddress()
 {
     global $CFG_GLPI;
     if (isset($this->options['_old_user']) && $this->options['_old_user']['type'] == CommonITILActor::ASSIGN && $this->options['_old_user']['use_notification']) {
         $user = new User();
         $user->getFromDB($this->options['_old_user']['users_id']);
         $author_email = UserEmail::getDefaultForUser($user->fields['id']);
         $author_lang = $user->fields["language"];
         $author_id = $user->fields['id'];
         if (!empty($this->options['_old_user']['alternative_email']) && $this->options['_old_user']['alternative_email'] != $author_email && NotificationMail::isUserAddressValid($this->options['_old_user']['alternative_email'])) {
             $author_email = $this->options['_old_user']['alternative_email'];
         }
         if (empty($author_lang)) {
             $author_lang = $CFG_GLPI["language"];
         }
         if (empty($author_id)) {
             $author_id = -1;
         }
         $this->addToAddressesList(array('email' => $author_email, 'language' => $author_lang, 'users_id' => $author_id));
     }
 }
Exemplo n.º 10
0
// Purpose of file:
// ----------------------------------------------------------------------
$AJAX_INCLUDE = 1;
if (strpos($_SERVER['PHP_SELF'], "uemailUpdate.php")) {
    define('GLPI_ROOT', '..');
    include GLPI_ROOT . "/inc/includes.php";
    header("Content-Type: text/html; charset=UTF-8");
    header_nocache();
}
checkLoginUser();
// print_r($_REQUEST);
if (isset($_REQUEST['field']) && $_REQUEST["value"] > 0 || isset($_REQUEST['allow_email']) && $_REQUEST['allow_email']) {
    $user = new User();
    $email = "";
    if ($user->getFromDB($_REQUEST["value"])) {
        $email = $user->getField('email');
    }
    echo $LANG['job'][19] . '&nbsp;:&nbsp;';
    $default_notif = true;
    if (isset($_REQUEST['use_notification'])) {
        $default_notif = $_REQUEST['use_notification'];
    }
    $rand = Dropdown::showYesNo($_REQUEST['field'] . '[use_notification]', $default_notif);
    echo '<br>' . $LANG['mailing'][118] . "&nbsp;:&nbsp;";
    if (!empty($email) && NotificationMail::isUserAddressValid($email)) {
        echo $email;
    } else {
        echo "<input type='text' size='25' name='" . $_REQUEST['field'] . "[alternative_email]'\n            value='{$email}'>";
    }
}
commonDropdownUpdateItem($_POST);
Exemplo n.º 11
0
 $mmail = new NotificationMail();
 $query = "SELECT email FROM glpi_useremails WHERE users_id=" . $_SESSION['glpiID'];
 if ($result = $DB->query($query)) {
     if ($DB->numrows($result) > 0) {
         $row = $DB->fetch_assoc($result);
         $mmail->From = $row['email'];
         $mmail->FromName = $row['email'];
     }
 }
 $body = str_replace("\\r", "", str_replace("\\n", "\n", $_POST['body']));
 if ($_POST['users_id_ticketmail']) {
     $address = PluginTicketmailProfile::getEmail($_POST['users_id_ticketmail']);
 } else {
     $address = $_POST["address"];
 }
 if (!NotificationMail::isUserAddressValid($address)) {
     Session::addMessageAfterRedirect(__("Invalid email address"), false, ERROR);
 }
 $mmail->AddAddress($address, $address);
 $mmail->Subject = $_POST["subject"];
 $mmail->Body = $body;
 $mmail->MessageID = "GLPI-ticketmail" . time() . "." . rand() . "@" . php_uname('n');
 if (!$mmail->Send()) {
     Session::addMessageAfterRedirect(__("Your email could not be processed.\nIf the problem persists, contact the administrator"), false, ERROR);
 } else {
     Toolbox::logInFile("mail", sprintf(__('%1$s: %2$s'), sprintf(__('An email was sent to %s'), $address), $_POST["subject"] . "\n"));
     $changes[0] = 0;
     $changes[1] = $address;
     $changes[2] = $_POST['subject'];
     Log::history($_POST['id'], 'Ticket', $changes, 'PluginTicketmailProfile', Log::HISTORY_PLUGIN + 1024);
     Session::addMessageAfterRedirect(sprintf(__('An email was sent to %s'), $address));
 function showFormMailServerConfig()
 {
     global $LANG, $CFG_GLPI;
     echo "<div>";
     echo "<form action='" . getItemTypeFormURL(__CLASS__) . "' method='post'>";
     echo "<table class='tab_cadre_fixe'>";
     echo "<input type='hidden' name='id' value='1'>";
     echo "<tr class='tab_bg_1'><th colspan='4'>" . $LANG['setup'][704] . "</th></tr>";
     echo "<tr class='tab_bg_2'><td>" . $LANG['setup'][202] . "&nbsp;:</td><td>";
     Dropdown::showYesNo("use_mailing", $CFG_GLPI["use_mailing"]);
     echo "</td>";
     if ($CFG_GLPI['use_mailing']) {
         echo "<td >" . $LANG['setup'][227] . "&nbsp;:</td>";
         echo "<td><input type='text' name='url_base' size='40' value='" . $CFG_GLPI["url_base"] . "'>";
         echo "</td></tr>";
         echo "<tr class='tab_bg_2'>";
         echo "<td>" . $LANG['setup'][203] . "&nbsp;:</td>";
         echo "<td><input type='text' name='admin_email' size='40' value='" . $CFG_GLPI["admin_email"] . "'>";
         if (!NotificationMail::isUserAddressValid($CFG_GLPI["admin_email"])) {
             echo "<span class='red'>&nbsp;" . $LANG['mailing'][110] . "</span>";
         }
         echo "</td>";
         echo "<td >" . $LANG['setup'][208] . "&nbsp;:</td>";
         echo "<td><input type='text' name='admin_email_name' size='40' value='" . $CFG_GLPI["admin_email_name"] . "'>";
         echo " </td></tr>";
         echo "<tr class='tab_bg_2'>";
         echo "<td >" . $LANG['setup'][207] . "&nbsp;:</td>";
         echo "<td><input type='text' name='admin_reply' size='40' value='" . $CFG_GLPI["admin_reply"] . "'>";
         if (!NotificationMail::isUserAddressValid($CFG_GLPI["admin_reply"])) {
             echo "<span class='red'>&nbsp;" . $LANG['mailing'][110] . "</span>";
         }
         echo " </td>";
         echo "<td >" . $LANG['setup'][209] . "&nbsp;:</td>";
         echo "<td><input type='text' name='admin_reply_name' size='40' value='" . $CFG_GLPI["admin_reply_name"] . "'>";
         echo " </td></tr>";
         if (!function_exists('mail')) {
             echo "<tr class='tab_bg_2'><td class='center' colspan='2'>";
             echo "<span class='red'>" . $LANG['setup'][217] . "&nbsp;:</span>" . $LANG['setup'][218] . "</td></tr>";
         }
         echo "<tr class='tab_bg_2'>";
         echo "<td>" . $LANG['setup'][204] . "&nbsp;:</td>";
         echo "<td colspan='3'><textarea cols='60' rows='3' name='mailing_signature'>" . $CFG_GLPI["mailing_signature"] . "</textarea></td></tr>";
         echo "<tr class='tab_bg_1'><th colspan='4'>" . $LANG['setup'][660] . "</th></tr>";
         echo "<tr class='tab_bg_2'><td>" . $LANG['setup'][231] . "&nbsp;:</td><td>";
         $mail_methods = array(MAIL_MAIL => $LANG['setup'][650], MAIL_SMTP => $LANG['setup'][651], MAIL_SMTPSSL => $LANG['setup'][652], MAIL_SMTPTLS => $LANG['setup'][653]);
         Dropdown::showFromArray("smtp_mode", $mail_methods, array('value' => $CFG_GLPI["smtp_mode"]));
         echo "</td><td colspan='2' class='center'>";
         echo "<input class='submit' type='submit' name='test_smtp_send' value=\"" . $LANG['setup'][229] . "\">";
         echo "</td></tr>";
         echo "<tr class='tab_bg_2'><td >" . $LANG['setup'][232] . "&nbsp;:</td>";
         echo "<td><input type='text' name='smtp_host' size='40' value='" . $CFG_GLPI["smtp_host"] . "'>";
         echo "</td>";
         echo "<td >" . $LANG['setup'][234] . "&nbsp;:</td>";
         echo "<td><input type='text' name='smtp_username' size='40' value='" . $CFG_GLPI["smtp_username"] . "'></td></tr>";
         echo "<tr class='tab_bg_2'><td >" . $LANG['setup'][175] . "&nbsp;:</td>";
         echo "<td><input type='text' name='smtp_port' size='5' value='" . $CFG_GLPI["smtp_port"] . "'>";
         echo "</td>";
         echo "<td >" . $LANG['setup'][235] . "&nbsp;:</td>";
         echo "<td><input type='password' name='smtp_passwd' size='40' value='' autocomplete='off'>";
         echo "</td></tr>";
     } else {
         echo "</tr>";
     }
     $options['candel'] = false;
     $this->showFormButtons($options);
     /*
           echo "<tr class='tab_bg_2'><td class='center' colspan='4'>";
           echo "<input class='submit' type='submit' name='update' value='".$LANG['buttons'][2]."'>";
           echo "</td></tr>";
           echo "</table></form>";*/
 }
Exemplo n.º 13
0
 /**
  * Print the ticket user form for notification
  *
  * @param $ID integer ID of the item
  * @param $options array
  *
  * @return Nothing (display)
  **/
 function showForm($ID, $options = array())
 {
     global $CFG_GLPI, $LANG;
     $this->check($ID, 'w');
     echo "<br><form method='post' action='" . $CFG_GLPI['root_doc'] . "/front/popup.php'>";
     echo "<div class='center'>";
     echo "<table class='tab_cadre'>";
     echo "<tr class='tab_bg_2'><td>" . $LANG['job'][38] . "&nbsp;:</td>";
     echo "<td>";
     $ticket = new Ticket();
     if ($ticket->getFromDB($this->fields["tickets_id"])) {
         echo $ticket->getField('name');
     }
     echo "</td></tr>";
     $user = new User();
     $email = "";
     if ($user->getFromDB($this->fields["users_id"])) {
         $email = $user->getField('email');
     }
     echo "<tr class='tab_bg_2'><td>" . $LANG['common'][34] . "&nbsp;:</td>";
     echo "<td>" . $user->getName() . "</td></tr>";
     echo "<tr class='tab_bg_1'><td>" . $LANG['job'][19] . "&nbsp;:</td>";
     echo "<td>";
     Dropdown::showYesNo('use_notification', $this->fields['use_notification']);
     echo "</td></tr>";
     echo "<tr class='tab_bg_1'><td>" . $LANG['mailing'][118] . "&nbsp;:</td>";
     echo "<td>";
     if (!empty($email) && NotificationMail::isUserAddressValid($email)) {
         echo $email;
     } else {
         echo "<input type='text' size='40' name='alternative_email' value='" . $this->fields['alternative_email'] . "'>";
     }
     echo "</td></tr>";
     echo "<tr class='tab_bg_2'>";
     echo "<td class='center' colspan='2'>";
     echo "<input type='submit' name='update' value=\"" . $LANG['buttons'][7] . "\" class='submit'>";
     echo "<input type='hidden' name='id' value='{$ID}'>";
     echo "</td></tr>";
     echo "</table></div></form>";
 }
Exemplo n.º 14
0
 /**
  * Print the object user form for notification
  *
  * @param $ID              integer ID of the item
  * @param $options   array
  *
  * @return Nothing (display)
  **/
 function showUserNotificationForm($ID, $options = array())
 {
     global $CFG_GLPI;
     $this->check($ID, UPDATE);
     if (!isset($this->fields['users_id'])) {
         return false;
     }
     $item = new static::$itemtype_1();
     echo "<br><form method='post' action='" . $_SERVER['PHP_SELF'] . "'>";
     echo "<div class='center'>";
     echo "<table class='tab_cadre' width='80%'>";
     echo "<tr class='tab_bg_2'><td>" . $item->getTypeName(1) . "</td>";
     echo "<td>";
     if ($item->getFromDB($this->fields[static::getItilObjectForeignKey()])) {
         echo $item->getField('name');
     }
     echo "</td></tr>";
     $user = new User();
     $default_email = "";
     $emails = array();
     if ($user->getFromDB($this->fields["users_id"])) {
         $default_email = $user->getDefaultEmail();
         $emails = $user->getAllEmails();
     }
     echo "<tr class='tab_bg_2'><td>" . __('User') . "</td>";
     echo "<td>" . $user->getName() . "</td></tr>";
     echo "<tr class='tab_bg_1'><td>" . __('Email Followup') . "</td>";
     echo "<td>";
     Dropdown::showYesNo('use_notification', $this->fields['use_notification']);
     echo "</td></tr>";
     echo "<tr class='tab_bg_1'><td>" . __('Email') . "</td>";
     echo "<td>";
     if (count($emails) == 1 && !empty($default_email) && NotificationMail::isUserAddressValid($default_email)) {
         echo $default_email;
     } else {
         if (count($emails) > 1) {
             // Several emails : select in the list
             $emailtab = array();
             foreach ($emails as $new_email) {
                 if ($new_email != $default_email) {
                     $emailtab[$new_email] = $new_email;
                 } else {
                     $emailtab[''] = $new_email;
                 }
             }
             Dropdown::showFromArray("alternative_email", $emailtab, array('value' => $this->fields['alternative_email']));
         } else {
             echo "<input type='text' size='40' name='alternative_email' value='" . $this->fields['alternative_email'] . "'>";
         }
     }
     echo "</td></tr>";
     echo "<tr class='tab_bg_2'>";
     echo "<td class='center' colspan='2'>";
     echo "<input type='submit' name='update' value=\"" . _sx('button', 'Save') . "\" class='submit'>";
     echo "<input type='hidden' name='id' value='{$ID}'>";
     echo "</td></tr>";
     echo "</table></div>";
     Html::closeForm();
 }
Exemplo n.º 15
0
 /**
  * show tooltip for user notification information
  *
  * @param $type      integer  user type
  * @param $canedit   boolean  can edit ?
  *
  * @return nothing display
  **/
 function showUsersAssociated($type, $canedit)
 {
     global $CFG_GLPI;
     $showuserlink = 0;
     if (Session::haveRight('user', 'r')) {
         $showuserlink = 2;
     }
     $usericon = self::getActorIcon('user', $type);
     $user = new User();
     if (isset($this->users[$type]) && count($this->users[$type])) {
         foreach ($this->users[$type] as $d) {
             $k = $d['users_id'];
             echo "{$usericon}&nbsp;";
             if ($k) {
                 $userdata = getUserName($k, 2);
             } else {
                 $email = $d['alternative_email'];
                 $userdata = "<a href='mailto:{$email}'>{$email}</a>";
             }
             if ($k) {
                 $param = array('display' => false);
                 if ($showuserlink) {
                     $param['link'] = $userdata["link"];
                 }
                 echo $userdata['name'] . "&nbsp;" . Html::showToolTip($userdata["comment"], $param);
             } else {
                 echo $userdata;
             }
             if ($CFG_GLPI['use_mailing']) {
                 $text = __('Email followup') . "&nbsp;" . Dropdown::getYesNo($d['use_notification']) . '<br>';
                 if ($d['use_notification']) {
                     $uemail = $d['alternative_email'];
                     if (empty($uemail) && $user->getFromDB($d['users_id'])) {
                         $uemail = $user->getDefaultEmail();
                     }
                     $text .= sprintf(__('%1$s: %2$s'), __('Email'), $uemail);
                     if (!NotificationMail::isUserAddressValid($uemail)) {
                         $text .= "&nbsp;<span class='red'>" . __('Invalid email address') . "</span>";
                     }
                 }
                 echo "&nbsp;";
                 if ($canedit || $d['users_id'] == Session::getLoginUserID()) {
                     $opt = array('img' => $CFG_GLPI['root_doc'] . '/pics/edit.png', 'popup' => 'edit_user_notification&amp;itemtype=' . $this->getType() . '&amp;id=' . $d['id']);
                     Html::showToolTip($text, $opt);
                 }
             }
             if ($canedit) {
                 echo "&nbsp;";
                 Html::showSimpleForm($this->getFormURL(), 'delete_user', _x('button', 'Delete permanently'), array('id' => $d['id'], $this->getForeignKeyField() => $this->fields['id']), $CFG_GLPI["root_doc"] . "/pics/delete.png");
             }
             echo "<br>";
         }
     }
 }
Exemplo n.º 16
0
 /**
  * @see CommonDBTM::prepareInputForAdd()
  **/
 function prepareInputForAdd($input)
 {
     if (isset($input["passwd"])) {
         if (empty($input["passwd"])) {
             unset($input["passwd"]);
         } else {
             $input["passwd"] = Toolbox::encrypt(stripslashes($input["passwd"]), GLPIKEY);
         }
     }
     if (isset($input['mail_server']) && !empty($input['mail_server'])) {
         $input["host"] = Toolbox::constructMailServerConfig($input);
     }
     if (!NotificationMail::isUserAddressValid($input['name'])) {
         Session::addMessageAfterRedirect(__('Invalid email address'), false, ERROR);
     }
     return $input;
 }
Exemplo n.º 17
0
 /**
  * Get the reply to address
  *
  * @param $options   array
  *
  * @return the reply to address
  **/
 function getReplyTo($options = array())
 {
     global $DB, $CFG_GLPI;
     //If the entity administrator's address is defined, return it
     foreach ($DB->request('glpi_entities', array('id' => $this->getEntity())) as $data) {
         if (NotificationMail::isUserAddressValid($data['admin_reply'])) {
             return array('email' => $data['admin_reply'], 'name' => $data['admin_reply_name']);
         }
     }
     //Entity admin is not defined, return the global admin's address
     return array('email' => $CFG_GLPI['admin_reply'], 'name' => $CFG_GLPI['admin_reply_name']);
 }
Exemplo n.º 18
0
 /**
  * Send password recovery for a user.
  *
  * @param $email email of the user
  *
  * @return nothing : send email or display error message
  **/
 function forgetPassword($email)
 {
     global $CFG_GLPI;
     echo "<div class='center'>";
     if ($this->getFromDBbyEmail($email, "`glpi_users`.`is_active` AND NOT `glpi_users`.`is_deleted`")) {
         // Send token if auth DB or not external auth defined
         if ($this->fields["authtype"] == Auth::DB_GLPI || !Auth::useAuthExt()) {
             if (NotificationMail::isUserAddressValid($email)) {
                 $input['password_forget_token'] = sha1(Toolbox::getRandomString(30));
                 $input['password_forget_token_date'] = $_SESSION["glpi_currenttime"];
                 $input['id'] = $this->fields['id'];
                 $this->update($input);
                 // Notication on root entity (glpi_users.entities_id is only a pref)
                 NotificationEvent::raiseEvent('passwordforget', $this, array('entities_id' => 0));
                 _e('An email has been sent to your email address. The email contains information for reset your password.');
             } else {
                 _e('Invalid email address');
             }
         } else {
             _e("The authentication method configuration doesn't allow you to change your password.");
         }
     } else {
         _e('Email address not found.');
     }
     echo "<br>";
     echo "<a href=\"" . $CFG_GLPI['root_doc'] . "/index.php\">" . __s('Back') . "</a>";
     echo "</div>";
 }
Exemplo n.º 19
0
 /**
  * Send password recovery for a user.
  *
  * @param $email email of the user
  *
  * @return nothing : send email or display error message
  **/
 function forgetPassword($email)
 {
     global $LANG, $CFG_GLPI;
     echo "<div class='center'>";
     if ($this->getFromDBbyEmail($email)) {
         // Send token if auth DB or not external auth defined
         if ($this->fields["authtype"] == Auth::DB_GLPI || !Auth::useAuthExt()) {
             if (NotificationMail::isUserAddressValid($email)) {
                 $input['token'] = sha1(getRandomString(30));
                 $input['tokendate'] = $_SESSION["glpi_currenttime"];
                 $input['id'] = $this->fields['id'];
                 $this->update($input);
                 NotificationEvent::raiseEvent('passwordforget', $this);
                 echo $LANG['users'][10];
             } else {
                 echo $LANG['mailing'][110];
             }
         } else {
             echo $LANG['users'][9];
         }
     } else {
         echo $LANG['users'][8];
     }
     echo "<br>";
     echo "<a href=\"" . $CFG_GLPI['root_doc'] . "/index.php\">" . $LANG['buttons'][13] . "</a>";
     echo "</div>";
 }