芝麻web文件管理V1.00
编辑当前文件:/home/pulsehostuk9/public_html/status.pulsehost.co.uk/app/controllers/api/ApiDnsMonitors.php
monitors_heartbeats->dns_monitors_is_enabled) { redirect('not-found'); } $this->verify_request(); /* Decide what to continue with */ switch($_SERVER['REQUEST_METHOD']) { case 'GET': /* Detect if we only need an object, or the whole list */ if(isset($this->params[0])) { $this->get(); } else { $this->get_all(); } break; case 'DELETE': $this->delete(); break; } $this->return_404(); } private function get_all() { /* Prepare the filtering system */ $filters = (new \Altum\Filters([], [], [])); $filters->set_default_order_by($this->api_user->preferences->dns_monitors_default_order_by, $this->api_user->preferences->default_order_type ?? settings()->main->default_order_type); $filters->set_default_results_per_page($this->api_user->preferences->default_results_per_page ?? settings()->main->default_results_per_page); $filters->process(); /* Prepare the paginator */ $total_rows = database()->query("SELECT COUNT(*) AS `total` FROM `dns_monitors` WHERE `user_id` = {$this->api_user->user_id}")->fetch_object()->total ?? 0; $paginator = (new \Altum\Paginator($total_rows, $filters->get_results_per_page(), $_GET['page'] ?? 1, url('api/dns_monitors?' . $filters->get_get() . '&page=%d'))); /* Get the data */ $data = []; $data_result = database()->query(" SELECT * FROM `dns_monitors` WHERE `user_id` = {$this->api_user->user_id} {$filters->get_sql_where()} {$filters->get_sql_order_by()} {$paginator->get_sql_limit()} "); while($row = $data_result->fetch_object()) { /* Prepare the data */ $row = [ 'id' => (int) $row->dns_monitor_id, 'user_id' => (int) $row->user_id, 'project_id' => (int) $row->project_id, 'name' => $row->name, 'target' => $row->target, 'dns' => json_decode($row->dns), 'notifications' => json_decode($row->notifications), 'settings' => json_decode($row->settings), 'total_checks' => (int) $row->total_checks, 'total_changes' => (int) $row->total_changes, 'last_check_datetime' => $row->last_check_datetime, 'next_check_datetime' => $row->next_check_datetime, 'last_change_datetime' => $row->last_change_datetime, 'is_enabled' => (bool) $row->is_enabled, 'datetime' => $row->datetime, 'last_datetime' => $row->last_datetime, ]; $data[] = $row; } /* Prepare the data */ $meta = [ 'page' => $_GET['page'] ?? 1, 'total_pages' => $paginator->getNumPages(), 'results_per_page' => $filters->get_results_per_page(), 'total_results' => (int) $total_rows, ]; /* Prepare the pagination links */ $others = ['links' => [ 'first' => $paginator->getPageUrl(1), 'last' => $paginator->getNumPages() ? $paginator->getPageUrl($paginator->getNumPages()) : null, 'next' => $paginator->getNextUrl(), 'prev' => $paginator->getPrevUrl(), 'self' => $paginator->getPageUrl($_GET['page'] ?? 1) ]]; Response::jsonapi_success($data, $meta, 200, $others); } private function get() { $dns_monitor_id = isset($this->params[0]) ? (int) $this->params[0] : null; /* Try to get details about the resource id */ $dns_monitor = db()->where('dns_monitor_id', $dns_monitor_id)->where('user_id', $this->api_user->user_id)->getOne('dns_monitors'); /* We haven't found the resource */ if(!$dns_monitor) { $this->return_404(); } /* Prepare the data */ $data = [ 'id' => (int) $dns_monitor->dns_monitor_id, 'user_id' => (int) $dns_monitor->user_id, 'project_id' => (int) $dns_monitor->project_id, 'name' => $dns_monitor->name, 'target' => $dns_monitor->target, 'dns' => json_decode($dns_monitor->dns), 'notifications' => json_decode($dns_monitor->notifications), 'settings' => json_decode($dns_monitor->settings), 'total_checks' => (int) $dns_monitor->total_checks, 'total_changes' => (int) $dns_monitor->total_changes, 'last_check_datetime' => $dns_monitor->last_check_datetime, 'next_check_datetime' => $dns_monitor->next_check_datetime, 'last_change_datetime' => $dns_monitor->last_change_datetime, 'is_enabled' => (bool) $dns_monitor->is_enabled, 'datetime' => $dns_monitor->datetime, 'last_datetime' => $dns_monitor->last_datetime, ]; Response::jsonapi_success($data); } private function delete() { $dns_monitor_id = isset($this->params[0]) ? (int) $this->params[0] : null; /* Try to get details about the resource id */ $dns_monitor = db()->where('dns_monitor_id', $dns_monitor_id)->where('user_id', $this->api_user->user_id)->getOne('dns_monitors'); /* We haven't found the resource */ if(!$dns_monitor) { $this->return_404(); } /* Delete the resource */ db()->where('dns_monitor_id', $dns_monitor_id)->delete('dns_monitors'); /* Clear cache */ cache()->deleteItemsByTag('dns_monitor_id=' . $dns_monitor->dns_monitor_id); http_response_code(200); die(); } }