<?php
/*
What needs to be added?
------------------------
Well for one this is core PHP and has no HTML/CSS/Javascript coding other than the occassional printing
Should update this so it adds the ids to a database, rather than relying on the files. The bigger the file gets the more impact it will have on your server!
What do I need to do to get this working?
-----------------------------------------
You need to add the missing HTML forms so people can switch the pages and post the cids.
Currently this works by saving IDs to a file and then using explode() to split all values to an array on a newline "\n"
You can add this to your site right now, make 2 file called "cid-valid.txt" and "cid-banned.txt" and chmod them so they're writable.
It will work, you just have to manually forge the requests because there are no forms to help you navigate.
Why haven't I done this?
-------------------------
1. Because you should all be able to easily add this to your own sites and integrate it with your software pretty easily
2. Because some people are still using mysqli_* and not PDO. not to mention the people still using mysql_ (._.)
3. I made this out of boredom and I finally found something better to do.
~ GHoST
*/
$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();
// Gather IDs we've collected, compare them against the ban list and add the working ones to a new array.
if(!in_array($cid, $bannedcid, false) && !in_array($cid, $workingcid, false)) {
array_push($workingcid, $cid);
}
}
// Check if we have any working IDs before printing
if(count($workingcid) < 1) {
return "No Working Console IDs currently";
}
// Load a random index from the working ID array
$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)) {
// The ID submitted is new and is added to our array
file_put_contents("cid-valid.txt", $_POST['cid']."\n", FILE_APPEND);
}
else {
// The ID submitted is already in our array
print("The Console ID: <strong>" .$_POST['cid']. "</strong> has already been added");
break;
}
}
else {
// The ID submitted does not match the regular expression (most likely a 1337 hax0r)
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)) {
// The ID submitted is new and is added to our ban list
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)) {
// The ID submitted is new and also not in our cid array, so is added to our cid and ban array
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 {
// The ID submitted is already in our banlist
print("The Console ID: <strong>" .$_POST['bannedcid']. "</strong> has already been added");
}
}
else {
// The ID submitted does not match the regular expression (most likely a 1337 hax0r) ~ sp00ky
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;
}
}
}
?>