crontabs.php
См. документацию.
1 <?php
2 
3 /**
4  * @file
5  * @brief выборка моделей типа "cron задача"
6  */
7 
8 isset($user) or require $_SERVER['DOCUMENT_ROOT'] . '/page/404.php';
9 
10 header("Content-type: application/json");
11 
12 $table_name = basename($request);
13 
14 $columns = ['id', 'threads', 'cli', 'request', 'user_id', 'shedule', 'method', 'headers', 'data', 'owner_group', 'run_at', 'note', 'act'];
15 
16 $order_column = isset($_GET['order'][0]['column']) && isset($columns[$_GET['order'][0]['column']]) ? $columns[$_GET['order'][0]['column']] : $columns[0];
17 $order_dir = isset($_GET['order'][0]['dir']) && $_GET['order'][0]['dir'] == 'asc' ? 'ASC' : 'DESC';
18 $start = abs(intval($_GET['start']));
19 $length = intval($_GET['length']);
20 
21 $query = "SELECT " . implode(', ', $columns) . " FROM `$table_name` ORDER BY `$order_column` $order_dir";
22 
23 $sth = $dbh->prepare($query);
24 $sth->execute();
25 $arr = $sth->fetchAll(PDO::FETCH_NUM);
26 
27 foreach ($arr as $key => $item) {
28  $threads = json_decode($item[1], true) ?: Wrong\Task\Cron::DEFAULT_THERADS_SET;
29  $threads['curr'] = intval(shell_exec("ps aux | grep 'php -f " . dirname(__DIR__, 3) . "/cron\.php " . $item[0] . "' | wc -l"));
30  $text = "{$threads['curr']} / {$threads['min']} / {$threads['max']} / {$threads['load']}% / " . ($threads['fixed'] ? '+' : '-');
31  $title = '<div class=\'text-left small\'>Потоков в работе: <b>' . $threads['curr'] . '</b><br>Минимум потоков: <b>' . $threads['min'] . '</b><br>Максимум потоков: <b>' . $threads['max'] . '</b><br>Предел нагрузки: <b>' . $threads['load'] . '%</b><br>Держать потоки: <b>' . ($threads['fixed'] ? 'да' : 'нет') . '</b></div>';
32  $arr[$key][1] = '<div title="' . $title . '" class="edit-wrapper editable-act" data-toggle="modal" data-target="#edit-threads" data-id="' . $item[0] . '">' . $text . '<i class="fa fa-edit"></i></div>';
33  $arr[$key][2] = htmlspecialchars($item[2], ENT_QUOTES);
34  $arr[$key][2] = '<div title="' . $item[2] . '" class="edit-wrapper editable-act" data-id="' . $item[0] . '" data-target="#edit-cli" data-toggle="modal" data-table="' . $table_name . '">' . $item[2] . '<i class="fa fa-edit"></i></div>';
35 }
36 
38 
39 
41 
42 if (!empty($_GET['search']['value'])) {
43  $searchable_columns = [];
44  $arr_filtered = [];
45  foreach ($_GET['columns'] as $key => $item) {
46  if ($item['searchable']) {
47  $searchable_columns[] = $key;
48  }
49  }
50 
51  if ($searchable_columns) {
52  foreach ($arr as $key => $item) {
53  $arr_search = array_intersect_key($item, $searchable_columns);
54  foreach ($arr_search as $word) {
55  if (mb_stripos(strip_tags($word), $_GET['search']['value']) !== false) {
56  $arr_filtered[] = $arr[$key];
57  continue 2;
58  }
59  }
60  }
61  }
62 }
63 
64 $response = [];
65 $response['recordsTotal'] = count($arr);
66 $response['recordsFiltered'] = $response['recordsTotal'];
67 $length = $length == -1 ? $response['recordsTotal'] : $length;
68 $response['recordsFiltered'] = count($arr_filtered);
69 $response['data'] = array_slice($arr_filtered, $start, $length);
70 $response['draw'] = abs(intval($_GET['draw']));
71 if ($user->id == 1) {
72  $response['uptime'] = shell_exec('uptime');
73 }
74 
75 
76 exit(json_encode($response, JSON_UNESCAPED_UNICODE));
if(!($row=Wrong\Models\Crontabs::find($_POST['id']))) if(! $user->access() ->write($row)) if($_POST['min']< 1|| $_POST['min'] > 100000|| $_POST['max']< 1|| $_POST['max'] > 100000|| $_POST['load']< 1|| $_POST['load'] > 1000) $threads
static formatter($arr, $columns, $table)
Definition: Selects.php:68
const DEFAULT_THERADS_SET
Definition: Cron.php:25
$user
Definition: from-user.php:38
setcookie('FROM_UID', $uid, [ 'expires'=> time()+31536000, 'path'=> '/', 'domain'=> $_SERVER['HTTP_HOST'], 'secure'=> Wrong\Start\Env::$e->IS_SECURE, 'httponly'=> false, 'samesite'=> Wrong\Start\Env::$e->IS_SECURE ? 'None' :'Lax']) or setcookie('FROM_UID' $_SERVER['HTTP_HOST']
Definition: from-user.php:36
if(($dbh=Connect::getInstance(true) ->dbh) && $dbh->query("SHOW TABLES") ->fetchAll() && $dbh->query("SELECT COUNT(*) FROM `users`") ->fetchColumn()) if(!empty($_POST)) exit
Definition: install.php:198
$columns
Definition: crontabs.php:14
if(!empty($_GET['search']['value'])) $response
Definition: crontabs.php:64
$order_column
Definition: crontabs.php:16
$start
Definition: crontabs.php:18
$arr
Definition: crontabs.php:25
$arr_filtered
Definition: crontabs.php:40
$table_name
Definition: crontabs.php:12
$order_dir
Definition: crontabs.php:17
$length
Definition: crontabs.php:19
$query
Definition: crontabs.php:21
$sth
Definition: crontabs.php:23
catch(\Throwable $th) $request
Definition: session.php:28
$dbh
Definition: session.php:19