Skip to content

Commit

Permalink
🧹 Code formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
anditv21 committed Oct 23, 2023
1 parent 3356b13 commit 55d717b
Show file tree
Hide file tree
Showing 23 changed files with 219 additions and 277 deletions.
21 changes: 7 additions & 14 deletions src/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@
$whitelistedIPs = $API->getiparray();
$serverIP = Util::securevar($_SERVER['SERVER_ADDR']);
$remoteIP = Util::securevar($_SERVER['REMOTE_ADDR']);

if ($remoteIP !== $serverIP && !in_array($remoteIP, $whitelistedIPs)) {
$response = array('status' => 'failed', 'error' => 'Unauthorized IP');
} else {
if (empty($_GET['key'])) {
$response = array('status' => 'failed', 'error' => 'Missing key');
} else {
$key = Util::securevar($_GET['key']);

if (BOT_KEY === $key) {
if (isset($_GET['function'])) {
$botFunction = Util::securevar($_GET['function']);
Expand All @@ -35,39 +35,32 @@
$response = $API->getbydcid($dcid);
} else {
$response = array('status' => 'failed', 'error' => "Missing or empty 'discord id' parameter");

}
} elseif ($botFunction === 'usercount') {
$response = $API->get_user_count();
}
elseif ($botFunction === 'linkedusers') {
} elseif ($botFunction === 'linkedusers') {
$response = $API->linked_users();
}
elseif ($botFunction === 'generate_sub') {
} elseif ($botFunction === 'generate_sub') {
if (isset($_GET['dcid']) && !empty($_GET['dcid']) && isset($_GET['time']) && !empty($_GET['time'])) {
$dcid = Util::securevar($_GET['dcid']);
$time = Util::securevar($_GET['time']);
$response = $API->generate_subscription($dcid, $time);
} else {
$response = array('status' => 'failed', 'error' => "Missing or empty 'discord id' or 'time' parameter");

}
}
elseif ($botFunction === 'generate_inv') {
} elseif ($botFunction === 'generate_inv') {
if (isset($_GET['dcid']) && !empty($_GET['dcid'])) {
$dcid = Util::securevar($_GET['dcid']);
$response = $API->generate_invite($dcid);
} else {
$response = array('status' => 'failed', 'error' => "Missing or empty 'discord id' parameter");
}
}
else {
} else {
$response = array('status' => 'failed', 'error' => 'Invalid bot function');
}
} else {
$response = array('status' => 'failed', 'error' => 'Missing bot function');
}

} else {
$response = array('status' => 'failed', 'error' => 'Invalid bot key');
}
Expand All @@ -94,4 +87,4 @@
}
}

echo(json_encode($response));
echo (json_encode($response));
2 changes: 1 addition & 1 deletion src/app/controllers/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function getInvCodeGen($username)
$code = Util::randomCode(20);
return $this->invCodeGen($code, $username);
}

public function delInvCode($delinv)
{
return $this->deleteinvcode($delinv);
Expand Down
6 changes: 3 additions & 3 deletions src/app/controllers/ApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ public function linked_users()
{
return $this->get_linked_users();
}

public function generate_subscription($dcid, $time)
{
return $this->generate_sub($dcid, $time);
return $this->generate_sub($dcid, $time);
}

public function generate_invite($dcid)
{
return $this->generate_inv($dcid);
return $this->generate_inv($dcid);
}

public function getiparray()
Expand Down
2 changes: 1 addition & 1 deletion src/app/controllers/SessionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public static function isAdmin()
public static function isSupp()
{
return isset($_SESSION['login']) && $_SESSION['supp'] === 1
? true : false;
? true : false;
}

public static function isBanned()
Expand Down
45 changes: 22 additions & 23 deletions src/app/controllers/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,7 @@ public function loginUser($data)
Util::redirect("/index.php");
} else {
$this->loginfail($username);
if(!$this->doesthisuserexist($username))
{
if (!$this->doesthisuserexist($username)) {
return "No user with this name was found.";
}
return "Username/Password combination is wrong.";
Expand Down Expand Up @@ -450,7 +449,7 @@ private function is_access_token_valid($access_token)
{
// Send a request to Discord's API to validate the access token
$url = 'https://discord.com/api/v6/users/@me';

$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => $url,
Expand All @@ -459,35 +458,35 @@ private function is_access_token_valid($access_token)
'Authorization: Bearer ' . $access_token,
],
]);

$response = curl_exec($curl);
$httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);

if ($httpCode !== 200) {
curl_close($curl);
return false;
return false;
}

curl_close($curl);

try {
$data = json_decode($response, true);

if (json_last_error() !== JSON_ERROR_NONE) {
return false;
return false;
}

// Check if the API response contains expected data
if (isset($data['id'])) {
return true; // Token is valid
} else {
return false;
return false;
}
} catch (Exception $e) {
return false;
return false;
}
}


private function get_new_access_token($refresh_token)
{
Expand Down Expand Up @@ -548,14 +547,14 @@ public function mutecheck($uid)
public function getdcid($uid)
{
$result = $this->check_dcid($uid);

if ($result === null || $result === false) {
return false;
}

return $result;
}


public function setdcid($dcid, $uid)
{
Expand All @@ -566,7 +565,7 @@ public function isDiscordLinked()
{
return $this->hasLinkedDiscord();
}


public function discord_link($code)
{
Expand Down Expand Up @@ -664,13 +663,13 @@ public function discord_link($code)
header("location: profile.php");
}
}


public function downloadAvatarWithAccessToken($userId, $uid)

public function downloadAvatarWithAccessToken($userId, $uid)
{
$accessToken = $this->get_access_token();


// Check if access token is available and valid
if ($accessToken && $this->is_access_token_valid($accessToken)) {
$url = "https://discord.com/api/v9/users/@me";
Expand All @@ -684,15 +683,15 @@ public function downloadAvatarWithAccessToken($userId, $uid)
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$result = curl_exec($ch);

if ($result === false) {
Util::display("Error: " . Util::securevar(curl_error($ch)));
curl_close($ch);
return false;
}

$result = json_decode($result, true);


if (!isset($result["id"])) {
Util::display("Error: Failed to get user ID from Discord.");
Expand Down
6 changes: 3 additions & 3 deletions src/app/controllers/UtilController.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public function getSubStatus()
$username = Session::get('username');
return $this->subActiveCheck($username);
}

// admin check
public static function adminCheck($redirect = true)
{
Expand Down Expand Up @@ -161,15 +161,15 @@ public static function banCheck($redirect = true)
return false;
}
}

public static function muteCheck()
{
$username = Session::get("username");
if ($username === null) {
error_log("user not found");
return false;
}

$util = new UtilMod();
$res = $util->checkmute($username);
return $res;
Expand Down
26 changes: 11 additions & 15 deletions src/app/models/AdminModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ protected function banned($uid)
if ($banned) {
$user->log($username, "Banned {$userData->username} ($uid)", admin_logs);
$user->loguser($userData->username, "Banned by $username", false);

// Delete shoutbox entries from banned user
$this->prepare('DELETE FROM `shoutbox` WHERE `uid` = ?');
$this->statement->execute([$uid]);
Expand Down Expand Up @@ -514,34 +514,34 @@ protected function DiscordLink()
protected function DiscordLogging()
{
if ($this->checkadmin()) {

// Get current discordlogging status
$this->prepare('SELECT `discordlogging` FROM `system`');
$this->statement->execute();
$status = $this->statement->fetch();

$username = Session::get('username');
$user = new UserController();

if ($status->discordlogging) {
// Send the log
$user->log($username, "Disabled discord logging", system_logs);

// Disable discordlogging in the database
$this->prepare('UPDATE `system` SET `discordlogging` = 0');
$this->statement->execute();
} else {
// Enable discordlogging in the database
$this->prepare('UPDATE `system` SET `discordlogging` = 1');
$this->statement->execute();

// Send the log
$user->log($username, "Enabled discord logging", system_logs);
}
}
}


//
protected function SystemVersion($ver)
{
Expand Down Expand Up @@ -782,9 +782,7 @@ protected function ip_whitelist($ip, $username)
if ($this->checkadmin() && filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
$this->prepare('INSERT INTO `ip_whitelist` (`ip`, `createdBy`) VALUES (?, ?)');
$this->statement->execute([$ip, $username]);
}
else
{
} else {
return "This is not a valid ipv4.";
}
}
Expand All @@ -798,9 +796,7 @@ protected function unlist_ip($ip, $username)
$user = new UserController();
$user->log($username, "Added $ip to whitelist", system_logs);
$user->loguser($username, "Added $ip to whitelist");
}
else
{
} else {
return "This is not a valid ipv4.";
}
}
Expand All @@ -814,4 +810,4 @@ protected function IPArray()
return $result;
}
}
}
}
Loading

0 comments on commit 55d717b

Please sign in to comment.