-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improved API Security Improved Code Overall Changed Class Names
- Loading branch information
Showing
10 changed files
with
158 additions
and
158 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
File renamed without changes.
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,40 @@ | ||
<?php | ||
class Helper | ||
{ | ||
// Check Tickets Status | ||
public function checkTicketStatus($ticketstatus) | ||
{ | ||
// Map array to check if status is available | ||
$NAcceptedTicketStatus = array_map(function($ticketstatus){ | ||
return (string) $ticketstatus; | ||
}, ATSTATUS); | ||
|
||
// then use in array | ||
if(!in_array($ticketstatus, $NAcceptedTicketStatus)) { | ||
throw new Exception("Ticket status not available."); | ||
} | ||
|
||
return true; | ||
} | ||
|
||
// Get formated date from string | ||
public function getFormatedDate($fullstring, $condition) | ||
{ | ||
|
||
switch ($condition) { | ||
case "start": | ||
$startDate = substr($fullstring, 0, 10); | ||
$result = str_replace("-","/",$startDate); | ||
break; | ||
case "end": | ||
$endDate = substr($fullstring, -10); | ||
$result = str_replace("-","/",$endDate); | ||
break; | ||
default: | ||
throw new Exception("Helper: condition date not recognize."); | ||
} | ||
|
||
return $result; | ||
|
||
} | ||
} |
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,56 @@ | ||
<?php | ||
class apiKey | ||
{ | ||
|
||
var $farray; | ||
|
||
function __construct() { | ||
$this->key = false; | ||
$this->cancreate = false; | ||
$this->isactive = false; | ||
$this->countR = false; | ||
} | ||
|
||
function OAuth($key) | ||
{ | ||
|
||
if($key) $this->key = $key; | ||
// Connect Database | ||
$Dbobj = new DBConnection(); | ||
$mysqli = $Dbobj->getDBConnect(); | ||
|
||
$GetKey = $mysqli->query("SELECT * FROM ".TABLE_PREFIX."api_key WHERE apiKey = '$key'"); | ||
$this->farray = $GetKey->fetch_array(); | ||
$this->countR = $GetKey->num_rows; | ||
|
||
// If exists | ||
if(!$this->countR) | ||
throw new Exception("No API Key found."); | ||
// Check IPAddress | ||
if(!$this->farray["isactive"] || APIKEY_RESTRICT && $this->farray["ipaddr"] != $_SERVER['REMOTE_ADDR']) | ||
throw new Exception("API key not found/active or source IP not authorized"); | ||
|
||
} | ||
|
||
function cancreate() | ||
{ | ||
return $this->farray["can_create_tickets"]; | ||
} | ||
|
||
function isactive() | ||
{ | ||
return $this->farray["isactive"]; | ||
} | ||
|
||
function ippaddr() | ||
{ | ||
return $this->farray["ippaddr"]; | ||
} | ||
|
||
} | ||
|
||
// Init API Key verification | ||
$apiAuth = new apiKey; | ||
$apiAuth->OAuth($key["apikey"]); | ||
|
||
?> |
File renamed without changes.
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
File renamed without changes.
This file was deleted.
Oops, something went wrong.
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