void urlcheck() { struct databuffer thisdb; struct databuffer thisdb2; // Block tries to read documents outside the document root thisdb = auto_db(".."); if (db_contains(&url, &thisdb)) { thisdb = auto_db("/"); db_set(&url, &thisdb); db_set(&file, &FILES); } // Avoid a bug if (file_isdir(db_raw(&file))) { thisdb = auto_db("/"); if (!db_endswith(&url, &thisdb)) { thisdb2 = auto_db("HTTP/1.0 302 Moved permanently\nLocation: "); db_set(&status, &thisdb2); //db_append(&status, &WEBSITE); db_append(&status, &url); db_append(&status, &thisdb); thisdb = auto_db("text/html"); db_set(&contenttype, &thisdb); httpheaders(); done = true; } } // Find index.html db_set(&thisdb, &file); thisdb2 = auto_db("index.html"); db_append(&thisdb, &thisdb2); if (file_isregfile(thisdb.data)) { db_append(&url, &thisdb2); db_append(&file, &thisdb2); } // Find index.php db_set(&thisdb, &file); thisdb2 = auto_db("index.php"); db_append(&thisdb, &thisdb2); if (file_isregfile(thisdb.data)) { db_append(&url, &thisdb2); db_append(&file, &thisdb2); } // Respond 404 if the file doesn't exist if (!file_exists(db_raw(&file))) { thisdb = auto_db("HTTP/1.0 404 Not Found"); db_set(&status, &thisdb); thisdb = auto_db("text/html"); db_set(&contenttype, &thisdb); db_set(&file, &FILES); db_append(&file, &ERROR404); } // Respond 403 if the file isn't readable if (!file_accessible(db_raw(&file), R_OK)) { thisdb = auto_db("HTTP/1.0 403 Forbidden"); db_set(&status, &thisdb); thisdb = auto_db("text/html"); db_set(&contenttype, &thisdb); db_set(&file, &FILES); db_append(&file, &ERROR403); } }