+++ /dev/null
-<?php
-/*=====================================================================*\
-|| ###################################################################
-|| # Bugdar
-|| # Copyright (c) 2010 Blue Static
-|| #
-|| # This program is free software; you can redistribute it and/or modify
-|| # it under the terms of the GNU General Public License as published by
-|| # the Free Software Foundation; version 2 of the License.
-|| #
-|| # This program is distributed in the hope that it will be useful, but
-|| # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
-|| # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
-|| # more details.
-|| #
-|| # You should have received a copy of the GNU General Public License along
-|| # with this program; if not, write to the Free Software Foundation, Inc.,
-|| # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
-|| ###################################################################
-\*=====================================================================*/
-
-require_once('./global.php');
-require_once('./includes/api_user.php');
-require_once('./includes/class_api_error.php');
-
-APIError(array(new API_Error_Handler($admin), 'admin_error'));
-
-NavLinks::usersPages();
-$navigator->set_focus('tab', 'users', null);
-
-if (!can_perform('canadminusers'))
-{
- admin_login();
-}
-
-$thirty_days_ago = time() - (60 * 60 * 24 * 30);
-$query = "
- SELECT user.displayname, user.userid, user.email, useractivation.activator, useractivation.dateline FROM " . TABLE_PREFIX . "user AS user
- LEFT JOIN " . TABLE_PREFIX . "useractivation AS useractivation
- ON (user.userid = useractivation.userid)
- WHERE user.usergroupid = 3
- OR useractivation.dateline <= $thirty_days_ago";
-
-// ###################################################################
-
-if (empty($_REQUEST['do']))
-{
- $_REQUEST['do'] = 'modify';
-}
-
-// ###################################################################
-
-if ($_REQUEST['do'] == 'kill')
-{
- $users = $db->query($query);
- while ($user = $db->fetch_array($users))
- {
- $data = new UserAPI($bugsys);
- $data->set('userid', $user['userid']);
- $data->set_condition();
- $data->delete();
- }
-
- $admin->redirect('purge_inactive.php');
-}
-
-// ###################################################################
-
-if ($_REQUEST['do'] == 'delete')
-{
- $admin->page_confirm(T('Are you sure you want to remove all users who within the past thirty days have not verified their accounts via email?'), 'purge_inactive.php', 'kill', array());
-}
-
-// ###################################################################
-
-if ($_REQUEST['do'] == 'modify')
-{
- NavLinks::usersAdd();
-
- LoadPaginationFramework();
- $pagination->setBitProcessor('AdminPageNavigatorBitCallback');
- $pagination->setNavigatorProcessor('AdminPageNavigatorCallback');
-
- $admin->page_start(T('Inactive Users'));
- $admin->table_start();
- $admin->table_head(T('Users Awaiting Email Confirmation for more than 30 Days'), 4);
- $admin->table_column_head(array(T('Display Name'), T('Email'), T('User ID'), T('Actions')));
-
- $count = $db->query_first("SELECT COUNT(*) AS count FROM ($query) AS inactive");
- $pagination->setTotal($count['count']);
- $pagination->splitPages();
-
- $users = $db->query("
- $query
- ORDER BY userid ASC LIMIT " . $pagination->fetchLimit($pagination->getPage() - 1) . ", " . $pagination->getPerPage()
- );
- while ($user = $db->fetch_array($users))
- {
- $admin->row_multi_item(array(
- $user['displayname'] => 'l',
- $user['email'] => 'c',
- $user['userid'] => 'c',
- '<a href="user.php?do=edit&userid=' . $user['userid'] . '">[' . T('Edit') . ']</a>' => 'c'
- ));
- }
-
- $admin->row_tfoot('<a href="purge_inactive.php?do=delete">[Remove All]</a>', 4);
-
- $admin->table_end();
-
- $admin->page_code($pagination->constructPageNav('purge_inactive.php'));
-
- $admin->page_end();
-}
--- /dev/null
+<?php
+/*=====================================================================*\
+|| ###################################################################
+|| # Bugdar
+|| # Copyright (c)2020 Blue Static
+|| # This program is free software; you can redistribute it and/or modify
+|| # it under the terms of the GNU General Public License as published by
+|| # the Free Software Foundation; version 2 of the License.
+|| #
+|| # This program is distributed in the hope that it will be useful, but
+|| # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+|| # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+|| # more details.
+|| #
+|| # You should have received a copy of the GNU General Public License along
+|| # with this program; if not, write to the Free Software Foundation, Inc.,
+|| # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+|| ###################################################################
+\*=====================================================================*/
+
+define('NO_TEMPLATES', true);
+
+require_once('./global.php');
+
+$jobs = [
+ 'admin_session' => [
+ 'time' => 60 * 60 * 1.5,
+ 'function' => 'CronAdminSession',
+ ],
+ 'awaiting_email_confirmation' => [
+ 'time' => 60 * 60 * 24 * 3,
+ 'function' => 'CronPurgeInactiveUsers',
+ ],
+];
+
+// List of cron jobs to remove.
+$remove = [];
+
+$update_query = bugdar::$db->prepare("
+ INSERT INTO " . TABLE_PREFIX . "cron
+ (name, lastrun)
+ VALUES
+ (:name, :lastrun)
+ ON DUPLICATE KEY
+ UPDATE lastrun = :lastrun
+");
+
+// Filter the |$jobs| array, removing jobs that do not need to run.
+$last_runs = bugdar::$db->query("SELECT * FROM " . TABLE_PREFIX . "cron");
+while ($last_run = $last_runs->fetch()) {
+ $name = $last_run['name'];
+ if (!isset($jobs[$name])) {
+ $remove[] = $name;
+ continue;
+ }
+
+ $earliest_run_time = TIMENOW - $jobs[$name]['time'];
+ if ($earliest_run_time < $last_run['lastrun']) {
+ unset($jobs[$name]);
+ }
+}
+
+// Run the jobs.
+$jobs_run = 0;
+foreach ($jobs as $name => $job) {
+ require("./includes/cron/$name.php");
+ $job['function']();
+
+ $update_query->execute([
+ 'name' => $name,
+ 'lastrun' => TIMENOW,
+ ]);
+
+ ++$jobs_run;
+}
+
+// Remove stale jobs.
+if (count($remove)) {
+ $remove_query = bugdar::$db->prepare("DELETE FROM " . TABLE_PREFIX . "cron WHERE name = ?");
+ foreach ($remove as $remove) {
+ $remove_query->execute([ $remove ]);
+ }
+}
+
+header('Content-Type: application/json');
+echo '(' . json_encode([ 'jobsRun' => $jobs_run ]) . ')';
## SVN $Id$
+CREATE TABLE cron (
+ name VARCHAR(255) PRIMARY KEY,
+ lastrun int
+);
$navigator->add_component('link', 'users-pages-users', 'users-pages', T('Users'), 'user.php');
$navigator->add_component('link', 'users-pages-usergroups', 'users-pages', T('Usergroups'), 'usergroup.php');
$navigator->add_component('link', 'users-pages-permissions', 'users-pages', T('Product-Level Permissions'), 'permission.php');
- $navigator->add_component('link', 'users-pages-purge', 'users-pages', T('Purge Inactive Users'), 'purge_inactive.php');
}
// ###################################################################
--- /dev/null
+<?php
+/*=====================================================================*\
+|| ###################################################################
+|| # Bugdar
+|| # Copyright (c)2020 Blue Static
+|| # This program is free software; you can redistribute it and/or modify
+|| # it under the terms of the GNU General Public License as published by
+|| # the Free Software Foundation; version 2 of the License.
+|| #
+|| # This program is distributed in the hope that it will be useful, but
+|| # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+|| # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+|| # more details.
+|| #
+|| # You should have received a copy of the GNU General Public License along
+|| # with this program; if not, write to the Free Software Foundation, Inc.,
+|| # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+|| ###################################################################
+\*=====================================================================*/
+
+function CronAdminSession()
+{
+ bugdar::$db->exec("DELETE FROM " . TABLE_PREFIX . "adminsession WHERE dateline < " . (TIMENOW - 3600));
+}
--- /dev/null
+<?php
+/*=====================================================================*\
+|| ###################################################################
+|| # Bugdar
+|| # Copyright (c)2020 Blue Static
+|| # This program is free software; you can redistribute it and/or modify
+|| # it under the terms of the GNU General Public License as published by
+|| # the Free Software Foundation; version 2 of the License.
+|| #
+|| # This program is distributed in the hope that it will be useful, but
+|| # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+|| # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+|| # more details.
+|| #
+|| # You should have received a copy of the GNU General Public License along
+|| # with this program; if not, write to the Free Software Foundation, Inc.,
+|| # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+|| ###################################################################
+\*=====================================================================*/
+
+require_once('./includes/api_user.php');
+
+function CronPurgeInactiveUsers()
+{
+ $thirty_days_ago = TIMENOW - (60 * 60 * 24 * 30);
+ $inactive_users = bugdar::$db->query("
+ SELECT user.displayname, user.userid, user.email,
+ useractivation.activator, useractivation.dateline
+ FROM " . TABLE_PREFIX . "user AS user
+ LEFT JOIN " . TABLE_PREFIX . "useractivation AS useractivation
+ ON (user.userid = useractivation.userid)
+ WHERE user.usergroupid = 3
+ AND useractivation.dateline <= $thirty_days_ago
+ ");
+ while ($user = $inactive_users->fetch()) {
+ $data = new UserAPI($bugsys);
+ $data->set('userid', $user['userid']);
+ $data->set_condition();
+ $data->delete();
+ }
+}
if ($_POST['do'] == 'cplogin')
{
$hash = $funct->rand(90);
- $db->query("DELETE FROM " . TABLE_PREFIX . "adminsession WHERE dateline < " . (TIMENOW - 3600));
$db->query("INSERT INTO " . TABLE_PREFIX . "adminsession (sessionid, userid, dateline) VALUES ('$hash', " . $auth->bugdarUser['userid'] . ", " . TIMENOW . ")");
$funct->cookie(COOKIE_PREFIX . 'adminsession', $hash, false);
}
<div>{@"Powered by Bugdar"}, {@"Copyright"} ©2002 - $year Blue Static</div>
</div>
+<script src="cron.php" async></script>
+
</body>
-</html>
\ No newline at end of file
+</html>