startTest.php
2.49 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
<?php
//GPL license
include sanitize_file_name('gplLicense.php');
/*To start the test after verifying the application*/
function Beagle_WP_start_Test() {
global $wpdb;
global $apiServerBaseUrl;
$Beagle_WP_scan_table = $wpdb->prefix."beagleScanData";
$getTokenFromTbl = $wpdb->get_results($wpdb->prepare("SELECT * FROM $Beagle_WP_scan_table"));
foreach ( $getTokenFromTbl as $print ){
$Beagle_WP_access_token = $print->access_token;
$Beagle_WP_application_token = $print->application_token;
}
$beaglrURL = $apiServerBaseUrl.'test/start';
$scanStartData = array("access_token" => $Beagle_WP_access_token, "application_token" => $Beagle_WP_application_token);
$startRequest = wp_remote_post($beaglrURL, array(
'headers' => array('Content-Type' => 'application/json; charset=utf-8'),
'body' => json_encode($scanStartData),
'method' => 'POST',
'data_format' => 'body',
));
$startMsgResponse = json_decode(wp_remote_retrieve_body( $startRequest ));
try {
if( $startMsgResponse ) {
try {
if ($startMsgResponse->status == 'Failed') {
$updateData = $wpdb->query($wpdb->prepare("UPDATE $Beagle_WP_scan_table SET status = %s WHERE application_token = %s",$startMsgResponse->status, $Beagle_WP_application_token));
?>
<script>
function app_Exist(){
var errorMsg=setTimeout("document.getElementById('errMsg').style.display='none';",4000);
}
app_Exist()
</script>
<div class="errormsg">
<p id="errMsg"><?php echo $startMsgResponse->message;?></p>
</div>
<?php
}else {
$resultToken = $startMsgResponse->result_token;
$updateData = $wpdb->query( $wpdb->prepare("UPDATE $Beagle_WP_scan_table SET status = %s , result_token = %s, runningStatus = %s WHERE application_token = %s",$startMsgResponse->status, $startMsgResponse->result_token, "Running", $Beagle_WP_application_token));
?>
<script>
function app_Exist(){
var errorMsg=setTimeout("document.getElementById('errMsg').style.display='none';",4000);
}
app_Exist()
</script>
<div class="message">
<p id="errMsg">Test started successfully.</p>
</div>
<?php
}
}
catch(Exception $e) {
}
}
else {
?>
<script>
function app_Exist(){
var errorMsg=setTimeout("document.getElementById('errMsg').style.display='none';",4000);
}
app_Exist()
</script>
<div class="errormsg">
<p id="errMsg">Test start failed!</p>
</div>
<?php
}
}catch(Exception $e) {
}
}