diff --git a/compile-web.sh b/compile-web.sh new file mode 100755 index 0000000..5ff35cc --- /dev/null +++ b/compile-web.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env sh +cd web +inliner page.html > ../index-inlined-minified.html diff --git a/devbox.json b/devbox.json index 4ed5580..3ef1ae4 100644 --- a/devbox.json +++ b/devbox.json @@ -3,7 +3,8 @@ "go", "gopls", "nodejs", - "nodePackages.vscode-html-languageserver-bin" + "nodePackages.vscode-html-languageserver-bin", + "nodePackages.inliner" ], "nixpkgs": { "commit": "f80ac848e3d6f0c12c52758c0f25c10c97ca3b62" diff --git a/index-inlined-minified.html b/index-inlined-minified.html new file mode 100644 index 0000000..1491f90 --- /dev/null +++ b/index-inlined-minified.html @@ -0,0 +1 @@ + Montehaselino - Automatic Status Response

ERROR

{{.Code}}

{{.Message}}

Go Back
This is an automatically generated error response page.
Please contact administration if you feel this shouldn't be here.
diff --git a/main.go b/main.go index e029191..51cdcff 100644 --- a/main.go +++ b/main.go @@ -1,17 +1,89 @@ package main import ( + "errors" "fmt" + "html/template" "log" "net/http" + "strconv" ) -func handler(w http.ResponseWriter, r *http.Request) { - // url path: r.URL.Path[1:] +type StatusData struct { + Code string + Message string + Response int +} +var Statuses = map[string]string{ + "401": "You are not authorized to access the resource", + "404": "The requested resource couldn't be found", + "403": "Access to the resource was denied for the server", + "405": "Method not supported by the server", + "407": "You are no authorized to access the resource", + "408": "Request timed out", + "410": "The requested content is permanently gone", + "414": "Requested URI is too long", + "415": "Unsupported media type", + "500": "The server encountered an internal error", + "501": "Method not supported by the server", + "502": "Requested endpoint encountered an error", + "503": "Service is currently unavailable", + "504": "Requested endpoint is unreachable", + "505": "Protocol version not supported", + "511": "Requested endpoint requires authentication for proxy", +} + +func isStatusCode(code string) (int, error) { + num, err := strconv.Atoi(code) + if err != nil { + return 500, errors.New("not a number") + } + + if num > 99 && num < 512 { + return num, nil + } + + return 500, errors.New("Invalid range") +} + +func genStatus(request string) StatusData { + // create and init page status + var status StatusData + status.Code = "500" + status.Message = fmt.Sprintf("Invalid error response code recieved: %.5s[..]", request) + status.Response = 500 + + // check if we have a valid status code + var code, err = isStatusCode(request) + if err == nil { + status.Code = request + status.Message = fmt.Sprintf("Interrupted unsupported error response: %s", request) + status.Response = code + } + + // set custom status message if present + description, ok := Statuses[request] + if ok { + status.Message = description + } + + return status } func main() { - http.HandleFunc("/", handler) + // load template + tmpl, err := template.ParseFiles("index-inlined-minified.html") + if err != nil { + log.Fatal(err) + } + + http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { + status := genStatus(r.URL.Path[1:]) + // set status code to propagate http error code + w.WriteHeader(status.Response) + tmpl.Execute(w, status) + }) + log.Fatal(http.ListenAndServe("127.0.0.1:8000", nil)) } diff --git a/nginx.conf b/nginx.conf deleted file mode 100644 index ef14c78..0000000 --- a/nginx.conf +++ /dev/null @@ -1,104 +0,0 @@ -worker_processes 1; -error_log stderr warn; -pid /run/nginx.pid; - -events { - worker_connections 1024; -} - -http { - include mime.types; - default_type application/octet-stream; - - # Define custom log format to include reponse times - log_format main_timed '$remote_addr - $remote_user [$time_local] "$request" ' - '$status $body_bytes_sent "$http_referer" ' - '"$http_user_agent" "$http_x_forwarded_for" ' - '$request_time $upstream_response_time $pipe $upstream_cache_status'; - - access_log /dev/stdout main_timed; - error_log /dev/stderr notice; - - keepalive_timeout 65; - - # Write temporary files to /tmp so they can be created as a non-privileged user - client_body_temp_path /tmp/client_temp; - proxy_temp_path /tmp/proxy_temp_path; - fastcgi_temp_path /tmp/fastcgi_temp; - uwsgi_temp_path /tmp/uwsgi_temp; - scgi_temp_path /tmp/scgi_temp; - - # Default server definition - server { - listen 8080 default_server; - server_name _; - - sendfile off; - - # Increase proxy buffers for large requests - proxy_buffer_size 128k; - proxy_buffers 4 256k; - proxy_busy_buffers_size 256k; - - # Upload limit - client_max_body_size 2M; - client_body_buffer_size 128k; - - root /var/www/html; - index index.php index.html; - - location / { - # First attempt to serve request as file, then - # as directory, then fall back to index.php - try_files $uri $uri/ /index.php?q=$uri&$args; - } - - # Redirect server error pages to the static page /50x.html - error_page 500 502 503 504 /50x.html; - location = /50x.html { - root /var/lib/nginx/html; - } - - # Pass the PHP scripts to PHP-FPM listening on 127.0.0.1:9000 - location ~ [^/]\.php(/|$) { - fastcgi_split_path_info ^(.+\.php)(/.+)$; - fastcgi_pass 127.0.0.1:9000; - fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; - fastcgi_param SCRIPT_NAME $fastcgi_script_name; - fastcgi_param PATH_INFO $fastcgi_path_info; - fastcgi_index index.php; - fastcgi_intercept_errors off; - include fastcgi_params; - } - - location ~* \.(jpg|jpeg|gif|png|css|js|ico|xml)$ { - expires 5d; - } - - # Deny access to . files, for security - location ~ /\. { - log_not_found off; - deny all; - } - - # Allow fpm ping and status from localhost - location ~ ^/(fpm-status|fpm-ping)$ { - access_log off; - allow 127.0.0.1; - deny all; - fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; - include fastcgi_params; - fastcgi_pass 127.0.0.1:9000; - } - } - - # Include other server configs - include /etc/nginx/conf.d/*.conf; - - gzip on; - gzip_proxied any; - gzip_types text/plain application/xml text/css text/js text/xml application/x-javascript text/javascript application/json application/xml+rss; - gzip_vary on; - gzip_disable "msie6"; - -} diff --git a/web/page.html b/web/page.html index 2f3ff34..f1767d9 100644 --- a/web/page.html +++ b/web/page.html @@ -5,6 +5,7 @@ + Montehaselino - Automatic Status Response @@ -16,9 +17,9 @@

ERROR

-

404

-

Page ot found

- Go Back +

{{.Code}}

+

{{.Message}}

+ Go Back
This is an automatically generated error response page.
diff --git a/web/res/font/Mont-Heavy.otf b/web/res/font/Mont-Heavy.otf new file mode 100644 index 0000000..7429cee Binary files /dev/null and b/web/res/font/Mont-Heavy.otf differ diff --git a/web/res/svg/cloud.svg b/web/res/svg/cloud.svg new file mode 100644 index 0000000..0337c44 --- /dev/null +++ b/web/res/svg/cloud.svg @@ -0,0 +1,41 @@ + + + + + + + + + + diff --git a/web/res/svg/error-page-overlay.svg b/web/res/svg/error-page-overlay.svg new file mode 100644 index 0000000..52947a9 --- /dev/null +++ b/web/res/svg/error-page-overlay.svg @@ -0,0 +1,63 @@ + + + + diff --git a/web/res/svg/rocks.svg b/web/res/svg/rocks.svg new file mode 100644 index 0000000..9d19a05 --- /dev/null +++ b/web/res/svg/rocks.svg @@ -0,0 +1,38 @@ + + + + + + + + + +