-
-
Notifications
You must be signed in to change notification settings - Fork 168
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #345 from wrongecho/api
API Enhancements
- Loading branch information
Showing
6 changed files
with
184 additions
and
25 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
require('../validate_api_key.php'); | ||
|
||
if($_SERVER['REQUEST_METHOD'] !== "GET"){ | ||
header("HTTP/1.1 405 Method Not Allowed"); | ||
$return_arr['success'] = "False"; | ||
$return_arr['message'] = "Can only send GET requests to this endpoint."; | ||
echo json_encode($return_arr); | ||
exit(); | ||
} | ||
|
||
// Specific certificate via ID (single) | ||
if(isset($_GET['certificate_id'])){ | ||
$id = intval($_GET['certificate_id']); | ||
$sql = mysqli_query($mysqli, "SELECT * FROM certificates WHERE certificate_id = '$id' AND company_id = '$company_id'"); | ||
} | ||
|
||
// Certificate by name | ||
elseif(isset($_GET['certificate_name'])){ | ||
$name = mysqli_real_escape_string($mysqli,$_GET['certificate_name']); | ||
$sql = mysqli_query($mysqli, "SELECT * FROM certificates WHERE certificate_name = '$name' AND company_id = '$company_id' ORDER BY certificate_id LIMIT $limit OFFSET $offset"); | ||
} | ||
|
||
// Certificate via client ID | ||
elseif(isset($_GET['certificate_client_id'])){ | ||
$client = intval($_GET['certificate_client_id']); | ||
$sql = mysqli_query($mysqli, "SELECT * FROM certificates WHERE certificate_client_id = '$client' AND company_id = '$company_id' ORDER BY certificate_id LIMIT $limit OFFSET $offset"); | ||
} | ||
|
||
// All certificates | ||
else{ | ||
$sql = mysqli_query($mysqli, "SELECT * FROM certificates WHERE company_id = '$company_id' ORDER BY certificate_id LIMIT $limit OFFSET $offset"); | ||
} | ||
|
||
// Output | ||
include("../read_output.php"); |
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,36 @@ | ||
<?php | ||
require('../validate_api_key.php'); | ||
|
||
if($_SERVER['REQUEST_METHOD'] !== "GET"){ | ||
header("HTTP/1.1 405 Method Not Allowed"); | ||
$return_arr['success'] = "False"; | ||
$return_arr['message'] = "Can only send GET requests to this endpoint."; | ||
echo json_encode($return_arr); | ||
exit(); | ||
} | ||
|
||
// Specific domain via ID (single) | ||
if(isset($_GET['domain_id'])){ | ||
$id = intval($_GET['domain_id']); | ||
$sql = mysqli_query($mysqli, "SELECT * FROM domains WHERE domain_id = '$id' AND company_id = '$company_id'"); | ||
} | ||
|
||
// Domain by name | ||
elseif(isset($_GET['domain_name'])){ | ||
$name = mysqli_real_escape_string($mysqli,$_GET['domain_name']); | ||
$sql = mysqli_query($mysqli, "SELECT * FROM domains WHERE domain_name = '$name' AND company_id = '$company_id' ORDER BY asset_id LIMIT $limit OFFSET $offset"); | ||
} | ||
|
||
// Domain via client ID | ||
elseif(isset($_GET['domain_client_id'])){ | ||
$client = intval($_GET['domain_client_id']); | ||
$sql = mysqli_query($mysqli, "SELECT * FROM domains WHERE domain_client_id = '$client' AND company_id = '$company_id' ORDER BY domain_id LIMIT $limit OFFSET $offset"); | ||
} | ||
|
||
// All domains | ||
else{ | ||
$sql = mysqli_query($mysqli, "SELECT * FROM domains WHERE company_id = '$company_id' ORDER BY domain_id LIMIT $limit OFFSET $offset"); | ||
} | ||
|
||
// Output | ||
include("../read_output.php"); |
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,36 @@ | ||
<?php | ||
require('../validate_api_key.php'); | ||
|
||
if($_SERVER['REQUEST_METHOD'] !== "GET"){ | ||
header("HTTP/1.1 405 Method Not Allowed"); | ||
$return_arr['success'] = "False"; | ||
$return_arr['message'] = "Can only send GET requests to this endpoint."; | ||
echo json_encode($return_arr); | ||
exit(); | ||
} | ||
|
||
// Specific network via ID (single) | ||
if(isset($_GET['network_id'])){ | ||
$id = intval($_GET['network_id']); | ||
$sql = mysqli_query($mysqli, "SELECT * FROM networks WHERE network_id = '$id' AND company_id = '$company_id'"); | ||
} | ||
|
||
// Network by name | ||
elseif(isset($_GET['network_name'])){ | ||
$name = mysqli_real_escape_string($mysqli,$_GET['network_name']); | ||
$sql = mysqli_query($mysqli, "SELECT * FROM networks WHERE network_name = '$name' AND company_id = '$company_id' ORDER BY network_id LIMIT $limit OFFSET $offset"); | ||
} | ||
|
||
// Network via client ID | ||
elseif(isset($_GET['network_client_id'])){ | ||
$client = intval($_GET['network_client_id']); | ||
$sql = mysqli_query($mysqli, "SELECT * FROM networks WHERE network_client_id = '$client' AND company_id = '$company_id' ORDER BY network_id LIMIT $limit OFFSET $offset"); | ||
} | ||
|
||
// All networks | ||
else{ | ||
$sql = mysqli_query($mysqli, "SELECT * FROM networks WHERE company_id = '$company_id' ORDER BY network_id LIMIT $limit OFFSET $offset"); | ||
} | ||
|
||
// Output | ||
include("../read_output.php"); |
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,21 @@ | ||
<?php | ||
|
||
// Output (to be included) | ||
if($sql && mysqli_num_rows($sql) > 0){ | ||
$return_arr['success'] = "True"; | ||
$return_arr['count'] = mysqli_num_rows($sql); | ||
|
||
$row = array(); | ||
while($row = mysqli_fetch_array($sql)){ | ||
$return_arr['data'][] = $row; | ||
} | ||
|
||
echo json_encode($return_arr); | ||
exit(); | ||
} | ||
else{ | ||
$return_arr['success'] = "False"; | ||
$return_arr['message'] = "No resource for this company with the specified parameter(s)."; | ||
echo json_encode($return_arr); | ||
exit(); | ||
} |
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,48 @@ | ||
<?php | ||
require('../validate_api_key.php'); | ||
|
||
if($_SERVER['REQUEST_METHOD'] !== "GET"){ | ||
header("HTTP/1.1 405 Method Not Allowed"); | ||
$return_arr['success'] = "False"; | ||
$return_arr['message'] = "Can only send GET requests to this endpoint."; | ||
echo json_encode($return_arr); | ||
exit(); | ||
} | ||
|
||
// Specific software via ID (single) | ||
if(isset($_GET['software_id'])){ | ||
$id = intval($_GET['software_id']); | ||
$sql = mysqli_query($mysqli, "SELECT * FROM software WHERE software_id = '$id' AND company_id = '$company_id'"); | ||
} | ||
|
||
// Specific software via License ID | ||
if(isset($_GET['software_license'])){ | ||
$license = mysqli_real_escape_string($mysqli,$_GET['software_license']); | ||
$sql = mysqli_query($mysqli, "SELECT * FROM software WHERE software_license = '$license' AND company_id = '$company_id' ORDER BY software_id LIMIT $limit OFFSET $offset"); | ||
} | ||
|
||
// Software by name | ||
elseif(isset($_GET['software_name'])){ | ||
$name = mysqli_real_escape_string($mysqli,$_GET['software_name']); | ||
$sql = mysqli_query($mysqli, "SELECT * FROM software WHERE software_name = '$name' AND company_id = '$company_id' ORDER BY asset_id LIMIT $limit OFFSET $offset"); | ||
} | ||
|
||
// Software via type | ||
elseif(isset($_GET['software_type'])){ | ||
$type = intval($_GET['software_type']); | ||
$sql = mysqli_query($mysqli, "SELECT * FROM software WHERE software_type = '$type' AND company_id = '$company_id' ORDER BY software_id LIMIT $limit OFFSET $offset"); | ||
} | ||
|
||
// Software via client ID | ||
elseif(isset($_GET['software_client_id'])){ | ||
$client = intval($_GET['software_client_id']); | ||
$sql = mysqli_query($mysqli, "SELECT * FROM software WHERE software_client_id = '$client' AND company_id = '$company_id' ORDER BY software_id LIMIT $limit OFFSET $offset"); | ||
} | ||
|
||
// All software(s) | ||
else{ | ||
$sql = mysqli_query($mysqli, "SELECT * FROM software WHERE company_id = '$company_id' ORDER BY software_id LIMIT $limit OFFSET $offset"); | ||
} | ||
|
||
// Output | ||
include("../read_output.php"); |