<?php /* Uptime Check */ ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(-1); require_once __DIR__ . "/../config.php"; require_once __DIR__ . "/../api.php"; // REMEMBER: The CloudFlare IPs are not whitelisted // if (!core_OnWhitelist($_SERVER['REMOTE_ADDR'], CMW_ACCESS_DATA)) { json_EmitError(401); } $response = json_NewResponse(); if (defined('CMW_USING_APCU')) { $response['apcu'] = ["uptime" => time() - intval(apcu_cache_info("user")['start_time'])]; } if (defined('CMW_USING_REDIS')) { $redis = new Redis(); $redis->connect(CMW_REDIS_HOST); $response['redis'] = ["uptime" => intval($redis->info('default')['uptime_in_seconds'])]; $redis->close(); } if (defined('CMW_USING_DB')) { require_once __DIR__ . "/../db.php"; db_connect(); $db_data = db_FetchArrayPair("show global status where Variable_Name = 'Uptime';"); $response['db'] = ["uptime" => intval($db_data['Uptime'])]; db_close(); } if (defined('CMW_USING_MEMCACHED')) { $m = new Memcached();
require_once __DIR__ . "/../db.php"; require_once __DIR__ . "/../core/legacy_user.php"; require_once __DIR__ . "/../core/access.php"; // IMPORTANT: This Legacy API is intended for use with the legacy LD website. // *** This code will not work for you *** $response = json_NewResponse(); // MAIN (Only accept POST requests) // if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action'])) { $action = trim($_POST['action']); if ($action == "LOGOUT") { setcookie("lusha", "", 0, "/", str_replace("theme", "", $_SERVER['SERVER_NAME'])); $response['logout'] = 1; } else { if ($action == "GET_HASH") { // This is only available to whitelisted clients, or while debugging // if (defined('LEGACY_DEBUG') || defined('IP_WHITELIST') && core_OnWhitelist($_SERVER['REMOTE_ADDR'], IP_WHITELIST)) { $id = intval($_POST['id']); $ip = $_POST['ip']; if ($id > 0 && inet_pton($ip) !== false) { //error_log($ip." - ".$_POST['ip']); $user = legacy_GetUser($id); // Not in Database yet if (empty($user)) { // Do handshake, confirm user exists // $result = legacy_FetchUserInfo($id); if (isset($result['register_date'])) { // Generate Hash // $user['hash'] = legacy_GenerateUserHash($id); } legacy_SetExtraInfo($id, $result); }
// Shorthand function for checking a configuration whitelist // function core_OnWhitelist($ip, $list) { if (is_string($list)) { $list = [$list]; } foreach ($list as $item) { if ($item == $ip) { return true; } } return false; } $data = []; if ($_SERVER['REQUEST_METHOD'] === 'POST') { if (core_OnWhitelist($_SERVER['REMOTE_ADDR'], $IP_WHITELIST)) { $id = intval($_POST['id']); $user = get_user_by('id', $id); if ($user) { // Data is good. Extract the pieces we want. // $data = ['id' => intval($user->ID), 'register_date' => $user->data->user_registered, 'name' => $user->data->display_name, 'gravatar' => md5(strtolower(trim($user->data->user_email)))]; // Do a Query to figure out how many Ludum Dare entries a user has // global $wpdb; $result = $wpdb->get_results("SELECT uid,cid,results FROM c2_entry WHERE\n\t\t\t\t\tuid=" . $data['id'] . " AND active=1;", ARRAY_A); $data['num_events'] = 0; foreach ($result as $item) { if ($item['results'] !== null) { $data['num_events']++; } } //$user['caps']['administrator']