This repository has been archived by the owner on Dec 1, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
APIManager.php
107 lines (93 loc) · 3.77 KB
/
APIManager.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<?php
require_once "Logger.php";
include_once("ConnectionManager.php");
include_once("QueryExecManager.php");
include_once("StatementRetrievalManager.php");
define("VERSION", "2.0.0.1");
if (empty($_POST))
{
echo "Array Empty";
exit(0);
}
$logger = new Logger();
$logID = $logger->getLogID();
$logger->writeToLog("Received API call from " . HelperClass::getIP());
$postArray = decryptPostArray($_POST);
switch ($postArray['type'])
{
case "GetAPIStatus":
$logger->writeToLog("Getting API Status");
$helperClass = new HelperClass();
$returnArray = $helperClass->returnSuccessArray(null);
$returnArray["Version"] = VERSION;
print json_encode($returnArray);
break;
case "TestDBConnection":
$logger->writeToLog("About to test connection to: " . $postArray["server"]);
$connManager = new ConnectionManager($logID);
print $connManager->testConnection($postArray);
//echo $encryption->encrypt("{\"result\":1,\"message\":\"there was a problem creating the tunnel\"}");
return;
case "RetrieveDatabasesAndTables":
$logger->writeToLog("About to retrieve databaes and tables");
$connManager = new ConnectionManager($logID);
print $connManager->retrieveDBsAndTables($postArray);
break;
case "GetDatabases":
$logger->writeToLog("About to retrieve databases");
$connManager = new ConnectionManager($logID);
print $connManager->getDatabases($postArray);
break;
case "GetTables":
$logger->writeToLog("About to retrieve tables");
$connManager = new ConnectionManager($logID);
print $connManager->getTableData($postArray);
break;
case "GetServerStatus":
$connManager = new ConnectionManager($logID);
print $connManager->getServerStatus($postArray);
break;
case "ExecuteSQL":
case "ExecuteSQLRepost":
$logger->writeToLog("About to perform SQL Query");
$queryExecMan = new QueryExecManager($logID);
print $queryExecMan->executeQuery($postArray);
break;
case "GetSelectAllStatementCopy":
case "GetSelectAllStatementEditor":
case "GetInsertStatementCopy":
case "GetInsertStatementEditor":
case "GetUpdateStatementCopy":
case "GetUpdateStatementEditor":
case "GetDeleteStatementCopy":
case "GetDeleteStatementEditor":
case "GetCreateStatementCopy":
case "GetCreateStatementEditor":
$logger->writeToLog("About to retrieve SQL statement");
$statementManager = new StatementRetrievalManager($logID);
return $statementManager->getSqlStatement($postArray);
default:
$helperClass = new HelperClass();
$returnArray = $helperClass->returnError("Unknown API Method. Type: '" . $_POST["type"] . "'");
print json_encode($returnArray);
}
function decryptPostArray($postArray)
{
require_once 'Encryption.php';
try
{
$decryptedPostArray = array();
$encryption = new Encryption();
foreach ($postArray as $key => $value) {
$decryptedPostArray[$encryption->decrypt($key)] = $encryption->decrypt($value);
}
return $decryptedPostArray;
}
catch (Exception $x)
{
$helperClass = new HelperClass();
$returnArray = $helperClass->returnError("DecryptionFailed");
$returnArray["version"] = VERSION;
print json_encode($returnArray);
}
}