Updated copyright notice as there are changes in this year
[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 - 2013 by Mailer Developer Team                   *
20  * For more information visit: http://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         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Called!');
47         if (isExtensionInstalledAndNewer('admins', '0.3.0')) $add .= ',`default_acl`';
48         if (isExtensionInstalledAndNewer('admins', '0.6.7')) $add .= ',`la_mode`';
49         if (isExtensionInstalledAndNewer('admins', '0.7.2')) $add .= ',`login_failures`,UNIX_TIMESTAMP(`last_failure`) AS `last_failure`';
50         if (isExtensionInstalledAndNewer('admins', '0.7.3')) $add .= ',`expert_settings`, `expert_warning`';
51
52         // Return it
53         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Done!');
54         return $add;
55 }
56
57 // Reset the login failures
58 function FILTER_RESET_ADMINS_LOGIN_FAILURES ($filterData) {
59         // Store it in session
60         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Called!');
61         setSession('mailer_admin_failures'    , getAdminLoginFailures($filterData['id']));
62         setSession('mailer_admin_last_failure', getAdminLastFailure($filterData['id']));
63
64         // Prepare update data
65         $postData['login'][getCurrentAdminId()]          = $filterData['login'];
66         $postData['login_failures'][getCurrentAdminId()] = '0';
67         $postData['last_failure'][getCurrentAdminId()]   = NULL;
68
69         // Change it in the admin
70         adminsChangeAdminAccount($postData);
71
72         // Always make sure the cache is destroyed
73         rebuildCache('admin');
74
75         // Return the data for further processing
76         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Done!');
77         return $filterData;
78 }
79
80 // Count the login failure
81 function FILTER_COUNT_ADMINS_LOGIN_FAILURE ($filterData) {
82         // Prepare update data
83         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Called!');
84         $postData['login'][getCurrentAdminId()]          = $filterData['login'];
85         $postData['login_failures'][getCurrentAdminId()] = '`login_failures`+1';
86         $postData['last_failure'][getCurrentAdminId()]   = 'NOW()';
87
88         // Change it in the admin
89         adminsChangeAdminAccount($postData);
90
91         // Always make sure the cache is destroyed
92         rebuildCache('admin');
93
94         // Return the data for further processing
95         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Done!');
96         return $filterData;
97 }
98
99 // Rehashes the given plain admin password and stores it the database
100 function FILTER_REHASH_ADMINS_PASSWORD ($filterData) {
101         // Generate new hash
102         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Called!');
103         $newHash = generateHash($filterData['plain_pass']);
104
105         // Prepare update data
106         $postData['login'][getCurrentAdminId()]    = $filterData['login'];
107         $postData['password'][getCurrentAdminId()] = $newHash;
108
109         // Change it in the admin
110         adminsChangeAdminAccount($postData);
111
112         // Update cookie/session and data array
113         setAdminMd5(encodeHashForCookie($newHash));
114         $filterData['pass_hash'] = $newHash;
115
116         // Always make sure the cache is destroyed
117         rebuildCache('admin');
118
119         // Return the data for further processing
120         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Done!');
121         return $filterData;
122 }
123
124 // [EOF]
125 ?>