function scheduled_daily_maintenance() { global $smcFunc, $modSettings, $sourcedir, $db_type; // First clean out the cache. clean_cache(); // If warning decrement is enabled and we have people who have not had a new warning in 24 hours, lower their warning level. list(, , $modSettings['warning_decrement']) = explode(',', $modSettings['warning_settings']); if ($modSettings['warning_decrement']) { // Find every member who has a warning level... $request = $smcFunc['db_query']('', ' SELECT id_member, warning FROM {db_prefix}members WHERE warning > {int:no_warning}', array('no_warning' => 0)); $members = array(); while ($row = $smcFunc['db_fetch_assoc']($request)) { $members[$row['id_member']] = $row['warning']; } $smcFunc['db_free_result']($request); // Have some members to check? if (!empty($members)) { // Find out when they were last warned. $request = $smcFunc['db_query']('', ' SELECT id_recipient, MAX(log_time) AS last_warning FROM {db_prefix}log_comments WHERE id_recipient IN ({array_int:member_list}) AND comment_type = {string:warning} GROUP BY id_recipient', array('member_list' => array_keys($members), 'warning' => 'warning')); $member_changes = array(); while ($row = $smcFunc['db_fetch_assoc']($request)) { // More than 24 hours ago? if ($row['last_warning'] <= time() - 86400) { $member_changes[] = array('id' => $row['id_recipient'], 'warning' => $members[$row['id_recipient']] >= $modSettings['warning_decrement'] ? $members[$row['id_recipient']] - $modSettings['warning_decrement'] : 0); } } $smcFunc['db_free_result']($request); // Have some members to change? if (!empty($member_changes)) { foreach ($member_changes as $change) { $smcFunc['db_query']('', ' UPDATE {db_prefix}members SET warning = {int:warning} WHERE id_member = {int:id_member}', array('warning' => $change['warning'], 'id_member' => $change['id'])); } } } } // Do any spider stuff. if (!empty($modSettings['spider_mode']) && $modSettings['spider_mode'] > 1) { require_once $sourcedir . '/ManageSearchEngines.php'; consolidateSpiderStats(); } // Check the database version - for some buggy MySQL version. $server_version = $smcFunc['db_server_info'](); if ($db_type == 'mysql' && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51'))) { updateSettings(array('db_mysql_group_by_fix' => '1')); } elseif (!empty($modSettings['db_mysql_group_by_fix'])) { $smcFunc['db_query']('', ' DELETE FROM {db_prefix}settings WHERE variable = {string:mysql_fix}', array('mysql_fix' => 'db_mysql_group_by_fix')); } // Regenerate the Diffie-Hellman keys if OpenID is enabled. if (!empty($modSettings['enableOpenID'])) { require_once $sourcedir . '/Subs-OpenID.php'; smf_openID_setup_DH(true); } elseif (!empty($modSettings['dh_keys'])) { $smcFunc['db_query']('', ' DELETE FROM {db_prefix}settings WHERE variable = {string:dh_keys}', array('dh_keys' => 'dh_keys')); } // Log we've done it... return true; }
function scheduled_daily_maintenance() { global $modSettings, $sourcedir, $db_type; // First clean out the cache. clean_cache(); // If warning decrement is enabled and we have people who have not had a new warning in 24 hours, lower their warning level. list(, , $modSettings['warning_decrement']) = explode(',', $modSettings['warning_settings']); if ($modSettings['warning_decrement']) { // Find every member who has a warning level... $request = smf_db_query(' SELECT id_member, warning FROM {db_prefix}members WHERE warning > {int:no_warning}', array('no_warning' => 0)); $members = array(); while ($row = mysql_fetch_assoc($request)) { $members[$row['id_member']] = $row['warning']; } mysql_free_result($request); // Have some members to check? if (!empty($members)) { // Find out when they were last warned. $request = smf_db_query(' SELECT id_recipient, MAX(log_time) AS last_warning FROM {db_prefix}log_comments WHERE id_recipient IN ({array_int:member_list}) AND comment_type = {string:warning} GROUP BY id_recipient', array('member_list' => array_keys($members), 'warning' => 'warning')); $member_changes = array(); while ($row = mysql_fetch_assoc($request)) { // More than 24 hours ago? if ($row['last_warning'] <= time() - 86400) { $member_changes[] = array('id' => $row['id_recipient'], 'warning' => $members[$row['id_recipient']] >= $modSettings['warning_decrement'] ? $members[$row['id_recipient']] - $modSettings['warning_decrement'] : 0); } } mysql_free_result($request); // Have some members to change? if (!empty($member_changes)) { foreach ($member_changes as $change) { smf_db_query(' UPDATE {db_prefix}members SET warning = {int:warning} WHERE id_member = {int:id_member}', array('warning' => $change['warning'], 'id_member' => $change['id'])); } } } } // Do any spider stuff. if (!empty($modSettings['spider_mode']) && $modSettings['spider_mode'] > 1) { require_once $sourcedir . '/ManageSearchEngines.php'; consolidateSpiderStats(); } // Check the database version - for some buggy MySQL version. $server_version = mysql_get_server_info(); if ($db_type == 'mysql' && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51'))) { updateSettings(array('db_mysql_group_by_fix' => '1')); } elseif (!empty($modSettings['db_mysql_group_by_fix'])) { smf_db_query(' DELETE FROM {db_prefix}settings WHERE variable = {string:mysql_fix}', array('mysql_fix' => 'db_mysql_group_by_fix')); } // Regenerate the Diffie-Hellman keys if OpenID is enabled. if (!empty($modSettings['enableOpenID'])) { require_once $sourcedir . '/lib/Subs-OpenID.php'; smf_openID_setup_DH(true); } elseif (!empty($modSettings['dh_keys'])) { smf_db_query(' DELETE FROM {db_prefix}settings WHERE variable = {string:dh_keys}', array('dh_keys' => 'dh_keys')); } // clean out old cached posts if ($modSettings['post_cache_cutoff'] < 10) { $modSettings['post_cache_cutoff'] = 10; } smf_db_query(' DELETE FROM {db_prefix}messages_cache WHERE updated < {int:cutoff}', array('cutoff' => time() - $modSettings['post_cache_cutoff'] * 86400)); // auto-expire topicbans (expires == 0 means the ban is permanent until lifted manually, so do not expire them) smf_db_query('DELETE FROM {db_prefix}topicbans WHERE expires <> 0 AND expires <= UNIX_TIMESTAMP(NOW())'); HookAPI::callHook('sys_daily_maint'); // Log we've done it... return true; }
/** * @todo Enter description here ... * @param string $server * @return array */ function smf_openID_makeAssociation($server) { global $smcFunc, $modSettings, $p; $parameters = array('openid.mode=associate'); // We'll need to get our keys for the Diffie-Hellman key exchange. $dh_keys = smf_openID_setup_DH(); // If we don't support DH we'll have to see if the provider will accept no encryption. if ($dh_keys === false) { $parameters[] = 'openid.session_type='; } else { $parameters[] = 'openid.session_type=DH-SHA1'; $parameters[] = 'openid.dh_consumer_public=' . urlencode(base64_encode(long_to_binary($dh_keys['public']))); $parameters[] = 'openid.assoc_type=HMAC-SHA1'; } // The data to post to the server. $post_data = implode('&', $parameters); $data = fetch_web_data($server, $post_data); // Parse the data given. preg_match_all('~^([^:]+):(.+)$~m', $data, $matches); $assoc_data = array(); foreach ($matches[1] as $key => $match) { $assoc_data[$match] = $matches[2][$key]; } if (!isset($assoc_data['assoc_type']) || empty($assoc_data['mac_key']) && empty($assoc_data['enc_mac_key'])) { fatal_lang_error('openid_server_bad_response'); } // Clean things up a bit. $handle = isset($assoc_data['assoc_handle']) ? $assoc_data['assoc_handle'] : ''; $issued = time(); $expires = $issued + min((int) $assoc_data['expires_in'], 60); $assoc_type = isset($assoc_data['assoc_type']) ? $assoc_data['assoc_type'] : ''; // @todo Is this really needed? foreach (array('dh_server_public', 'enc_mac_key') as $key) { if (isset($assoc_data[$key])) { $assoc_data[$key] = str_replace(' ', '+', $assoc_data[$key]); } } // Figure out the Diffie-Hellman secret. if (!empty($assoc_data['enc_mac_key'])) { $dh_secret = bcpowmod(binary_to_long(base64_decode($assoc_data['dh_server_public'])), $dh_keys['private'], $p); $secret = base64_encode(binary_xor(sha1(long_to_binary($dh_secret), true), base64_decode($assoc_data['enc_mac_key']))); } else { $secret = $assoc_data['mac_key']; } // Store the data $smcFunc['db_insert']('replace', '{db_prefix}openid_assoc', array('server_url' => 'string', 'handle' => 'string', 'secret' => 'string', 'issued' => 'int', 'expires' => 'int', 'assoc_type' => 'string'), array($server, $handle, $secret, $issued, $expires, $assoc_type), array('server_url', 'handle')); return array('server' => $server, 'handle' => $assoc_data['assoc_handle'], 'secret' => $secret, 'issued' => $issued, 'expires' => $expires, 'assoc_type' => $assoc_data['assoc_type']); }