- Added upstream objects

- Renamed host templates to nginx templates
- Generate upstream templates
- Better nginx error reporting when reloading
- Use tparse for golang test reporting
This commit is contained in:
Jamie Curnow
2023-01-04 15:36:56 +10:00
parent b3ae2f4dbb
commit 5e5f0de0e2
82 changed files with 2209 additions and 294 deletions

View File

@ -91,6 +91,25 @@
"$ref": "file://./paths/hosts/hostID/delete.json"
}
},
"/nginx-templates": {
"get": {
"$ref": "file://./paths/nginx-templates/get.json"
},
"post": {
"$ref": "file://./paths/nginx-templates/post.json"
}
},
"/nginx-templates/{templateID}": {
"get": {
"$ref": "file://./paths/nginx-templates/templateID/get.json"
},
"put": {
"$ref": "file://./paths/nginx-templates/templateID/put.json"
},
"delete": {
"$ref": "file://./paths/nginx-templates/templateID/delete.json"
}
},
"/schema": {
"get": {
"$ref": "file://./paths/schema/get.json"
@ -139,6 +158,22 @@
"$ref": "file://./paths/tokens/post.json"
}
},
"/upstreams": {
"get": {
"$ref": "file://./paths/upstreams/get.json"
},
"post": {
"$ref": "file://./paths/upstreams/post.json"
}
},
"/upstreams/{upstreamID}": {
"get": {
"$ref": "file://./paths/upstreams/upstreamID/get.json"
},
"delete": {
"$ref": "file://./paths/upstreams/upstreamID/delete.json"
}
},
"/users": {
"get": {
"$ref": "file://./paths/users/get.json"
@ -205,11 +240,11 @@
"HostObject": {
"$ref": "file://./components/HostObject.json"
},
"HostTemplateList": {
"$ref": "file://./components/HostTemplateList.json"
"NginxTemplateList": {
"$ref": "file://./components/NginxTemplateList.json"
},
"HostTemplateObject": {
"$ref": "file://./components/HostTemplateObject.json"
"NginxTemplateObject": {
"$ref": "file://./components/NginxTemplateObject.json"
},
"SettingList": {
"$ref": "file://./components/SettingList.json"
@ -229,6 +264,12 @@
"TokenObject": {
"$ref": "file://./components/TokenObject.json"
},
"UpstreamList": {
"$ref": "file://./components/UpstreamList.json"
},
"UpstreamObject": {
"$ref": "file://./components/UpstreamObject.json"
},
"UserAuthObject": {
"$ref": "file://./components/UserAuthObject.json"
},

View File

@ -0,0 +1,40 @@
{
"type": "object",
"description": "NginxTemplateList",
"additionalProperties": false,
"required": ["total", "offset", "limit", "sort"],
"properties": {
"total": {
"type": "integer",
"description": "Total number of rows"
},
"offset": {
"type": "integer",
"description": "Pagination Offset"
},
"limit": {
"type": "integer",
"description": "Pagination Limit"
},
"sort": {
"type": "array",
"description": "Sorting",
"items": {
"$ref": "#/components/schemas/SortObject"
}
},
"filter": {
"type": "array",
"description": "Filters",
"items": {
"$ref": "#/components/schemas/FilterObject"
}
},
"items": {
"type": "array",
"items": {
"$ref": "#/components/schemas/NginxTemplateObject"
}
}
}
}

View File

@ -1,6 +1,6 @@
{
"type": "object",
"description": "HostTemplateObject",
"description": "NginxTemplateObject",
"additionalProperties": false,
"required": [
"id",
@ -8,7 +8,7 @@
"modified_on",
"user_id",
"name",
"host_type",
"type",
"template"
],
"properties": {
@ -32,9 +32,9 @@
"type": "string",
"minLength": 1
},
"host_type": {
"type": {
"type": "string",
"pattern": "^proxy|redirect|dead|stream$"
"pattern": "^proxy|redirect|dead|stream|upstream$"
},
"template": {
"type": "string",

View File

@ -1,6 +1,6 @@
{
"type": "object",
"description": "HostTemplateList",
"description": "UpstreamList",
"additionalProperties": false,
"required": ["total", "offset", "limit", "sort"],
"properties": {
@ -33,7 +33,7 @@
"items": {
"type": "array",
"items": {
"$ref": "#/components/schemas/HostTemplateObject"
"$ref": "#/components/schemas/UpstreamObject"
}
}
}

View File

@ -0,0 +1,133 @@
{
"type": "object",
"description": "UpstreamObject",
"additionalProperties": false,
"required": [
"id",
"created_on",
"modified_on",
"user_id",
"name",
"nginx_template_id",
"ip_hash",
"ntlm",
"keepalive",
"keepalive_requests",
"keepalive_time",
"keepalive_timeout",
"advanced_config",
"status",
"error_message",
"servers"
],
"properties": {
"id": {
"type": "integer",
"minimum": 1
},
"created_on": {
"type": "integer",
"minimum": 1
},
"modified_on": {
"type": "integer",
"minimum": 1
},
"user_id": {
"type": "integer",
"minimum": 1
},
"name": {
"type": "string",
"minLength": 1,
"maxLength": 100
},
"nginx_template_id": {
"type": "integer",
"minimum": 1
},
"ip_hash": {
"type": "boolean"
},
"ntlm": {
"type": "boolean"
},
"keepalive": {
"type": "integer"
},
"keepalive_requests": {
"type": "integer"
},
"keepalive_time": {
"type": "string"
},
"keepalive_timeout": {
"type": "string"
},
"advanced_config": {
"type": "string"
},
"status": {
"type": "string"
},
"error_message": {
"type": "string"
},
"servers": {
"type": "array",
"items": {
"type": "object",
"additionalProperties": false,
"required": [
"id",
"created_on",
"modified_on",
"upstream_id",
"server",
"weight",
"max_conns",
"max_fails",
"fail_timeout",
"backup"
],
"properties": {
"id": {
"type": "integer",
"minimum": 1
},
"created_on": {
"type": "integer",
"minimum": 1
},
"modified_on": {
"type": "integer",
"minimum": 1
},
"upstream_id": {
"type": "integer",
"minimum": 1
},
"server": {
"type": "string",
"minLength": 2
},
"weight": {
"type": "integer"
},
"max_conns": {
"type": "integer"
},
"max_fails": {
"type": "integer"
},
"fail_timeout": {
"type": "integer"
},
"backup": {
"type": "boolean"
}
}
}
}
}
}

View File

@ -64,7 +64,7 @@
"modified_on": 1646279455,
"user_id": 2,
"type": "proxy",
"host_template_id": 1,
"nginx_template_id": 1,
"listen_interface": "",
"domain_names": ["jc21.com"],
"upstream_id": 0,
@ -78,7 +78,6 @@
"hsts_enabled": false,
"hsts_subdomains": false,
"paths": "",
"upstream_options": "",
"advanced_config": "",
"is_disabled": false
}

View File

@ -37,7 +37,7 @@
"modified_on": 1646279455,
"user_id": 2,
"type": "proxy",
"host_template_id": 1,
"nginx_template_id": 1,
"listen_interface": "",
"domain_names": ["jc21.com"],
"upstream_id": 0,
@ -51,7 +51,6 @@
"hsts_enabled": false,
"hsts_subdomains": false,
"paths": "",
"upstream_options": "",
"advanced_config": "",
"is_disabled": false
}

View File

@ -46,7 +46,7 @@
"modified_on": 1646279455,
"user_id": 2,
"type": "proxy",
"host_template_id": 1,
"nginx_template_id": 1,
"listen_interface": "",
"domain_names": ["jc21.com"],
"upstream_id": 0,
@ -60,7 +60,6 @@
"hsts_enabled": false,
"hsts_subdomains": false,
"paths": "",
"upstream_options": "",
"advanced_config": "",
"is_disabled": false
}

View File

@ -33,7 +33,7 @@
"modified_on": 1645700556,
"user_id": 2,
"type": "proxy",
"host_template_id": 1,
"nginx_template_id": 1,
"listen_interface": "",
"domain_names": ["jc21.com"],
"upstream_id": 0,
@ -47,7 +47,6 @@
"hsts_enabled": false,
"hsts_subdomains": false,
"paths": "",
"upstream_options": "",
"advanced_config": "",
"is_disabled": false
}

View File

@ -1,7 +1,7 @@
{
"operationId": "getHostTemplates",
"summary": "Get a list of Host Templates",
"tags": ["Hosts"],
"operationId": "getNginxTemplates",
"summary": "Get a list of Nginx Templates",
"tags": ["Nginx Templates"],
"parameters": [
{
"in": "query",
@ -40,7 +40,7 @@
"required": ["result"],
"properties": {
"result": {
"$ref": "#/components/schemas/HostTemplateList"
"$ref": "#/components/schemas/NginxTemplateList"
}
}
},
@ -64,7 +64,7 @@
"modified_on": 1646218093,
"user_id": 1,
"name": "Default Proxy Template",
"host_type": "proxy",
"type": "proxy",
"template": "# this is a proxy template"
}
]

View File

@ -1,13 +1,13 @@
{
"operationId": "createHost",
"summary": "Create a new Host",
"tags": ["Hosts"],
"operationId": "createNginxTemplate",
"summary": "Create a new Nginx Template",
"tags": ["Nginx Templates"],
"requestBody": {
"description": "Host to Create",
"description": "Template to Create",
"required": true,
"content": {
"application/json": {
"schema": "{{schema.CreateHostTemplate}}"
"schema": "{{schema.CreateNginxTemplate}}"
}
}
},
@ -20,7 +20,7 @@
"required": ["result"],
"properties": {
"result": {
"$ref": "#/components/schemas/HostTemplateObject"
"$ref": "#/components/schemas/NginxTemplateObject"
}
}
},
@ -33,7 +33,7 @@
"modified_on": 1646218093,
"user_id": 1,
"name": "My proxy template",
"host_type": "proxy",
"type": "proxy",
"template": "# this is a proxy template"
}
}

View File

@ -1,17 +1,17 @@
{
"operationId": "deleteHostTemplate",
"summary": "Delete a Host Template",
"tags": ["Host Templates"],
"operationId": "deleteNginxTemplate",
"summary": "Delete a Nginx Template",
"tags": ["Nginx Templates"],
"parameters": [
{
"in": "path",
"name": "hostTemplateID",
"name": "templateID",
"schema": {
"type": "integer",
"minimum": 1
},
"required": true,
"description": "Numeric ID of the Host Template",
"description": "Numeric ID of the Template",
"example": 1
}
],
@ -46,7 +46,7 @@
"result": null,
"error": {
"code": 400,
"message": "You cannot delete a host template that is in use!"
"message": "You cannot delete a template that is in use!"
}
}
}

View File

@ -1,11 +1,11 @@
{
"operationId": "getHostTemplate",
"summary": "Get a Host Template object by ID",
"tags": ["Hosts"],
"operationId": "getNginxTemplate",
"summary": "Get a Nginx Template object by ID",
"tags": ["Nginx Templates"],
"parameters": [
{
"in": "path",
"name": "hostTemplateID",
"name": "templateID",
"schema": {
"type": "integer",
"minimum": 1
@ -24,7 +24,7 @@
"required": ["result"],
"properties": {
"result": {
"$ref": "#/components/schemas/HostTemplateObject"
"$ref": "#/components/schemas/NginxTemplateObject"
}
}
},
@ -36,8 +36,8 @@
"created_on": 1646218093,
"modified_on": 1646218093,
"user_id": 1,
"name": "Default Host Template",
"host_type": "proxy",
"name": "Default Proxy Template",
"type": "proxy",
"template": "# this is a proxy template"
}
}

View File

@ -1,26 +1,26 @@
{
"operationId": "updateHostTemplate",
"summary": "Update an existing Host Template",
"tags": ["Hosts"],
"operationId": "updateNginxTemplate",
"summary": "Update an existing Nginx Template",
"tags": ["Nginx Templates"],
"parameters": [
{
"in": "path",
"name": "hostTemplateID",
"name": "templateID",
"schema": {
"type": "integer",
"minimum": 1
},
"required": true,
"description": "ID of the Host Template",
"description": "ID of the Template",
"example": 1
}
],
"requestBody": {
"description": "Host Template details to update",
"description": "Template details to update",
"required": true,
"content": {
"application/json": {
"schema": "{{schema.UpdateHostTemplate}}"
"schema": "{{schema.UpdateNginxTemplate}}"
}
}
},
@ -33,7 +33,7 @@
"required": ["result"],
"properties": {
"result": {
"$ref": "#/components/schemas/HostTemplateObject"
"$ref": "#/components/schemas/NginxTemplateObject"
}
}
},
@ -46,7 +46,7 @@
"modified_on": 1646218093,
"user_id": 1,
"name": "My renamed proxy template",
"host_type": "proxy",
"type": "proxy",
"template": "# this is a proxy template"
}
}

View File

@ -1,11 +1,9 @@
{
"operationId": "createStream",
"summary": "Create a new Stream",
"tags": [
"Streams"
],
"tags": ["Streams"],
"requestBody": {
"description": "Host to Create",
"description": "Stream to Create",
"required": true,
"content": {
"application/json": {
@ -19,9 +17,7 @@
"content": {
"application/json": {
"schema": {
"required": [
"result"
],
"required": ["result"],
"properties": {
"result": {
"$ref": "#/components/schemas/StreamObject"
@ -39,4 +35,4 @@
}
}
}
}
}

View File

@ -0,0 +1,285 @@
{
"operationId": "getUpstreams",
"summary": "Get a list of Upstreams",
"tags": ["Upstreams"],
"parameters": [
{
"in": "query",
"name": "offset",
"schema": {
"type": "number"
},
"description": "The pagination row offset, default 0",
"example": 0
},
{
"in": "query",
"name": "limit",
"schema": {
"type": "number"
},
"description": "The pagination row limit, default 10",
"example": 10
},
{
"in": "query",
"name": "sort",
"schema": {
"type": "string"
},
"description": "The sorting of the list",
"example": "id,name.asc,value.desc"
}
],
"responses": {
"200": {
"description": "200 response",
"content": {
"application/json": {
"schema": {
"required": ["result"],
"properties": {
"result": {
"$ref": "#/components/schemas/UpstreamList"
}
}
},
"examples": {
"default": {
"value": {
"result": {
"total": 5,
"offset": 0,
"limit": 10,
"sort": [
{
"field": "name",
"direction": "ASC"
}
],
"items": [
{
"id": 1,
"created_on": 1672804124,
"modified_on": 1672804124,
"user_id": 2,
"name": "API servers",
"nginx_template_id": 5,
"ip_hash": true,
"ntlm": false,
"keepalive": 10,
"keepalive_requests": 10,
"keepalive_time": "60s",
"keepalive_timeout": "3s",
"advanced_config": "",
"status": "ok",
"error_message": "",
"servers": [
{
"id": 1,
"created_on": 1672804124,
"modified_on": 1672804124,
"upstream_group_id": 1,
"server": "192.168.0.10:80",
"weight": 100,
"max_conns": 0,
"max_fails": 0,
"fail_timeout": 0,
"backup": false
},
{
"id": 2,
"created_on": 1672804124,
"modified_on": 1672804124,
"upstream_group_id": 1,
"server": "192.168.0.11:80",
"weight": 50,
"max_conns": 0,
"max_fails": 0,
"fail_timeout": 0,
"backup": false
}
]
},
{
"id": 2,
"created_on": 1672804197,
"modified_on": 1672804197,
"user_id": 2,
"name": "API servers 2",
"nginx_template_id": 5,
"ip_hash": false,
"ntlm": false,
"keepalive": 0,
"keepalive_requests": 0,
"keepalive_time": "",
"keepalive_timeout": "",
"advanced_config": "",
"status": "ok",
"error_message": "",
"servers": [
{
"id": 3,
"created_on": 1672804197,
"modified_on": 1672804197,
"upstream_group_id": 2,
"server": "192.168.0.10:80",
"weight": 100,
"max_conns": 0,
"max_fails": 0,
"fail_timeout": 0,
"backup": false
},
{
"id": 4,
"created_on": 1672804197,
"modified_on": 1672804197,
"upstream_group_id": 2,
"server": "192.168.0.11:80",
"weight": 50,
"max_conns": 0,
"max_fails": 0,
"fail_timeout": 0,
"backup": false
}
]
},
{
"id": 3,
"created_on": 1672804200,
"modified_on": 1672804200,
"user_id": 2,
"name": "API servers 2",
"nginx_template_id": 5,
"ip_hash": false,
"ntlm": false,
"keepalive": 0,
"keepalive_requests": 0,
"keepalive_time": "",
"keepalive_timeout": "",
"advanced_config": "",
"status": "ok",
"error_message": "",
"servers": [
{
"id": 5,
"created_on": 1672804200,
"modified_on": 1672804200,
"upstream_group_id": 3,
"server": "192.168.0.10:80",
"weight": 100,
"max_conns": 0,
"max_fails": 0,
"fail_timeout": 0,
"backup": false
},
{
"id": 6,
"created_on": 1672804200,
"modified_on": 1672804200,
"upstream_group_id": 3,
"server": "192.168.0.11:80",
"weight": 50,
"max_conns": 0,
"max_fails": 0,
"fail_timeout": 0,
"backup": false
}
]
},
{
"id": 4,
"created_on": 1672804201,
"modified_on": 1672804201,
"user_id": 2,
"name": "API servers 2",
"nginx_template_id": 5,
"ip_hash": false,
"ntlm": false,
"keepalive": 0,
"keepalive_requests": 0,
"keepalive_time": "",
"keepalive_timeout": "",
"advanced_config": "",
"status": "ok",
"error_message": "",
"servers": [
{
"id": 7,
"created_on": 1672804201,
"modified_on": 1672804201,
"upstream_group_id": 4,
"server": "192.168.0.10:80",
"weight": 100,
"max_conns": 0,
"max_fails": 0,
"fail_timeout": 0,
"backup": false
},
{
"id": 8,
"created_on": 1672804201,
"modified_on": 1672804201,
"upstream_group_id": 4,
"server": "192.168.0.11:80",
"weight": 50,
"max_conns": 0,
"max_fails": 0,
"fail_timeout": 0,
"backup": false
}
]
},
{
"id": 5,
"created_on": 1672804201,
"modified_on": 1672804201,
"user_id": 2,
"name": "API servers 2",
"nginx_template_id": 5,
"ip_hash": false,
"ntlm": false,
"keepalive": 0,
"keepalive_requests": 0,
"keepalive_time": "",
"keepalive_timeout": "",
"advanced_config": "",
"status": "ok",
"error_message": "",
"servers": [
{
"id": 9,
"created_on": 1672804201,
"modified_on": 1672804201,
"upstream_group_id": 5,
"server": "192.168.0.10:80",
"weight": 100,
"max_conns": 0,
"max_fails": 0,
"fail_timeout": 0,
"backup": false
},
{
"id": 10,
"created_on": 1672804201,
"modified_on": 1672804201,
"upstream_group_id": 5,
"server": "192.168.0.11:80",
"weight": 50,
"max_conns": 0,
"max_fails": 0,
"fail_timeout": 0,
"backup": false
}
]
}
]
}
}
}
}
}
}
}
}
}

View File

@ -0,0 +1,80 @@
{
"operationId": "createUpstream",
"summary": "Create a new Upstream",
"tags": ["Upstreams"],
"requestBody": {
"description": "Upstream to Create",
"required": true,
"content": {
"application/json": {
"schema": "{{schema.CreateUpstream}}"
}
}
},
"responses": {
"201": {
"description": "201 response",
"content": {
"application/json": {
"schema": {
"required": ["result"],
"properties": {
"result": {
"$ref": "#/components/schemas/UpstreamObject"
}
}
},
"examples": {
"default": {
"value": {
"result": {
"id": 6,
"created_on": 1672806857,
"modified_on": 1672806857,
"user_id": 2,
"name": "API servers 2",
"nginx_template_id": 5,
"ip_hash": false,
"ntlm": false,
"keepalive": 0,
"keepalive_requests": 0,
"keepalive_time": "",
"keepalive_timeout": "",
"advanced_config": "",
"status": "ready",
"error_message": "",
"servers": [
{
"id": 11,
"created_on": 1672806857,
"modified_on": 1672806857,
"upstream_id": 6,
"server": "192.168.0.10:80",
"weight": 100,
"max_conns": 0,
"max_fails": 0,
"fail_timeout": 0,
"backup": false
},
{
"id": 12,
"created_on": 1672806857,
"modified_on": 1672806857,
"upstream_id": 6,
"server": "192.168.0.11:80",
"weight": 50,
"max_conns": 0,
"max_fails": 0,
"fail_timeout": 0,
"backup": false
}
]
}
}
}
}
}
}
}
}
}

View File

@ -0,0 +1,58 @@
{
"operationId": "deleteUpstream",
"summary": "Delete a Upstream",
"tags": ["Upstreams"],
"parameters": [
{
"in": "path",
"name": "upstreamID",
"schema": {
"type": "integer",
"minimum": 1
},
"required": true,
"description": "Numeric ID of the Upstream",
"example": 1
}
],
"responses": {
"200": {
"description": "200 response",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/DeletedItemResponse"
},
"examples": {
"default": {
"value": {
"result": true
}
}
}
}
}
},
"400": {
"description": "400 response",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/DeletedItemResponse"
},
"examples": {
"default": {
"value": {
"result": null,
"error": {
"code": 400,
"message": "You cannot delete a Upstream that is in use!"
}
}
}
}
}
}
}
}
}

View File

@ -0,0 +1,81 @@
{
"operationId": "getUpstream",
"summary": "Get a Upstream object by ID",
"tags": ["Upstreams"],
"parameters": [
{
"in": "path",
"name": "upstreamID",
"schema": {
"type": "integer",
"minimum": 1
},
"required": true,
"description": "ID of the Upstream",
"example": 1
}
],
"responses": {
"200": {
"description": "200 response",
"content": {
"application/json": {
"schema": {
"required": ["result"],
"properties": {
"result": {
"$ref": "#/components/schemas/UpstreamObject"
}
}
},
"examples": {
"default": {
"value": {
"result": {
"id": 1,
"created_on": 1672786008,
"modified_on": 1672786008,
"user_id": 2,
"name": "API servers 3",
"ip_hash": true,
"ntlm": false,
"keepalive": 10,
"keepalive_requests": 10,
"keepalive_time": "60s",
"keepalive_timeout": "3s",
"advanced_config": "",
"servers": [
{
"id": 1,
"created_on": 1672786009,
"modified_on": 1672786009,
"upstream_id": 1,
"server": "api1.localhost:1234",
"weight": 100,
"max_conns": 0,
"max_fails": 0,
"fail_timeout": 0,
"backup": false
},
{
"id": 2,
"created_on": 1672786009,
"modified_on": 1672786009,
"upstream_id": 1,
"server": "api2.localhost:1234",
"weight": 50,
"max_conns": 0,
"max_fails": 0,
"fail_timeout": 0,
"backup": true
}
]
}
}
}
}
}
}
}
}
}

View File

@ -123,7 +123,6 @@ CREATE TABLE IF NOT EXISTS `stream`
user_id INTEGER NOT NULL,
listen_interface TEXT NOT NULL,
incoming_port INTEGER NOT NULL,
upstream_options TEXT NOT NULL,
tcp_forwarding INTEGER NOT NULL DEFAULT 0,
udp_forwarding INTEGER NOT NULL DEFAULT 0,
advanced_config TEXT NOT NULL,
@ -138,13 +137,36 @@ CREATE TABLE IF NOT EXISTS `upstream`
created_on INTEGER NOT NULL DEFAULT 0,
modified_on INTEGER NOT NULL DEFAULT 0,
user_id INTEGER NOT NULL,
hosts TEXT NOT NULL,
balance_method TEXT NOT NULL,
max_fails INTEGER NOT NULL DEFAULT 1,
fail_timeout INTEGER NOT NULL DEFAULT 10,
name TEXT NOT NULL,
nginx_template_id INTEGER NOT NULL,
ip_hash INTEGER NOT NULL DEFAULT 0,
ntlm INTEGER NOT NULL DEFAULT 0,
keepalive INTEGER NOT NULL DEFAULT 0,
keepalive_requests INTEGER NOT NULL DEFAULT 0,
keepalive_time TEXT NOT NULL DEFAULT "",
keepalive_timeout TEXT NOT NULL DEFAULT "",
advanced_config TEXT NOT NULL,
status TEXT NOT NULL DEFAULT "",
error_message TEXT NOT NULL DEFAULT "",
is_deleted INTEGER NOT NULL DEFAULT 0,
FOREIGN KEY (user_id) REFERENCES user (id)
FOREIGN KEY (user_id) REFERENCES user (id),
FOREIGN KEY (nginx_template_id) REFERENCES nginx_template (id)
);
CREATE TABLE IF NOT EXISTS `upstream_server`
(
id INTEGER PRIMARY KEY AUTOINCREMENT,
created_on INTEGER NOT NULL DEFAULT 0,
modified_on INTEGER NOT NULL DEFAULT 0,
upstream_id INTEGER NOT NULL,
server TEXT NOT NULL,
weight INTEGER NOT NULL DEFAULT 0,
max_conns INTEGER NOT NULL DEFAULT 0,
max_fails INTEGER NOT NULL DEFAULT 0,
fail_timeout INTEGER NOT NULL DEFAULT 0,
backup INTEGER NOT NULL DEFAULT 0,
is_deleted INTEGER NOT NULL DEFAULT 0,
FOREIGN KEY (upstream_id) REFERENCES upstream (id)
);
CREATE TABLE IF NOT EXISTS `access_list`
@ -159,14 +181,14 @@ CREATE TABLE IF NOT EXISTS `access_list`
FOREIGN KEY (user_id) REFERENCES user (id)
);
CREATE TABLE IF NOT EXISTS `host_template`
CREATE TABLE IF NOT EXISTS `nginx_template`
(
id INTEGER PRIMARY KEY AUTOINCREMENT,
created_on INTEGER NOT NULL DEFAULT 0,
modified_on INTEGER NOT NULL DEFAULT 0,
user_id INTEGER NOT NULL,
name TEXT NOT NULL,
host_type TEXT NOT NULL,
type TEXT NOT NULL,
template TEXT NOT NULL,
is_deleted INTEGER NOT NULL DEFAULT 0,
FOREIGN KEY (user_id) REFERENCES user (id)
@ -179,7 +201,7 @@ CREATE TABLE IF NOT EXISTS `host`
modified_on INTEGER NOT NULL DEFAULT 0,
user_id INTEGER NOT NULL,
type TEXT NOT NULL,
host_template_id INTEGER NOT NULL,
nginx_template_id INTEGER NOT NULL,
listen_interface TEXT NOT NULL DEFAULT "",
domain_names TEXT NOT NULL,
upstream_id INTEGER NOT NULL DEFAULT 0,
@ -193,14 +215,13 @@ CREATE TABLE IF NOT EXISTS `host`
hsts_enabled INTEGER NOT NULL DEFAULT 0,
hsts_subdomains INTEGER NOT NULL DEFAULT 0,
paths TEXT NOT NULL DEFAULT "",
upstream_options TEXT NOT NULL DEFAULT "",
advanced_config TEXT NOT NULL DEFAULT "",
status TEXT NOT NULL DEFAULT "",
error_message TEXT NOT NULL DEFAULT "",
is_disabled INTEGER NOT NULL DEFAULT 0,
is_deleted INTEGER NOT NULL DEFAULT 0,
FOREIGN KEY (user_id) REFERENCES user (id),
FOREIGN KEY (host_template_id) REFERENCES host_template (id),
FOREIGN KEY (nginx_template_id) REFERENCES nginx_template (id),
FOREIGN KEY (upstream_id) REFERENCES upstream (id),
FOREIGN KEY (certificate_id) REFERENCES certificate (id),
FOREIGN KEY (access_list_id) REFERENCES access_list (id)

View File

@ -16,8 +16,8 @@ INSERT INTO `capability` (
("dns-providers.manage"),
("hosts.view"),
("hosts.manage"),
("host-templates.view"),
("host-templates.manage"),
("nginx-templates.view"),
("nginx-templates.manage"),
("settings.manage"),
("streams.view"),
("streams.manage"),
@ -131,12 +131,12 @@ INSERT INTO `user` (
);
-- Host Templates
INSERT INTO `host_template` (
INSERT INTO `nginx_template` (
created_on,
modified_on,
user_id,
name,
host_type,
type,
template
) VALUES (
strftime('%s', 'now'),
@ -144,7 +144,119 @@ INSERT INTO `host_template` (
(SELECT id FROM user WHERE is_system = 1 LIMIT 1),
"Default Proxy Template",
"proxy",
"# this is a proxy template"
"# ------------------------------------------------------------
{{#each Host.DomainNames}}
# {{this}}
{{/each}}
# ------------------------------------------------------------
{{#if Host.IsDisabled}}
# This Proxy Host is disabled and will not generate functional config
{{/if}}
{{#unless Host.IsDisabled}}
server {
set $forward_scheme {{Host.ForwardScheme}};
set $server ""{{Host.ForwardHost}}"";
set $port {{Host.ForwardPort}};
{{#if Config.Ipv4}}
listen 80;
{{/if}}
{{#if Config.Ipv6}}
listen [::]:80;
{{/if}}
{{#if Certificate.ID}}
listen 443 ssl {{#if Host.HTTP2Support}}http2{{/if}};
{{/if}}
{{#if Config.Ipv6}}
listen [::]:443 ssl {{#if Host.HTTP2Support}}http2{{/if}};
{{/if}}
server_name {{#each Host.DomainNames}}{{this}} {{/each}};
{{#if Certificate.ID}}
include conf.d/include/ssl-ciphers.conf;
{{#if Certificate.IsAcme}}
ssl_certificate {{Certificate.Folder}}/fullchain.pem;
ssl_certificate_key {{Certificate.Folder}}/privkey.pem;
{{else}}
# Custom SSL
ssl_certificate /data/custom_ssl/npm-{{Certicicate.ID}}/fullchain.pem;
ssl_certificate_key /data/custom_ssl/npm-{{Certificate.ID}}/privkey.pem;
{{/if}}
{{/if}}
{{#if Host.CachingEnabled}}
include conf.d/include/assets.conf;
{{/if}}
{{#if Host.BlockExploits}}
include conf.d/include/block-exploits.conf;
{{/if}}
{{#if Certificate.ID}}
{{#if Host.SSLForced}}
{{#if Host.HSTSEnabled}}
# HSTS (ngx_http_headers_module is required) (63072000 seconds = 2 years)
add_header Strict-Transport-Security ""max-age=63072000;{{#if Host.HSTSSubdomains}} includeSubDomains;{{/if}} preload"" always;
{{/if}}
# Force SSL
include conf.d/include/force-ssl.conf;
{{/if}}
{{/if}}
{{#if Host.AllowWebsocketUpgrade}}
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $http_connection;
proxy_http_version 1.1;
{{/if}}
access_log /data/logs/host-{{Host.ID}}_access.log proxy;
error_log /data/logs/host-{{Host.ID}}_error.log warn;
{{Host.AdvancedConfig}}
# locations ?
# default location:
location / {
{{#if Host.AccessListID}}
# Authorization
auth_basic ""Authorization required"";
auth_basic_user_file /data/access/{{Host.AccessListID}};
# access_list.passauth ? todo
{{/if}}
# Access Rules ? todo
# Access checks must...? todo
{{#if Certificate.ID}}
{{#if Host.SSLForced}}
{{#if Host.HSTSEnabled}}
# HSTS (ngx_http_headers_module is required) (63072000 seconds = 2 years)
add_header Strict-Transport-Security ""max-age=63072000;{{#if Host.HSTSSubdomains}} includeSubDomains;{{/if}} preload"" always;
{{/if}}
{{/if}}
{{/if}}
{{#if Host.AllowWebsocketUpgrade}}
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $http_connection;
proxy_http_version 1.1;
{{/if}}
# Proxy!
include conf.d/include/proxy.conf;
}
# Legacy Custom Configuration
include /data/nginx/custom/server_proxy[.]conf;
}
{{/unless}}
"
), (
strftime('%s', 'now'),
strftime('%s', 'now'),
@ -166,6 +278,55 @@ INSERT INTO `host_template` (
"Default Stream Template",
"stream",
"# this is a stream template"
), (
strftime('%s', 'now'),
strftime('%s', 'now'),
(SELECT id FROM user WHERE is_system = 1 LIMIT 1),
"Default Upstream Template",
"upstream",
"# ------------------------------------------------------------
# Upstream {{Upstream.ID}}: {{Upstream.Name}}
# ------------------------------------------------------------
{{#unless Upstream.IsDeleted~}}
upstream npm_upstream_{{Upstream.ID}} {
{{#if Upstream.IPHash~}}
ip_hash;
{{~/if}}
{{#if Upstream.NTLM~}}
ntlm;
{{~/if}}
{{#if Upstream.Keepalive~}}
keepalive {{Upstream.Keepalive}};
{{~/if}}
{{#if Upstream.KeepaliveRequests~}}
keepalive_requests {{Upstream.KeepaliveRequests}};
{{~/if}}
{{#if Upstream.KeepaliveTime~}}
keepalive_time {{Upstream.KeepaliveTime}};
{{~/if}}
{{#if Upstream.KeepaliveTimeout~}}
keepalive_timeout {{Upstream.KeepaliveTimeout}};
{{~/if}}
{{Upstream.AdvancedConfig}}
{{#each Upstream.Servers~}}
{{#unless IsDeleted~}}
server {{Server}} {{#if Weight}}weight={{Weight}} {{/if}}{{#if MaxConns}}max_conns={{MaxConns}} {{/if}}{{#if MaxFails}}max_fails={{MaxFails}} {{/if}}{{#if FailTimeout}}fail_timeout={{FailTimeout}} {{/if}}{{#if Backup}}backup{{/if}};
{{/unless}}
{{/each}}
}
{{~/unless~}}
"
);
-- migrate:down