-
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Made api call limiter (brute force mitigation system)
- Loading branch information
Ziga
committed
May 16, 2021
1 parent
76bd745
commit 3ebaac0
Showing
5 changed files
with
146 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,94 @@ | ||
<?php | ||
require_once "Display.php"; | ||
require_once "Database.php"; | ||
require_once "Settings.php"; | ||
|
||
if(!empty($_GET['action'])){ | ||
switch($_GET['action']){ | ||
case "createAccount": | ||
if(isset($_SERVER['PHP_AUTH_USER']) && isset($_POST['email']) && isset($_SERVER['PHP_AUTH_PW'])){ | ||
echo Database::createAccount($_SERVER['PHP_AUTH_USER'], $_POST['email'], $_SERVER['PHP_AUTH_PW']); | ||
}else{ | ||
echo Display::json(403); | ||
} | ||
break; | ||
case "getPasswords": | ||
if(isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW'])){ | ||
echo Database::getPasswords($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']); | ||
}else{ | ||
echo Display::json(403); | ||
} | ||
break; | ||
case "savePassword": | ||
if(isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW']) && isset($_POST['website']) && isset($_POST['username']) && isset($_POST['password'])){ | ||
echo Database::savePassword($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW'], $_POST['website'], $_POST['username'], $_POST['password']); | ||
}else{ | ||
echo Display::json(403); | ||
} | ||
break; | ||
case "editPassword": | ||
if(isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW']) && isset($_POST['password_id']) && isset($_POST['website']) && isset($_POST['username']) && isset($_POST['password'])){ | ||
echo Database::editPassword($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW'], $_POST['password_id'], $_POST['website'], $_POST['username'], $_POST['password']); | ||
}else{ | ||
echo Display::json(403); | ||
} | ||
break; | ||
case "deletePassword": | ||
if(isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW']) && isset($_POST['password_id'])){ | ||
echo Database::deletePassword($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW'], $_POST['password_id']); | ||
}else{ | ||
echo Display::json(403); | ||
} | ||
break; | ||
case "deleteAccount": | ||
if(isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW'])){ | ||
echo Database::deleteAccount($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']); | ||
}else{ | ||
echo Display::json(403); | ||
} | ||
break; | ||
default: | ||
echo Display::json(401); | ||
break; | ||
} | ||
}else{ | ||
echo Display::json(400); | ||
if(empty($_GET['action'])){ | ||
echo Display::json(400); | ||
return; | ||
} | ||
|
||
switch($_GET['action']){ | ||
case "createAccount": | ||
if(Database::userSentToManyRequests('createAccount')){ | ||
echo Display::json(429); | ||
return; | ||
} | ||
|
||
if(!isset($_SERVER['PHP_AUTH_USER']) || !isset($_POST['email']) || !isset($_SERVER['PHP_AUTH_PW'])){ | ||
echo Display::json(403); | ||
return; | ||
} | ||
|
||
echo Database::createAccount($_SERVER['PHP_AUTH_USER'], $_POST['email'], $_SERVER['PHP_AUTH_PW']); | ||
break; | ||
case "getPasswords": | ||
if(Database::userSentToManyRequests('getPasswords')){ | ||
echo Display::json(429); | ||
return; | ||
} | ||
|
||
if(!isset($_SERVER['PHP_AUTH_USER']) || !isset($_SERVER['PHP_AUTH_PW'])){ | ||
echo Display::json(403); | ||
return; | ||
} | ||
|
||
echo Database::getPasswords($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']); | ||
break; | ||
case "savePassword": | ||
if(Database::userSentToManyRequests('savePassword')){ | ||
echo Display::json(429); | ||
return; | ||
} | ||
|
||
if(!isset($_SERVER['PHP_AUTH_USER']) || !isset($_SERVER['PHP_AUTH_PW']) || !isset($_POST['website']) || !isset($_POST['username']) || !isset($_POST['password'])){ | ||
echo Display::json(403); | ||
return; | ||
} | ||
|
||
echo Database::savePassword($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW'], $_POST['website'], $_POST['username'], $_POST['password']); | ||
break; | ||
case "editPassword": | ||
if(Database::userSentToManyRequests('editPassword')){ | ||
echo Display::json(429); | ||
return; | ||
} | ||
|
||
if(!isset($_SERVER['PHP_AUTH_USER']) || !isset($_SERVER['PHP_AUTH_PW']) || !isset($_POST['password_id']) || !isset($_POST['website']) || !isset($_POST['username']) || !isset($_POST['password'])){ | ||
echo Display::json(403); | ||
return; | ||
} | ||
|
||
echo Database::editPassword($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW'], $_POST['password_id'], $_POST['website'], $_POST['username'], $_POST['password']); | ||
break; | ||
case "deletePassword": | ||
if(Database::userSentToManyRequests('deletePassword')){ | ||
echo Display::json(429); | ||
return; | ||
} | ||
|
||
if(!isset($_SERVER['PHP_AUTH_USER']) || !isset($_SERVER['PHP_AUTH_PW']) || !isset($_POST['password_id'])){ | ||
echo Display::json(403); | ||
return; | ||
} | ||
|
||
echo Database::deletePassword($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW'], $_POST['password_id']); | ||
break; | ||
case "deleteAccount": | ||
if(Database::userSentToManyRequests('deleteAccount')){ | ||
echo Display::json(429); | ||
return; | ||
} | ||
|
||
if(!isset($_SERVER['PHP_AUTH_USER']) || !isset($_SERVER['PHP_AUTH_PW'])){ | ||
echo Display::json(403); | ||
return; | ||
} | ||
|
||
echo Database::deleteAccount($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']); | ||
break; | ||
default: | ||
echo Display::json(401); | ||
break; | ||
} | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"getPasswords": {}, | ||
"savePassword": {}, | ||
"editPassword": {}, | ||
"deletePassword": {}, | ||
"createAccount": {}, | ||
"deleteAccount": {} | ||
} |