-
Notifications
You must be signed in to change notification settings - Fork 44
/
cron.php
103 lines (82 loc) · 3.37 KB
/
cron.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<?php
// SSO Server Cron interface.
// (C) 2014 CubicleSoft. All Rights Reserved.
define("SSO_FILE", 1);
if (!isset($_SERVER["argc"]) || !$_SERVER["argc"])
{
echo "This file is intended to be run from the command-line.";
exit();
}
// Temporary root.
$rootpath = str_replace("\\", "/", dirname(__FILE__));
require_once $rootpath . "/config.php";
require_once SSO_ROOT_PATH . "/" . SSO_SUPPORT_PATH . "/debug.php";
require_once SSO_ROOT_PATH . "/" . SSO_SUPPORT_PATH . "/cli.php";
require_once SSO_ROOT_PATH . "/" . SSO_SUPPORT_PATH . "/str_basics.php";
require_once SSO_ROOT_PATH . "/" . SSO_SUPPORT_PATH . "/page_basics.php";
require_once SSO_ROOT_PATH . "/" . SSO_SUPPORT_PATH . "/sso_functions.php";
require_once SSO_ROOT_PATH . "/" . SSO_SUPPORT_PATH . "/random.php";
$sso_start = microtime(true);
SetDebugLevel();
// Process the command-line options.
$options = array(
"shortmap" => array(
"d" => "debug",
"v" => "verbose",
"?" => "help"
),
"rules" => array(
"debug" => array("arg" => false),
"verbose" => array("arg" => false),
"help" => array("arg" => false)
)
);
$sso_args = CLI::ParseCommandLine($options);
if (count($sso_args["params"]) != 0 || isset($sso_args["opts"]["help"]))
{
echo "SSO Server Cron Interface\n";
echo "Purpose: Run cleanup operations that need to be executed periodically.\n";
echo "\n";
echo "Syntax: " . $args["file"] . " [options]\n";
echo "Options:\n";
echo "\t-d Output debugging information.\n";
echo "\t-v Verbose output.\n";
echo "\t-? This help documentation.\n";
exit();
}
$sso_debug = isset($sso_args["opts"]["debug"]);
$sso_verbose = isset($sso_args["opts"]["verbose"]);
// Initialize language settings.
BB_InitLangmap(SSO_ROOT_PATH . "/" . SSO_LANG_PATH . "/", SSO_DEFAULT_LANG);
BB_SetLanguage(SSO_ROOT_PATH . "/" . SSO_LANG_PATH . "/", SSO_ADMIN_LANG);
// Initialize the global CSPRNG instance.
$sso_rng = new CSPRNG();
// Connect to the database and generate database globals.
SSO_DBConnect(true);
// Load in fields without admin select.
SSO_LoadFields(false);
// Load in $sso_settings and initialize it.
SSO_LoadSettings();
// Get system clock drift.
$sso_clockdrift = (isset($sso_settings[""]["clock_drift"]) ? $sso_settings[""]["clock_drift"] : 300);
// Allow developers to inject code here.
if (file_exists(SSO_ROOT_PATH . "/cron_hook.php")) require_once SSO_ROOT_PATH . "/cron_hook.php";
// Run cleanup queries.
try
{
$sso_db->Query("DELETE", array($sso_db_temp_sessions, "WHERE" => "updated < ?"), CSDB::ConvertToDBTime(time() - 60 * 60));
$sso_db->Query("DELETE", array($sso_db_temp_sessions, "WHERE" => "heartbeat = ? AND updated < ?"), SSO_HEARTBEAT_LIMIT, CSDB::ConvertToDBTime(time() - $sso_clockdrift));
$sso_db->Query("DELETE", array($sso_db_user_sessions, "WHERE" => "updated < ?"), CSDB::ConvertToDBTime(time() - $sso_clockdrift));
$sso_db->Query("DELETE", array($sso_db_ipcache, "WHERE" => "created < ?"), CSDB::ConvertToDBTime(time() - 24 * 60 * 60 * $sso_settings[""]["iprestrict"]["ip_cache_len"]));
}
catch (Exception $e)
{
echo "Database query error. " . $e->getMessage() . "\n\n";
}
if ($sso_verbose)
{
echo "Time taken: " . number_format(microtime(true) - $sso_start, 2) . " sec\n";
if (function_exists("memory_get_peak_usage")) echo "Maximum RAM used: " . number_format(memory_get_peak_usage(), 0) . "\n";
echo "Done.\n";
}
?>