sock = $sock; $this->datapath = $datapath; $this->isRunning = true; $this->cfg = new Config($datapath . "config.yml", Config::YAML); } public function onRun() { $sock = $this->sock; socket_listen($sock); while ($this->isRunning) { $client = socket_accept($sock); $input = socket_read($client, 1024); $incoming = explode("\r\n", $input); $fetchArray = explode(" ", $incoming[0]); if($fetchArray[1] == "/"){ $file = "index.html"; $fetchArray[1] = "index.html"; } else { $filearray = []; $filearray = explode("/", $fetchArray[1]); $file = $fetchArray[1]; } $output = ""; $Header = "HTTP/1.1 200 OK \r\n" . "Date: Fri, 31 Dec 1999 23:59:59 GMT \r\n" . "Content-Type: text/html \r\n\r\n"; $file = ltrim($file, '/'); echo $fetchArray[1]; if(file_exists($this->datapath . $file)) { $Content = file_get_contents($this->datapath . $file); } else { $Content = file_get_contents($this->datapath . "404.html"); } if(in_array($file, $this->cfg->get("denied-pages"))) { $Content = file_get_contents($this->datapath . "403.html"); } $output = $Header . $Content; socket_write($client,$output,strlen($output)); } } public function close() { $this->isRunning = false; } }