-
Notifications
You must be signed in to change notification settings - Fork 4
/
dashboard.php
85 lines (72 loc) · 1.91 KB
/
dashboard.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
<?php
session_start();
include("db.php");
include("conf.php");
if($conf['auth'] == true && !isloggedin()) {
header("Location: index.php");
exit();
}
// add IP entry to table
$sql = "insert into workers(worker_ip,last_ping) values('".$_SERVER['REMOTE_ADDR']."', now())";
update($sql);
?>
<!doctype html>
<html>
<head>
<?php require_once("common-head.php"); ?>
<title>Plug n Play cluster</title>
</head>
<body>
<?php require_once("nav.php"); ?>
<div class="container">
<div class="row">
<div class="col-md-12 text-center">
<h2 style="font-weight:bold;">Connected to cluster !</h2><hr>
<p>To disconnect your device from the cluster, please click the button below<br><br>
<a class="btn btn-primary" href="logout.php">Disconnect</a>.</p>
</div>
<div>
</div>
<?php require_once("footer.php"); ?>
<script>
var x;
// This function will process the job.
function processjob(data){
clearInterval(x);
// Variable to store the processed data.
var return_data = "";
eval(JSON.parse(data).process);
// Preparing the data to be stored as a file.
var processed = {};
processed["job_id"] = JSON.parse(data).job_id;
processed["task_id"] = JSON.parse(data).task_id;
processed["file_name"] = JSON.parse(data).file;
processed["process"] = return_data;
$.post("task.php",processed,function(returndata, status){
console.log(returndata);
});
checkjob();
}
// This function checks for the job and if found then it processes the job.
function checkjob(){
x = setInterval(function(){
$.get("getjob.php",function(data, status){
if(JSON.parse(data).message == true){
processjob(data);
}
});
}, 5000);
}
$(document).ready(function() {
// update server about your
// presence every 5 second
setInterval(function(){
$.get("update.php", function(data, status){
});
}, 5000);
// checks for the job.
checkjob();
});
</script>
</body>
</html>