-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcreatedb_status.php
executable file
·124 lines (114 loc) · 2.49 KB
/
createdb_status.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<?php if(!isset($_SESSION)){session_start();} ?>
<?php if(!isset($_SESSION["db_ids"])){$_SESSION["db_ids"]=array();} ?>
<?php if(!isset($_SESSION["blast_ids"])){$_SESSION["blast_ids"]=array();} ?>
<?php
require_once("createdb_lib.php");
function check_mail($ad) {
if (filter_var($ad, FILTER_VALIDATE_EMAIL)) {
return $ad;
} else {
return "";
}
}
function check_text($t) {
if ($t) {
return $t;
} else {
return "";
}
}
function check_blocks_tol($btol) {
# Default: btol = 2
if (!ctype_digit($btol)) {
$btol = 2;
}
# Out of bounds: closest (0 or 5)
elseif ($btol < 0) {
$btol = 0;
}
elseif ($btol > 5) {
$btol = 5;
}
return $btol;
}
function start_job() {
$config = get_config();
# Change from "preparation" to "waiting"
if (isset($config) && isset($config['status']) && $config["status"] == 'preparation') {
$config["status"] = "waiting";
# Get a mail address too?
if (isset($_GET["mail"])) {
$mail = check_mail($_GET["mail"]);
if ($mail == '') {
return array(
'status' => "mail_error",
);
} else {
$config["mail"] = $mail;
}
}
# Get an author?
if (isset($_GET["author"])) {
$author = check_text($_GET["author"]);
if ($author == '') {
return array(
'status' => "author_error",
);
} else {
$config["author"] = $author;
}
}
# Get a description?
if (isset($_GET["description"])) {
$description = check_text($_GET["description"]);
if ($description == '') {
return array(
'status' => "description_error",
);
} else {
$config["description"] = $description;
}
}
# Get a blocks tolerance value?
if (isset($_GET["btol"])) {
$btol = check_blocks_tol($_GET["btol"]);
$config["blocks_tolerance"] = $btol;
}
set_config($config);
return $config;
} else {
return array(
'status' => "error",
'details' => "Status already exists (" . $status['status'] . ")",
);
}
}
$output = array();
# Check id
if (!check_id($id)) {
$output = array(
"status" => "error",
"details" => "Invalid id ($id)",
);
} else if (isset($_GET["command"])) {
$command = $_GET["command"];
# Check for the status of the current working dir
if ($command == "check") {
$output = get_config();
# Start the job (=create an empty status file)
} else if ($command == "start") {
$output = start_job();
} else {
$output = array(
"status" => 'error',
"details" => 'invalid command',
);
}
} else {
$output = array(
"status" => "error",
"details" => "No command",
);
}
echo json_encode($output);
?>