insertInToTable.php
4.85 KB
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
108
109
110
111
112
113
114
115
116
117
118
119
120
<?php
//GPL license
include sanitize_file_name('gplLicense.php');
/*To post the signature in the wordpress root directory*/
function Beagle_WP_addDataTo_DB()
{
global $wpdb;
global $apiServerBaseUrl;
$Beagle_WP_scan_table = $wpdb->prefix . "beagleScanData";
$Beagle_WP_access_token = sanitize_text_field($_POST['access_token']);
$Beagle_WP_application_token = sanitize_text_field($_POST['application_token']);
try {
if (isset($_POST['startVerify'])) {
$Beagle_WP_dataInDB = $wpdb->get_results("SELECT * FROM $Beagle_WP_scan_table WHERE `application_token`='$Beagle_WP_application_token'");
try {
if (!$Beagle_WP_dataInDB) {
$beaglrURL = $apiServerBaseUrl . 'test/signature';
$getverifiedToken = array("access_token" => $Beagle_WP_access_token, "application_token" => $Beagle_WP_application_token);
$request = wp_remote_post($beaglrURL, array(
'headers' => array('Content-Type' => 'application/json; charset=utf-8'),
'body' => json_encode($getverifiedToken),
'method' => 'POST',
'data_format' => 'body',
));
$statusResponse = json_decode(wp_remote_retrieve_body($request));
try {
$dateLog = date("Y-m-d");
if ($statusResponse->status == "Failed") {
try {
$Beagle_WP_log_save_path = plugin_dir_path(__FILE__) . '../log.txt';
if (is_writable($Beagle_WP_log_save_path)) {
$Beagle_WP_log_open = fopen($Beagle_WP_log_save_path, "a");
$Beagle_WP_log_write = fputs($Beagle_WP_log_open, "\n" .$dateLog. " -> " .$statusResponse->message. + "\n");
fclose($Beagle_WP_log_open);
}
} catch (Exception $e) {
}
?>
<script>
function appExist() {
var errorMsg = setTimeout("document.getElementById('errMsg').style.display='none';", 4000);
}
appExist()
</script>
<div class="errormsg">
<p id="errMsg">Invalid credentials. Please try again!</p>
</div>
<?php
} else if($statusResponse == null) {
try {
$Beagle_WP_log_save_path = plugin_dir_path(__FILE__) . '../log.txt';
if (is_writable($Beagle_WP_log_save_path)) {
$Beagle_WP_log_open = fopen($Beagle_WP_log_save_path, "a");
$Beagle_WP_log_write = fputs($Beagle_WP_log_open, "\n" .$dateLog. "-> User not authorized. \n");
fclose($Beagle_WP_log_open);
}
} catch (Exception $e) {
}
?>
<script>
function appExist() {
var errorMsg = setTimeout("document.getElementById('errMsg').style.display='none';", 4000);
}
appExist()
</script>
<div class="errormsg">
<p id="errMsg">User not authorized!</p>
</div>
<?php
}
else if ($statusResponse->status == "NotVerified") {
$verifyText = $statusResponse->signature;
try {
$Beagle_WP_file_save_path = plugin_dir_path(__FILE__) . '../' . $verifyText . '.txt';
$Beagle_WP_file_save_path_test = plugin_dir_path(__FILE__) . '../fileWrightTest.txt';
if (is_writable($Beagle_WP_file_save_path_test)) {
$Beagle_WP_file_open = fopen($Beagle_WP_file_save_path, "a");
$Beagle_WP_file_write = fputs($Beagle_WP_file_open, $verifyText);
fclose($Beagle_WP_file_open);
if ($Beagle_WP_file_write) {
$wpdb->insert($Beagle_WP_scan_table, array("access_token" => $Beagle_WP_access_token, "application_token" => $Beagle_WP_application_token, "verified" => 0, "title" => $statusResponse->title, "url" => $statusResponse->url, "runningStatus" => "notRunning", "autoVerify" => "0"), array("%s", "%s", "%d", "%s", "%s", "%s", "%d"));
} else {
?>
<script>
function appExist() {
var errorMsg = setTimeout("document.getElementById('errMsg').style.display='none';", 4000);
}
appExist()
</script>
<div class="errormsg">
<p id="errMsg">An unexpected error occurred. Please try again!</p>
</div>
<?php
}
}else {
$wpdb->insert($Beagle_WP_scan_table, array("access_token" => $Beagle_WP_access_token, "application_token" => $Beagle_WP_application_token, "verified" => 0, "title" => $statusResponse->title, "url" => $statusResponse->url, "runningStatus" => "notRunning", "autoVerify" => "1"), array("%s", "%s", "%d", "%s", "%s", "%s", "%d"));
}
} catch (Exception $e) {
}
} else {
$wpdb->insert($Beagle_WP_scan_table, array("access_token" => $Beagle_WP_access_token, "application_token" => $Beagle_WP_application_token, "verified" => 1, "title" => $statusResponse->title, "url" => $statusResponse->url, "runningStatus" => "notRunning", "autoVerify" => "0"), array("%s", "%s", "%d", "%s", "%s", "%s", "%d"));
}
} catch (Exception $e) {
}
}
} catch (Exception $e) {
}
}
} catch (Exception $e) {
}
}