diff --git a/.htaccess b/.htaccess index 547f9d3..0c567a6 100755 --- a/.htaccess +++ b/.htaccess @@ -2,6 +2,12 @@ RewriteEngine on + # Never serve build/VCS/ops artefacts that live in the webroot (2026-11-18). + # Dotfiles + .git are also blocked server-wide on test (conf block-sensitive). + RewriteRule (^|/)\.(?!well-known(/|$)) - [R=404,L] + RewriteRule \.(md|rst|log|7z|zip|tar|gz|sql|csv|lock|bak|old|orig|swp|env|ini|sh)$ - [R=404,NC,L] + RewriteRule ^(composer\.json|vendor/|documents/|archive/|cgi-bin/) - [R=404,NC,L] + # Job ad renamed: ledigestilling.html -> negletekniker.html (2026-07-17) RewriteRule ^ledigestilling/ledigestilling\.html$ /ledigestilling/negletekniker.html [R=301,L] diff --git a/application/controllers/Admin.php b/application/controllers/Admin.php index 18490ca..4b4ad37 100755 --- a/application/controllers/Admin.php +++ b/application/controllers/Admin.php @@ -130,6 +130,7 @@ class Admin extends CI_Controller { } public function worker_schedule_overrides() { + $this->_requireLogin(); $this->load->model('Service_model'); $data['currentUser'] = $this->User_model->getUserByUsername($_SESSION['username']); $data['workerSchedules'] = $this->Service_model->getWorkerScheduleOverrides(); @@ -139,6 +140,7 @@ class Admin extends CI_Controller { } public function admin_worker_schedule() { + $this->_requireLogin(); $this->load->helper('url'); $this->load->model('User_model'); $this->load->model('Service_model'); @@ -174,6 +176,7 @@ class Admin extends CI_Controller { } public function store_worker_schedule() { + $this->_requireLogin(); $this->load->model('Service_model'); $this->load->helper('url'); @@ -212,6 +215,7 @@ class Admin extends CI_Controller { public function manage_worker_schedule($worker_id = null) { + $this->_requireLogin(); $this->load->model('Service_model'); $data['workers'] = $this->Service_model->getAllWorkers(); $data['selectedWorker'] = null; @@ -226,6 +230,7 @@ class Admin extends CI_Controller { } public function save_worker_schedule() { + $this->_requireLogin(); $this->load->model('Service_model'); $worker_id = $this->input->post('worker_id'); @@ -1358,6 +1363,20 @@ class Admin extends CI_Controller { } } + /** + * Stop here unless an admin is logged in. Every public method of this + * controller is reachable at /admin/ through CodeIgniter's default + * routing, routed or not, so each one must check the session itself. + */ + private function _requireLogin(){ + $this->load->helper('url'); + $this->load->model('User_model'); + if(empty($_SESSION['username']) || !is_object($this->User_model->getUserByUsername($_SESSION['username']))){ + header("Location:".SITEURL."login"); + exit; + } + } + private function _ntfy($title, $message, $workerTopic = null){ $this->config->load('google_calendar'); $evelinTopic = $this->config->item('ntfy_topic'); diff --git a/application/controllers/Pages.php b/application/controllers/Pages.php index 84460ad..07492ce 100755 --- a/application/controllers/Pages.php +++ b/application/controllers/Pages.php @@ -136,6 +136,23 @@ class Pages extends CI_Controller { $data['pageTitle'] = ''; + // Admin-only actions. /ajax is a public endpoint (the booking form uses it), + // so these must check the session themselves: without this, anyone could + // disable the admin accounts, enumerate usernames or read the full system + // log (guest names, e-mails, phones). Same access rule as UserManagement: + // admins, or users granted the module. + $adminActions = array( + 'changeUserStatus' => 'user-management', + 'checkUser' => 'user-management', + 'refreshLogMonitor' => 'log-monitor', + ); + if(isset($_POST['action']) && is_string($_POST['action']) && isset($adminActions[$_POST['action']]) + && !$this->_ajaxUserCan($adminActions[$_POST['action']])){ + $this->output->set_status_header(403); + echo json_encode(array('error' => 'forbidden')); + return; + } + if(isset($_POST['action']) && $_POST['action'] == 'getAvailableWorkersByServiceCategory' && isset($_POST['serv_cat_slug'])){ // The picker must only offer workers who can perform EVERY service the // guest has ticked. service_ids is supplied by the booking form; when it @@ -180,8 +197,21 @@ class Pages extends CI_Controller { } } + // Public response: only what the booking page needs. The full worker + // rows carry ntfy_topic (anyone knowing it can read every booking + // notification) and google_calendar_id. + $publicWorkers = array(); + if(is_array($workers)){ + foreach($workers as $workerItem){ + $publicWorkers[] = array( + 'worker_id' => $workerItem->worker_id, + 'worker_name' => $workerItem->worker_name + ); + } + } + $responseArray = array( - 'workers' => $workers, + 'workers' => $publicWorkers, 'workerListShow' => $workerListShow ); @@ -284,10 +314,10 @@ class Pages extends CI_Controller { if(isset($_POST['action']) && $_POST['action'] == 'changeUserStatus' && isset($_POST['user_id']) && isset($_POST['newValue']) && isset($_POST['operator'])){ $data['currentUser'] = $this->User_model->getUserById($_POST['user_id']); $userArray = array( - 'is_enabled' => $_POST['newValue'] + 'is_enabled' => $_POST['newValue'] ? 1 : 0 ); $this->User_model->updateUser($_POST['user_id'], $userArray); - $this->Log_model->addLog('change_user_status', $data['currentUser']->username.' státusza változott - '.($_POST['newValue']?'aktív':'letiltva').' állapotra', $_POST['operator']); + $this->Log_model->addLog('change_user_status', $data['currentUser']->username.' státusza változott - '.($_POST['newValue']?'aktív':'letiltva').' állapotra', $_SESSION['username']); } if(isset($_POST['action']) && $_POST['action'] == 'checkUser'){ @@ -310,6 +340,25 @@ class Pages extends CI_Controller { } + /** + * True if the logged-in user may use an admin AJAX action: an enabled admin, + * or a user granted the given module. + */ + private function _ajaxUserCan($moduleSlug){ + if(empty($_SESSION['username'])){ + return false; + } + $user = $this->User_model->getUserByUsername($_SESSION['username']); + if(!is_object($user) || !$user->is_enabled){ + return false; + } + if($user->permission_slug == 'admin'){ + return true; + } + $this->load->model('Module_model'); + return (bool)$this->Module_model->user_can_access_this_module($moduleSlug, $user->user_id); + } + /** * Render a guest-facing error page instead of raw JSON. The public booking * form is a normal full-page POST, so whatever this outputs is what the