public static function tryGeneratePublicToken() { $Settings = Settings::getInstance(); if ($Settings['ApiPublic']['IntValue'] < time()) { $PublicToken = md5(Random::getBytes(2048)); // Store old token so that running requests don't fail if (isset($Settings['ApiPublic'])) { $Settings['ApiPublicOld'] = array('IntValue' => $Settings['ApiPublic']['IntValue'], 'TextValue' => $Settings['ApiPublic']['TextValue']); } // New token $Settings['ApiPublic'] = array('IntValue' => time() + self::$PublicUpdateInterval, 'TextValue' => $PublicToken); } }
private static function generateKey40() { return sha1(Random::getBytes(2048)); }
/** * Generate a Version 4 UUID. * These are derived soly from random numbers. */ protected static function mintRand() { // generate random fields $uuid = Random::getBytes(16); // set variant $uuid[8] = chr(ord($uuid[8]) & self::clearVar | self::varRFC); // set version $uuid[6] = chr(ord($uuid[6]) & self::clearVer | self::version4); return $uuid; }
<?php header("Content-type: text/xml"); echo "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"; define("LOCALE_SETUP", true); require_once "../../lib/private/connector.class.php"; require_once "../../lib/private/random.class.php"; require_once "../../lib/config/config.php"; $Out = Out::getInstance(); $Connector = Connector::getInstance(); $TestQuery = $Connector->prepare("SELECT Login FROM `" . RP_TABLE_PREFIX . "User` WHERE UserId=1 LIMIT 1"); try { $TestQuery->fetchFirst(true); $Salt = md5(Random::getBytes(2048)); $HashedPassword = hash("sha256", sha1($_REQUEST["password"]) . $Salt); if ($TestQuery->getAffectedRows() == 0) { $NewAdmin = $Connector->prepare("INSERT INTO `" . RP_TABLE_PREFIX . "User` " . "VALUES(1, 'admin', 0, 'none', 'true', :Name, :Password, :Salt, '', FROM_UNIXTIME(:Now));"); $NewAdmin->BindValue(":Name", $_REQUEST["name"], PDO::PARAM_STR); $NewAdmin->BindValue(":Password", $HashedPassword, PDO::PARAM_STR); $NewAdmin->BindValue(":Salt", $Salt, PDO::PARAM_STR); $NewAdmin->BindValue(":Now", time(), PDO::PARAM_STR); $NewAdmin->execute(true); } else { $UpdateAdmin = $Connector->prepare("UPDATE `" . RP_TABLE_PREFIX . "User` SET `Login`= :Name, `Password`= :Password, `Salt`= :Salt WHERE UserId=1 LIMIT 1;"); $UpdateAdmin->BindValue(":Name", $_REQUEST["name"], PDO::PARAM_STR); $UpdateAdmin->BindValue(":Password", $HashedPassword, PDO::PARAM_STR); $UpdateAdmin->BindValue(":Salt", $Salt, PDO::PARAM_STR); $UpdateAdmin->execute(true); } } catch (PDOException $Exception) { $Out->pushError($Exception->getMessage());
public static function generateKey32() { return md5(Random::getBytes(2048)); }
function InstallDefaultSettings($Prefix) { $Connector = Connector::getInstance(); // Add default values for settings table $TestQuery = $Connector->prepare("SELECT * FROM `" . $Prefix . "Setting`"); $ExistingSettings = array(); $TestQuery->loop(function ($Row) use($ExistingSettings) { array_push($ExistingSettings, $Row["Name"]); }); if (!in_array("PurgeRaids", $ExistingSettings)) { $Connector->exec("INSERT INTO `" . $Prefix . "Setting` (`Name`, `IntValue`, `TextValue`) VALUES('PurgeRaids', 7257600, '');"); } if (!in_array("LockRaids", $ExistingSettings)) { $Connector->exec("INSERT INTO `" . $Prefix . "Setting` (`Name`, `IntValue`, `TextValue`) VALUES('LockRaids', 3600, '');"); } if (!in_array("RaidStartHour", $ExistingSettings)) { $Connector->exec("INSERT INTO `" . $Prefix . "Setting` (`Name`, `IntValue`, `TextValue`) VALUES('RaidStartHour', 19, '');"); } if (!in_array("RaidStartMinute", $ExistingSettings)) { $Connector->exec("INSERT INTO `" . $Prefix . "Setting` (`Name`, `IntValue`, `TextValue`) VALUES('RaidStartMinute', 30, '');"); } if (!in_array("RaidEndHour", $ExistingSettings)) { $Connector->exec("INSERT INTO `" . $Prefix . "Setting` (`Name`, `IntValue`, `TextValue`) VALUES('RaidEndHour', 23, '');"); } if (!in_array("RaidEndMinute", $ExistingSettings)) { $Connector->exec("INSERT INTO `" . $Prefix . "Setting` (`Name`, `IntValue`, `TextValue`) VALUES('RaidEndMinute', 0, '');"); } if (!in_array("RaidSize", $ExistingSettings)) { $Connector->exec("INSERT INTO `" . $Prefix . "Setting` (`Name`, `IntValue`, `TextValue`) VALUES('RaidSize', 10, '');"); } if (!in_array("RaidMode", $ExistingSettings)) { $Connector->exec("INSERT INTO `" . $Prefix . "Setting` (`Name`, `IntValue`, `TextValue`) VALUES('RaidMode', 0, 'manual');"); } if (!in_array("Site", $ExistingSettings)) { $Connector->exec("INSERT INTO `" . $Prefix . "Setting` (`Name`, `IntValue`, `TextValue`) VALUES('Site', 0, '');"); } if (!in_array("HelpPage", $ExistingSettings)) { $Connector->exec("INSERT INTO `" . $Prefix . "Setting` (`Name`, `IntValue`, `TextValue`) VALUES('HelpPage', 0, '');"); } if (!in_array("Theme", $ExistingSettings)) { $Connector->exec("INSERT INTO `" . $Prefix . "Setting` (`Name`, `IntValue`, `TextValue`) VALUES('Theme', 0, 'cataclysm');"); } if (!in_array("GameConfig", $ExistingSettings)) { $Connector->exec("INSERT INTO `" . $Prefix . "Setting` (`Name`, `IntValue`, `TextValue`) VALUES('GameConfig', 0, 'wow');"); } if (!in_array("TimeFormat", $ExistingSettings)) { $Connector->exec("INSERT INTO `" . $Prefix . "Setting` (`Name`, `IntValue`, `TextValue`) VALUES('TimeFormat', 24, '');"); } if (!in_array("StartOfWeek", $ExistingSettings)) { $Connector->exec("INSERT INTO `" . $Prefix . "Setting` (`Name`, `IntValue`, `TextValue`) VALUES('StartOfWeek', 1, '');"); } if (!in_array("PrimaryRole", $ExistingSettings)) { $Connector->exec("INSERT INTO `" . $Prefix . "Setting` (`Name`, `IntValue`, `TextValue`) VALUES('PrimaryRole', 0, 'true');"); } if (!in_array("ApiPrivate", $ExistingSettings)) { $PrivateToken = dechex(crc32(Random::getBytes(2048))) . dechex(crc32(Random::getBytes(2048))); $Connector->exec("INSERT INTO `" . $Prefix . "Setting` (`Name`, `IntValue`, `TextValue`) VALUES('ApiPrivate', 0, '" . $PrivateToken . "');"); } if (!in_array("Version", $ExistingSettings)) { $Connector->exec("INSERT INTO `" . $Prefix . "Setting` (`Name`, `IntValue`, `TextValue`) VALUES('Version', 110, '');"); } else { $Connector->exec("UPDATE `" . $Prefix . "Setting` SET IntValue=110 WHERE Name='Version' LIMIT 1"); } }