81beec2b1920ee17ab0fe9d758a2c26169479687
[mailer.git] / inc / filter / admins_filter.php
1 <?php
2 /************************************************************************
3  * Mailer v0.2.1-FINAL                                Start: 06/02/2011 *
4  * ===================                          Last change: 06/02/2011 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : _filter.php                                      *
8  * -------------------------------------------------------------------- *
9  * Short description : Filters for ext-                                 *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Filter fuer ext-                                 *
12  * -------------------------------------------------------------------- *
13  * $Revision::                                                        $ *
14  * $Date::                                                            $ *
15  * $Tag:: 0.2.1-FINAL                                                 $ *
16  * $Author::                                                          $ *
17  * -------------------------------------------------------------------- *
18  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
19  * Copyright (c) 2009 - 2011 by Mailer Developer Team                   *
20  * For more information visit: http://www.mxchange.org                  *
21  *                                                                      *
22  * This program is free software; you can redistribute it and/or modify *
23  * it under the terms of the GNU General Public License as published by *
24  * the Free Software Foundation; either version 2 of the License, or    *
25  * (at your option) any later version.                                  *
26  *                                                                      *
27  * This program is distributed in the hope that it will be useful,      *
28  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
29  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
30  * GNU General Public License for more details.                         *
31  *                                                                      *
32  * You should have received a copy of the GNU General Public License    *
33  * along with this program; if not, write to the Free Software          *
34  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
35  * MA  02110-1301  USA                                                  *
36  ************************************************************************/
37
38 // Some security stuff...
39 if (!defined('__SECURITY')) {
40         die();
41 } // END - if
42
43 // Filter for adding extra data to the query
44 function FILTER_ADD_EXTRA_SQL_DATA ($add = '') {
45         // Is the admins extension updated? (should be!)
46         if (isExtensionInstalledAndNewer('admins', '0.3.0')) $add .= ', `default_acl` AS def_acl';
47         if (isExtensionInstalledAndNewer('admins', '0.6.7')) $add .= ', `la_mode`';
48         if (isExtensionInstalledAndNewer('admins', '0.7.2')) $add .= ', `login_failures`, UNIX_TIMESTAMP(`last_failure`) AS last_failure';
49         if (isExtensionInstalledAndNewer('admins', '0.7.3')) $add .= ', `expert_settings`, `expert_warning`';
50
51         // Return it
52         return $add;
53 }
54
55 // Reset the login failures
56 function FILTER_RESET_ADMINS_LOGIN_FAILURES ($data) {
57         // Store it in session
58         setSession('mailer_admin_failures'    , getAdminLoginFailures($data['id']));
59         setSession('mailer_admin_last_failure', getAdminLastFailure($data['id']));
60
61         // Prepare update data
62         $postData['login'][getCurrentAdminId()]          = $data['login'];
63         $postData['login_failures'][getCurrentAdminId()] = '0';
64         $postData['last_failure'][getCurrentAdminId()]   = null;
65
66         // Change it in the admin
67         adminsChangeAdminAccount($postData);
68
69         // Always make sure the cache is destroyed
70         rebuildCache('admin');
71
72         // Return the data for further processing
73         return $data;
74 }
75
76 // Count the login failure
77 function FILTER_COUNT_ADMINS_LOGIN_FAILURE ($data) {
78         // Prepare update data
79         $postData['login'][getCurrentAdminId()]          = $data['login'];
80         $postData['login_failures'][getCurrentAdminId()] = '`login_failures`+1';
81         $postData['last_failure'][getCurrentAdminId()]   = 'NOW()';
82
83         // Change it in the admin
84         adminsChangeAdminAccount($postData);
85
86         // Always make sure the cache is destroyed
87         rebuildCache('admin');
88
89         // Return the data for further processing
90         return $data;
91 }
92
93 // Rehashes the given plain admin password and stores it the database
94 function FILTER_REHASH_ADMINS_PASSWORD ($data) {
95         // Generate new hash
96         $newHash = generateHash($data['plain_pass']);
97
98         // Prepare update data
99         $postData['login'][getCurrentAdminId()]    = $data['login'];
100         $postData['password'][getCurrentAdminId()] = $newHash;
101
102         // Change it in the admin
103         adminsChangeAdminAccount($postData);
104
105         // Update cookie/session and data array
106         setAdminMd5(encodeHashForCookie($newHash));
107         $data['pass_hash'] = $newHash;
108
109         // Always make sure the cache is destroyed
110         rebuildCache('admin');
111
112         // Return the data for further processing
113         return $data;
114 }
115
116 // [EOF]
117 ?>