-
Notifications
You must be signed in to change notification settings - Fork 0
/
taskls.php
128 lines (115 loc) · 2.63 KB
/
taskls.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
124
125
126
127
<?php
require_once("auth.php");
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>CBSD Project</title>
<link type="text/css" href="./css/all.css" rel="stylesheet" />
<style>
body {
font-size:14px;
}
</style>
</head>
<body>
<a href="javascript:location.reload(true)">[ Refresh Page ]</a> | <a href="taskls.php?flushlog=true">[ Flush Log ]</a>
<?php
// clean all log records in taskdb
function flush_log()
{
$handle=popen("env NOCOLOR=1 /usr/local/bin/sudo /usr/local/bin/cbsd task mode=flushall", "r");
$read = fgets($handle, 4096);
pclose($handle);
header( 'Location: taskls.php' ) ;
}
// just show all log where owner is cbsdweb
function show_logs()
{
global $workdir;
$db = new SQLite3("$workdir/var/db/cbsdtaskd.sqlite"); $db->busyTimeout(5000);
$sql = "SELECT id,st_time,end_time,cmd,status,errcode,logfile FROM taskd WHERE owner='cbsdweb' ORDER BY id DESC;";
$result = $db->query($sql);//->fetchArray(SQLITE3_ASSOC);
$row = array();
$i = 0;
?>
<table class="images">
<thead>
<tr>
<th>id</th>
<th>cmd</th>
<th>start time</th>
<th>end time</th>
<th>status</th>
<th>errcode</th>
<th>logfile</th>
<th>logsize</th>
</tr>
</thead><tbody align="center">
<?php
while($res = $result->fetchArray(SQLITE3_ASSOC)){
if(!isset($res['id'])) continue;
$id = $res['id'];
$cmd = $res['cmd'];
$start_time = $res['st_time'];
$end_time = $res['end_time'];
$status = $res['status'];
$errcode = $res['errcode'];
$logfile = $res['logfile'];
if (file_exists($logfile)) {
$tmplogsize=filesize($logfile);
$logsize=human_filesize($tmplogsize,0);
} else {
$logsize=0;
}
$i++;
switch ($status) {
case 0:
//pending
$hdr = '<tr style="background-color:#51FF5F">';
break;
case 1:
//in progress
$hdr = '<tr style="background-color:#F3FF05">';
break;
case 2:
//complete
switch ($errcode) {
case 0:
$hdr = '<tr style="background-color:#EDECEA">';
break;
default:
//errcode not 0
$hdr = '<tr style="background-color:#FFA7A1">';
break;
}
break;
}
$s_time=date("Y-M-d H:i", strtotime($start_time));
$e_time=date("Y-M-d H:i", strtotime($end_time));
if ( $logsize!= 0 ) {
$logfiletd="<td><a href=\"showtasklog.php?log=$logfile\">$logfile</a></td>";
} else {
$logfiletd="<td>$logfile</td>";
}
$str = <<<EOF
<td>$id</td>
<td>$cmd</td>
<td>$s_time</td>
<td>$e_time</td>
<td>$status</td>
<td>$errcode</td>
$logfiletd
<td>$logsize</td>
</tr>
EOF;
echo $hdr.$str;
}
echo "</tbody></table>";
}
// MAIN
require('cbsd.php');
if (isset($_GET['flushlog'])) {
flush_log();
}
show_logs();