<?php
$validcid = explode("\n", file_get_contents("cid-valid.txt"));
$bannedcid = explode("\n", file_get_contents("cid-banned.txt"));
function generate_random_cid($cids, $bannedcid) {
foreach($cids as $cid) {
$workingcid = array();
if(!in_array($cid, $bannedcid, false) && !in_array($cid, $workingcid, false)) {
array_push($workingcid, $cid);
}
}
if(count($workingcid) < 1) {
return "No Working Console IDs currently";
}
$workingcid = $workingcid[mt_rand(count($workingcid) - 1)];
}
if(isset($_GET['page']) && !empty($_GET['page'])) {
switch($_GET['page']) {
case "newcid": {
if(isset($_POST['cid']) && !empty($_POST['cid'])) {
if(preg_match("/^00000001008[A-F,0-9]000[A-F,0-9]{17}$/", $_POST['cid'])) {
if(!in_array($_POST['cid'], $validcid, false) && !in_array($_POST['cid'], $bannedcid, false)) {
file_put_contents("cid-valid.txt", $_POST['cid']."\n", FILE_APPEND);
}
else {
print("The Console ID: <strong>" .$_POST['cid']. "</strong> has already been added");
break;
}
}
else {
print("The Console ID: <strong>" .$_POST['cid']. "</strong> is not valid <br />Please contact the admin of the forum if this is incorrect");
}
}
}
break;
case "bannedcid": {
if(isset($_POST['bannedcid']) && !empty($_POST['bannedcid'])) {
if(preg_match("/^00000001008[A-F,0-9]000[A-F,0-9]{17}$/", $_POST['bannedcid'])) {
if(!in_array($_POST['bannedcid'], $bannedcid, false) && in_array($_POST['bannedcid'], $validcid, false)) {
file_put_contents("cid-banned.txt", $_POST['bannedcid']."\n", FILE_APPEND);
print("The Console ID: <strong>" .$_POST['bannedcid']. "</strong> has been added");
}
elseif(!in_array($_POST['bannedcid'], $bannedcid, false) && !in_array($_POST['bannedcid'], $validcid, false)) {
file_put_contents("cid-banned.txt", $_POST['bannedcid']."\n", FILE_APPEND);
file_put_contents("cid-valid.txt", $_POST['bannedcid']."\n", FILE_APPEND);
print("The Console ID: <strong>" .$_POST['bannedcid']. "</strong> has been added");
}
else {
print("The Console ID: <strong>" .$_POST['bannedcid']. "</strong> has already been added");
}
}
else {
print("The Console ID: <strong>" .$_POST['bannedcid']. "</strong> is not valid <br />Please contact the admin of the forum if this is incorrect");
}
}
}
break;
default: {
$workingcid = generate_random_cid($validcid, $bannedcid);
print $workingcid;
}
}
}
?>