├── .gitignore
├── LICENSE
├── README.md
├── config
└── configuration.json
├── go.mod
├── go.sum
├── logs
└── .gitignore
├── private
├── includes
│ └── template.gop
├── scripts
│ ├── DirectoryListing.gop
│ ├── ip_denied.gop
│ └── ip_ratelimited.gop
└── uploads
│ └── .gitignore
├── public
├── examples
│ ├── dependencies
│ │ ├── example_required1.gop
│ │ ├── example_required2.gop
│ │ ├── example_required3.gop
│ │ └── example_required4.gop
│ ├── directorylisting
│ │ └── info.txt
│ ├── errors
│ │ ├── go_file_empty.go
│ │ ├── go_file_while_true.go
│ │ ├── go_file_without_import.go
│ │ ├── gop_file_empty.gop
│ │ ├── gop_file_syntax_error.gop
│ │ ├── gop_file_while_true.gop
│ │ ├── gop_without_import.gop
│ │ └── gop_without_tag.gop
│ ├── for_loop_100000.gop
│ ├── go_file.go
│ ├── go_file_with_functions.go
│ ├── gop_api.gop
│ ├── gop_content_type.gop
│ ├── gop_file.gop
│ ├── gop_file_cookies.gop
│ ├── gop_file_get_parameters.gop
│ ├── gop_file_import_syntax.gop
│ ├── gop_file_methods.gop
│ ├── gop_file_minified.gop
│ ├── gop_file_post_parameters.gop
│ ├── gop_file_require.gop
│ ├── gop_file_server.gop
│ ├── gop_file_upload.gop
│ ├── gop_file_with_functions.gop
│ ├── gop_file_with_headers.gop
│ ├── gop_file_with_included_functions.gop
│ ├── gop_httpauth.gop
│ ├── gop_mysql.gop
│ ├── gop_sessions.gop
│ ├── gop_unprivileged_user.gop
│ ├── image.png
│ ├── index.gop
│ └── text.txt
├── favicon.ico
├── index.gop
├── license.gop
└── page.go
└── src
├── controller
├── go.go
├── gop.go
└── index.go
├── handler
├── alias.go
├── errors
│ ├── errors.go
│ └── explainer.go
├── gopinfo.go
├── handler.go
├── iplist.go
├── parameters.go
├── ratelimit.go
└── serverstatus.go
├── main.go
├── parser
├── functions.go
├── glue.go
├── middleware.go
├── parser.go
└── utils.go
├── repository
├── cache
│ └── cache.go
└── filesystem
│ ├── read.go
│ ├── utils.go
│ └── write.go
├── server
├── config
│ └── config.go
├── logs
│ ├── logs.go
│ └── status.go
└── server.go
└── worker
├── build.go
└── run.go
/.gitignore:
--------------------------------------------------------------------------------
1 | /cache/*
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2021 Raúl Martínez (RME)
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | # Golang Preprocessor for Web Services - GOP Server #
6 |
7 |
8 | ## Introduction ###
9 |
10 | The GOP Server is an open-source web server for Linux and Windows systems that handles HTTP requests to scripts programmed in Go returning the result of the execution to the client.
11 |
12 | The software is able to, depending on the requested path, return static files or execute Go scripts, which are compiled on the fly and have specific functionality. This functionality is transparently embedded by the GOP Server into the script files to provide them with functions inherent to web application development such as URL parameter management, cookie management, session management, includes a library of basic functions and database support.
13 |
14 | GOP scripts are .gop files coded in Go but that follow the GOP specification, a superset of Go defined to integrate the extra functionality provided by the server.
15 |
16 | In summary, the server allows to easily develop web applications programmed in Go with the comfort and functionality analogous to PHP, which makes it a multipurpose tool capable of being used both in educational environments to learn the language and in development and production environments for web applications or HTTP APIs.
17 |
18 | ## Disclaimer ###
19 |
20 | *The software has just been released an has to be considered as beta, as might contain bugs and/or security vulnerabilities. Audit the code before using it in production enviroments. The software is provided as is without warranty of any kind.*
21 |
22 | ## How to run ###
23 | **The steps are simple: install Golang, clone the repository and execute from source (go run).**
24 |
25 | Then, place your files under the /public directory and access them from http://localhost:80.
26 |
27 | ### Windows Prerequisites
28 | Install Golang from https://golang.org/doc/install
29 |
30 | Clone the repository.
31 |
32 | Edit the configuration if needed (config/configuration.json)
33 |
34 | Open a terminal inside the GOP-Server folder.
35 |
36 | ### Linux Prerequisites
37 | ```
38 | sudo apt update
39 | sudo apt install golang
40 | ```
41 | ```
42 | git clone https://github.com/i-rme/GOP-Server.git
43 | cd GOP-Server
44 | nano config/configuration.json
45 | ```
46 |
47 | ### Linux
48 | ```sudo go run src/main.go```
49 |
50 | ### Windows
51 | ```go run src/main.go```
52 |
53 | ### WSL
54 | ```wsl sudo go run src/main.go```
55 |
56 | ## Optional Settings
57 | Enable database support by setting *MySQLSupportEnabled* to `true` in the config file.
58 |
59 | Enable privilege downgrade by setting *RunScriptsAsNobody* to `true` in the config file.
60 |
61 | ## Important paths
62 | **Configuration file**: `./config/configuration.json`
63 |
64 | **Default document root**: `./public`
65 |
66 | **Default log directory**: `./logs`
67 |
68 | **Default uploads directory**: `./private/uploads`
69 |
70 | **CMS Example database details**: `./public/examples/cms/components/repository.gop`
71 |
72 | ## Troubleshooting
73 | **Error**: *CreateFile src/main.go: The system cannot find the path specified.* when launching the GOP Server with go run.
74 |
75 | **Solution**: Navigate to the GOP-Server directory before launching. ```cd GOP-Server```
76 |
77 | **Error**: "*no required module provides package*" when MySQL support is enabled.
78 |
79 | **Solution**: Install the missing package using ```go get github.com/go-sql-driver/mysql```
80 |
81 | **Error**: "*listen tcp 127.0.0.1:80: bind: permission denied*" when starting the server on linux.
82 |
83 | **Solution**: Run the server with root privileges ```sudo go run src/main.go```
84 |
85 |
86 | ## Architecture
87 | 
88 |
--------------------------------------------------------------------------------
/config/configuration.json:
--------------------------------------------------------------------------------
1 | {
2 | "Port": 80,
3 | "Address": "127.0.0.1",
4 |
5 | "ReadTimeout": 12000000000,
6 | "WriteTimeout": 12000000000,
7 | "IdleTimeout": 60000000000,
8 | "MaxHeaderBytes": 1000000,
9 |
10 | "DocumentRoot": "public",
11 | "CacheRoot": "cache",
12 | "LogRoot": "logs",
13 | "UploadsRoot": "private/uploads",
14 |
15 | "Aliases": {
16 | "/api/": "/examples/gop_api.gop"
17 | },
18 |
19 | "DenyFrom": [
20 | "10.1.2.0/24"
21 | ],
22 |
23 | "ServerSignature": "Golang Preprocessor for Web Services v1.0",
24 |
25 | "DirectoryListingScript": "/../private/scripts/DirectoryListing.gop",
26 | "IPDeniedScript": "/../private/scripts/ip_denied.gop",
27 |
28 | "SessionCookieName": "GopSession",
29 |
30 | "GopHeadersSeparator": "