Exemplo n.º 1
0
 static function form()
 {
     try {
         $anonymous = Variable::get('anonymous_setup');
     } catch (NoSuchVariableException $e) {
         $anonymous = true;
     }
     if (!Base_AclCommon::is_user() && Base_User_LoginCommon::is_banned()) {
         return self::t('You have exceeded the number of allowed login attempts.');
     }
     require_once 'modules/Libs/QuickForm/requires.php';
     if (!Base_AclCommon::is_user() && !$anonymous) {
         Base_User_LoginCommon::autologin();
     }
     if (!Base_AclCommon::is_user() && !$anonymous) {
         $get = count($_GET) ? '?' . http_build_query($_GET) : '';
         $form = new HTML_QuickForm('loginform', 'post', $_SERVER['PHP_SELF'] . $get);
         $form->setRequiredNote('<span style="font-size:80%; color:#ff0000;">*</span><span style="font-size:80%;">' . self::t('denotes required field') . '</span>');
         $form->addElement('text', 'username', self::t('Username'));
         $form->addRule('username', 'Field required', 'required');
         $form->addElement('password', 'password', self::t('Password'));
         $form->addRule('password', 'Field required', 'required');
         // register and add a rule to check if user is banned
         $form->registerRule('check_user_banned', 'callback', 'rule_login_banned', 'Base_User_LoginCommon');
         $form->addRule('username', self::t('You have exceeded the number of allowed login attempts.'), 'check_user_banned');
         // register and add a rule to check if user and password exists
         $form->registerRule('check_login', 'callback', 'submit_login', 'Base_User_LoginCommon');
         $form->addRule(array('username', 'password'), self::t('Login or password incorrect'), 'check_login', $form);
         $form->addElement('submit', null, self::t('Login'));
         if ($form->validate()) {
             $user = $form->exportValue('username');
             Base_AclCommon::set_user(Base_UserCommon::get_user_id($user), true);
             // redirect below is used to better browser refresh behavior.
             header('Location: ' . $_SERVER['REQUEST_URI']);
         } else {
             return "<center>" . $form->toHtml() . "</center>";
         }
     }
 }
Exemplo n.º 2
0
 public static function telegram()
 {
     $tokens = DB::GetAssoc('SELECT token,single_cache_uid FROM base_notify WHERE telegram=1 AND single_cache_uid is not null');
     if (!$tokens) {
         return;
     }
     $ret = array();
     $map = array();
     $refresh_time = time();
     $notified_cache = array();
     foreach ($tokens as $token => $uid) {
         $msgs = array();
         if (Base_NotifyCommon::is_refresh_due_telegram($token)) {
             Base_AclCommon::set_user($uid);
             $notified_cache[$token] = array();
             $notifications = Base_NotifyCommon::get_notifications($token);
             foreach ($notifications as $module => $module_new_notifications) {
                 foreach ($module_new_notifications as $id => $message) {
                     $notified_cache[$token][$module][] = $id;
                     $title = EPESI . ' ' . Base_NotifyCommon::strip_html($message['title']);
                     $body = Base_NotifyCommon::strip_html($message['body']);
                     //$icon = Base_NotifyCommon::get_icon($module, $message);
                     $msgs[] = array('title' => $title, 'body' => $body);
                 }
             }
         }
         $remote_token = md5($uid . '#' . Base_UserCommon::get_user_login($uid) . '#' . $token);
         $ret[$remote_token] = $msgs ? $msgs : '0';
         $map[$remote_token] = $token;
     }
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL, "https://telegram.epesicrm.com/");
     curl_setopt($ch, CURLOPT_POST, 1);
     curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($ret));
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     $status = curl_exec($ch);
     curl_close($ch);
     $status = @json_decode($status);
     if (is_array($status)) {
         foreach ($status as $remove) {
             if (isset($map[$remove])) {
                 DB::Execute('UPDATE base_notify SET telegram=0 WHERE token=%s', array($map[$remove]));
                 unset($notified_cache[$map[$remove]]);
             }
         }
         foreach ($notified_cache as $token => $nc) {
             Base_NotifyCommon::set_notified_cache($nc, $token, $refresh_time);
         }
     }
 }