Compare commits
37 Commits
450250c419
...
1.0.0
Author | SHA1 | Date | |
---|---|---|---|
|
99e4a64b5a | ||
|
498eb05514 | ||
|
8a5cc34bb4 | ||
|
006a22cd7b | ||
|
2cfc9cd7fa | ||
|
2125239d42 | ||
|
70e5e5eddf | ||
|
f22affc05c | ||
|
dd36e2ab1a | ||
|
ae12eb2a15 | ||
|
f66f144f2e | ||
|
632d37caf5 | ||
|
28d3a3fa06 | ||
|
232ded4cd4 | ||
|
e158cb8819 | ||
|
90e7b03975 | ||
|
9a2192aa43 | ||
|
283a646eb4 | ||
|
17322108ff | ||
|
64272e786b | ||
|
6607e1dc5e | ||
|
d2710d1718 | ||
|
7b544f370d | ||
|
09c4800143 | ||
|
ef10fab47d | ||
|
11cf35cf0d | ||
|
28fd5aca8b | ||
|
e55077c7e9 | ||
|
910a9849f7 | ||
|
2860542e44 | ||
|
302491741f | ||
72d23c35f5 | |||
|
1cebff59e1 | ||
|
74d8b3848f | ||
|
7a3c489797 | ||
|
440851a305 | ||
|
61d30315ec |
@@ -1,10 +0,0 @@
|
|||||||
{
|
|
||||||
"configurations": [
|
|
||||||
{
|
|
||||||
"type": "go",
|
|
||||||
"name": "Run RoadSign",
|
|
||||||
"goExecPath": "/opt/homebrew/bin/go",
|
|
||||||
"buildParams": ["code.smartsheep.studio/goatworks/roadsign/pkg/cmd/server"],
|
|
||||||
},
|
|
||||||
]
|
|
||||||
}
|
|
@@ -2,27 +2,27 @@ name: release-nightly
|
|||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches: [ master ]
|
branches: [master]
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build-docker:
|
build-image:
|
||||||
runs-on: edge
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v4
|
||||||
- name: Set up QEMU
|
- name: Set up QEMU
|
||||||
uses: docker/setup-qemu-action@v2
|
uses: docker/setup-qemu-action@v3
|
||||||
- name: Set up Docker Buildx
|
- name: Set up Docker Buildx
|
||||||
uses: docker/setup-buildx-action@v2
|
uses: docker/setup-buildx-action@v3
|
||||||
- name: Login to Docker Hub
|
- name: Login to Docker Hub
|
||||||
uses: docker/login-action@v2
|
uses: docker/login-action@v3
|
||||||
with:
|
with:
|
||||||
username: ${{ secrets.DOCKER_REGISTRY_USERNAME }}
|
username: ${{ secrets.DOCKER_REGISTRY_USERNAME }}
|
||||||
password: ${{ secrets.DOCKER_REGISTRY_TOKEN }}
|
password: ${{ secrets.DOCKER_REGISTRY_TOKEN }}
|
||||||
- name: Build and push
|
- name: Build and push
|
||||||
uses: docker/build-push-action@v4
|
uses: docker/build-push-action@v5
|
||||||
with:
|
with:
|
||||||
context: .
|
context: .
|
||||||
file: ./Dockerfile
|
|
||||||
push: true
|
push: true
|
||||||
tags: xsheep2010/roadsign:nightly
|
file: ./Dockerfile
|
||||||
|
tags: xsheep2010/roadsign:delta
|
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1,3 +1,5 @@
|
|||||||
/letsencrypt
|
/letsencrypt
|
||||||
|
/certs
|
||||||
|
/dist
|
||||||
|
|
||||||
.DS_Store
|
.DS_Store
|
1
.idea/RoadSign.iml
generated
1
.idea/RoadSign.iml
generated
@@ -11,5 +11,6 @@
|
|||||||
<orderEntry type="inheritedJdk" />
|
<orderEntry type="inheritedJdk" />
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
<orderEntry type="library" name="Python 3.9 interpreter library" level="application" />
|
<orderEntry type="library" name="Python 3.9 interpreter library" level="application" />
|
||||||
|
<orderEntry type="library" name="daisyui" level="application" />
|
||||||
</component>
|
</component>
|
||||||
</module>
|
</module>
|
7
.idea/inspectionProfiles/Project_Default.xml
generated
Normal file
7
.idea/inspectionProfiles/Project_Default.xml
generated
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
<component name="InspectionProjectProfileManager">
|
||||||
|
<profile version="1.0">
|
||||||
|
<option name="myName" value="Project Default" />
|
||||||
|
<inspection_tool class="DuplicatedCode" enabled="false" level="WEAK WARNING" enabled_by_default="false" />
|
||||||
|
<inspection_tool class="ExceptionCaughtLocallyJS" enabled="false" level="WARNING" enabled_by_default="false" />
|
||||||
|
</profile>
|
||||||
|
</component>
|
6
.idea/jsLibraryMappings.xml
generated
Normal file
6
.idea/jsLibraryMappings.xml
generated
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="JavaScriptLibraryMappings">
|
||||||
|
<file url="PROJECT" libraries="{daisyui}" />
|
||||||
|
</component>
|
||||||
|
</project>
|
16
.vscode/launch.json
vendored
16
.vscode/launch.json
vendored
@@ -1,16 +0,0 @@
|
|||||||
{
|
|
||||||
// Use IntelliSense to learn about possible attributes.
|
|
||||||
// Hover to view descriptions of existing attributes.
|
|
||||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
|
||||||
"version": "0.2.0",
|
|
||||||
"configurations": [
|
|
||||||
{
|
|
||||||
"name": "Run RoadSign",
|
|
||||||
"type": "go",
|
|
||||||
"request": "launch",
|
|
||||||
"mode": "auto",
|
|
||||||
"program": "${workspaceFolder}/pkg/cmd/main.go",
|
|
||||||
"cwd": "${workspaceFolder}"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
@@ -1,19 +1,15 @@
|
|||||||
# Building Backend
|
# Building Backend
|
||||||
FROM golang:alpine as roadsign-server
|
FROM golang:alpine as roadsign-server
|
||||||
|
|
||||||
RUN apk add nodejs npm
|
|
||||||
|
|
||||||
WORKDIR /source
|
WORKDIR /source
|
||||||
COPY . .
|
COPY . .
|
||||||
WORKDIR /source/pkg/sideload/view
|
|
||||||
RUN npm install
|
|
||||||
RUN npm run build
|
|
||||||
WORKDIR /source
|
|
||||||
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -buildvcs -o /dist ./pkg/cmd/server/main.go
|
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -buildvcs -o /dist ./pkg/cmd/server/main.go
|
||||||
|
|
||||||
# Runtime
|
# Runtime
|
||||||
FROM golang:alpine
|
FROM golang:alpine
|
||||||
|
|
||||||
|
RUN apk add zip
|
||||||
|
|
||||||
COPY --from=roadsign-server /dist /roadsign/server
|
COPY --from=roadsign-server /dist /roadsign/server
|
||||||
|
|
||||||
EXPOSE 81
|
EXPOSE 81
|
||||||
|
39
README.md
39
README.md
@@ -1,23 +1,30 @@
|
|||||||
# 🚦 RoadSign
|
# 🚦 RoadSign
|
||||||
|
|
||||||
A blazing fast reverse proxy with a lot of shining features.
|
A blazing fast http server with a lot of shining features.
|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
|
|
||||||
1. Reverse proxy
|
1. Reverse proxy
|
||||||
2. Static file hosting
|
2. WebSocket Support
|
||||||
3. ~~Analytics and Metrics~~
|
3. Static File Hosting
|
||||||
4. Integrate with CI/CD
|
4. Low Configuration
|
||||||
5. Webhook integration
|
5. Analytics and Metrics
|
||||||
6. ~~Web management panel~~
|
6. Integrate with CI/CD
|
||||||
7. One-liner CLI
|
7. One-liner CLI
|
||||||
8. **Blazing fast ⚡**
|
8. Open-source and free
|
||||||
|
9. **Blazing fast ⚡**
|
||||||
|
|
||||||
> Deleted item means under construction, check out our roadmap!
|
But, as we said, this isn't a reverse proxy. It's a http server.
|
||||||
|
So we didn't recommend you directly use it as a gateway to users, because it doesn't support all the features of http.
|
||||||
|
For example like doesn't support multiple site HTTPS, HTTP/2.0, HTTP/3 and Server-Side Events.
|
||||||
|
|
||||||
|
You can use RoadSign behind a reverse proxy like caddy, and let it handle the HTTP/2.0, HTTP/3 and all the other
|
||||||
|
cutting-edge stuff.
|
||||||
|
|
||||||
### How fast is it?
|
### How fast is it?
|
||||||
|
|
||||||
We use roadsign and nginx to host a same static file, and test them with [go-wrk](https://github.com/tsliwowicz/go-wrk).
|
We use roadsign and nginx to host the same static file
|
||||||
|
and test them with [go-wrk](https://github.com/tsliwowicz/go-wrk).
|
||||||
Here's the result:
|
Here's the result:
|
||||||
|
|
||||||
| **Software** | Total Requests | Requests per Seconds | Transfer per Seconds | Avg Time | Fastest Time | Slowest Time | Errors Count |
|
| **Software** | Total Requests | Requests per Seconds | Transfer per Seconds | Avg Time | Fastest Time | Slowest Time | Errors Count |
|
||||||
@@ -42,7 +49,7 @@ We strongly recommend you install RoadSign via docker compose.
|
|||||||
version: "3"
|
version: "3"
|
||||||
services:
|
services:
|
||||||
roadsign:
|
roadsign:
|
||||||
image: code.smartsheep.studio/goatworks/roadsign:nightly
|
image: xsheep2010/roadsign:nightly
|
||||||
restart: always
|
restart: always
|
||||||
volumes:
|
volumes:
|
||||||
- "./certs:/certs" # Optional, use for storage certificates
|
- "./certs:/certs" # Optional, use for storage certificates
|
||||||
@@ -55,25 +62,25 @@ services:
|
|||||||
- "81:81"
|
- "81:81"
|
||||||
```
|
```
|
||||||
|
|
||||||
After that, you can manage your roadsign instance with RoadSign CLI aka. RDS CLI.
|
After that, you can manage your roadsign instance with RoadSign CLI aka. RDC.
|
||||||
To install it, run this command. (Make sure you have golang toolchain on your computer)
|
To install it, run this command. (Make sure you have golang toolchain on your computer)
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
go install -buildvcs code.smartsheep.studio/goatworks/roadsign/pkg/cmd/rdc@latest
|
go install git.solsynth.dev/goatworks/roadsign/pkg/cmd/rdc@latest
|
||||||
# Tips: Add `buildvsc` flag to provide more detail compatibility check.
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
To use roadsign, you need to add a configuration for it. Create a file locally.
|
To use roadsign, you need to add a configuration for it. Create a file locally.
|
||||||
Name whatever you like. And follow our [documentation](https://wiki.smartsheep.studio/roadsign/configuration/index.html) to
|
Name whatever you like. And follow our [documentation](https://wiki.smartsheep.studio/roadsign/configuration/index.html)
|
||||||
|
to
|
||||||
write it.
|
write it.
|
||||||
|
|
||||||
After configure, you need sync your config to remote server. Before that, add a connection between roadsign server and
|
After configure, you need sync your config to remote server. Before that, add a connection between roadsign server and
|
||||||
rds cli with this command.
|
rds cli with this command.
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
rds connect <id> <url> <password>
|
rdc connect <id> <url> <password>
|
||||||
# ID will allow you find this server in after commands.
|
# ID will allow you find this server in after commands.
|
||||||
# URL is to your roadsign server sideload api.
|
# URL is to your roadsign server sideload api.
|
||||||
# Password is your roadsign server credential.
|
# Password is your roadsign server credential.
|
||||||
@@ -85,7 +92,7 @@ rds connect <id> <url> <password>
|
|||||||
Then, sync your local config to remote.
|
Then, sync your local config to remote.
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
rds sync <server id> <site id> <config file>
|
rdc sync <server id> <region id> <config file>
|
||||||
# Server ID is your server added by last command.
|
# Server ID is your server added by last command.
|
||||||
# Site ID is your new site id or old site id if you need update it.
|
# Site ID is your new site id or old site id if you need update it.
|
||||||
# Config File is your local config file path.
|
# Config File is your local config file path.
|
||||||
|
177
cli/.gitignore
vendored
Normal file
177
cli/.gitignore
vendored
Normal file
@@ -0,0 +1,177 @@
|
|||||||
|
# Based on https://raw.githubusercontent.com/github/gitignore/main/Node.gitignore
|
||||||
|
|
||||||
|
# Logs
|
||||||
|
|
||||||
|
logs
|
||||||
|
_.log
|
||||||
|
npm-debug.log_
|
||||||
|
yarn-debug.log*
|
||||||
|
yarn-error.log*
|
||||||
|
lerna-debug.log*
|
||||||
|
.pnpm-debug.log*
|
||||||
|
|
||||||
|
# Caches
|
||||||
|
|
||||||
|
.cache
|
||||||
|
|
||||||
|
# Diagnostic reports (https://nodejs.org/api/report.html)
|
||||||
|
|
||||||
|
report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json
|
||||||
|
|
||||||
|
# Runtime data
|
||||||
|
|
||||||
|
pids
|
||||||
|
_.pid
|
||||||
|
_.seed
|
||||||
|
*.pid.lock
|
||||||
|
|
||||||
|
# Directory for instrumented libs generated by jscoverage/JSCover
|
||||||
|
|
||||||
|
lib-cov
|
||||||
|
|
||||||
|
# Coverage directory used by tools like istanbul
|
||||||
|
|
||||||
|
coverage
|
||||||
|
*.lcov
|
||||||
|
|
||||||
|
# nyc test coverage
|
||||||
|
|
||||||
|
.nyc_output
|
||||||
|
|
||||||
|
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
|
||||||
|
|
||||||
|
.grunt
|
||||||
|
|
||||||
|
# Bower dependency directory (https://bower.io/)
|
||||||
|
|
||||||
|
bower_components
|
||||||
|
|
||||||
|
# node-waf configuration
|
||||||
|
|
||||||
|
.lock-wscript
|
||||||
|
|
||||||
|
# Compiled binary addons (https://nodejs.org/api/addons.html)
|
||||||
|
|
||||||
|
build/Release
|
||||||
|
|
||||||
|
# Dependency directories
|
||||||
|
|
||||||
|
node_modules/
|
||||||
|
jspm_packages/
|
||||||
|
|
||||||
|
# Snowpack dependency directory (https://snowpack.dev/)
|
||||||
|
|
||||||
|
web_modules/
|
||||||
|
|
||||||
|
# TypeScript cache
|
||||||
|
|
||||||
|
*.tsbuildinfo
|
||||||
|
|
||||||
|
# Optional npm cache directory
|
||||||
|
|
||||||
|
.npm
|
||||||
|
|
||||||
|
# Optional eslint cache
|
||||||
|
|
||||||
|
.eslintcache
|
||||||
|
|
||||||
|
# Optional stylelint cache
|
||||||
|
|
||||||
|
.stylelintcache
|
||||||
|
|
||||||
|
# Microbundle cache
|
||||||
|
|
||||||
|
.rpt2_cache/
|
||||||
|
.rts2_cache_cjs/
|
||||||
|
.rts2_cache_es/
|
||||||
|
.rts2_cache_umd/
|
||||||
|
|
||||||
|
# Optional REPL history
|
||||||
|
|
||||||
|
.node_repl_history
|
||||||
|
|
||||||
|
# Output of 'npm pack'
|
||||||
|
|
||||||
|
*.tgz
|
||||||
|
|
||||||
|
# Yarn Integrity file
|
||||||
|
|
||||||
|
.yarn-integrity
|
||||||
|
|
||||||
|
# dotenv environment variable files
|
||||||
|
|
||||||
|
.env
|
||||||
|
.env.development.local
|
||||||
|
.env.test.local
|
||||||
|
.env.production.local
|
||||||
|
.env.local
|
||||||
|
|
||||||
|
# parcel-bundler cache (https://parceljs.org/)
|
||||||
|
|
||||||
|
.parcel-cache
|
||||||
|
|
||||||
|
# Next.js build output
|
||||||
|
|
||||||
|
.next
|
||||||
|
out
|
||||||
|
|
||||||
|
# Nuxt.js build / generate output
|
||||||
|
|
||||||
|
.nuxt
|
||||||
|
dist
|
||||||
|
|
||||||
|
# Gatsby files
|
||||||
|
|
||||||
|
# Comment in the public line in if your project uses Gatsby and not Next.js
|
||||||
|
|
||||||
|
# https://nextjs.org/blog/next-9-1#public-directory-support
|
||||||
|
|
||||||
|
# public
|
||||||
|
|
||||||
|
# vuepress build output
|
||||||
|
|
||||||
|
.vuepress/dist
|
||||||
|
|
||||||
|
# vuepress v2.x temp and cache directory
|
||||||
|
|
||||||
|
.temp
|
||||||
|
|
||||||
|
# Docusaurus cache and generated files
|
||||||
|
|
||||||
|
.docusaurus
|
||||||
|
|
||||||
|
# Serverless directories
|
||||||
|
|
||||||
|
.serverless/
|
||||||
|
|
||||||
|
# FuseBox cache
|
||||||
|
|
||||||
|
.fusebox/
|
||||||
|
|
||||||
|
# DynamoDB Local files
|
||||||
|
|
||||||
|
.dynamodb/
|
||||||
|
|
||||||
|
# TernJS port file
|
||||||
|
|
||||||
|
.tern-port
|
||||||
|
|
||||||
|
# Stores VSCode versions used for testing VSCode extensions
|
||||||
|
|
||||||
|
.vscode-test
|
||||||
|
|
||||||
|
# yarn v2
|
||||||
|
|
||||||
|
.yarn/cache
|
||||||
|
.yarn/unplugged
|
||||||
|
.yarn/build-state.yml
|
||||||
|
.yarn/install-state.gz
|
||||||
|
.pnp.*
|
||||||
|
|
||||||
|
# IntelliJ based IDEs
|
||||||
|
.idea
|
||||||
|
|
||||||
|
# Finder (MacOS) folder config
|
||||||
|
.DS_Store
|
||||||
|
|
||||||
|
/test/static-files
|
13
cli/.roadsignrc
Normal file
13
cli/.roadsignrc
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
{
|
||||||
|
"sync": {
|
||||||
|
"region": "static-files",
|
||||||
|
"configPath": "test/static-files.toml"
|
||||||
|
},
|
||||||
|
"deployments": [
|
||||||
|
{
|
||||||
|
"path": "test/static-files",
|
||||||
|
"region": "static-files",
|
||||||
|
"site": "static-files-des"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
3
cli/README.md
Normal file
3
cli/README.md
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
# RoadSign CLI
|
||||||
|
|
||||||
|
RoadSign CLI is a command-line interface (CLI) tool that allows you to manage your RoadSign servers and applications.
|
BIN
cli/bun.lockb
Executable file
BIN
cli/bun.lockb
Executable file
Binary file not shown.
42
cli/index.ts
Executable file
42
cli/index.ts
Executable file
@@ -0,0 +1,42 @@
|
|||||||
|
import { Builtins, Cli } from "clipanion"
|
||||||
|
import figlet from "figlet"
|
||||||
|
import chalk from "chalk"
|
||||||
|
|
||||||
|
import { LoginCommand } from "./src/cmd/login.ts"
|
||||||
|
import { LogoutCommand } from "./src/cmd/logout.ts"
|
||||||
|
import { ListServerCommand } from "./src/cmd/list.ts"
|
||||||
|
import { StatusCommand } from "./src/cmd/status.ts"
|
||||||
|
import { InfoCommand } from "./src/cmd/info.ts"
|
||||||
|
import { ProcessCommand } from "./src/cmd/process-info.ts"
|
||||||
|
import { DeployCommand } from "./src/cmd/deploy.ts"
|
||||||
|
import { SyncCommand } from "./src/cmd/sync.ts"
|
||||||
|
import { ReloadCommand } from "./src/cmd/reload.ts"
|
||||||
|
|
||||||
|
const [node, app, ...args] = process.argv
|
||||||
|
|
||||||
|
const ENABLE_STARTUP_ASCII_ART = false
|
||||||
|
|
||||||
|
if (process.env["ENABLE_STARTUP_ASCII_ART"] || ENABLE_STARTUP_ASCII_ART) {
|
||||||
|
console.log(
|
||||||
|
chalk.yellow(figlet.textSync("RoadSign CLI", { horizontalLayout: "default", verticalLayout: "default" }))
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
const cli = new Cli({
|
||||||
|
binaryLabel: `RoadSign CLI`,
|
||||||
|
binaryName: `${node} ${app}`,
|
||||||
|
binaryVersion: `1.0.0`
|
||||||
|
})
|
||||||
|
|
||||||
|
cli.register(Builtins.VersionCommand)
|
||||||
|
cli.register(Builtins.HelpCommand)
|
||||||
|
cli.register(LoginCommand)
|
||||||
|
cli.register(LogoutCommand)
|
||||||
|
cli.register(ListServerCommand)
|
||||||
|
cli.register(StatusCommand)
|
||||||
|
cli.register(InfoCommand)
|
||||||
|
cli.register(ProcessCommand)
|
||||||
|
cli.register(DeployCommand)
|
||||||
|
cli.register(SyncCommand)
|
||||||
|
cli.register(ReloadCommand)
|
||||||
|
cli.runExit(args)
|
36
cli/package.json
Normal file
36
cli/package.json
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
{
|
||||||
|
"name": "roadsign-cli",
|
||||||
|
"module": "index.ts",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"repository": "https://github.com/solsynth/roadsign",
|
||||||
|
"type": "module",
|
||||||
|
"scripts": {
|
||||||
|
"build": "rimraf dist && rollup -c rollup.config.js"
|
||||||
|
},
|
||||||
|
"bin": {
|
||||||
|
"rdcli": "./dist/index.cjs"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@rollup/plugin-commonjs": "^28.0.0",
|
||||||
|
"@rollup/plugin-json": "^6.1.0",
|
||||||
|
"@rollup/plugin-node-resolve": "^15.3.0",
|
||||||
|
"@rollup/plugin-typescript": "^12.1.0",
|
||||||
|
"@types/bun": "latest",
|
||||||
|
"@types/cli-progress": "^3.11.6",
|
||||||
|
"@types/figlet": "^1.5.8",
|
||||||
|
"rimraf": "^6.0.1",
|
||||||
|
"rollup": "^4.24.0",
|
||||||
|
"rollup-plugin-typescript2": "^0.36.0"
|
||||||
|
},
|
||||||
|
"peerDependencies": {
|
||||||
|
"typescript": "^5.6.2"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"chalk": "^5.3.0",
|
||||||
|
"cli-progress": "^3.12.0",
|
||||||
|
"cli-table3": "^0.6.5",
|
||||||
|
"clipanion": "^4.0.0-rc.4",
|
||||||
|
"figlet": "^1.7.0",
|
||||||
|
"ora": "^8.1.0"
|
||||||
|
}
|
||||||
|
}
|
22
cli/rollup.config.js
Normal file
22
cli/rollup.config.js
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
import resolve from "@rollup/plugin-node-resolve"
|
||||||
|
import commonjs from "@rollup/plugin-commonjs"
|
||||||
|
import typescript from "@rollup/plugin-typescript"
|
||||||
|
import json from "@rollup/plugin-json"
|
||||||
|
|
||||||
|
export default {
|
||||||
|
input: "index.ts",
|
||||||
|
output: {
|
||||||
|
banner: "#!/usr/bin/env node",
|
||||||
|
file: "dist/index.cjs",
|
||||||
|
format: "cjs",
|
||||||
|
inlineDynamicImports: true,
|
||||||
|
},
|
||||||
|
plugins: [
|
||||||
|
resolve(),
|
||||||
|
commonjs(),
|
||||||
|
json(),
|
||||||
|
typescript({
|
||||||
|
tsconfig: "./tsconfig.json"
|
||||||
|
})
|
||||||
|
],
|
||||||
|
}
|
113
cli/src/cmd/deploy.ts
Normal file
113
cli/src/cmd/deploy.ts
Normal file
@@ -0,0 +1,113 @@
|
|||||||
|
import { RsConfig } from "../utils/config.ts"
|
||||||
|
import { Command, Option, type Usage } from "clipanion"
|
||||||
|
import chalk from "chalk"
|
||||||
|
import ora from "ora"
|
||||||
|
import * as fs from "node:fs"
|
||||||
|
import * as child_process from "node:child_process"
|
||||||
|
import * as path from "node:path"
|
||||||
|
import { createAuthHeader } from "../utils/auth.ts"
|
||||||
|
import { RsLocalConfig } from "../utils/config-local.ts"
|
||||||
|
|
||||||
|
export class DeployCommand extends Command {
|
||||||
|
static paths = [[`deploy`]]
|
||||||
|
static usage: Usage = {
|
||||||
|
category: `Building`,
|
||||||
|
description: `Deploying App / Static Site onto RoadSign`,
|
||||||
|
details: `Deploying an application or hosting a static site via RoadSign, you need preconfigured the RoadSign, or sync the configurations via sync command.`,
|
||||||
|
examples: [
|
||||||
|
["Deploying to RoadSign", `deploy <server> <region> <site> <file / directory>`],
|
||||||
|
["Deploying to RoadSign with .roadsignrc file", `deploy <server>`]
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
server = Option.String({ required: true })
|
||||||
|
region = Option.String({ required: false })
|
||||||
|
site = Option.String({ required: false })
|
||||||
|
input = Option.String({ required: false })
|
||||||
|
|
||||||
|
async deploy(serverLabel: string, region: string, site: string, input: string) {
|
||||||
|
const cfg = await RsConfig.getInstance()
|
||||||
|
const server = cfg.config.servers.find(item => item.label === serverLabel)
|
||||||
|
if (server == null) {
|
||||||
|
this.context.stdout.write(chalk.red(`Server with label ${chalk.bold(this.server)} was not found.\n`))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!fs.existsSync(input)) {
|
||||||
|
this.context.stdout.write(chalk.red(`Input file ${chalk.bold(this.input)} was not found.\n`))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
let isDirectory = false
|
||||||
|
if (fs.statSync(input).isDirectory()) {
|
||||||
|
input = path.join(input, "*")
|
||||||
|
|
||||||
|
const compressPrefStart = performance.now()
|
||||||
|
const compressSpinner = ora(`Compressing ${chalk.bold(input)}...`).start()
|
||||||
|
const destName = `${Date.now()}-roadsign-archive.zip`
|
||||||
|
child_process.execSync(`zip -rj ${destName} ${input}`)
|
||||||
|
const compressPrefTook = performance.now() - compressPrefStart
|
||||||
|
compressSpinner.succeed(`Compressing completed in ${(compressPrefTook / 1000).toFixed(2)}s 🎉`)
|
||||||
|
input = destName
|
||||||
|
isDirectory = true
|
||||||
|
}
|
||||||
|
|
||||||
|
const destBreadcrumb = [region, site].join(" ➜ ")
|
||||||
|
const spinner = ora(`Deploying ${chalk.bold(destBreadcrumb)} to ${chalk.bold(this.server)}...`).start()
|
||||||
|
|
||||||
|
const prefStart = performance.now()
|
||||||
|
|
||||||
|
try {
|
||||||
|
const payload = new FormData()
|
||||||
|
payload.set("attachments", await fs.openAsBlob(input), isDirectory ? "dist.zip" : path.basename(input))
|
||||||
|
const res = await fetch(`${server.url}/webhooks/publish/${region}/${site}?mimetype=application/zip`, {
|
||||||
|
method: "PUT",
|
||||||
|
body: payload,
|
||||||
|
headers: {
|
||||||
|
Authorization: createAuthHeader(server.credential)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
if (res.status !== 200) {
|
||||||
|
throw new Error(await res.text())
|
||||||
|
}
|
||||||
|
const prefTook = performance.now() - prefStart
|
||||||
|
spinner.succeed(`Deploying completed in ${(prefTook / 1000).toFixed(2)}s 🎉`)
|
||||||
|
} catch (e) {
|
||||||
|
this.context.stdout.write(`Failed to deploy to remote: ${e}\n`)
|
||||||
|
spinner.fail(`Server with label ${chalk.bold(this.server)} is not running! 😢`)
|
||||||
|
} finally {
|
||||||
|
if (isDirectory && input.endsWith(".zip")) {
|
||||||
|
fs.unlinkSync(input)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async execute() {
|
||||||
|
if (this.region && this.site && this.input) {
|
||||||
|
await this.deploy(this.server, this.region, this.site, this.input)
|
||||||
|
} else {
|
||||||
|
let localCfg: RsLocalConfig
|
||||||
|
try {
|
||||||
|
localCfg = await RsLocalConfig.getInstance()
|
||||||
|
} catch (e) {
|
||||||
|
this.context.stdout.write(chalk.red(`Unable to load .roadsignrc: ${e}\n`))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!localCfg.config.deployments) {
|
||||||
|
this.context.stdout.write(chalk.red(`No deployments found in .roadsignrc, exiting...\n`))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
let idx = 0
|
||||||
|
for (const deployment of localCfg.config.deployments ?? []) {
|
||||||
|
this.context.stdout.write(chalk.cyan(`Deploying ${idx + 1} out of ${localCfg.config.deployments.length} deployments...\n`))
|
||||||
|
await this.deploy(this.server, deployment.region, deployment.site, deployment.path)
|
||||||
|
}
|
||||||
|
|
||||||
|
this.context.stdout.write(chalk.green(`All deployments has been deployed!\n`))
|
||||||
|
}
|
||||||
|
|
||||||
|
process.exit(0)
|
||||||
|
}
|
||||||
|
}
|
175
cli/src/cmd/info.ts
Normal file
175
cli/src/cmd/info.ts
Normal file
@@ -0,0 +1,175 @@
|
|||||||
|
import { Command, Option, type Usage } from "clipanion"
|
||||||
|
import { RsConfig, type RsConfigServerData } from "../utils/config.ts"
|
||||||
|
import { createAuthHeader } from "../utils/auth.ts"
|
||||||
|
import chalk from "chalk"
|
||||||
|
import ora from "ora"
|
||||||
|
|
||||||
|
export class InfoCommand extends Command {
|
||||||
|
static paths = [[`info`], [`if`]]
|
||||||
|
static usage: Usage = {
|
||||||
|
category: `Networking`,
|
||||||
|
description: `Fetching the stats of RoadSign Server`,
|
||||||
|
details: `Fetching the configured things amount and other things of a connected server`,
|
||||||
|
examples: [["Fetch stats from labeled server", `info <label> [area]`]]
|
||||||
|
}
|
||||||
|
|
||||||
|
label = Option.String({ required: true })
|
||||||
|
area = Option.String({ required: false })
|
||||||
|
loop = Option.Boolean("--loop,--follow,-f", false, { description: "Keep updating the results" })
|
||||||
|
|
||||||
|
private static formatUptime(ms: number): string {
|
||||||
|
let seconds: number = Math.floor(ms / 1000)
|
||||||
|
let minutes: number = Math.floor(seconds / 60)
|
||||||
|
let hours: number = Math.floor(minutes / 60)
|
||||||
|
let days: number = Math.floor(hours / 24)
|
||||||
|
|
||||||
|
seconds = seconds % 60
|
||||||
|
minutes = minutes % 60
|
||||||
|
hours = hours % 24
|
||||||
|
|
||||||
|
const uptimeParts: string[] = []
|
||||||
|
|
||||||
|
if (days > 0) uptimeParts.push(`${days} day${days > 1 ? "s" : ""}`)
|
||||||
|
if (hours > 0) uptimeParts.push(`${hours} hour${hours > 1 ? "s" : ""}`)
|
||||||
|
if (minutes > 0) uptimeParts.push(`${minutes} minute${minutes > 1 ? "s" : ""}`)
|
||||||
|
if (seconds > 0 || uptimeParts.length === 0) uptimeParts.push(`${seconds} second${seconds > 1 ? "s" : ""}`)
|
||||||
|
|
||||||
|
return uptimeParts.join(", ")
|
||||||
|
}
|
||||||
|
|
||||||
|
async fetchOverview(server: RsConfigServerData) {
|
||||||
|
try {
|
||||||
|
const res = await fetch(`${server.url}/cgi/stats`, {
|
||||||
|
headers: {
|
||||||
|
Authorization: createAuthHeader(server.credential)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
if (res.status !== 200) {
|
||||||
|
throw new Error(await res.text())
|
||||||
|
}
|
||||||
|
|
||||||
|
const data: any = await res.json()
|
||||||
|
this.context.stdout.write('\n')
|
||||||
|
this.context.stdout.write(`\nServer stats of ${chalk.bold(this.label)}\n`)
|
||||||
|
this.context.stdout.write(` • Uptime: ${chalk.bold(InfoCommand.formatUptime(data["uptime"]))}\n`)
|
||||||
|
this.context.stdout.write(` • Traffic since last startup: ${chalk.bold(data["traffic"]["total"])}\n`)
|
||||||
|
this.context.stdout.write(` • Unique clients since last startup: ${chalk.bold(data["traffic"]["unique_client"])}\n`)
|
||||||
|
this.context.stdout.write(`\nServer info of ${chalk.bold(this.label)}\n`)
|
||||||
|
this.context.stdout.write(` • Warden Applications: ${chalk.bold(data["applications"])}\n`)
|
||||||
|
this.context.stdout.write(` • Destinations: ${chalk.bold(data["destinations"])}\n`)
|
||||||
|
this.context.stdout.write(` • Locations: ${chalk.bold(data["locations"])}\n`)
|
||||||
|
this.context.stdout.write(` • Regions: ${chalk.bold(data["regions"])}\n`)
|
||||||
|
this.context.stdout.write('\n')
|
||||||
|
} catch (e) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async fetchTrace(server: RsConfigServerData) {
|
||||||
|
const res = await fetch(`${server.url}/cgi/traces`, {
|
||||||
|
headers: {
|
||||||
|
Authorization: createAuthHeader(server.credential)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
if (res.status !== 200) {
|
||||||
|
throw new Error(await res.text())
|
||||||
|
}
|
||||||
|
|
||||||
|
const data: any = await res.json()
|
||||||
|
for (const trace of data) {
|
||||||
|
const ts = new Date(trace["timestamp"]).toLocaleString()
|
||||||
|
const path = [trace["region"], trace["location"], trace["destination"]].join(" ➜ ")
|
||||||
|
const uri = trace["uri"].split("?").length == 1 ? trace["uri"] : trace["uri"].split("?")[0] + ` ${chalk.grey(`w/ query parameters`)}`
|
||||||
|
this.context.stdout.write(`${chalk.bgGrey(`[${ts}]`)} ${chalk.bold(path)} ${chalk.cyan(trace["ip_address"])} ${uri}\n`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async fetchRegions(server: RsConfigServerData) {
|
||||||
|
const res = await fetch(`${server.url}/cgi/regions`, {
|
||||||
|
headers: {
|
||||||
|
Authorization: createAuthHeader(server.credential)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
if (res.status !== 200) {
|
||||||
|
throw new Error(await res.text())
|
||||||
|
}
|
||||||
|
|
||||||
|
const data: any = await res.json()
|
||||||
|
this.context.stdout.write("\n\n")
|
||||||
|
for (const region of data) {
|
||||||
|
this.context.stdout.write(` • ${chalk.bgGrey('region#')}${chalk.bold(region.id)} ${chalk.gray(`(${region.locations.length} locations)`)}\n`)
|
||||||
|
for (const location of region.locations) {
|
||||||
|
this.context.stdout.write(` • ${chalk.bgGrey('location#')} ${chalk.bold(location.id)} ${chalk.gray(`(${location.destinations.length} destinations)`)}\n`)
|
||||||
|
for (const destination of location.destinations) {
|
||||||
|
this.context.stdout.write(` • ${chalk.bgGrey('destination#')}${chalk.bold(destination.id)}\n`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.context.stdout.write("\n")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async execute() {
|
||||||
|
const config = await RsConfig.getInstance()
|
||||||
|
|
||||||
|
const server = config.config.servers.find(item => item.label === this.label)
|
||||||
|
if (server == null) {
|
||||||
|
this.context.stdout.write(chalk.red(`Server with label ${chalk.bold(this.label)} was not found.\n`))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.area == null) {
|
||||||
|
this.area = "overview"
|
||||||
|
}
|
||||||
|
|
||||||
|
const spinner = ora(`Fetching stats from server ${this.label}...`).start()
|
||||||
|
const prefStart = performance.now()
|
||||||
|
|
||||||
|
switch (this.area) {
|
||||||
|
case "overview":
|
||||||
|
try {
|
||||||
|
await this.fetchOverview(server)
|
||||||
|
const prefTook = performance.now() - prefStart
|
||||||
|
spinner.succeed(`Fetching completed in ${(prefTook / 1000).toFixed(2)}s 🎉`)
|
||||||
|
} catch (e) {
|
||||||
|
spinner.fail(`Server with label ${chalk.bold(this.label)} is not running! 😢`)
|
||||||
|
}
|
||||||
|
break
|
||||||
|
case "trace":
|
||||||
|
while (true) {
|
||||||
|
try {
|
||||||
|
await this.fetchTrace(server)
|
||||||
|
const prefTook = performance.now() - prefStart
|
||||||
|
if (!this.loop) {
|
||||||
|
spinner.succeed(`Fetching completed in ${(prefTook / 1000).toFixed(2)}s 🎉`)
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
spinner.fail(`Server with label ${chalk.bold(this.label)} is not running! 😢`)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!this.loop) {
|
||||||
|
break
|
||||||
|
} else {
|
||||||
|
spinner.text = "Updating..."
|
||||||
|
await new Promise(resolve => setTimeout(resolve, 3000))
|
||||||
|
this.context.stdout.write("\x1Bc")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break
|
||||||
|
case "regions":
|
||||||
|
try {
|
||||||
|
await this.fetchRegions(server)
|
||||||
|
const prefTook = performance.now() - prefStart
|
||||||
|
spinner.succeed(`Fetching completed in ${(prefTook / 1000).toFixed(2)}s 🎉`)
|
||||||
|
} catch (e) {
|
||||||
|
spinner.fail(`Server with label ${chalk.bold(this.label)} is not running! 😢`)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
break
|
||||||
|
default:
|
||||||
|
spinner.fail(chalk.red(`Info area was not exists ${chalk.bold(this.area)}...`))
|
||||||
|
}
|
||||||
|
|
||||||
|
process.exit(0)
|
||||||
|
}
|
||||||
|
}
|
26
cli/src/cmd/list.ts
Normal file
26
cli/src/cmd/list.ts
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
import { Command, type Usage } from "clipanion"
|
||||||
|
import { RsConfig } from "../utils/config.ts"
|
||||||
|
import chalk from "chalk"
|
||||||
|
|
||||||
|
export class ListServerCommand extends Command {
|
||||||
|
static paths = [[`list`], [`ls`]]
|
||||||
|
static usage: Usage = {
|
||||||
|
category: `Networking`,
|
||||||
|
description: `List all connected RoadSign Sideload Services`,
|
||||||
|
details: `Listing all servers that already saved in RoadSign CLI configuration file`,
|
||||||
|
examples: [["List all", `list`]]
|
||||||
|
}
|
||||||
|
|
||||||
|
async execute() {
|
||||||
|
const config = await RsConfig.getInstance()
|
||||||
|
|
||||||
|
for (let idx = 0; idx < config.config.servers.length; idx++) {
|
||||||
|
const server = config.config.servers[idx]
|
||||||
|
this.context.stdout.write(`${idx + 1}. ${chalk.bold(server.label)} ${chalk.gray(`(${server.url})`)}\n`)
|
||||||
|
}
|
||||||
|
|
||||||
|
this.context.stdout.write("\n" + chalk.cyan(`Connected ${config.config.servers.length} server(s) in total.`) + "\n")
|
||||||
|
|
||||||
|
process.exit(0)
|
||||||
|
}
|
||||||
|
}
|
55
cli/src/cmd/login.ts
Normal file
55
cli/src/cmd/login.ts
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
import { Command, Option, type Usage } from "clipanion"
|
||||||
|
import { createAuthHeader } from "../utils/auth.ts"
|
||||||
|
import { RsConfig } from "../utils/config.ts"
|
||||||
|
import ora, { oraPromise } from "ora"
|
||||||
|
|
||||||
|
export class LoginCommand extends Command {
|
||||||
|
static paths = [[`login`]]
|
||||||
|
static usage: Usage = {
|
||||||
|
category: `Networking`,
|
||||||
|
description: `Login to RoadSign Sideload Service`,
|
||||||
|
details: `Login to RoadSign Server`,
|
||||||
|
examples: [["Login with credentials", `login <label> <host> <password>`]]
|
||||||
|
}
|
||||||
|
|
||||||
|
label = Option.String({ required: true })
|
||||||
|
host = Option.String({ required: true })
|
||||||
|
credentials = Option.String({ required: true })
|
||||||
|
|
||||||
|
async execute() {
|
||||||
|
const config = await RsConfig.getInstance()
|
||||||
|
const spinner = ora(`Connecting to ${this.host}...`).start()
|
||||||
|
|
||||||
|
if (!this.host.includes(":")) {
|
||||||
|
this.host += ":81"
|
||||||
|
}
|
||||||
|
if (!this.host.startsWith("http")) {
|
||||||
|
this.host = "http://" + this.host
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const pingRes = await fetch(`${this.host}/cgi/metadata`, {
|
||||||
|
headers: {
|
||||||
|
Authorization: createAuthHeader(this.credentials)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
if (pingRes.status !== 200) {
|
||||||
|
throw new Error(await pingRes.text())
|
||||||
|
} else {
|
||||||
|
const info: any = await pingRes.json()
|
||||||
|
spinner.succeed(`Connected to ${this.host}, remote version ${info["version"]}`)
|
||||||
|
|
||||||
|
config.config.servers.push({
|
||||||
|
label: this.label,
|
||||||
|
url: this.host,
|
||||||
|
credential: this.credentials
|
||||||
|
})
|
||||||
|
await oraPromise(config.writeConfig(), { text: "Saving changes..." })
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
spinner.fail(`Unable connect to remote: ${e}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
process.exit(0)
|
||||||
|
}
|
||||||
|
}
|
31
cli/src/cmd/logout.ts
Normal file
31
cli/src/cmd/logout.ts
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
import { Command, Option, type Usage } from "clipanion"
|
||||||
|
import { RsConfig } from "../utils/config.ts"
|
||||||
|
import { oraPromise } from "ora"
|
||||||
|
import chalk from "chalk"
|
||||||
|
|
||||||
|
export class LogoutCommand extends Command {
|
||||||
|
static paths = [[`logout`]]
|
||||||
|
static usage: Usage = {
|
||||||
|
category: `Networking`,
|
||||||
|
description: `Logout from RoadSign Sideload Service`,
|
||||||
|
details: `Logout from RoadSign Server`,
|
||||||
|
examples: [["Logout with server label", `logout <label>`]]
|
||||||
|
}
|
||||||
|
|
||||||
|
label = Option.String({ required: true })
|
||||||
|
|
||||||
|
async execute() {
|
||||||
|
const config = await RsConfig.getInstance()
|
||||||
|
|
||||||
|
const server = config.config.servers.findIndex(item => item.label === this.label)
|
||||||
|
if (server === -1) {
|
||||||
|
this.context.stdout.write(chalk.red(`Server with label ${chalk.bold(this.label)} was not found.\n`))
|
||||||
|
} else {
|
||||||
|
config.config.servers.splice(server, 1)
|
||||||
|
this.context.stdout.write(chalk.green(`Server with label ${chalk.bold(this.label)} was successfully removed.\n`))
|
||||||
|
await oraPromise(config.writeConfig(), { text: "Saving changes..." })
|
||||||
|
}
|
||||||
|
|
||||||
|
process.exit(0)
|
||||||
|
}
|
||||||
|
}
|
146
cli/src/cmd/process-info.ts
Normal file
146
cli/src/cmd/process-info.ts
Normal file
@@ -0,0 +1,146 @@
|
|||||||
|
import { Command, Option, type Usage } from "clipanion"
|
||||||
|
import { RsConfig } from "../utils/config.ts"
|
||||||
|
import { createAuthHeader } from "../utils/auth.ts"
|
||||||
|
import Table from "cli-table3"
|
||||||
|
import chalk from "chalk"
|
||||||
|
import ora from "ora"
|
||||||
|
|
||||||
|
export class ProcessCommand extends Command {
|
||||||
|
static paths = [[`process`], [`ps`]]
|
||||||
|
static usage: Usage = {
|
||||||
|
category: `Networking`,
|
||||||
|
description: `Loading the application of RoadSign Server`,
|
||||||
|
details: `Fetching the configured things amount and other things of a connected server`,
|
||||||
|
examples: [
|
||||||
|
["Fetch app directory from labeled server", `ps <label>`],
|
||||||
|
["Fetch app logs from labeled server", `ps <label> <applicationId> logs`]
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
label = Option.String({ required: true })
|
||||||
|
applicationId = Option.String({ required: false })
|
||||||
|
subcommand = Option.String({ required: false })
|
||||||
|
loop = Option.Boolean("--loop,--follow,-f", false, { description: "Keep updating the results" })
|
||||||
|
|
||||||
|
async execute() {
|
||||||
|
const config = await RsConfig.getInstance()
|
||||||
|
|
||||||
|
const server = config.config.servers.find(item => item.label === this.label)
|
||||||
|
if (server == null) {
|
||||||
|
this.context.stdout.write(chalk.red(`Server with label ${chalk.bold(this.label)} was not found.\n`))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const spinner = ora(`Fetching stats from server ${this.label}...`).start()
|
||||||
|
const prefStart = performance.now()
|
||||||
|
|
||||||
|
|
||||||
|
if (this.applicationId == null) {
|
||||||
|
try {
|
||||||
|
const res = await fetch(`${server.url}/cgi/applications`, {
|
||||||
|
headers: {
|
||||||
|
Authorization: createAuthHeader(server.credential)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
if (res.status !== 200) {
|
||||||
|
throw new Error(await res.text())
|
||||||
|
}
|
||||||
|
const prefTook = performance.now() - prefStart
|
||||||
|
if (!this.loop) {
|
||||||
|
spinner.succeed(`Fetching completed in ${(prefTook / 1000).toFixed(2)}s 🎉`)
|
||||||
|
}
|
||||||
|
|
||||||
|
const table = new Table({
|
||||||
|
head: ["ID", "Status", "Command"],
|
||||||
|
colWidths: [20, 10, 48]
|
||||||
|
})
|
||||||
|
|
||||||
|
const statusMapping = ["Created", "Starting", "Started", "Exited", "Failed"]
|
||||||
|
|
||||||
|
const data: any = await res.json()
|
||||||
|
for (const app of data) {
|
||||||
|
table.push([app["id"], statusMapping[app["status"]], app["command"].join(" ")])
|
||||||
|
}
|
||||||
|
|
||||||
|
this.context.stdout.write(table.toString())
|
||||||
|
} catch (e) {
|
||||||
|
spinner.fail(`Server with label ${chalk.bold(this.label)} is not running! 😢`)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
switch (this.subcommand) {
|
||||||
|
case "logs":
|
||||||
|
while (true) {
|
||||||
|
try {
|
||||||
|
const res = await fetch(`${server.url}/cgi/applications/${this.applicationId}/logs`, {
|
||||||
|
headers: {
|
||||||
|
Authorization: createAuthHeader(server.credential)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
if (res.status === 404) {
|
||||||
|
spinner.fail(`App with id ${chalk.bold(this.applicationId)} was not found! 😢`)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (res.status !== 200) {
|
||||||
|
throw new Error(await res.text())
|
||||||
|
}
|
||||||
|
const prefTook = performance.now() - prefStart
|
||||||
|
if (!this.loop) {
|
||||||
|
spinner.succeed(`Fetching completed in ${(prefTook / 1000).toFixed(2)}s 🎉`)
|
||||||
|
}
|
||||||
|
|
||||||
|
this.context.stdout.write(await res.text())
|
||||||
|
} catch (e) {
|
||||||
|
spinner.fail(`Server with label ${chalk.bold(this.label)} is not running! 😢`)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!this.loop) {
|
||||||
|
break
|
||||||
|
} else {
|
||||||
|
spinner.text = "Updating..."
|
||||||
|
await new Promise(resolve => setTimeout(resolve, 3000))
|
||||||
|
this.context.stdout.write("\x1Bc")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break
|
||||||
|
case "start":
|
||||||
|
case "stop":
|
||||||
|
case "restart":
|
||||||
|
try {
|
||||||
|
const res = await fetch(`${server.url}/cgi/applications/${this.applicationId}/${this.subcommand}`, {
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
Authorization: createAuthHeader(server.credential)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
if (res.status === 404) {
|
||||||
|
spinner.fail(`App with id ${chalk.bold(this.applicationId)} was not found! 😢`)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (res.status === 500) {
|
||||||
|
this.context.stdout.write(chalk.red(`Server failed to perform action for application: ${await res.text()}\n`))
|
||||||
|
spinner.fail(`Failed to perform action ${chalk.bold(this.applicationId)}... 😢`)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (res.status !== 200) {
|
||||||
|
throw new Error(await res.text())
|
||||||
|
}
|
||||||
|
const prefTook = performance.now() - prefStart
|
||||||
|
if (!this.loop) {
|
||||||
|
spinner.succeed(`Fetching completed in ${(prefTook / 1000).toFixed(2)}s 🎉`)
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
spinner.fail(`Server with label ${chalk.bold(this.label)} is not running! 😢`)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
spinner.succeed(`Action for application ${chalk.bold(this.applicationId)} has been performed. 🎉`)
|
||||||
|
break
|
||||||
|
default:
|
||||||
|
this.context.stdout.write(chalk.red(`Subcommand ${chalk.bold(this.subcommand)} was not found.\n`))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
process.exit(0)
|
||||||
|
}
|
||||||
|
}
|
53
cli/src/cmd/reload.ts
Normal file
53
cli/src/cmd/reload.ts
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
import { RsConfig } from "../utils/config.ts"
|
||||||
|
import { Command, Option, type Usage } from "clipanion"
|
||||||
|
import chalk from "chalk"
|
||||||
|
import ora from "ora"
|
||||||
|
import * as fs from "node:fs"
|
||||||
|
import { createAuthHeader } from "../utils/auth.ts"
|
||||||
|
import { RsLocalConfig } from "../utils/config-local.ts"
|
||||||
|
|
||||||
|
export class ReloadCommand extends Command {
|
||||||
|
static paths = [[`reload`]]
|
||||||
|
static usage: Usage = {
|
||||||
|
category: `Building`,
|
||||||
|
description: `Reload configuration on RoadSign`,
|
||||||
|
details: `Reload configuration on remote RoadSign to make changes applied.`,
|
||||||
|
examples: [
|
||||||
|
["Reload an connected server", `reload <server>`],
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
server = Option.String({ required: true })
|
||||||
|
|
||||||
|
async execute() {
|
||||||
|
const cfg = await RsConfig.getInstance()
|
||||||
|
const server = cfg.config.servers.find(item => item.label === this.server)
|
||||||
|
if (server == null) {
|
||||||
|
this.context.stdout.write(chalk.red(`Server with label ${chalk.bold(this.server)} was not found.\n`))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const spinner = ora(`Reloading server ${chalk.bold(this.server)}...`).start()
|
||||||
|
|
||||||
|
const prefStart = performance.now()
|
||||||
|
|
||||||
|
try {
|
||||||
|
const res = await fetch(`${server.url}/cgi/reload`, {
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
Authorization: createAuthHeader(server.credential)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
if (res.status !== 200) {
|
||||||
|
throw new Error(await res.text())
|
||||||
|
}
|
||||||
|
const prefTook = performance.now() - prefStart
|
||||||
|
spinner.succeed(`Reloading completed in ${(prefTook / 1000).toFixed(2)}s 🎉`)
|
||||||
|
} catch (e) {
|
||||||
|
this.context.stdout.write(`Failed to reload remote: ${e}\n`)
|
||||||
|
spinner.fail(`Server with label ${chalk.bold(this.server)} is not running! 😢`)
|
||||||
|
}
|
||||||
|
|
||||||
|
process.exit(0)
|
||||||
|
}
|
||||||
|
}
|
46
cli/src/cmd/status.ts
Normal file
46
cli/src/cmd/status.ts
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
import { Command, Option, type Usage } from "clipanion"
|
||||||
|
import { RsConfig } from "../utils/config.ts"
|
||||||
|
import { createAuthHeader } from "../utils/auth.ts"
|
||||||
|
import chalk from "chalk"
|
||||||
|
import ora from "ora"
|
||||||
|
|
||||||
|
export class StatusCommand extends Command {
|
||||||
|
static paths = [[`status`]]
|
||||||
|
static usage: Usage = {
|
||||||
|
category: `Networking`,
|
||||||
|
description: `Check the status of RoadSign Sideload Service`,
|
||||||
|
details: `Check the running status of a connected server`,
|
||||||
|
examples: [["Check the status of labeled server", `status <label>`]]
|
||||||
|
}
|
||||||
|
|
||||||
|
label = Option.String({ required: true })
|
||||||
|
|
||||||
|
async execute() {
|
||||||
|
const config = await RsConfig.getInstance()
|
||||||
|
|
||||||
|
const server = config.config.servers.find(item => item.label === this.label)
|
||||||
|
if (server == null) {
|
||||||
|
this.context.stdout.write(chalk.red(`Server with label ${chalk.bold(this.label)} was not found.\n`))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const spinner = ora(`Checking status of ${this.label}...`).start()
|
||||||
|
|
||||||
|
try {
|
||||||
|
const res = await fetch(`${server.url}/cgi/metadata`, {
|
||||||
|
headers: {
|
||||||
|
Authorization: createAuthHeader(server.credential)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
if (res.status !== 200) {
|
||||||
|
throw new Error(await res.text())
|
||||||
|
}
|
||||||
|
spinner.succeed(`Server with label ${chalk.bold(this.label)} is up and running! 🎉`)
|
||||||
|
} catch (e) {
|
||||||
|
spinner.fail(`Server with label ${chalk.bold(this.label)} is not running! 😢`)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
process.exit(0)
|
||||||
|
}
|
||||||
|
}
|
87
cli/src/cmd/sync.ts
Normal file
87
cli/src/cmd/sync.ts
Normal file
@@ -0,0 +1,87 @@
|
|||||||
|
import { RsConfig } from "../utils/config.ts"
|
||||||
|
import { Command, Option, type Usage } from "clipanion"
|
||||||
|
import chalk from "chalk"
|
||||||
|
import ora from "ora"
|
||||||
|
import * as fs from "node:fs"
|
||||||
|
import { createAuthHeader } from "../utils/auth.ts"
|
||||||
|
import { RsLocalConfig } from "../utils/config-local.ts"
|
||||||
|
|
||||||
|
export class SyncCommand extends Command {
|
||||||
|
static paths = [[`sync`]]
|
||||||
|
static usage: Usage = {
|
||||||
|
category: `Building`,
|
||||||
|
description: `Sync configuration to RoadSign over Sideload`,
|
||||||
|
details: `Update remote RoadSign configuration with local ones.`,
|
||||||
|
examples: [
|
||||||
|
["Sync to RoadSign", `sync <server> <region> <file>`],
|
||||||
|
["Sync to RoadSign with .roadsignrc file", `sync <server>`]
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
server = Option.String({ required: true })
|
||||||
|
region = Option.String({ required: false })
|
||||||
|
input = Option.String({ required: false })
|
||||||
|
|
||||||
|
async sync(serverLabel: string, region: string, input: string) {
|
||||||
|
const cfg = await RsConfig.getInstance()
|
||||||
|
const server = cfg.config.servers.find(item => item.label === serverLabel)
|
||||||
|
if (server == null) {
|
||||||
|
this.context.stdout.write(chalk.red(`Server with label ${chalk.bold(this.server)} was not found.\n`))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!fs.existsSync(input)) {
|
||||||
|
this.context.stdout.write(chalk.red(`Input file ${chalk.bold(this.input)} was not found.\n`))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (!fs.statSync(input).isFile()) {
|
||||||
|
this.context.stdout.write(chalk.red(`Input file ${chalk.bold(this.input)} is not a file.\n`))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const spinner = ora(`Syncing ${chalk.bold(region)} to ${chalk.bold(this.server)}...`).start()
|
||||||
|
|
||||||
|
const prefStart = performance.now()
|
||||||
|
|
||||||
|
try {
|
||||||
|
const res = await fetch(`${server.url}/webhooks/sync/${region}`, {
|
||||||
|
method: "PUT",
|
||||||
|
body: fs.readFileSync(input, "utf8"),
|
||||||
|
headers: {
|
||||||
|
Authorization: createAuthHeader(server.credential)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
if (res.status !== 200) {
|
||||||
|
throw new Error(await res.text())
|
||||||
|
}
|
||||||
|
const prefTook = performance.now() - prefStart
|
||||||
|
spinner.succeed(`Syncing completed in ${(prefTook / 1000).toFixed(2)}s 🎉`)
|
||||||
|
} catch (e) {
|
||||||
|
this.context.stdout.write(`Failed to sync to remote: ${e}\n`)
|
||||||
|
spinner.fail(`Server with label ${chalk.bold(this.server)} is not running! 😢`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async execute() {
|
||||||
|
if (this.region && this.input) {
|
||||||
|
await this.sync(this.server, this.region, this.input)
|
||||||
|
} else {
|
||||||
|
let localCfg: RsLocalConfig
|
||||||
|
try {
|
||||||
|
localCfg = await RsLocalConfig.getInstance()
|
||||||
|
} catch (e) {
|
||||||
|
this.context.stdout.write(chalk.red(`Unable to load .roadsignrc: ${e}\n`))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!localCfg.config.sync) {
|
||||||
|
this.context.stdout.write(chalk.red(`No sync configuration found in .roadsignrc, exiting...\n`))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
await this.sync(this.server, localCfg.config.sync.region, localCfg.config.sync.configPath)
|
||||||
|
}
|
||||||
|
|
||||||
|
process.exit(0)
|
||||||
|
}
|
||||||
|
}
|
4
cli/src/utils/auth.ts
Normal file
4
cli/src/utils/auth.ts
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
export function createAuthHeader(password: string, username: string = "RoadSign CLI") {
|
||||||
|
const credentials = Buffer.from(`${username}:${password}`).toString("base64")
|
||||||
|
return `Basic ${credentials}`
|
||||||
|
}
|
60
cli/src/utils/config-local.ts
Normal file
60
cli/src/utils/config-local.ts
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
import * as path from "node:path"
|
||||||
|
import * as fs from "node:fs"
|
||||||
|
|
||||||
|
interface RsLocalConfigData {
|
||||||
|
sync?: RsLocalConfigSyncData
|
||||||
|
deployments?: RsLocalConfigDeploymentData[]
|
||||||
|
}
|
||||||
|
|
||||||
|
interface RsLocalConfigSyncData {
|
||||||
|
configPath: string
|
||||||
|
region: string
|
||||||
|
}
|
||||||
|
|
||||||
|
interface RsLocalConfigDeploymentData {
|
||||||
|
path: string
|
||||||
|
region: string
|
||||||
|
site: string
|
||||||
|
autoBuild?: RsLocalConfigDeploymentAutoBuildData
|
||||||
|
}
|
||||||
|
|
||||||
|
interface RsLocalConfigDeploymentAutoBuildData {
|
||||||
|
command: string
|
||||||
|
environment?: string[]
|
||||||
|
}
|
||||||
|
|
||||||
|
class RsLocalConfig {
|
||||||
|
private static instance: RsLocalConfig
|
||||||
|
|
||||||
|
public config: RsLocalConfigData = {}
|
||||||
|
|
||||||
|
private constructor() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public static async getInstance(): Promise<RsLocalConfig> {
|
||||||
|
if (!RsLocalConfig.instance) {
|
||||||
|
RsLocalConfig.instance = new RsLocalConfig()
|
||||||
|
await RsLocalConfig.instance.readConfig()
|
||||||
|
}
|
||||||
|
return RsLocalConfig.instance
|
||||||
|
}
|
||||||
|
|
||||||
|
public async readConfig() {
|
||||||
|
const basepath = process.cwd()
|
||||||
|
const filepath = path.join(basepath, ".roadsignrc")
|
||||||
|
if (!fs.existsSync(filepath)) {
|
||||||
|
throw new Error(`.roadsignrc file was not found at ${filepath}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
const data = fs.readFileSync(filepath, "utf8")
|
||||||
|
this.config = JSON.parse(data)
|
||||||
|
}
|
||||||
|
|
||||||
|
public async writeConfig() {
|
||||||
|
const basepath = process.cwd()
|
||||||
|
const filepath = path.join(basepath, ".roadsignrc")
|
||||||
|
fs.writeFileSync(filepath, JSON.stringify(this.config))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export { RsLocalConfig, type RsLocalConfigData }
|
51
cli/src/utils/config.ts
Normal file
51
cli/src/utils/config.ts
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
import * as os from "node:os"
|
||||||
|
import * as path from "node:path"
|
||||||
|
import * as fs from "node:fs"
|
||||||
|
|
||||||
|
interface RsConfigData {
|
||||||
|
servers: RsConfigServerData[]
|
||||||
|
}
|
||||||
|
|
||||||
|
interface RsConfigServerData {
|
||||||
|
label: string
|
||||||
|
url: string
|
||||||
|
credential: string
|
||||||
|
}
|
||||||
|
|
||||||
|
class RsConfig {
|
||||||
|
private static instance: RsConfig
|
||||||
|
|
||||||
|
public config: RsConfigData = {
|
||||||
|
servers: []
|
||||||
|
}
|
||||||
|
|
||||||
|
private constructor() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public static async getInstance(): Promise<RsConfig> {
|
||||||
|
if (!RsConfig.instance) {
|
||||||
|
RsConfig.instance = new RsConfig()
|
||||||
|
await RsConfig.instance.readConfig()
|
||||||
|
}
|
||||||
|
return RsConfig.instance
|
||||||
|
}
|
||||||
|
|
||||||
|
public async readConfig() {
|
||||||
|
const basepath = os.homedir()
|
||||||
|
const filepath = path.join(basepath, ".roadsignrc")
|
||||||
|
if (!fs.existsSync(filepath)) {
|
||||||
|
fs.writeFileSync(filepath, JSON.stringify(this.config))
|
||||||
|
}
|
||||||
|
|
||||||
|
const data = fs.readFileSync(filepath, "utf8")
|
||||||
|
this.config = JSON.parse(data)
|
||||||
|
}
|
||||||
|
|
||||||
|
public async writeConfig() {
|
||||||
|
const basepath = os.homedir()
|
||||||
|
const filepath = path.join(basepath, ".roadsignrc")
|
||||||
|
fs.writeFileSync(filepath, JSON.stringify(this.config))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export { RsConfig, type RsConfigData, type RsConfigServerData }
|
9
cli/test/static-files.toml
Normal file
9
cli/test/static-files.toml
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
id = "static-files-num2"
|
||||||
|
|
||||||
|
[[locations]]
|
||||||
|
id = "static-files-loc-num2"
|
||||||
|
hosts = ["127.0.0.1:8000"]
|
||||||
|
paths = ["/"]
|
||||||
|
[[locations.destinations]]
|
||||||
|
id = "static-files-des-num2"
|
||||||
|
uri = "files://../data/static-files"
|
12
cli/test/static-files/index.html
Normal file
12
cli/test/static-files/index.html
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
|
<title>Hello, World!</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<p>Hello, there!</p>
|
||||||
|
<p>Here's the newer version of static files hosted by roadsign!</p>
|
||||||
|
</body>
|
||||||
|
</html>
|
27
cli/tsconfig.json
Normal file
27
cli/tsconfig.json
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"lib": ["ESNext"],
|
||||||
|
"target": "ESNext",
|
||||||
|
"module": "NodeNext",
|
||||||
|
"allowJs": true,
|
||||||
|
|
||||||
|
// Bundler mode
|
||||||
|
"esModuleInterop": true,
|
||||||
|
"moduleResolution": "NodeNext",
|
||||||
|
"allowImportingTsExtensions": true,
|
||||||
|
"verbatimModuleSyntax": true,
|
||||||
|
"noEmit": true,
|
||||||
|
"resolveJsonModule": true,
|
||||||
|
|
||||||
|
// Best practices
|
||||||
|
"strict": true,
|
||||||
|
"skipLibCheck": true,
|
||||||
|
"noFallthroughCasesInSwitch": true,
|
||||||
|
|
||||||
|
// Some stricter flags (disabled by default)
|
||||||
|
"noUnusedLocals": false,
|
||||||
|
"noUnusedParameters": false,
|
||||||
|
"noPropertyAccessFromIndexSignature": false,
|
||||||
|
"useUnknownInCatchVariables": false,
|
||||||
|
}
|
||||||
|
}
|
@@ -1,28 +1,32 @@
|
|||||||
id = "example-region"
|
id = "example-region"
|
||||||
|
|
||||||
[[locations]]
|
# [[locations]]
|
||||||
id = "example-sse"
|
# id = "example-websocket"
|
||||||
host = ["localhost:8000"]
|
# host = ["localhost:8000"]
|
||||||
path = ["/sse"]
|
# path = ["/ws"]
|
||||||
[[locations.destinations]]
|
# [[locations.destinations]]
|
||||||
id = "example-sse-destination"
|
# id = "example-websocket-destination"
|
||||||
uri = "http://localhost:5000?sse=enable"
|
# uri = "http://localhost:8765"
|
||||||
[[locations.transformers]]
|
|
||||||
type = "replacePath"
|
# [[locations]]
|
||||||
options = { pattern = "/sse", value = "" }
|
# id = "example-warden"
|
||||||
|
# host = ["localhost:4321"]
|
||||||
|
# path = ["/"]
|
||||||
|
# [[locations.destinations]]
|
||||||
|
# id = "example-warden-destination"
|
||||||
|
# uri = "http://localhost:4321"
|
||||||
|
|
||||||
|
# [[applications]]
|
||||||
|
# id = "example-warden-app"
|
||||||
|
# workdir = "test/data/warden"
|
||||||
|
# command = ["node", "dist/server/entry.mjs"]
|
||||||
|
# environment = ["PUBLIC_CMS=https://smartsheep.studio"]
|
||||||
|
|
||||||
[[locations]]
|
[[locations]]
|
||||||
id = "example-websocket"
|
id = "example"
|
||||||
host = ["localhost:8000"]
|
|
||||||
path = ["/ws"]
|
|
||||||
[[locations.destinations]]
|
|
||||||
id = "example-websocket-destination"
|
|
||||||
uri = "http://localhost:8765"
|
|
||||||
|
|
||||||
[[locations]]
|
|
||||||
id = "example-location"
|
|
||||||
host = ["localhost:8000"]
|
host = ["localhost:8000"]
|
||||||
path = ["/"]
|
path = ["/"]
|
||||||
[[locations.destinations]]
|
[[locations.destinations]]
|
||||||
id = "example-destination"
|
id = "example-destination"
|
||||||
uri = "files://test/data"
|
uri = "https://example.com"
|
||||||
|
helmet = { x_frame_options = "SAMEORIGIN" }
|
26
go.mod
26
go.mod
@@ -1,10 +1,11 @@
|
|||||||
module code.smartsheep.studio/goatworks/roadsign
|
module git.solsynth.dev/goatworks/roadsign
|
||||||
|
|
||||||
go 1.21.4
|
go 1.21.4
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/gofiber/contrib/websocket v1.3.0
|
github.com/fasthttp/websocket v1.5.7
|
||||||
github.com/gofiber/fiber/v2 v2.52.0
|
github.com/gofiber/fiber/v2 v2.52.5
|
||||||
|
github.com/gofiber/template/html/v2 v2.1.0
|
||||||
github.com/google/uuid v1.6.0
|
github.com/google/uuid v1.6.0
|
||||||
github.com/json-iterator/go v1.1.12
|
github.com/json-iterator/go v1.1.12
|
||||||
github.com/rs/zerolog v1.31.0
|
github.com/rs/zerolog v1.31.0
|
||||||
@@ -12,35 +13,36 @@ require (
|
|||||||
github.com/saracen/fastzip v0.1.11
|
github.com/saracen/fastzip v0.1.11
|
||||||
github.com/spf13/viper v1.17.0
|
github.com/spf13/viper v1.17.0
|
||||||
github.com/urfave/cli/v2 v2.26.0
|
github.com/urfave/cli/v2 v2.26.0
|
||||||
github.com/valyala/fasthttp v1.51.0
|
github.com/valyala/fasthttp v1.56.0
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
|
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
|
||||||
github.com/fasthttp/websocket v1.5.7 // indirect
|
github.com/gofiber/template v1.8.2 // indirect
|
||||||
|
github.com/gofiber/utils v1.1.0 // indirect
|
||||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
||||||
github.com/modern-go/reflect2 v1.0.2 // indirect
|
github.com/modern-go/reflect2 v1.0.2 // indirect
|
||||||
github.com/russross/blackfriday/v2 v2.1.0 // indirect
|
github.com/russross/blackfriday/v2 v2.1.0 // indirect
|
||||||
github.com/saracen/zipextra v0.0.0-20220303013732-0187cb0159ea // indirect
|
github.com/saracen/zipextra v0.0.0-20220303013732-0187cb0159ea // indirect
|
||||||
github.com/savsgio/gotils v0.0.0-20230208104028-c358bd845dee // indirect
|
github.com/savsgio/gotils v0.0.0-20230208104028-c358bd845dee // indirect
|
||||||
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
|
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
|
||||||
golang.org/x/net v0.20.0 // indirect
|
golang.org/x/net v0.29.0 // indirect
|
||||||
golang.org/x/sync v0.5.0 // indirect
|
golang.org/x/sync v0.8.0 // indirect
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/andybalholm/brotli v1.1.0 // indirect
|
github.com/andybalholm/brotli v1.1.0 // indirect
|
||||||
github.com/fsnotify/fsnotify v1.6.0 // indirect
|
github.com/fsnotify/fsnotify v1.6.0 // indirect
|
||||||
github.com/hashicorp/hcl v1.0.0 // indirect
|
github.com/hashicorp/hcl v1.0.0 // indirect
|
||||||
github.com/klauspost/compress v1.17.4 // indirect
|
github.com/klauspost/compress v1.17.10 // indirect
|
||||||
github.com/magiconair/properties v1.8.7 // indirect
|
github.com/magiconair/properties v1.8.7 // indirect
|
||||||
github.com/mattn/go-colorable v0.1.13 // indirect
|
github.com/mattn/go-colorable v0.1.13 // indirect
|
||||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||||
github.com/mattn/go-runewidth v0.0.15 // indirect
|
github.com/mattn/go-runewidth v0.0.16 // indirect
|
||||||
github.com/mitchellh/mapstructure v1.5.0 // indirect
|
github.com/mitchellh/mapstructure v1.5.0 // indirect
|
||||||
github.com/pelletier/go-toml/v2 v2.1.1
|
github.com/pelletier/go-toml/v2 v2.1.1
|
||||||
github.com/philhofer/fwd v1.1.2 // indirect
|
github.com/philhofer/fwd v1.1.2 // indirect
|
||||||
github.com/rivo/uniseg v0.4.4 // indirect
|
github.com/rivo/uniseg v0.4.7 // indirect
|
||||||
github.com/sagikazarmark/locafero v0.3.0 // indirect
|
github.com/sagikazarmark/locafero v0.3.0 // indirect
|
||||||
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
|
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
|
||||||
github.com/sourcegraph/conc v0.3.0 // indirect
|
github.com/sourcegraph/conc v0.3.0 // indirect
|
||||||
@@ -54,8 +56,8 @@ require (
|
|||||||
go.uber.org/atomic v1.9.0 // indirect
|
go.uber.org/atomic v1.9.0 // indirect
|
||||||
go.uber.org/multierr v1.9.0 // indirect
|
go.uber.org/multierr v1.9.0 // indirect
|
||||||
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect
|
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect
|
||||||
golang.org/x/sys v0.16.0 // indirect
|
golang.org/x/sys v0.25.0 // indirect
|
||||||
golang.org/x/text v0.14.0 // indirect
|
golang.org/x/text v0.18.0 // indirect
|
||||||
gopkg.in/ini.v1 v1.67.0 // indirect
|
gopkg.in/ini.v1 v1.67.0 // indirect
|
||||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||||
)
|
)
|
||||||
|
44
go.sum
44
go.sum
@@ -14,10 +14,14 @@ github.com/frankban/quicktest v1.14.4/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7z
|
|||||||
github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY=
|
github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY=
|
||||||
github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw=
|
github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw=
|
||||||
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
|
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
|
||||||
github.com/gofiber/contrib/websocket v1.3.0 h1:XADFAGorer1VJ1bqC4UkCjqS37kwRTV0415+050NrMk=
|
github.com/gofiber/fiber/v2 v2.52.5 h1:tWoP1MJQjGEe4GB5TUGOi7P2E0ZMMRx5ZTG4rT+yGMo=
|
||||||
github.com/gofiber/contrib/websocket v1.3.0/go.mod h1:xguaOzn2ZZ759LavtosEP+rcxIgBEE/rdumPINhR+Xo=
|
github.com/gofiber/fiber/v2 v2.52.5/go.mod h1:KEOE+cXMhXG0zHc9d8+E38hoX+ZN7bhOtgeF2oT6jrQ=
|
||||||
github.com/gofiber/fiber/v2 v2.52.0 h1:S+qXi7y+/Pgvqq4DrSmREGiFwtB7Bu6+QFLuIHYw/UE=
|
github.com/gofiber/template v1.8.2 h1:PIv9s/7Uq6m+Fm2MDNd20pAFFKt5wWs7ZBd8iV9pWwk=
|
||||||
github.com/gofiber/fiber/v2 v2.52.0/go.mod h1:KEOE+cXMhXG0zHc9d8+E38hoX+ZN7bhOtgeF2oT6jrQ=
|
github.com/gofiber/template v1.8.2/go.mod h1:bs/2n0pSNPOkRa5VJ8zTIvedcI/lEYxzV3+YPXdBvq8=
|
||||||
|
github.com/gofiber/template/html/v2 v2.1.0 h1:FjwzqhhdJpnhyCvav60Z1ytnBqOUr5sGO/aTeob9/ng=
|
||||||
|
github.com/gofiber/template/html/v2 v2.1.0/go.mod h1:txXsRQN/G7Fr2cqGfr6zhVHgreCfpsBS+9+DJyrddJc=
|
||||||
|
github.com/gofiber/utils v1.1.0 h1:vdEBpn7AzIUJRhe+CiTOJdUcTg4Q9RK+pEa0KPbLdrM=
|
||||||
|
github.com/gofiber/utils v1.1.0/go.mod h1:poZpsnhBykfnY1Mc0KeEa6mSHrS3dV0+oBWyeQmb2e0=
|
||||||
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
|
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
|
||||||
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||||
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
||||||
@@ -27,8 +31,8 @@ github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
|
|||||||
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
|
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
|
||||||
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
|
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
|
||||||
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
|
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
|
||||||
github.com/klauspost/compress v1.17.4 h1:Ej5ixsIri7BrIjBkRZLTo6ghwrEtHFk7ijlczPW4fZ4=
|
github.com/klauspost/compress v1.17.10 h1:oXAz+Vh0PMUvJczoi+flxpnBEPxoER1IaAnU/NMPtT0=
|
||||||
github.com/klauspost/compress v1.17.4/go.mod h1:/dCuZOvVtNoHsyb+cuJD3itjs3NbnF6KH9zAO4BDxPM=
|
github.com/klauspost/compress v1.17.10/go.mod h1:pMDklpSncoRMuLFrf1W9Ss9KT+0rH90U12bZKk7uwG0=
|
||||||
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
|
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
|
||||||
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
|
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
|
||||||
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
||||||
@@ -41,8 +45,8 @@ github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/
|
|||||||
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
||||||
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
|
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
|
||||||
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
||||||
github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U=
|
github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc=
|
||||||
github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
|
github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
|
||||||
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
|
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
|
||||||
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
|
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
|
||||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||||
@@ -59,8 +63,8 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN
|
|||||||
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
|
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
|
||||||
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
|
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
|
||||||
github.com/rivo/uniseg v0.4.4 h1:8TfxU8dW6PdqD27gjM8MVNuicgxIjxpm4K7x4jp8sis=
|
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
|
||||||
github.com/rivo/uniseg v0.4.4/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
|
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
|
||||||
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
|
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
|
||||||
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
|
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
|
||||||
github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
|
github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
|
||||||
@@ -106,8 +110,8 @@ github.com/urfave/cli/v2 v2.26.0 h1:3f3AMg3HpThFNT4I++TKOejZO8yU55t3JnnSr4S4QEI=
|
|||||||
github.com/urfave/cli/v2 v2.26.0/go.mod h1:8qnjx1vcq5s2/wpsqoZFndg2CE5tNFyrTvS6SinrnYQ=
|
github.com/urfave/cli/v2 v2.26.0/go.mod h1:8qnjx1vcq5s2/wpsqoZFndg2CE5tNFyrTvS6SinrnYQ=
|
||||||
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
|
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
|
||||||
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
|
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
|
||||||
github.com/valyala/fasthttp v1.51.0 h1:8b30A5JlZ6C7AS81RsWjYMQmrZG6feChmgAolCl1SqA=
|
github.com/valyala/fasthttp v1.56.0 h1:bEZdJev/6LCBlpdORfrLu/WOZXXxvrUQSiyniuaoW8U=
|
||||||
github.com/valyala/fasthttp v1.51.0/go.mod h1:oI2XroL+lI7vdXyYoQk03bXBThfFl2cVdIA3Xl7cH8g=
|
github.com/valyala/fasthttp v1.56.0/go.mod h1:sReBt3XZVnudxuLOx4J/fMrJVorWRiWY2koQKgABiVI=
|
||||||
github.com/valyala/tcplisten v1.0.0 h1:rBHj/Xf+E1tRGZyWIWwJDiRY0zc1Js+CV5DqwacVSA8=
|
github.com/valyala/tcplisten v1.0.0 h1:rBHj/Xf+E1tRGZyWIWwJDiRY0zc1Js+CV5DqwacVSA8=
|
||||||
github.com/valyala/tcplisten v1.0.0/go.mod h1:T0xQ8SeCZGxckz9qRXTfG43PvQ/mcWh7FwZEA7Ioqkc=
|
github.com/valyala/tcplisten v1.0.0/go.mod h1:T0xQ8SeCZGxckz9qRXTfG43PvQ/mcWh7FwZEA7Ioqkc=
|
||||||
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU=
|
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU=
|
||||||
@@ -127,13 +131,13 @@ golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLL
|
|||||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||||
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
|
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
|
||||||
golang.org/x/net v0.3.0/go.mod h1:MBQ8lrhLObU/6UmLb4fmbmk5OcyYmqtbGd/9yIeKjEE=
|
golang.org/x/net v0.3.0/go.mod h1:MBQ8lrhLObU/6UmLb4fmbmk5OcyYmqtbGd/9yIeKjEE=
|
||||||
golang.org/x/net v0.20.0 h1:aCL9BSgETF1k+blQaYUBx9hJ9LOGP3gAVemcZlf1Kpo=
|
golang.org/x/net v0.29.0 h1:5ORfpBpCs4HzDYoodCDBbwHzdR5UrLBZ3sOnUJmFoHo=
|
||||||
golang.org/x/net v0.20.0/go.mod h1:z8BVo6PvndSri0LbOE3hAn0apkU+1YvI6E70E9jsnvY=
|
golang.org/x/net v0.29.0/go.mod h1:gLkgy8jTGERgjzMic6DS9+SP0ajcu6Xu3Orq/SpETg0=
|
||||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
golang.org/x/sync v0.5.0 h1:60k92dhOjHxJkrqnwsfl8KuaHbn/5dl0lUPUklKo3qE=
|
golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=
|
||||||
golang.org/x/sync v0.5.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
|
golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
|
||||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
@@ -144,8 +148,8 @@ golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBc
|
|||||||
golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU=
|
golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34=
|
||||||
golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||||
golang.org/x/term v0.3.0/go.mod h1:q750SLmJuPmVoN1blW3UFBPREJfb1KmY3vwxfr+nFDA=
|
golang.org/x/term v0.3.0/go.mod h1:q750SLmJuPmVoN1blW3UFBPREJfb1KmY3vwxfr+nFDA=
|
||||||
@@ -153,8 +157,8 @@ golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
|||||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||||
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
||||||
golang.org/x/text v0.5.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
golang.org/x/text v0.5.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
||||||
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
|
golang.org/x/text v0.18.0 h1:XvMDiNzPAl0jr17s6W9lcaIhGUfUORdGCNsuLmPG224=
|
||||||
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
|
golang.org/x/text v0.18.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
|
||||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||||
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||||
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
|
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
|
||||||
|
661
license
Normal file
661
license
Normal file
@@ -0,0 +1,661 @@
|
|||||||
|
GNU AFFERO GENERAL PUBLIC LICENSE
|
||||||
|
Version 3, 19 November 2007
|
||||||
|
|
||||||
|
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||||
|
Everyone is permitted to copy and distribute verbatim copies
|
||||||
|
of this license document, but changing it is not allowed.
|
||||||
|
|
||||||
|
Preamble
|
||||||
|
|
||||||
|
The GNU Affero General Public License is a free, copyleft license for
|
||||||
|
software and other kinds of works, specifically designed to ensure
|
||||||
|
cooperation with the community in the case of network server software.
|
||||||
|
|
||||||
|
The licenses for most software and other practical works are designed
|
||||||
|
to take away your freedom to share and change the works. By contrast,
|
||||||
|
our General Public Licenses are intended to guarantee your freedom to
|
||||||
|
share and change all versions of a program--to make sure it remains free
|
||||||
|
software for all its users.
|
||||||
|
|
||||||
|
When we speak of free software, we are referring to freedom, not
|
||||||
|
price. Our General Public Licenses are designed to make sure that you
|
||||||
|
have the freedom to distribute copies of free software (and charge for
|
||||||
|
them if you wish), that you receive source code or can get it if you
|
||||||
|
want it, that you can change the software or use pieces of it in new
|
||||||
|
free programs, and that you know you can do these things.
|
||||||
|
|
||||||
|
Developers that use our General Public Licenses protect your rights
|
||||||
|
with two steps: (1) assert copyright on the software, and (2) offer
|
||||||
|
you this License which gives you legal permission to copy, distribute
|
||||||
|
and/or modify the software.
|
||||||
|
|
||||||
|
A secondary benefit of defending all users' freedom is that
|
||||||
|
improvements made in alternate versions of the program, if they
|
||||||
|
receive widespread use, become available for other developers to
|
||||||
|
incorporate. Many developers of free software are heartened and
|
||||||
|
encouraged by the resulting cooperation. However, in the case of
|
||||||
|
software used on network servers, this result may fail to come about.
|
||||||
|
The GNU General Public License permits making a modified version and
|
||||||
|
letting the public access it on a server without ever releasing its
|
||||||
|
source code to the public.
|
||||||
|
|
||||||
|
The GNU Affero General Public License is designed specifically to
|
||||||
|
ensure that, in such cases, the modified source code becomes available
|
||||||
|
to the community. It requires the operator of a network server to
|
||||||
|
provide the source code of the modified version running there to the
|
||||||
|
users of that server. Therefore, public use of a modified version, on
|
||||||
|
a publicly accessible server, gives the public access to the source
|
||||||
|
code of the modified version.
|
||||||
|
|
||||||
|
An older license, called the Affero General Public License and
|
||||||
|
published by Affero, was designed to accomplish similar goals. This is
|
||||||
|
a different license, not a version of the Affero GPL, but Affero has
|
||||||
|
released a new version of the Affero GPL which permits relicensing under
|
||||||
|
this license.
|
||||||
|
|
||||||
|
The precise terms and conditions for copying, distribution and
|
||||||
|
modification follow.
|
||||||
|
|
||||||
|
TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
0. Definitions.
|
||||||
|
|
||||||
|
"This License" refers to version 3 of the GNU Affero General Public License.
|
||||||
|
|
||||||
|
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||||
|
works, such as semiconductor masks.
|
||||||
|
|
||||||
|
"The Program" refers to any copyrightable work licensed under this
|
||||||
|
License. Each licensee is addressed as "you". "Licensees" and
|
||||||
|
"recipients" may be individuals or organizations.
|
||||||
|
|
||||||
|
To "modify" a work means to copy from or adapt all or part of the work
|
||||||
|
in a fashion requiring copyright permission, other than the making of an
|
||||||
|
exact copy. The resulting work is called a "modified version" of the
|
||||||
|
earlier work or a work "based on" the earlier work.
|
||||||
|
|
||||||
|
A "covered work" means either the unmodified Program or a work based
|
||||||
|
on the Program.
|
||||||
|
|
||||||
|
To "propagate" a work means to do anything with it that, without
|
||||||
|
permission, would make you directly or secondarily liable for
|
||||||
|
infringement under applicable copyright law, except executing it on a
|
||||||
|
computer or modifying a private copy. Propagation includes copying,
|
||||||
|
distribution (with or without modification), making available to the
|
||||||
|
public, and in some countries other activities as well.
|
||||||
|
|
||||||
|
To "convey" a work means any kind of propagation that enables other
|
||||||
|
parties to make or receive copies. Mere interaction with a user through
|
||||||
|
a computer network, with no transfer of a copy, is not conveying.
|
||||||
|
|
||||||
|
An interactive user interface displays "Appropriate Legal Notices"
|
||||||
|
to the extent that it includes a convenient and prominently visible
|
||||||
|
feature that (1) displays an appropriate copyright notice, and (2)
|
||||||
|
tells the user that there is no warranty for the work (except to the
|
||||||
|
extent that warranties are provided), that licensees may convey the
|
||||||
|
work under this License, and how to view a copy of this License. If
|
||||||
|
the interface presents a list of user commands or options, such as a
|
||||||
|
menu, a prominent item in the list meets this criterion.
|
||||||
|
|
||||||
|
1. Source Code.
|
||||||
|
|
||||||
|
The "source code" for a work means the preferred form of the work
|
||||||
|
for making modifications to it. "Object code" means any non-source
|
||||||
|
form of a work.
|
||||||
|
|
||||||
|
A "Standard Interface" means an interface that either is an official
|
||||||
|
standard defined by a recognized standards body, or, in the case of
|
||||||
|
interfaces specified for a particular programming language, one that
|
||||||
|
is widely used among developers working in that language.
|
||||||
|
|
||||||
|
The "System Libraries" of an executable work include anything, other
|
||||||
|
than the work as a whole, that (a) is included in the normal form of
|
||||||
|
packaging a Major Component, but which is not part of that Major
|
||||||
|
Component, and (b) serves only to enable use of the work with that
|
||||||
|
Major Component, or to implement a Standard Interface for which an
|
||||||
|
implementation is available to the public in source code form. A
|
||||||
|
"Major Component", in this context, means a major essential component
|
||||||
|
(kernel, window system, and so on) of the specific operating system
|
||||||
|
(if any) on which the executable work runs, or a compiler used to
|
||||||
|
produce the work, or an object code interpreter used to run it.
|
||||||
|
|
||||||
|
The "Corresponding Source" for a work in object code form means all
|
||||||
|
the source code needed to generate, install, and (for an executable
|
||||||
|
work) run the object code and to modify the work, including scripts to
|
||||||
|
control those activities. However, it does not include the work's
|
||||||
|
System Libraries, or general-purpose tools or generally available free
|
||||||
|
programs which are used unmodified in performing those activities but
|
||||||
|
which are not part of the work. For example, Corresponding Source
|
||||||
|
includes interface definition files associated with source files for
|
||||||
|
the work, and the source code for shared libraries and dynamically
|
||||||
|
linked subprograms that the work is specifically designed to require,
|
||||||
|
such as by intimate data communication or control flow between those
|
||||||
|
subprograms and other parts of the work.
|
||||||
|
|
||||||
|
The Corresponding Source need not include anything that users
|
||||||
|
can regenerate automatically from other parts of the Corresponding
|
||||||
|
Source.
|
||||||
|
|
||||||
|
The Corresponding Source for a work in source code form is that
|
||||||
|
same work.
|
||||||
|
|
||||||
|
2. Basic Permissions.
|
||||||
|
|
||||||
|
All rights granted under this License are granted for the term of
|
||||||
|
copyright on the Program, and are irrevocable provided the stated
|
||||||
|
conditions are met. This License explicitly affirms your unlimited
|
||||||
|
permission to run the unmodified Program. The output from running a
|
||||||
|
covered work is covered by this License only if the output, given its
|
||||||
|
content, constitutes a covered work. This License acknowledges your
|
||||||
|
rights of fair use or other equivalent, as provided by copyright law.
|
||||||
|
|
||||||
|
You may make, run and propagate covered works that you do not
|
||||||
|
convey, without conditions so long as your license otherwise remains
|
||||||
|
in force. You may convey covered works to others for the sole purpose
|
||||||
|
of having them make modifications exclusively for you, or provide you
|
||||||
|
with facilities for running those works, provided that you comply with
|
||||||
|
the terms of this License in conveying all material for which you do
|
||||||
|
not control copyright. Those thus making or running the covered works
|
||||||
|
for you must do so exclusively on your behalf, under your direction
|
||||||
|
and control, on terms that prohibit them from making any copies of
|
||||||
|
your copyrighted material outside their relationship with you.
|
||||||
|
|
||||||
|
Conveying under any other circumstances is permitted solely under
|
||||||
|
the conditions stated below. Sublicensing is not allowed; section 10
|
||||||
|
makes it unnecessary.
|
||||||
|
|
||||||
|
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||||
|
|
||||||
|
No covered work shall be deemed part of an effective technological
|
||||||
|
measure under any applicable law fulfilling obligations under article
|
||||||
|
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||||
|
similar laws prohibiting or restricting circumvention of such
|
||||||
|
measures.
|
||||||
|
|
||||||
|
When you convey a covered work, you waive any legal power to forbid
|
||||||
|
circumvention of technological measures to the extent such circumvention
|
||||||
|
is effected by exercising rights under this License with respect to
|
||||||
|
the covered work, and you disclaim any intention to limit operation or
|
||||||
|
modification of the work as a means of enforcing, against the work's
|
||||||
|
users, your or third parties' legal rights to forbid circumvention of
|
||||||
|
technological measures.
|
||||||
|
|
||||||
|
4. Conveying Verbatim Copies.
|
||||||
|
|
||||||
|
You may convey verbatim copies of the Program's source code as you
|
||||||
|
receive it, in any medium, provided that you conspicuously and
|
||||||
|
appropriately publish on each copy an appropriate copyright notice;
|
||||||
|
keep intact all notices stating that this License and any
|
||||||
|
non-permissive terms added in accord with section 7 apply to the code;
|
||||||
|
keep intact all notices of the absence of any warranty; and give all
|
||||||
|
recipients a copy of this License along with the Program.
|
||||||
|
|
||||||
|
You may charge any price or no price for each copy that you convey,
|
||||||
|
and you may offer support or warranty protection for a fee.
|
||||||
|
|
||||||
|
5. Conveying Modified Source Versions.
|
||||||
|
|
||||||
|
You may convey a work based on the Program, or the modifications to
|
||||||
|
produce it from the Program, in the form of source code under the
|
||||||
|
terms of section 4, provided that you also meet all of these conditions:
|
||||||
|
|
||||||
|
a) The work must carry prominent notices stating that you modified
|
||||||
|
it, and giving a relevant date.
|
||||||
|
|
||||||
|
b) The work must carry prominent notices stating that it is
|
||||||
|
released under this License and any conditions added under section
|
||||||
|
7. This requirement modifies the requirement in section 4 to
|
||||||
|
"keep intact all notices".
|
||||||
|
|
||||||
|
c) You must license the entire work, as a whole, under this
|
||||||
|
License to anyone who comes into possession of a copy. This
|
||||||
|
License will therefore apply, along with any applicable section 7
|
||||||
|
additional terms, to the whole of the work, and all its parts,
|
||||||
|
regardless of how they are packaged. This License gives no
|
||||||
|
permission to license the work in any other way, but it does not
|
||||||
|
invalidate such permission if you have separately received it.
|
||||||
|
|
||||||
|
d) If the work has interactive user interfaces, each must display
|
||||||
|
Appropriate Legal Notices; however, if the Program has interactive
|
||||||
|
interfaces that do not display Appropriate Legal Notices, your
|
||||||
|
work need not make them do so.
|
||||||
|
|
||||||
|
A compilation of a covered work with other separate and independent
|
||||||
|
works, which are not by their nature extensions of the covered work,
|
||||||
|
and which are not combined with it such as to form a larger program,
|
||||||
|
in or on a volume of a storage or distribution medium, is called an
|
||||||
|
"aggregate" if the compilation and its resulting copyright are not
|
||||||
|
used to limit the access or legal rights of the compilation's users
|
||||||
|
beyond what the individual works permit. Inclusion of a covered work
|
||||||
|
in an aggregate does not cause this License to apply to the other
|
||||||
|
parts of the aggregate.
|
||||||
|
|
||||||
|
6. Conveying Non-Source Forms.
|
||||||
|
|
||||||
|
You may convey a covered work in object code form under the terms
|
||||||
|
of sections 4 and 5, provided that you also convey the
|
||||||
|
machine-readable Corresponding Source under the terms of this License,
|
||||||
|
in one of these ways:
|
||||||
|
|
||||||
|
a) Convey the object code in, or embodied in, a physical product
|
||||||
|
(including a physical distribution medium), accompanied by the
|
||||||
|
Corresponding Source fixed on a durable physical medium
|
||||||
|
customarily used for software interchange.
|
||||||
|
|
||||||
|
b) Convey the object code in, or embodied in, a physical product
|
||||||
|
(including a physical distribution medium), accompanied by a
|
||||||
|
written offer, valid for at least three years and valid for as
|
||||||
|
long as you offer spare parts or customer support for that product
|
||||||
|
model, to give anyone who possesses the object code either (1) a
|
||||||
|
copy of the Corresponding Source for all the software in the
|
||||||
|
product that is covered by this License, on a durable physical
|
||||||
|
medium customarily used for software interchange, for a price no
|
||||||
|
more than your reasonable cost of physically performing this
|
||||||
|
conveying of source, or (2) access to copy the
|
||||||
|
Corresponding Source from a network server at no charge.
|
||||||
|
|
||||||
|
c) Convey individual copies of the object code with a copy of the
|
||||||
|
written offer to provide the Corresponding Source. This
|
||||||
|
alternative is allowed only occasionally and noncommercially, and
|
||||||
|
only if you received the object code with such an offer, in accord
|
||||||
|
with subsection 6b.
|
||||||
|
|
||||||
|
d) Convey the object code by offering access from a designated
|
||||||
|
place (gratis or for a charge), and offer equivalent access to the
|
||||||
|
Corresponding Source in the same way through the same place at no
|
||||||
|
further charge. You need not require recipients to copy the
|
||||||
|
Corresponding Source along with the object code. If the place to
|
||||||
|
copy the object code is a network server, the Corresponding Source
|
||||||
|
may be on a different server (operated by you or a third party)
|
||||||
|
that supports equivalent copying facilities, provided you maintain
|
||||||
|
clear directions next to the object code saying where to find the
|
||||||
|
Corresponding Source. Regardless of what server hosts the
|
||||||
|
Corresponding Source, you remain obligated to ensure that it is
|
||||||
|
available for as long as needed to satisfy these requirements.
|
||||||
|
|
||||||
|
e) Convey the object code using peer-to-peer transmission, provided
|
||||||
|
you inform other peers where the object code and Corresponding
|
||||||
|
Source of the work are being offered to the general public at no
|
||||||
|
charge under subsection 6d.
|
||||||
|
|
||||||
|
A separable portion of the object code, whose source code is excluded
|
||||||
|
from the Corresponding Source as a System Library, need not be
|
||||||
|
included in conveying the object code work.
|
||||||
|
|
||||||
|
A "User Product" is either (1) a "consumer product", which means any
|
||||||
|
tangible personal property which is normally used for personal, family,
|
||||||
|
or household purposes, or (2) anything designed or sold for incorporation
|
||||||
|
into a dwelling. In determining whether a product is a consumer product,
|
||||||
|
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||||
|
product received by a particular user, "normally used" refers to a
|
||||||
|
typical or common use of that class of product, regardless of the status
|
||||||
|
of the particular user or of the way in which the particular user
|
||||||
|
actually uses, or expects or is expected to use, the product. A product
|
||||||
|
is a consumer product regardless of whether the product has substantial
|
||||||
|
commercial, industrial or non-consumer uses, unless such uses represent
|
||||||
|
the only significant mode of use of the product.
|
||||||
|
|
||||||
|
"Installation Information" for a User Product means any methods,
|
||||||
|
procedures, authorization keys, or other information required to install
|
||||||
|
and execute modified versions of a covered work in that User Product from
|
||||||
|
a modified version of its Corresponding Source. The information must
|
||||||
|
suffice to ensure that the continued functioning of the modified object
|
||||||
|
code is in no case prevented or interfered with solely because
|
||||||
|
modification has been made.
|
||||||
|
|
||||||
|
If you convey an object code work under this section in, or with, or
|
||||||
|
specifically for use in, a User Product, and the conveying occurs as
|
||||||
|
part of a transaction in which the right of possession and use of the
|
||||||
|
User Product is transferred to the recipient in perpetuity or for a
|
||||||
|
fixed term (regardless of how the transaction is characterized), the
|
||||||
|
Corresponding Source conveyed under this section must be accompanied
|
||||||
|
by the Installation Information. But this requirement does not apply
|
||||||
|
if neither you nor any third party retains the ability to install
|
||||||
|
modified object code on the User Product (for example, the work has
|
||||||
|
been installed in ROM).
|
||||||
|
|
||||||
|
The requirement to provide Installation Information does not include a
|
||||||
|
requirement to continue to provide support service, warranty, or updates
|
||||||
|
for a work that has been modified or installed by the recipient, or for
|
||||||
|
the User Product in which it has been modified or installed. Access to a
|
||||||
|
network may be denied when the modification itself materially and
|
||||||
|
adversely affects the operation of the network or violates the rules and
|
||||||
|
protocols for communication across the network.
|
||||||
|
|
||||||
|
Corresponding Source conveyed, and Installation Information provided,
|
||||||
|
in accord with this section must be in a format that is publicly
|
||||||
|
documented (and with an implementation available to the public in
|
||||||
|
source code form), and must require no special password or key for
|
||||||
|
unpacking, reading or copying.
|
||||||
|
|
||||||
|
7. Additional Terms.
|
||||||
|
|
||||||
|
"Additional permissions" are terms that supplement the terms of this
|
||||||
|
License by making exceptions from one or more of its conditions.
|
||||||
|
Additional permissions that are applicable to the entire Program shall
|
||||||
|
be treated as though they were included in this License, to the extent
|
||||||
|
that they are valid under applicable law. If additional permissions
|
||||||
|
apply only to part of the Program, that part may be used separately
|
||||||
|
under those permissions, but the entire Program remains governed by
|
||||||
|
this License without regard to the additional permissions.
|
||||||
|
|
||||||
|
When you convey a copy of a covered work, you may at your option
|
||||||
|
remove any additional permissions from that copy, or from any part of
|
||||||
|
it. (Additional permissions may be written to require their own
|
||||||
|
removal in certain cases when you modify the work.) You may place
|
||||||
|
additional permissions on material, added by you to a covered work,
|
||||||
|
for which you have or can give appropriate copyright permission.
|
||||||
|
|
||||||
|
Notwithstanding any other provision of this License, for material you
|
||||||
|
add to a covered work, you may (if authorized by the copyright holders of
|
||||||
|
that material) supplement the terms of this License with terms:
|
||||||
|
|
||||||
|
a) Disclaiming warranty or limiting liability differently from the
|
||||||
|
terms of sections 15 and 16 of this License; or
|
||||||
|
|
||||||
|
b) Requiring preservation of specified reasonable legal notices or
|
||||||
|
author attributions in that material or in the Appropriate Legal
|
||||||
|
Notices displayed by works containing it; or
|
||||||
|
|
||||||
|
c) Prohibiting misrepresentation of the origin of that material, or
|
||||||
|
requiring that modified versions of such material be marked in
|
||||||
|
reasonable ways as different from the original version; or
|
||||||
|
|
||||||
|
d) Limiting the use for publicity purposes of names of licensors or
|
||||||
|
authors of the material; or
|
||||||
|
|
||||||
|
e) Declining to grant rights under trademark law for use of some
|
||||||
|
trade names, trademarks, or service marks; or
|
||||||
|
|
||||||
|
f) Requiring indemnification of licensors and authors of that
|
||||||
|
material by anyone who conveys the material (or modified versions of
|
||||||
|
it) with contractual assumptions of liability to the recipient, for
|
||||||
|
any liability that these contractual assumptions directly impose on
|
||||||
|
those licensors and authors.
|
||||||
|
|
||||||
|
All other non-permissive additional terms are considered "further
|
||||||
|
restrictions" within the meaning of section 10. If the Program as you
|
||||||
|
received it, or any part of it, contains a notice stating that it is
|
||||||
|
governed by this License along with a term that is a further
|
||||||
|
restriction, you may remove that term. If a license document contains
|
||||||
|
a further restriction but permits relicensing or conveying under this
|
||||||
|
License, you may add to a covered work material governed by the terms
|
||||||
|
of that license document, provided that the further restriction does
|
||||||
|
not survive such relicensing or conveying.
|
||||||
|
|
||||||
|
If you add terms to a covered work in accord with this section, you
|
||||||
|
must place, in the relevant source files, a statement of the
|
||||||
|
additional terms that apply to those files, or a notice indicating
|
||||||
|
where to find the applicable terms.
|
||||||
|
|
||||||
|
Additional terms, permissive or non-permissive, may be stated in the
|
||||||
|
form of a separately written license, or stated as exceptions;
|
||||||
|
the above requirements apply either way.
|
||||||
|
|
||||||
|
8. Termination.
|
||||||
|
|
||||||
|
You may not propagate or modify a covered work except as expressly
|
||||||
|
provided under this License. Any attempt otherwise to propagate or
|
||||||
|
modify it is void, and will automatically terminate your rights under
|
||||||
|
this License (including any patent licenses granted under the third
|
||||||
|
paragraph of section 11).
|
||||||
|
|
||||||
|
However, if you cease all violation of this License, then your
|
||||||
|
license from a particular copyright holder is reinstated (a)
|
||||||
|
provisionally, unless and until the copyright holder explicitly and
|
||||||
|
finally terminates your license, and (b) permanently, if the copyright
|
||||||
|
holder fails to notify you of the violation by some reasonable means
|
||||||
|
prior to 60 days after the cessation.
|
||||||
|
|
||||||
|
Moreover, your license from a particular copyright holder is
|
||||||
|
reinstated permanently if the copyright holder notifies you of the
|
||||||
|
violation by some reasonable means, this is the first time you have
|
||||||
|
received notice of violation of this License (for any work) from that
|
||||||
|
copyright holder, and you cure the violation prior to 30 days after
|
||||||
|
your receipt of the notice.
|
||||||
|
|
||||||
|
Termination of your rights under this section does not terminate the
|
||||||
|
licenses of parties who have received copies or rights from you under
|
||||||
|
this License. If your rights have been terminated and not permanently
|
||||||
|
reinstated, you do not qualify to receive new licenses for the same
|
||||||
|
material under section 10.
|
||||||
|
|
||||||
|
9. Acceptance Not Required for Having Copies.
|
||||||
|
|
||||||
|
You are not required to accept this License in order to receive or
|
||||||
|
run a copy of the Program. Ancillary propagation of a covered work
|
||||||
|
occurring solely as a consequence of using peer-to-peer transmission
|
||||||
|
to receive a copy likewise does not require acceptance. However,
|
||||||
|
nothing other than this License grants you permission to propagate or
|
||||||
|
modify any covered work. These actions infringe copyright if you do
|
||||||
|
not accept this License. Therefore, by modifying or propagating a
|
||||||
|
covered work, you indicate your acceptance of this License to do so.
|
||||||
|
|
||||||
|
10. Automatic Licensing of Downstream Recipients.
|
||||||
|
|
||||||
|
Each time you convey a covered work, the recipient automatically
|
||||||
|
receives a license from the original licensors, to run, modify and
|
||||||
|
propagate that work, subject to this License. You are not responsible
|
||||||
|
for enforcing compliance by third parties with this License.
|
||||||
|
|
||||||
|
An "entity transaction" is a transaction transferring control of an
|
||||||
|
organization, or substantially all assets of one, or subdividing an
|
||||||
|
organization, or merging organizations. If propagation of a covered
|
||||||
|
work results from an entity transaction, each party to that
|
||||||
|
transaction who receives a copy of the work also receives whatever
|
||||||
|
licenses to the work the party's predecessor in interest had or could
|
||||||
|
give under the previous paragraph, plus a right to possession of the
|
||||||
|
Corresponding Source of the work from the predecessor in interest, if
|
||||||
|
the predecessor has it or can get it with reasonable efforts.
|
||||||
|
|
||||||
|
You may not impose any further restrictions on the exercise of the
|
||||||
|
rights granted or affirmed under this License. For example, you may
|
||||||
|
not impose a license fee, royalty, or other charge for exercise of
|
||||||
|
rights granted under this License, and you may not initiate litigation
|
||||||
|
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||||
|
any patent claim is infringed by making, using, selling, offering for
|
||||||
|
sale, or importing the Program or any portion of it.
|
||||||
|
|
||||||
|
11. Patents.
|
||||||
|
|
||||||
|
A "contributor" is a copyright holder who authorizes use under this
|
||||||
|
License of the Program or a work on which the Program is based. The
|
||||||
|
work thus licensed is called the contributor's "contributor version".
|
||||||
|
|
||||||
|
A contributor's "essential patent claims" are all patent claims
|
||||||
|
owned or controlled by the contributor, whether already acquired or
|
||||||
|
hereafter acquired, that would be infringed by some manner, permitted
|
||||||
|
by this License, of making, using, or selling its contributor version,
|
||||||
|
but do not include claims that would be infringed only as a
|
||||||
|
consequence of further modification of the contributor version. For
|
||||||
|
purposes of this definition, "control" includes the right to grant
|
||||||
|
patent sublicenses in a manner consistent with the requirements of
|
||||||
|
this License.
|
||||||
|
|
||||||
|
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||||
|
patent license under the contributor's essential patent claims, to
|
||||||
|
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||||
|
propagate the contents of its contributor version.
|
||||||
|
|
||||||
|
In the following three paragraphs, a "patent license" is any express
|
||||||
|
agreement or commitment, however denominated, not to enforce a patent
|
||||||
|
(such as an express permission to practice a patent or covenant not to
|
||||||
|
sue for patent infringement). To "grant" such a patent license to a
|
||||||
|
party means to make such an agreement or commitment not to enforce a
|
||||||
|
patent against the party.
|
||||||
|
|
||||||
|
If you convey a covered work, knowingly relying on a patent license,
|
||||||
|
and the Corresponding Source of the work is not available for anyone
|
||||||
|
to copy, free of charge and under the terms of this License, through a
|
||||||
|
publicly available network server or other readily accessible means,
|
||||||
|
then you must either (1) cause the Corresponding Source to be so
|
||||||
|
available, or (2) arrange to deprive yourself of the benefit of the
|
||||||
|
patent license for this particular work, or (3) arrange, in a manner
|
||||||
|
consistent with the requirements of this License, to extend the patent
|
||||||
|
license to downstream recipients. "Knowingly relying" means you have
|
||||||
|
actual knowledge that, but for the patent license, your conveying the
|
||||||
|
covered work in a country, or your recipient's use of the covered work
|
||||||
|
in a country, would infringe one or more identifiable patents in that
|
||||||
|
country that you have reason to believe are valid.
|
||||||
|
|
||||||
|
If, pursuant to or in connection with a single transaction or
|
||||||
|
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||||
|
covered work, and grant a patent license to some of the parties
|
||||||
|
receiving the covered work authorizing them to use, propagate, modify
|
||||||
|
or convey a specific copy of the covered work, then the patent license
|
||||||
|
you grant is automatically extended to all recipients of the covered
|
||||||
|
work and works based on it.
|
||||||
|
|
||||||
|
A patent license is "discriminatory" if it does not include within
|
||||||
|
the scope of its coverage, prohibits the exercise of, or is
|
||||||
|
conditioned on the non-exercise of one or more of the rights that are
|
||||||
|
specifically granted under this License. You may not convey a covered
|
||||||
|
work if you are a party to an arrangement with a third party that is
|
||||||
|
in the business of distributing software, under which you make payment
|
||||||
|
to the third party based on the extent of your activity of conveying
|
||||||
|
the work, and under which the third party grants, to any of the
|
||||||
|
parties who would receive the covered work from you, a discriminatory
|
||||||
|
patent license (a) in connection with copies of the covered work
|
||||||
|
conveyed by you (or copies made from those copies), or (b) primarily
|
||||||
|
for and in connection with specific products or compilations that
|
||||||
|
contain the covered work, unless you entered into that arrangement,
|
||||||
|
or that patent license was granted, prior to 28 March 2007.
|
||||||
|
|
||||||
|
Nothing in this License shall be construed as excluding or limiting
|
||||||
|
any implied license or other defenses to infringement that may
|
||||||
|
otherwise be available to you under applicable patent law.
|
||||||
|
|
||||||
|
12. No Surrender of Others' Freedom.
|
||||||
|
|
||||||
|
If conditions are imposed on you (whether by court order, agreement or
|
||||||
|
otherwise) that contradict the conditions of this License, they do not
|
||||||
|
excuse you from the conditions of this License. If you cannot convey a
|
||||||
|
covered work so as to satisfy simultaneously your obligations under this
|
||||||
|
License and any other pertinent obligations, then as a consequence you may
|
||||||
|
not convey it at all. For example, if you agree to terms that obligate you
|
||||||
|
to collect a royalty for further conveying from those to whom you convey
|
||||||
|
the Program, the only way you could satisfy both those terms and this
|
||||||
|
License would be to refrain entirely from conveying the Program.
|
||||||
|
|
||||||
|
13. Remote Network Interaction; Use with the GNU General Public License.
|
||||||
|
|
||||||
|
Notwithstanding any other provision of this License, if you modify the
|
||||||
|
Program, your modified version must prominently offer all users
|
||||||
|
interacting with it remotely through a computer network (if your version
|
||||||
|
supports such interaction) an opportunity to receive the Corresponding
|
||||||
|
Source of your version by providing access to the Corresponding Source
|
||||||
|
from a network server at no charge, through some standard or customary
|
||||||
|
means of facilitating copying of software. This Corresponding Source
|
||||||
|
shall include the Corresponding Source for any work covered by version 3
|
||||||
|
of the GNU General Public License that is incorporated pursuant to the
|
||||||
|
following paragraph.
|
||||||
|
|
||||||
|
Notwithstanding any other provision of this License, you have
|
||||||
|
permission to link or combine any covered work with a work licensed
|
||||||
|
under version 3 of the GNU General Public License into a single
|
||||||
|
combined work, and to convey the resulting work. The terms of this
|
||||||
|
License will continue to apply to the part which is the covered work,
|
||||||
|
but the work with which it is combined will remain governed by version
|
||||||
|
3 of the GNU General Public License.
|
||||||
|
|
||||||
|
14. Revised Versions of this License.
|
||||||
|
|
||||||
|
The Free Software Foundation may publish revised and/or new versions of
|
||||||
|
the GNU Affero General Public License from time to time. Such new versions
|
||||||
|
will be similar in spirit to the present version, but may differ in detail to
|
||||||
|
address new problems or concerns.
|
||||||
|
|
||||||
|
Each version is given a distinguishing version number. If the
|
||||||
|
Program specifies that a certain numbered version of the GNU Affero General
|
||||||
|
Public License "or any later version" applies to it, you have the
|
||||||
|
option of following the terms and conditions either of that numbered
|
||||||
|
version or of any later version published by the Free Software
|
||||||
|
Foundation. If the Program does not specify a version number of the
|
||||||
|
GNU Affero General Public License, you may choose any version ever published
|
||||||
|
by the Free Software Foundation.
|
||||||
|
|
||||||
|
If the Program specifies that a proxy can decide which future
|
||||||
|
versions of the GNU Affero General Public License can be used, that proxy's
|
||||||
|
public statement of acceptance of a version permanently authorizes you
|
||||||
|
to choose that version for the Program.
|
||||||
|
|
||||||
|
Later license versions may give you additional or different
|
||||||
|
permissions. However, no additional obligations are imposed on any
|
||||||
|
author or copyright holder as a result of your choosing to follow a
|
||||||
|
later version.
|
||||||
|
|
||||||
|
15. Disclaimer of Warranty.
|
||||||
|
|
||||||
|
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||||
|
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||||
|
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||||
|
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||||
|
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||||
|
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||||
|
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||||
|
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||||
|
|
||||||
|
16. Limitation of Liability.
|
||||||
|
|
||||||
|
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||||
|
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||||
|
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||||
|
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||||
|
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||||
|
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||||
|
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||||
|
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||||
|
SUCH DAMAGES.
|
||||||
|
|
||||||
|
17. Interpretation of Sections 15 and 16.
|
||||||
|
|
||||||
|
If the disclaimer of warranty and limitation of liability provided
|
||||||
|
above cannot be given local legal effect according to their terms,
|
||||||
|
reviewing courts shall apply local law that most closely approximates
|
||||||
|
an absolute waiver of all civil liability in connection with the
|
||||||
|
Program, unless a warranty or assumption of liability accompanies a
|
||||||
|
copy of the Program in return for a fee.
|
||||||
|
|
||||||
|
END OF TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
How to Apply These Terms to Your New Programs
|
||||||
|
|
||||||
|
If you develop a new program, and you want it to be of the greatest
|
||||||
|
possible use to the public, the best way to achieve this is to make it
|
||||||
|
free software which everyone can redistribute and change under these terms.
|
||||||
|
|
||||||
|
To do so, attach the following notices to the program. It is safest
|
||||||
|
to attach them to the start of each source file to most effectively
|
||||||
|
state the exclusion of warranty; and each file should have at least
|
||||||
|
the "copyright" line and a pointer to where the full notice is found.
|
||||||
|
|
||||||
|
<one line to give the program's name and a brief idea of what it does.>
|
||||||
|
Copyright (C) <year> <name of author>
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Affero General Public License as published
|
||||||
|
by the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Affero General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Affero General Public License
|
||||||
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
Also add information on how to contact you by electronic and paper mail.
|
||||||
|
|
||||||
|
If your software can interact with users remotely through a computer
|
||||||
|
network, you should also make sure that it provides a way for users to
|
||||||
|
get its source. For example, if your program is a web application, its
|
||||||
|
interface could display a "Source" link that leads users to an archive
|
||||||
|
of the code. There are many ways you could offer source, and different
|
||||||
|
solutions will be better for different programs; see section 13 for the
|
||||||
|
specific requirements.
|
||||||
|
|
||||||
|
You should also get your employer (if you work as a programmer) or school,
|
||||||
|
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||||
|
For more information on this, and how to apply and follow the GNU AGPL, see
|
||||||
|
<https://www.gnu.org/licenses/>.
|
@@ -1,89 +0,0 @@
|
|||||||
package conn
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"github.com/rs/zerolog/log"
|
|
||||||
"github.com/samber/lo"
|
|
||||||
"github.com/spf13/viper"
|
|
||||||
"github.com/urfave/cli/v2"
|
|
||||||
)
|
|
||||||
|
|
||||||
var CliCommands = []*cli.Command{
|
|
||||||
{
|
|
||||||
Name: "list",
|
|
||||||
Aliases: []string{"ls"},
|
|
||||||
Description: "List all connected remote server",
|
|
||||||
Action: func(ctx *cli.Context) error {
|
|
||||||
var servers []CliConnection
|
|
||||||
raw, _ := json.Marshal(viper.Get("servers"))
|
|
||||||
_ = json.Unmarshal(raw, &servers)
|
|
||||||
|
|
||||||
log.Info().Msgf("There are %d server(s) connected in total.", len(servers))
|
|
||||||
for idx, server := range servers {
|
|
||||||
log.Info().Msgf("%d) %s: %s", idx+1, server.ID, server.Url)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Name: "connect",
|
|
||||||
Aliases: []string{"add"},
|
|
||||||
Description: "Connect and save configuration of remote server",
|
|
||||||
ArgsUsage: "<id> <server url> <credential>",
|
|
||||||
Action: func(ctx *cli.Context) error {
|
|
||||||
if ctx.Args().Len() < 3 {
|
|
||||||
return fmt.Errorf("must have three arguments: <id> <server url> <credential>")
|
|
||||||
}
|
|
||||||
|
|
||||||
c := CliConnection{
|
|
||||||
ID: ctx.Args().Get(0),
|
|
||||||
Url: ctx.Args().Get(1),
|
|
||||||
Credential: ctx.Args().Get(2),
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := c.CheckConnectivity(); err != nil {
|
|
||||||
return fmt.Errorf("couldn't connect server: %s", err.Error())
|
|
||||||
} else {
|
|
||||||
var servers []CliConnection
|
|
||||||
raw, _ := json.Marshal(viper.Get("servers"))
|
|
||||||
_ = json.Unmarshal(raw, &servers)
|
|
||||||
viper.Set("servers", append(servers, c))
|
|
||||||
|
|
||||||
if err := viper.WriteConfig(); err != nil {
|
|
||||||
return err
|
|
||||||
} else {
|
|
||||||
log.Info().Msg("Successfully connected a new remote server, enter \"rds ls\" to get more info.")
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Name: "disconnect",
|
|
||||||
Aliases: []string{"remove"},
|
|
||||||
Description: "Remove a remote server configuration",
|
|
||||||
ArgsUsage: "<id>",
|
|
||||||
Action: func(ctx *cli.Context) error {
|
|
||||||
if ctx.Args().Len() < 1 {
|
|
||||||
return fmt.Errorf("must have more one arguments: <server url>")
|
|
||||||
}
|
|
||||||
|
|
||||||
var servers []CliConnection
|
|
||||||
raw, _ := json.Marshal(viper.Get("servers"))
|
|
||||||
_ = json.Unmarshal(raw, &servers)
|
|
||||||
viper.Set("servers", lo.Filter(servers, func(item CliConnection, idx int) bool {
|
|
||||||
return item.ID != ctx.Args().Get(0)
|
|
||||||
}))
|
|
||||||
|
|
||||||
if err := viper.WriteConfig(); err != nil {
|
|
||||||
return err
|
|
||||||
} else {
|
|
||||||
log.Info().Msg("Successfully disconnected a remote server, enter \"rds ls\" to get more info.")
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
@@ -1,42 +0,0 @@
|
|||||||
package conn
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
roadsign "code.smartsheep.studio/goatworks/roadsign/pkg"
|
|
||||||
"github.com/gofiber/fiber/v2"
|
|
||||||
"github.com/rs/zerolog/log"
|
|
||||||
)
|
|
||||||
|
|
||||||
type CliConnection struct {
|
|
||||||
ID string `json:"id"`
|
|
||||||
Url string `json:"url"`
|
|
||||||
Credential string `json:"credential"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func (v CliConnection) CheckConnectivity() error {
|
|
||||||
client := fiber.Get(v.Url + "/cgi/metadata")
|
|
||||||
client.BasicAuth("RoadSign CLI", v.Credential)
|
|
||||||
|
|
||||||
if status, data, err := client.Bytes(); len(err) > 0 {
|
|
||||||
return fmt.Errorf("couldn't connect to server: %q", err)
|
|
||||||
} else if status != 200 {
|
|
||||||
return fmt.Errorf("server rejected request, may cause by invalid credential")
|
|
||||||
} else {
|
|
||||||
var resp fiber.Map
|
|
||||||
if err := json.Unmarshal(data, &resp); err != nil {
|
|
||||||
return err
|
|
||||||
} else if resp["server"] != "RoadSign" {
|
|
||||||
return fmt.Errorf("remote server isn't roadsign")
|
|
||||||
} else if resp["version"] != roadsign.AppVersion {
|
|
||||||
if strings.Contains(roadsign.AppVersion, "#") {
|
|
||||||
return fmt.Errorf("remote server version mismatch client version, update or downgrade client required")
|
|
||||||
} else {
|
|
||||||
log.Warn().Msg("RoadSign CLI didn't complied with vcs information, compatibility was disabled. To enable it, reinstall cli with -buildvcs flag.")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
@@ -1,17 +0,0 @@
|
|||||||
package conn
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
|
|
||||||
"github.com/samber/lo"
|
|
||||||
"github.com/spf13/viper"
|
|
||||||
)
|
|
||||||
|
|
||||||
func GetConnection(id string) (CliConnection, bool) {
|
|
||||||
var servers []CliConnection
|
|
||||||
raw, _ := json.Marshal(viper.Get("servers"))
|
|
||||||
_ = json.Unmarshal(raw, &servers)
|
|
||||||
return lo.Find(servers, func(item CliConnection) bool {
|
|
||||||
return item.ID == id
|
|
||||||
})
|
|
||||||
}
|
|
@@ -1,98 +0,0 @@
|
|||||||
package deploy
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"io"
|
|
||||||
"os"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
jsoniter "github.com/json-iterator/go"
|
|
||||||
|
|
||||||
"code.smartsheep.studio/goatworks/roadsign/pkg/cmd/rdc/conn"
|
|
||||||
"github.com/gofiber/fiber/v2"
|
|
||||||
"github.com/rs/zerolog/log"
|
|
||||||
"github.com/urfave/cli/v2"
|
|
||||||
)
|
|
||||||
|
|
||||||
var DeployCommands = []*cli.Command{
|
|
||||||
{
|
|
||||||
Name: "deploy",
|
|
||||||
Aliases: []string{"dp"},
|
|
||||||
ArgsUsage: "<server> <site> <upstream> [path]",
|
|
||||||
Action: func(ctx *cli.Context) error {
|
|
||||||
if ctx.Args().Len() < 4 {
|
|
||||||
return fmt.Errorf("must have four arguments: <server> <site> <upstream> <path>")
|
|
||||||
}
|
|
||||||
|
|
||||||
if !strings.HasSuffix(ctx.Args().Get(3), ".zip") {
|
|
||||||
return fmt.Errorf("input file must be a zip file and ends with .zip")
|
|
||||||
}
|
|
||||||
|
|
||||||
server, ok := conn.GetConnection(ctx.Args().Get(0))
|
|
||||||
if !ok {
|
|
||||||
return fmt.Errorf("server was not found, use \"rds connect\" add one first")
|
|
||||||
} else if err := server.CheckConnectivity(); err != nil {
|
|
||||||
return fmt.Errorf("couldn't connect server: %s", err.Error())
|
|
||||||
}
|
|
||||||
|
|
||||||
// Send request
|
|
||||||
log.Info().Msg("Now publishing to remote server...")
|
|
||||||
|
|
||||||
url := fmt.Sprintf("/webhooks/publish/%s/%s?mimetype=%s", ctx.Args().Get(1), ctx.Args().Get(2), "application/zip")
|
|
||||||
client := fiber.Put(server.Url+url).
|
|
||||||
SendFile(ctx.Args().Get(3), "attachments").
|
|
||||||
MultipartForm(nil).
|
|
||||||
BasicAuth("RoadSign CLI", server.Credential)
|
|
||||||
|
|
||||||
if status, data, err := client.Bytes(); len(err) > 0 {
|
|
||||||
return fmt.Errorf("failed to publish to remote: %q", err)
|
|
||||||
} else if status != 200 {
|
|
||||||
return fmt.Errorf("server rejected request, status code %d, response %s", status, string(data))
|
|
||||||
}
|
|
||||||
|
|
||||||
log.Info().Msg("Well done! Your site is successfully published! 🎉")
|
|
||||||
|
|
||||||
return nil
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Name: "sync",
|
|
||||||
ArgsUsage: "<server> <site> <configuration path>",
|
|
||||||
Action: func(ctx *cli.Context) error {
|
|
||||||
if ctx.Args().Len() < 3 {
|
|
||||||
return fmt.Errorf("must have three arguments: <server> <site> <configuration path>")
|
|
||||||
}
|
|
||||||
|
|
||||||
server, ok := conn.GetConnection(ctx.Args().Get(0))
|
|
||||||
if !ok {
|
|
||||||
return fmt.Errorf("server was not found, use \"rds connect\" add one first")
|
|
||||||
} else if err := server.CheckConnectivity(); err != nil {
|
|
||||||
return fmt.Errorf("couldn't connect server: %s", err.Error())
|
|
||||||
}
|
|
||||||
|
|
||||||
var raw []byte
|
|
||||||
if file, err := os.Open(ctx.Args().Get(2)); err != nil {
|
|
||||||
return err
|
|
||||||
} else {
|
|
||||||
raw, _ = io.ReadAll(file)
|
|
||||||
}
|
|
||||||
|
|
||||||
url := fmt.Sprintf("/webhooks/sync/%s", ctx.Args().Get(1))
|
|
||||||
client := fiber.Put(server.Url+url).
|
|
||||||
JSONEncoder(jsoniter.ConfigCompatibleWithStandardLibrary.Marshal).
|
|
||||||
JSONDecoder(jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal).
|
|
||||||
Body(raw).
|
|
||||||
BasicAuth("RoadSign CLI", server.Credential)
|
|
||||||
|
|
||||||
if status, data, err := client.Bytes(); len(err) > 0 {
|
|
||||||
return fmt.Errorf("failed to sync to remote: %q", err)
|
|
||||||
} else if status != 200 {
|
|
||||||
return fmt.Errorf("server rejected request, status code %d, response %s", status, string(data))
|
|
||||||
}
|
|
||||||
|
|
||||||
log.Info().Msg("Well done! Your site configuration is up-to-date! 🎉")
|
|
||||||
|
|
||||||
return nil
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
@@ -1,48 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"os"
|
|
||||||
|
|
||||||
roadsign "code.smartsheep.studio/goatworks/roadsign/pkg"
|
|
||||||
"code.smartsheep.studio/goatworks/roadsign/pkg/cmd/rdc/conn"
|
|
||||||
"code.smartsheep.studio/goatworks/roadsign/pkg/cmd/rdc/deploy"
|
|
||||||
"github.com/rs/zerolog"
|
|
||||||
"github.com/rs/zerolog/log"
|
|
||||||
"github.com/spf13/viper"
|
|
||||||
"github.com/urfave/cli/v2"
|
|
||||||
)
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
zerolog.TimeFieldFormat = zerolog.TimeFormatUnix
|
|
||||||
log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stdout})
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
// Configure settings
|
|
||||||
viper.AddConfigPath("$HOME")
|
|
||||||
viper.SetConfigName(".roadsignrc")
|
|
||||||
viper.SetConfigType("toml")
|
|
||||||
|
|
||||||
// Load settings
|
|
||||||
if err := viper.ReadInConfig(); err != nil {
|
|
||||||
if _, ok := err.(viper.ConfigFileNotFoundError); ok {
|
|
||||||
viper.SafeWriteConfig()
|
|
||||||
viper.ReadInConfig()
|
|
||||||
} else {
|
|
||||||
log.Panic().Err(err).Msg("An error occurred when loading settings.")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Configure CLI
|
|
||||||
app := &cli.App{
|
|
||||||
Name: "RoadSign CLI",
|
|
||||||
Version: roadsign.AppVersion,
|
|
||||||
Suggest: true,
|
|
||||||
Commands: append(append([]*cli.Command{}, conn.CliCommands...), deploy.DeployCommands...),
|
|
||||||
}
|
|
||||||
|
|
||||||
// Run CLI
|
|
||||||
if err := app.Run(os.Args); err != nil {
|
|
||||||
log.Fatal().Err(err).Msg("An error occurred when running cli.")
|
|
||||||
}
|
|
||||||
}
|
|
@@ -6,10 +6,10 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
roadsign "code.smartsheep.studio/goatworks/roadsign/pkg"
|
roadsign "git.solsynth.dev/goatworks/roadsign/pkg"
|
||||||
"code.smartsheep.studio/goatworks/roadsign/pkg/hypertext"
|
"git.solsynth.dev/goatworks/roadsign/pkg/hypertext"
|
||||||
"code.smartsheep.studio/goatworks/roadsign/pkg/navi"
|
"git.solsynth.dev/goatworks/roadsign/pkg/navi"
|
||||||
"code.smartsheep.studio/goatworks/roadsign/pkg/sideload"
|
"git.solsynth.dev/goatworks/roadsign/pkg/sideload"
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"github.com/rs/zerolog"
|
"github.com/rs/zerolog"
|
||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
@@ -25,6 +25,7 @@ func main() {
|
|||||||
// Configure settings
|
// Configure settings
|
||||||
viper.AddConfigPath(".")
|
viper.AddConfigPath(".")
|
||||||
viper.AddConfigPath("..")
|
viper.AddConfigPath("..")
|
||||||
|
viper.AddConfigPath("/")
|
||||||
viper.SetConfigName("settings")
|
viper.SetConfigName("settings")
|
||||||
viper.SetConfigType("toml")
|
viper.SetConfigType("toml")
|
||||||
|
|
||||||
@@ -58,17 +59,13 @@ func main() {
|
|||||||
hypertext.InitServer(),
|
hypertext.InitServer(),
|
||||||
viper.GetStringSlice("hypertext.ports"),
|
viper.GetStringSlice("hypertext.ports"),
|
||||||
viper.GetStringSlice("hypertext.secured_ports"),
|
viper.GetStringSlice("hypertext.secured_ports"),
|
||||||
viper.GetString("hypertext.certificate.pem"),
|
|
||||||
viper.GetString("hypertext.certificate.key"),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Init sideload server
|
// Init sideload server
|
||||||
hypertext.RunServer(
|
hypertext.RunServer(
|
||||||
sideload.InitSideload(),
|
sideload.InitSideload(),
|
||||||
viper.GetStringSlice("hypertext.sideload_ports"),
|
viper.GetStringSlice("sideload.ports"),
|
||||||
viper.GetStringSlice("hypertext.sideload_secured_ports"),
|
[]string{},
|
||||||
viper.GetString("hypertext.certificate.sideload_pem"),
|
|
||||||
viper.GetString("hypertext.certificate.sideload_key"),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
log.Info().Msgf("RoadSign v%s is started...", roadsign.AppVersion)
|
log.Info().Msgf("RoadSign v%s is started...", roadsign.AppVersion)
|
||||||
|
@@ -1,115 +1,114 @@
|
|||||||
package hypertext
|
package hypertext
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/spf13/viper"
|
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
|
||||||
"code.smartsheep.studio/goatworks/roadsign/pkg/navi"
|
"github.com/spf13/viper"
|
||||||
|
|
||||||
|
"git.solsynth.dev/goatworks/roadsign/pkg/navi"
|
||||||
"github.com/gofiber/fiber/v2"
|
"github.com/gofiber/fiber/v2"
|
||||||
"github.com/samber/lo"
|
"github.com/samber/lo"
|
||||||
)
|
)
|
||||||
|
|
||||||
func UseProxies(app *fiber.App) {
|
func ProxiesHandler(ctx *fiber.Ctx) error {
|
||||||
app.All("/*", func(ctx *fiber.Ctx) error {
|
host := ctx.Hostname()
|
||||||
host := ctx.Hostname()
|
path := ctx.Path()
|
||||||
path := ctx.Path()
|
queries := ctx.Queries()
|
||||||
queries := ctx.Queries()
|
headers := ctx.GetReqHeaders()
|
||||||
headers := ctx.GetReqHeaders()
|
|
||||||
|
|
||||||
// Filtering sites
|
// Filtering sites
|
||||||
for _, region := range navi.R.Regions {
|
for _, region := range navi.R.Regions {
|
||||||
// Matching rules
|
// Matching rules
|
||||||
for _, location := range region.Locations {
|
for _, location := range region.Locations {
|
||||||
if !lo.Contains(location.Host, host) {
|
if !lo.Contains(location.Hosts, host) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if !func() bool {
|
if !func() bool {
|
||||||
flag := false
|
flag := false
|
||||||
for _, pattern := range location.Path {
|
for _, pattern := range location.Paths {
|
||||||
if ok, _ := regexp.MatchString(pattern, path); ok {
|
if ok, _ := regexp.MatchString(pattern, path); ok {
|
||||||
flag = true
|
flag = true
|
||||||
break
|
break
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return flag
|
|
||||||
}() {
|
|
||||||
continue
|
|
||||||
}
|
}
|
||||||
|
return flag
|
||||||
|
}() {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
// Filter query strings
|
// Filter query strings
|
||||||
flag := true
|
flag := true
|
||||||
for rk, rv := range location.Queries {
|
for rk, rv := range location.Queries {
|
||||||
for ik, iv := range queries {
|
for ik, iv := range queries {
|
||||||
if rk != ik && rv != iv {
|
if rk != ik && rv != iv {
|
||||||
flag = false
|
flag = false
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if !flag {
|
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !flag {
|
if !flag {
|
||||||
continue
|
break
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if !flag {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
// Filter headers
|
// Filter headers
|
||||||
for rk, rv := range location.Headers {
|
for rk, rv := range location.Headers {
|
||||||
for ik, iv := range headers {
|
for ik, iv := range headers {
|
||||||
if rk == ik {
|
if rk == ik {
|
||||||
for _, ov := range iv {
|
for _, ov := range iv {
|
||||||
if !lo.Contains(rv, ov) {
|
if !lo.Contains(rv, ov) {
|
||||||
flag = false
|
flag = false
|
||||||
break
|
break
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !flag {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if !flag {
|
if !flag {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !flag {
|
if !flag {
|
||||||
continue
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
idx := rand.Intn(len(location.Destinations))
|
|
||||||
dest := location.Destinations[idx]
|
|
||||||
|
|
||||||
// Passing all the rules means the site is what we are looking for.
|
|
||||||
// Let us respond to our client!
|
|
||||||
return makeResponse(ctx, region, &location, &dest)
|
|
||||||
}
|
}
|
||||||
}
|
if !flag {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
// There is no site available for this request.
|
idx := rand.Intn(len(location.Destinations))
|
||||||
// Just ignore it and give our client a not found status.
|
dest := location.Destinations[idx]
|
||||||
// Do not care about the user experience, we can do it in custom error handler.
|
|
||||||
return fiber.ErrNotFound
|
// Passing all the rules means the site is what we are looking for.
|
||||||
})
|
// Let us respond to our client!
|
||||||
|
return makeResponse(ctx, region, &location, &dest)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// There is no site available for this request.
|
||||||
|
// Just ignore it and give our client a not found status.
|
||||||
|
// Do not care about the user experience, we can do it in custom error handler.
|
||||||
|
return fiber.ErrNotFound
|
||||||
}
|
}
|
||||||
|
|
||||||
func makeResponse(ctx *fiber.Ctx, region *navi.Region, location *navi.Location, dest *navi.Destination) error {
|
func makeResponse(c *fiber.Ctx, region *navi.Region, location *navi.Location, dest *navi.Destination) error {
|
||||||
uri := ctx.Request().URI().String()
|
uri := c.Request().URI().String()
|
||||||
|
|
||||||
// Modify request
|
// Modify request
|
||||||
for _, transformer := range dest.Transformers {
|
for _, transformer := range dest.Transformers {
|
||||||
if err := transformer.TransformRequest(ctx); err != nil {
|
if err := transformer.TransformRequest(c); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Forward
|
// Forward
|
||||||
err := navi.R.Forward(ctx, dest)
|
err := navi.R.Forward(c, dest)
|
||||||
|
|
||||||
// Modify response
|
// Modify response
|
||||||
for _, transformer := range dest.Transformers {
|
for _, transformer := range dest.Transformers {
|
||||||
if err := transformer.TransformResponse(ctx); err != nil {
|
if err := transformer.TransformResponse(c); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -121,15 +120,15 @@ func makeResponse(ctx *fiber.Ctx, region *navi.Region, location *navi.Location,
|
|||||||
message = err.Error()
|
message = err.Error()
|
||||||
}
|
}
|
||||||
|
|
||||||
go navi.R.AddTrace(navi.RoadTrace{
|
go navi.R.Metrics.AddTrace(navi.RoadTrace{
|
||||||
Region: region.ID,
|
Region: region.ID,
|
||||||
Location: location.ID,
|
Location: location.ID,
|
||||||
Destination: dest.ID,
|
Destination: dest.ID,
|
||||||
Uri: uri,
|
Uri: uri,
|
||||||
IpAddress: ctx.IP(),
|
IpAddress: c.IP(),
|
||||||
UserAgent: ctx.Get(fiber.HeaderUserAgent),
|
UserAgent: c.Get(fiber.HeaderUserAgent),
|
||||||
Error: navi.RoadTraceError{
|
Error: navi.RoadTraceError{
|
||||||
IsNull: err == nil,
|
IsNull: err == nil,
|
||||||
Message: message,
|
Message: message,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
@@ -1,30 +1,53 @@
|
|||||||
package hypertext
|
package hypertext
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"crypto/tls"
|
||||||
|
"git.solsynth.dev/goatworks/roadsign/pkg/hypertext/status"
|
||||||
jsoniter "github.com/json-iterator/go"
|
jsoniter "github.com/json-iterator/go"
|
||||||
|
"net"
|
||||||
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/gofiber/fiber/v2"
|
"github.com/gofiber/fiber/v2"
|
||||||
"github.com/gofiber/fiber/v2/middleware/limiter"
|
"github.com/gofiber/fiber/v2/middleware/limiter"
|
||||||
"github.com/gofiber/fiber/v2/middleware/logger"
|
"github.com/gofiber/fiber/v2/middleware/logger"
|
||||||
|
"github.com/gofiber/template/html/v2"
|
||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
)
|
)
|
||||||
|
|
||||||
func InitServer() *fiber.App {
|
func InitServer() *fiber.App {
|
||||||
|
views := html.NewFileSystem(http.FS(status.FS), ".gohtml")
|
||||||
app := fiber.New(fiber.Config{
|
app := fiber.New(fiber.Config{
|
||||||
|
ViewsLayout: "views/index",
|
||||||
AppName: "RoadSign",
|
AppName: "RoadSign",
|
||||||
ServerHeader: "RoadSign",
|
ServerHeader: "RoadSign",
|
||||||
DisableStartupMessage: true,
|
DisableStartupMessage: true,
|
||||||
EnableIPValidation: true,
|
EnableIPValidation: true,
|
||||||
|
Views: views,
|
||||||
|
ErrorHandler: status.StatusPageHandler,
|
||||||
JSONDecoder: jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal,
|
JSONDecoder: jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal,
|
||||||
JSONEncoder: jsoniter.ConfigCompatibleWithStandardLibrary.Marshal,
|
JSONEncoder: jsoniter.ConfigCompatibleWithStandardLibrary.Marshal,
|
||||||
|
ProxyHeader: fiber.HeaderXForwardedFor,
|
||||||
Prefork: viper.GetBool("performance.prefork"),
|
Prefork: viper.GetBool("performance.prefork"),
|
||||||
BodyLimit: viper.GetInt("hypertext.limitation.max_body_size"),
|
BodyLimit: viper.GetInt("hypertext.limitation.max_body_size"),
|
||||||
})
|
})
|
||||||
|
|
||||||
if viper.GetBool("performance.request_logging") {
|
if viper.GetBool("hypertext.force_https") {
|
||||||
|
app.Use(func(c *fiber.Ctx) error {
|
||||||
|
if !c.Secure() {
|
||||||
|
return c.Redirect(
|
||||||
|
strings.Replace(c.Request().URI().String(), "http", "https", 1),
|
||||||
|
fiber.StatusMovedPermanently,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.Next()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
if viper.GetBool("telemetry.request_logging") {
|
||||||
app.Use(logger.New(logger.Config{
|
app.Use(logger.New(logger.Config{
|
||||||
Output: log.Logger,
|
Output: log.Logger,
|
||||||
Format: "[Proxies] [${time}] ${status} - ${latency} ${method} ${path}\n",
|
Format: "[Proxies] [${time}] ${status} - ${latency} ${method} ${path}\n",
|
||||||
@@ -35,19 +58,48 @@ func InitServer() *fiber.App {
|
|||||||
app.Use(limiter.New(limiter.Config{
|
app.Use(limiter.New(limiter.Config{
|
||||||
Max: viper.GetInt("hypertext.limitation.max_qps"),
|
Max: viper.GetInt("hypertext.limitation.max_qps"),
|
||||||
Expiration: 1 * time.Second,
|
Expiration: 1 * time.Second,
|
||||||
|
LimitReached: func(c *fiber.Ctx) error {
|
||||||
|
return fiber.ErrTooManyRequests
|
||||||
|
},
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
UseProxies(app)
|
app.All("/*", ProxiesHandler)
|
||||||
|
|
||||||
return app
|
return app
|
||||||
}
|
}
|
||||||
|
|
||||||
func RunServer(app *fiber.App, ports []string, securedPorts []string, pem string, key string) {
|
type CertificateConfig struct {
|
||||||
|
Key string `json:"key"`
|
||||||
|
Pem string `json:"pem"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func RunServer(app *fiber.App, ports []string, securedPorts []string) {
|
||||||
|
var certs []CertificateConfig
|
||||||
|
raw, _ := jsoniter.Marshal(viper.Get("hypertext.certificate"))
|
||||||
|
_ = jsoniter.Unmarshal(raw, &certs)
|
||||||
|
|
||||||
|
tlsCfg := &tls.Config{
|
||||||
|
MinVersion: tls.VersionTLS12,
|
||||||
|
Certificates: []tls.Certificate{},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, info := range certs {
|
||||||
|
cert, err := tls.LoadX509KeyPair(info.Pem, info.Key)
|
||||||
|
if err != nil {
|
||||||
|
log.Error().Err(err).
|
||||||
|
Str("pem", info.Pem).
|
||||||
|
Str("key", info.Key).
|
||||||
|
Msg("An error occurred when loading certificate.")
|
||||||
|
} else {
|
||||||
|
tlsCfg.Certificates = append(tlsCfg.Certificates, cert)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for _, port := range ports {
|
for _, port := range ports {
|
||||||
port := port
|
port := port
|
||||||
go func() {
|
go func() {
|
||||||
if viper.GetBool("hypertext.certificate.redirect") {
|
if viper.GetBool("hypertext.redirect_to_https") {
|
||||||
redirector := fiber.New(fiber.Config{
|
redirector := fiber.New(fiber.Config{
|
||||||
AppName: "RoadSign",
|
AppName: "RoadSign",
|
||||||
ServerHeader: "RoadSign",
|
ServerHeader: "RoadSign",
|
||||||
@@ -58,22 +110,30 @@ func RunServer(app *fiber.App, ports []string, securedPorts []string, pem string
|
|||||||
return c.Redirect(strings.ReplaceAll(string(c.Request().URI().FullURI()), "http", "https"))
|
return c.Redirect(strings.ReplaceAll(string(c.Request().URI().FullURI()), "http", "https"))
|
||||||
})
|
})
|
||||||
if err := redirector.Listen(port); err != nil {
|
if err := redirector.Listen(port); err != nil {
|
||||||
log.Panic().Err(err).Msg("An error occurred when listening hypertext common ports.")
|
log.Panic().Err(err).Msg("An error occurred when listening hypertext non-tls ports.")
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if err := app.Listen(port); err != nil {
|
if err := app.Listen(port); err != nil {
|
||||||
log.Panic().Err(err).Msg("An error occurred when listening hypertext common ports.")
|
log.Panic().Err(err).Msg("An error occurred when listening hypertext non-tls ports.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
log.Info().Msgf("Listening for %s... http://0.0.0.0%s", app.Config().AppName, port)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, port := range securedPorts {
|
for _, port := range securedPorts {
|
||||||
port := port
|
port := port
|
||||||
go func() {
|
go func() {
|
||||||
if err := app.ListenTLS(port, pem, key); err != nil {
|
listener, err := net.Listen("tcp", port)
|
||||||
|
if err != nil {
|
||||||
|
log.Panic().Err(err).Msg("An error occurred when listening hypertext tls ports.")
|
||||||
|
}
|
||||||
|
if err := app.Listener(tls.NewListener(listener, tlsCfg)); err != nil {
|
||||||
log.Panic().Err(err).Msg("An error occurred when listening hypertext tls ports.")
|
log.Panic().Err(err).Msg("An error occurred when listening hypertext tls ports.")
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
log.Info().Msgf("Listening for %s... https://0.0.0.0%s", app.Config().AppName, port)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
6
pkg/hypertext/status/embed.go
Normal file
6
pkg/hypertext/status/embed.go
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
package status
|
||||||
|
|
||||||
|
import "embed"
|
||||||
|
|
||||||
|
//go:embed all:views
|
||||||
|
var FS embed.FS
|
56
pkg/hypertext/status/serve.go
Normal file
56
pkg/hypertext/status/serve.go
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
package status
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
roadsign "git.solsynth.dev/goatworks/roadsign/pkg"
|
||||||
|
"github.com/gofiber/fiber/v2"
|
||||||
|
"github.com/spf13/viper"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ErrorPayload struct {
|
||||||
|
Title string `json:"title"`
|
||||||
|
Message string `json:"message"`
|
||||||
|
Version string `json:"version"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func StatusPageHandler(c *fiber.Ctx, err error) error {
|
||||||
|
var reqErr *fiber.Error
|
||||||
|
var status = fiber.StatusInternalServerError
|
||||||
|
if errors.As(err, &reqErr) {
|
||||||
|
status = reqErr.Code
|
||||||
|
}
|
||||||
|
|
||||||
|
c.Status(status)
|
||||||
|
|
||||||
|
payload := ErrorPayload{
|
||||||
|
Version: roadsign.AppVersion,
|
||||||
|
}
|
||||||
|
|
||||||
|
switch status {
|
||||||
|
case fiber.StatusNotFound:
|
||||||
|
payload.Title = "Not Found"
|
||||||
|
payload.Message = fmt.Sprintf("no resource for \"%s\"", c.OriginalURL())
|
||||||
|
return c.Render("views/not-found", payload)
|
||||||
|
case fiber.StatusTooManyRequests:
|
||||||
|
payload.Title = "Request Too Fast"
|
||||||
|
payload.Message = fmt.Sprintf("you have sent over %d request(s) in a second", viper.GetInt("hypertext.limitation.max_qps"))
|
||||||
|
return c.Render("views/too-many-requests", payload)
|
||||||
|
case fiber.StatusRequestEntityTooLarge:
|
||||||
|
payload.Title = "Request Too Large"
|
||||||
|
payload.Message = fmt.Sprintf("you have sent a request over %d bytes", viper.GetInt("hypertext.limitation.max_body_size"))
|
||||||
|
return c.Render("views/request-too-large", payload)
|
||||||
|
case fiber.StatusBadGateway:
|
||||||
|
payload.Title = "Backend Down"
|
||||||
|
payload.Message = fmt.Sprintf("all destnations configured to handle your request are down: %s", err.Error())
|
||||||
|
return c.Render("views/bad-gateway", payload)
|
||||||
|
case fiber.StatusGatewayTimeout:
|
||||||
|
payload.Title = "Backend Took Too Long To Response"
|
||||||
|
payload.Message = fmt.Sprintf("the destnation took too long to response your request: %s", err.Error())
|
||||||
|
return c.Render("views/gateway-timeout", payload)
|
||||||
|
default:
|
||||||
|
payload.Title = "Oops"
|
||||||
|
payload.Message = err.Error()
|
||||||
|
return c.Render("views/fallback", payload)
|
||||||
|
}
|
||||||
|
}
|
6
pkg/hypertext/status/views/bad-gateway.gohtml
Normal file
6
pkg/hypertext/status/views/bad-gateway.gohtml
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<h1 class="text-2xl font-bold">502</h1>
|
||||||
|
<h2 class="text-lg">No one is standing...</h2>
|
||||||
|
|
||||||
|
<div class="mt-3 mx-auto p-5 w-[360px] max-w-screen bg-neutral text-neutral-content rounded">
|
||||||
|
<code class="capitalize">{{ .Message }}</code>
|
||||||
|
</div>
|
6
pkg/hypertext/status/views/fallback.gohtml
Normal file
6
pkg/hypertext/status/views/fallback.gohtml
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<h1 class="text-2xl font-bold">Oops</h1>
|
||||||
|
<h2 class="text-lg">Something went wrong...</h2>
|
||||||
|
|
||||||
|
<div class="mt-3 mx-auto p-5 w-[360px] max-w-screen bg-neutral text-neutral-content rounded">
|
||||||
|
<code class="capitalize">{{ .Message }}</code>
|
||||||
|
</div>
|
6
pkg/hypertext/status/views/gateway-timeout.gohtml
Normal file
6
pkg/hypertext/status/views/gateway-timeout.gohtml
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<h1 class="text-2xl font-bold">504</h1>
|
||||||
|
<h2 class="text-lg">Looks like the server in the back fell asleep</h2>
|
||||||
|
|
||||||
|
<div class="mt-3 mx-auto p-5 w-[360px] max-w-screen bg-neutral text-neutral-content rounded">
|
||||||
|
<code class="capitalize">{{ .Message }}</code>
|
||||||
|
</div>
|
83
pkg/hypertext/status/views/index.gohtml
Normal file
83
pkg/hypertext/status/views/index.gohtml
Normal file
@@ -0,0 +1,83 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
|
||||||
|
<link href="https://cdn.jsdelivr.net/npm/daisyui@4.6.1/dist/full.min.css" rel="stylesheet" type="text/css" />
|
||||||
|
<script src="https://cdn.tailwindcss.com"></script>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
tailwind.config = {
|
||||||
|
daisyui: {
|
||||||
|
themes: [
|
||||||
|
{
|
||||||
|
light: {
|
||||||
|
primary: "#4750a3",
|
||||||
|
secondary: "#93c5fd",
|
||||||
|
accent: "#0f766e",
|
||||||
|
info: "#67e8f9",
|
||||||
|
success: "#15803d",
|
||||||
|
warning: "#f97316",
|
||||||
|
error: "#dc2626",
|
||||||
|
neutral: "#2B3440",
|
||||||
|
"secondary-content": "oklch(98.71% 0.0106 342.55)",
|
||||||
|
"neutral-content": "#D7DDE4",
|
||||||
|
"base-100": "oklch(100% 0 0)",
|
||||||
|
"base-200": "#F2F2F2",
|
||||||
|
"base-300": "#E5E6E6",
|
||||||
|
"base-content": "#1f2937",
|
||||||
|
"color-scheme": "light",
|
||||||
|
"--rounded-box": "0",
|
||||||
|
"--rounded-btn": "0",
|
||||||
|
"--rounded-badge": "0",
|
||||||
|
"--tab-radius": "0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
dark: {
|
||||||
|
primary: "#4750a3",
|
||||||
|
secondary: "#93c5fd",
|
||||||
|
accent: "#0f766e",
|
||||||
|
info: "#67e8f9",
|
||||||
|
success: "#15803d",
|
||||||
|
warning: "#f97316",
|
||||||
|
error: "#dc2626",
|
||||||
|
neutral: "#2a323c",
|
||||||
|
"neutral-content": "#A6ADBB",
|
||||||
|
"base-100": "#1d232a",
|
||||||
|
"base-200": "#191e24",
|
||||||
|
"base-300": "#15191e",
|
||||||
|
"base-content": "#A6ADBB",
|
||||||
|
"color-scheme": "dark",
|
||||||
|
"--rounded-box": "0",
|
||||||
|
"--rounded-btn": "0",
|
||||||
|
"--rounded-badge": "0",
|
||||||
|
"--tab-radius": "0"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<title>{{ .Title }} | RoadSign</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<main class="w-full h-screen flex justify-center items-center">
|
||||||
|
<div class="text-center">
|
||||||
|
{{embed}}
|
||||||
|
|
||||||
|
<footer class="mt-3 text-sm">
|
||||||
|
<p>
|
||||||
|
Powered by
|
||||||
|
<a href="https://wiki.smartsheep.studio/roadsign/index.html" target="_blank" class="link link-primary">
|
||||||
|
RoadSign
|
||||||
|
</a>
|
||||||
|
</p>
|
||||||
|
<p class="text-xs">v{{ .Version }}</p>
|
||||||
|
</footer>
|
||||||
|
</div>
|
||||||
|
</main>
|
||||||
|
</body>
|
||||||
|
</html>
|
6
pkg/hypertext/status/views/not-found.gohtml
Normal file
6
pkg/hypertext/status/views/not-found.gohtml
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<h1 class="text-2xl font-bold">404</h1>
|
||||||
|
<h2 class="text-lg">Not Found</h2>
|
||||||
|
|
||||||
|
<div class="mt-3 mx-auto p-5 w-[360px] max-w-screen bg-neutral text-neutral-content rounded">
|
||||||
|
<code class="capitalize">{{ .Message }}</code>
|
||||||
|
</div>
|
6
pkg/hypertext/status/views/request-too-large.gohtml
Normal file
6
pkg/hypertext/status/views/request-too-large.gohtml
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<h1 class="text-2xl font-bold">413</h1>
|
||||||
|
<h2 class="text-lg">Auh, you are too big.</h2>
|
||||||
|
|
||||||
|
<div class="mt-3 mx-auto p-5 w-[360px] max-w-screen bg-neutral text-neutral-content rounded">
|
||||||
|
<code class="capitalize">{{ .Message }}</code>
|
||||||
|
</div>
|
6
pkg/hypertext/status/views/too-many-requests.gohtml
Normal file
6
pkg/hypertext/status/views/too-many-requests.gohtml
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<h1 class="text-2xl font-bold">429</h1>
|
||||||
|
<h2 class="text-lg">Stop it, you just to fast!</h2>
|
||||||
|
|
||||||
|
<div class="mt-3 mx-auto p-5 w-[360px] max-w-screen bg-neutral text-neutral-content rounded">
|
||||||
|
<code class="capitalize">{{ .Message }}</code>
|
||||||
|
</div>
|
@@ -14,4 +14,4 @@ func init() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var AppVersion = "2.0.0-delta1"
|
var AppVersion = "2.1.0"
|
||||||
|
@@ -5,8 +5,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
"github.com/spf13/viper"
|
|
||||||
|
|
||||||
"github.com/pelletier/go-toml/v2"
|
"github.com/pelletier/go-toml/v2"
|
||||||
)
|
)
|
||||||
@@ -16,7 +15,13 @@ var R *RoadApp
|
|||||||
func ReadInConfig(root string) error {
|
func ReadInConfig(root string) error {
|
||||||
instance := &RoadApp{
|
instance := &RoadApp{
|
||||||
Regions: make([]*Region, 0),
|
Regions: make([]*Region, 0),
|
||||||
Traces: make([]RoadTrace, 0, viper.GetInt("performance.traces_limit")),
|
Metrics: &RoadMetrics{
|
||||||
|
Traces: make([]RoadTrace, 0),
|
||||||
|
Traffic: make(map[string]int64),
|
||||||
|
TrafficFrom: make(map[string]int64),
|
||||||
|
TotalTraffic: 0,
|
||||||
|
StartupAt: time.Now(),
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := filepath.Walk(root, func(fp string, info os.FileInfo, _ error) error {
|
if err := filepath.Walk(root, func(fp string, info os.FileInfo, _ error) error {
|
||||||
@@ -46,6 +51,7 @@ func ReadInConfig(root string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Hot swap
|
||||||
R = instance
|
R = instance
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
89
pkg/navi/helmet.go
Normal file
89
pkg/navi/helmet.go
Normal file
@@ -0,0 +1,89 @@
|
|||||||
|
package navi
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/gofiber/fiber/v2"
|
||||||
|
)
|
||||||
|
|
||||||
|
type HelmetConfig struct {
|
||||||
|
XSSProtection string `json:"xss_protection" toml:"xss_protection"`
|
||||||
|
ContentTypeNosniff string `json:"content_type_nosniff" toml:"content_type_nosniff"`
|
||||||
|
XFrameOptions string `json:"x_frame_options" toml:"x_frame_options"`
|
||||||
|
HSTSMaxAge int `json:"hsts_max_age" toml:"hsts_max_age"`
|
||||||
|
HSTSExcludeSubdomains bool `json:"hsts_exclude_subdomains" toml:"hsts_exclude_subdomains"`
|
||||||
|
ContentSecurityPolicy string `json:"content_security_policy" toml:"content_security_policy"`
|
||||||
|
CSPReportOnly bool `json:"csp_report_only" toml:"csp_report_only"`
|
||||||
|
HSTSPreloadEnabled bool `json:"hsts_preload_enabled" toml:"hsts_preload_enabled"`
|
||||||
|
ReferrerPolicy string `json:"referrer_policy" toml:"referrer_policy"`
|
||||||
|
PermissionPolicy string `json:"permission_policy" toml:"permission_policy"`
|
||||||
|
CrossOriginEmbedderPolicy string `json:"cross_origin_embedder_policy" toml:"cross_origin_embedder_policy"`
|
||||||
|
CrossOriginOpenerPolicy string `json:"cross_origin_opener_policy" toml:"cross_origin_opener_policy"`
|
||||||
|
CrossOriginResourcePolicy string `json:"cross_origin_resource_policy" toml:"cross_origin_resource_policy"`
|
||||||
|
OriginAgentCluster string `json:"origin_agent_cluster" toml:"origin_agent_cluster"`
|
||||||
|
XDNSPrefetchControl string `json:"xdns_prefetch_control" toml:"xdns_prefetch_control"`
|
||||||
|
XDownloadOptions string `json:"x_download_options" toml:"x_download_options"`
|
||||||
|
XPermittedCrossDomain string `json:"x_permitted_cross_domain" toml:"x_permitted_cross_domain"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (cfg HelmetConfig) Apply(c *fiber.Ctx) {
|
||||||
|
// Apply other headers
|
||||||
|
if cfg.XSSProtection != "" {
|
||||||
|
c.Set(fiber.HeaderXXSSProtection, cfg.XSSProtection)
|
||||||
|
}
|
||||||
|
if cfg.ContentTypeNosniff != "" {
|
||||||
|
c.Set(fiber.HeaderXContentTypeOptions, cfg.ContentTypeNosniff)
|
||||||
|
}
|
||||||
|
if cfg.XFrameOptions != "" {
|
||||||
|
c.Set(fiber.HeaderXFrameOptions, cfg.XFrameOptions)
|
||||||
|
}
|
||||||
|
if cfg.CrossOriginEmbedderPolicy != "" {
|
||||||
|
c.Set("Cross-Origin-Embedder-Policy", cfg.CrossOriginEmbedderPolicy)
|
||||||
|
}
|
||||||
|
if cfg.CrossOriginOpenerPolicy != "" {
|
||||||
|
c.Set("Cross-Origin-Opener-Policy", cfg.CrossOriginOpenerPolicy)
|
||||||
|
}
|
||||||
|
if cfg.CrossOriginResourcePolicy != "" {
|
||||||
|
c.Set("Cross-Origin-Resource-Policy", cfg.CrossOriginResourcePolicy)
|
||||||
|
}
|
||||||
|
if cfg.OriginAgentCluster != "" {
|
||||||
|
c.Set("Origin-Agent-Cluster", cfg.OriginAgentCluster)
|
||||||
|
}
|
||||||
|
if cfg.ReferrerPolicy != "" {
|
||||||
|
c.Set("Referrer-Policy", cfg.ReferrerPolicy)
|
||||||
|
}
|
||||||
|
if cfg.XDNSPrefetchControl != "" {
|
||||||
|
c.Set("X-DNS-Prefetch-Control", cfg.XDNSPrefetchControl)
|
||||||
|
}
|
||||||
|
if cfg.XDownloadOptions != "" {
|
||||||
|
c.Set("X-Download-Options", cfg.XDownloadOptions)
|
||||||
|
}
|
||||||
|
if cfg.XPermittedCrossDomain != "" {
|
||||||
|
c.Set("X-Permitted-Cross-Domain-Policies", cfg.XPermittedCrossDomain)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle HSTS headers
|
||||||
|
if c.Protocol() == "https" && cfg.HSTSMaxAge != 0 {
|
||||||
|
subdomains := ""
|
||||||
|
if !cfg.HSTSExcludeSubdomains {
|
||||||
|
subdomains = "; includeSubDomains"
|
||||||
|
}
|
||||||
|
if cfg.HSTSPreloadEnabled {
|
||||||
|
subdomains = fmt.Sprintf("%s; preload", subdomains)
|
||||||
|
}
|
||||||
|
c.Set(fiber.HeaderStrictTransportSecurity, fmt.Sprintf("max-age=%d%s", cfg.HSTSMaxAge, subdomains))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle Content-Security-Policy headers
|
||||||
|
if cfg.ContentSecurityPolicy != "" {
|
||||||
|
if cfg.CSPReportOnly {
|
||||||
|
c.Set(fiber.HeaderContentSecurityPolicyReportOnly, cfg.ContentSecurityPolicy)
|
||||||
|
} else {
|
||||||
|
c.Set(fiber.HeaderContentSecurityPolicy, cfg.ContentSecurityPolicy)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle Permissions-Policy headers
|
||||||
|
if cfg.PermissionPolicy != "" {
|
||||||
|
c.Set(fiber.HeaderPermissionsPolicy, cfg.PermissionPolicy)
|
||||||
|
}
|
||||||
|
}
|
@@ -1,8 +1,21 @@
|
|||||||
package navi
|
package navi
|
||||||
|
|
||||||
import "github.com/spf13/viper"
|
import (
|
||||||
|
"github.com/spf13/viper"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
type RoadMetrics struct {
|
||||||
|
Traces []RoadTrace `json:"-"`
|
||||||
|
|
||||||
|
Traffic map[string]int64 `json:"traffic"`
|
||||||
|
TrafficFrom map[string]int64 `json:"traffic_from"`
|
||||||
|
TotalTraffic int64 `json:"total_traffic"`
|
||||||
|
StartupAt time.Time `json:"startup_at"`
|
||||||
|
}
|
||||||
|
|
||||||
type RoadTrace struct {
|
type RoadTrace struct {
|
||||||
|
Timestamp time.Time `json:"timestamp"`
|
||||||
Region string `json:"region"`
|
Region string `json:"region"`
|
||||||
Location string `json:"location"`
|
Location string `json:"location"`
|
||||||
Destination string `json:"destination"`
|
Destination string `json:"destination"`
|
||||||
@@ -17,8 +30,29 @@ type RoadTraceError struct {
|
|||||||
Message string `json:"message"`
|
Message string `json:"message"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *RoadApp) AddTrace(trace RoadTrace) {
|
func (v *RoadMetrics) AddTrace(trace RoadTrace) {
|
||||||
|
v.TotalTraffic++
|
||||||
|
trace.Timestamp = time.Now()
|
||||||
|
if _, ok := v.Traffic[trace.Region]; !ok {
|
||||||
|
v.Traffic[trace.Region] = 0
|
||||||
|
} else {
|
||||||
|
v.Traffic[trace.Region]++
|
||||||
|
}
|
||||||
|
if _, ok := v.TrafficFrom[trace.IpAddress]; !ok {
|
||||||
|
v.TrafficFrom[trace.IpAddress] = 0
|
||||||
|
} else {
|
||||||
|
v.TrafficFrom[trace.IpAddress]++
|
||||||
|
}
|
||||||
|
|
||||||
v.Traces = append(v.Traces, trace)
|
v.Traces = append(v.Traces, trace)
|
||||||
|
|
||||||
|
// Garbage recycle
|
||||||
|
if len(v.Traffic) > viper.GetInt("performance.traces_limit") {
|
||||||
|
v.Traffic = make(map[string]int64)
|
||||||
|
}
|
||||||
|
if len(v.TrafficFrom) > viper.GetInt("performance.traces_limit") {
|
||||||
|
v.TrafficFrom = make(map[string]int64)
|
||||||
|
}
|
||||||
if len(v.Traces) > viper.GetInt("performance.traces_limit") {
|
if len(v.Traces) > viper.GetInt("performance.traces_limit") {
|
||||||
v.Traces = v.Traces[1:]
|
v.Traces = v.Traces[1:]
|
||||||
}
|
}
|
||||||
|
@@ -9,7 +9,6 @@ import (
|
|||||||
"github.com/gofiber/fiber/v2/utils"
|
"github.com/gofiber/fiber/v2/utils"
|
||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
"github.com/samber/lo"
|
"github.com/samber/lo"
|
||||||
"github.com/spf13/viper"
|
|
||||||
"github.com/valyala/fasthttp"
|
"github.com/valyala/fasthttp"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"net/http"
|
"net/http"
|
||||||
@@ -24,22 +23,25 @@ func makeUnifiedResponse(c *fiber.Ctx, dest *Destination) error {
|
|||||||
// Handle websocket
|
// Handle websocket
|
||||||
return makeWebsocketResponse(c, dest)
|
return makeWebsocketResponse(c, dest)
|
||||||
} else {
|
} else {
|
||||||
_, queries := dest.GetRawUri()
|
// TODO Impl SSE with https://github.com/gofiber/recipes/blob/master/sse/main.go
|
||||||
if len(queries.Get("sse")) > 0 {
|
// Handle normal http request
|
||||||
// Handle server-side event
|
return makeHypertextResponse(c, dest)
|
||||||
return makeSeverSideEventResponse(c, dest)
|
|
||||||
} else {
|
|
||||||
// Handle normal http request
|
|
||||||
return makeHypertextResponse(c, dest)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func makeHypertextResponse(c *fiber.Ctx, dest *Destination) error {
|
func makeHypertextResponse(c *fiber.Ctx, dest *Destination) error {
|
||||||
timeout := time.Duration(viper.GetInt64("performance.network_timeout")) * time.Millisecond
|
_, queries := dest.GetRawUri()
|
||||||
return proxy.Do(c, dest.MakeUri(c), &fasthttp.Client{
|
raw := lo.Ternary(len(queries.Get("timeout")) > 0, queries.Get("timeout"), "5000")
|
||||||
ReadTimeout: timeout,
|
num, err := strconv.Atoi(raw)
|
||||||
WriteTimeout: timeout,
|
if err != nil {
|
||||||
|
num = 5000
|
||||||
|
}
|
||||||
|
|
||||||
|
limit := time.Duration(num) * time.Millisecond
|
||||||
|
uri := dest.BuildUri(c)
|
||||||
|
return proxy.Do(c, uri, &fasthttp.Client{
|
||||||
|
ReadTimeout: limit,
|
||||||
|
WriteTimeout: limit,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -98,11 +100,6 @@ func makeWebsocketResponse(c *fiber.Ctx, dest *Destination) error {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func makeSeverSideEventResponse(c *fiber.Ctx, dest *Destination) error {
|
|
||||||
// TODO Impl SSE with https://github.com/gofiber/recipes/blob/master/sse/main.go
|
|
||||||
return fiber.NewError(fiber.StatusNotImplemented, "Server-side-events was not available now.")
|
|
||||||
}
|
|
||||||
|
|
||||||
func makeFileResponse(c *fiber.Ctx, dest *Destination) error {
|
func makeFileResponse(c *fiber.Ctx, dest *Destination) error {
|
||||||
uri, queries := dest.GetRawUri()
|
uri, queries := dest.GetRawUri()
|
||||||
root := http.Dir(uri)
|
root := http.Dir(uri)
|
||||||
|
@@ -1,25 +1,57 @@
|
|||||||
package navi
|
package navi
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"code.smartsheep.studio/goatworks/roadsign/pkg/navi/transformers"
|
"fmt"
|
||||||
|
roadsign "git.solsynth.dev/goatworks/roadsign/pkg"
|
||||||
|
"git.solsynth.dev/goatworks/roadsign/pkg/navi/transformers"
|
||||||
|
"github.com/spf13/viper"
|
||||||
|
|
||||||
"github.com/gofiber/fiber/v2"
|
"github.com/gofiber/fiber/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
type RoadApp struct {
|
type RoadApp struct {
|
||||||
Regions []*Region `json:"regions"`
|
Regions []*Region `json:"regions"`
|
||||||
Traces []RoadTrace `json:"traces"`
|
Metrics *RoadMetrics `json:"metrics"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *RoadApp) Forward(ctx *fiber.Ctx, dest *Destination) error {
|
func (v *RoadApp) Forward(c *fiber.Ctx, dest *Destination) error {
|
||||||
|
// Add reserve proxy headers
|
||||||
|
ip := c.IP()
|
||||||
|
scheme := c.Protocol()
|
||||||
|
protocol := string(c.Request().Header.Protocol())
|
||||||
|
c.Request().Header.Set(fiber.HeaderXForwardedFor, ip)
|
||||||
|
c.Request().Header.Set(fiber.HeaderXForwardedHost, ip)
|
||||||
|
c.Request().Header.Set(fiber.HeaderXForwardedProto, scheme)
|
||||||
|
c.Request().Header.Set(
|
||||||
|
fiber.HeaderVia,
|
||||||
|
fmt.Sprintf("%s %s", protocol, viper.GetString("central")),
|
||||||
|
)
|
||||||
|
c.Request().Header.Set(
|
||||||
|
fiber.HeaderForwarded,
|
||||||
|
fmt.Sprintf("by=%s; for=%s; host=%s; proto=%s", c.IP(), c.IP(), c.Get(fiber.HeaderHost), scheme),
|
||||||
|
)
|
||||||
|
|
||||||
|
// Response body
|
||||||
|
var err error
|
||||||
switch dest.GetType() {
|
switch dest.GetType() {
|
||||||
case DestinationHypertext:
|
case DestinationHypertext:
|
||||||
return makeUnifiedResponse(ctx, dest)
|
err = makeUnifiedResponse(c, dest)
|
||||||
case DestinationStaticFile:
|
case DestinationStaticFile:
|
||||||
return makeFileResponse(ctx, dest)
|
err = makeFileResponse(c, dest)
|
||||||
default:
|
default:
|
||||||
return fiber.ErrBadGateway
|
err = fiber.ErrBadGateway
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Apply helmet
|
||||||
|
if dest.Helmet != nil {
|
||||||
|
dest.Helmet.Apply(c)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Apply watermark
|
||||||
|
c.Response().Header.Set(fiber.HeaderServer, "RoadSign")
|
||||||
|
c.Response().Header.Set(fiber.HeaderXPoweredBy, fmt.Sprintf("RoadSign %s", roadsign.AppVersion))
|
||||||
|
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
type RequestTransformerConfig = transformers.TransformerConfig
|
type RequestTransformerConfig = transformers.TransformerConfig
|
||||||
|
@@ -5,8 +5,8 @@ import (
|
|||||||
"net/url"
|
"net/url"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"code.smartsheep.studio/goatworks/roadsign/pkg/navi/transformers"
|
"git.solsynth.dev/goatworks/roadsign/pkg/navi/transformers"
|
||||||
"code.smartsheep.studio/goatworks/roadsign/pkg/warden"
|
"git.solsynth.dev/goatworks/roadsign/pkg/warden"
|
||||||
"github.com/gofiber/fiber/v2"
|
"github.com/gofiber/fiber/v2"
|
||||||
"github.com/samber/lo"
|
"github.com/samber/lo"
|
||||||
)
|
)
|
||||||
@@ -20,8 +20,8 @@ type Region struct {
|
|||||||
|
|
||||||
type Location struct {
|
type Location struct {
|
||||||
ID string `json:"id" toml:"id"`
|
ID string `json:"id" toml:"id"`
|
||||||
Host []string `json:"host" toml:"host"`
|
Hosts []string `json:"hosts" toml:"hosts"`
|
||||||
Path []string `json:"path" toml:"path"`
|
Paths []string `json:"paths" toml:"paths"`
|
||||||
Queries map[string]string `json:"queries" toml:"queries"`
|
Queries map[string]string `json:"queries" toml:"queries"`
|
||||||
Headers map[string][]string `json:"headers" toml:"headers"`
|
Headers map[string][]string `json:"headers" toml:"headers"`
|
||||||
Destinations []Destination `json:"destinations" toml:"destinations"`
|
Destinations []Destination `json:"destinations" toml:"destinations"`
|
||||||
@@ -38,6 +38,7 @@ const (
|
|||||||
type Destination struct {
|
type Destination struct {
|
||||||
ID string `json:"id" toml:"id"`
|
ID string `json:"id" toml:"id"`
|
||||||
Uri string `json:"uri" toml:"uri"`
|
Uri string `json:"uri" toml:"uri"`
|
||||||
|
Helmet *HelmetConfig `json:"helmet" toml:"helmet"`
|
||||||
Transformers []transformers.TransformerConfig `json:"transformers" toml:"transformers"`
|
Transformers []transformers.TransformerConfig `json:"transformers" toml:"transformers"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -59,13 +60,13 @@ func (v *Destination) GetType() DestinationType {
|
|||||||
func (v *Destination) GetRawUri() (string, url.Values) {
|
func (v *Destination) GetRawUri() (string, url.Values) {
|
||||||
uri := strings.SplitN(v.Uri, "://", 2)[1]
|
uri := strings.SplitN(v.Uri, "://", 2)[1]
|
||||||
data := strings.SplitN(uri, "?", 2)
|
data := strings.SplitN(uri, "?", 2)
|
||||||
data = append(data, " ") // Make data array least have two element
|
data = append(data, " ") // Make the data array least have two elements
|
||||||
qs, _ := url.ParseQuery(data[1])
|
qs, _ := url.ParseQuery(data[1])
|
||||||
|
|
||||||
return data[0], qs
|
return data[0], qs
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *Destination) MakeUri(ctx *fiber.Ctx) string {
|
func (v *Destination) BuildUri(ctx *fiber.Ctx) string {
|
||||||
var queries []string
|
var queries []string
|
||||||
for k, v := range ctx.Queries() {
|
for k, v := range ctx.Queries() {
|
||||||
parsed, _ := url.QueryUnescape(v)
|
parsed, _ := url.QueryUnescape(v)
|
||||||
@@ -75,13 +76,14 @@ func (v *Destination) MakeUri(ctx *fiber.Ctx) string {
|
|||||||
|
|
||||||
path := string(ctx.Request().URI().Path())
|
path := string(ctx.Request().URI().Path())
|
||||||
hash := string(ctx.Request().URI().Hash())
|
hash := string(ctx.Request().URI().Hash())
|
||||||
|
protocol := v.GetProtocol()
|
||||||
uri, _ := v.GetRawUri()
|
uri, _ := v.GetRawUri()
|
||||||
|
|
||||||
return uri + path +
|
return protocol + "://" + uri + path +
|
||||||
lo.Ternary(len(queries) > 0, "?"+strings.Join(queries, "&"), "") +
|
lo.Ternary(len(queries) > 0, "?"+strings.Join(queries, "&"), "") +
|
||||||
lo.Ternary(len(hash) > 0, "#"+hash, "")
|
lo.Ternary(len(hash) > 0, "#"+hash, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *Destination) MakeWebsocketUri(ctx *fiber.Ctx) string {
|
func (v *Destination) MakeWebsocketUri(ctx *fiber.Ctx) string {
|
||||||
return strings.Replace(v.MakeUri(ctx), "http", "ws", 1)
|
return strings.Replace(v.BuildUri(ctx), "http", "ws", 1)
|
||||||
}
|
}
|
||||||
|
@@ -1,17 +1,19 @@
|
|||||||
package navi
|
package navi
|
||||||
|
|
||||||
import "code.smartsheep.studio/goatworks/roadsign/pkg/warden"
|
import "git.solsynth.dev/goatworks/roadsign/pkg/warden"
|
||||||
|
|
||||||
func InitializeWarden(regions []*Region) {
|
func InitializeWarden(regions []*Region) {
|
||||||
|
pool := make([]*warden.AppInstance, 0)
|
||||||
|
|
||||||
for _, region := range regions {
|
for _, region := range regions {
|
||||||
for _, application := range region.Applications {
|
for _, application := range region.Applications {
|
||||||
warden.InstancePool = append(warden.InstancePool, &warden.AppInstance{
|
pool = append(pool, &warden.AppInstance{
|
||||||
Manifest: application,
|
Manifest: application,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, instance := range warden.InstancePool {
|
// Hot swap
|
||||||
instance.Wake()
|
warden.InstancePool = pool
|
||||||
}
|
warden.StartPool()
|
||||||
}
|
}
|
||||||
|
@@ -1,15 +1,20 @@
|
|||||||
package sideload
|
package sideload
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"code.smartsheep.studio/goatworks/roadsign/pkg/navi"
|
"git.solsynth.dev/goatworks/roadsign/pkg/navi"
|
||||||
"code.smartsheep.studio/goatworks/roadsign/pkg/warden"
|
"git.solsynth.dev/goatworks/roadsign/pkg/warden"
|
||||||
"github.com/gofiber/fiber/v2"
|
"github.com/gofiber/fiber/v2"
|
||||||
"github.com/samber/lo"
|
"github.com/samber/lo"
|
||||||
)
|
)
|
||||||
|
|
||||||
func getApplications(c *fiber.Ctx) error {
|
func getApplications(c *fiber.Ctx) error {
|
||||||
applications := lo.FlatMap(navi.R.Regions, func(item *navi.Region, idx int) []warden.Application {
|
applications := lo.FlatMap(navi.R.Regions, func(item *navi.Region, idx int) []warden.ApplicationInfo {
|
||||||
return item.Applications
|
return lo.Map(item.Applications, func(item warden.Application, index int) warden.ApplicationInfo {
|
||||||
|
return warden.ApplicationInfo{
|
||||||
|
Application: item,
|
||||||
|
Status: warden.GetFromPool(item.ID).Status,
|
||||||
|
}
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
return c.JSON(applications)
|
return c.JSON(applications)
|
||||||
@@ -24,3 +29,45 @@ func getApplicationLogs(c *fiber.Ctx) error {
|
|||||||
return c.SendString(instance.Logs())
|
return c.SendString(instance.Logs())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func letApplicationStart(c *fiber.Ctx) error {
|
||||||
|
if instance, ok := lo.Find(warden.InstancePool, func(item *warden.AppInstance) bool {
|
||||||
|
return item.Manifest.ID == c.Params("id")
|
||||||
|
}); !ok {
|
||||||
|
return fiber.NewError(fiber.StatusNotFound)
|
||||||
|
} else {
|
||||||
|
if err := instance.Wake(); err != nil {
|
||||||
|
return fiber.NewError(fiber.StatusInternalServerError, err.Error())
|
||||||
|
}
|
||||||
|
return c.SendStatus(fiber.StatusOK)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func letApplicationStop(c *fiber.Ctx) error {
|
||||||
|
if instance, ok := lo.Find(warden.InstancePool, func(item *warden.AppInstance) bool {
|
||||||
|
return item.Manifest.ID == c.Params("id")
|
||||||
|
}); !ok {
|
||||||
|
return fiber.NewError(fiber.StatusNotFound)
|
||||||
|
} else {
|
||||||
|
if err := instance.Stop(); err != nil {
|
||||||
|
return fiber.NewError(fiber.StatusInternalServerError, err.Error())
|
||||||
|
}
|
||||||
|
return c.SendStatus(fiber.StatusOK)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func letApplicationRestart(c *fiber.Ctx) error {
|
||||||
|
if instance, ok := lo.Find(warden.InstancePool, func(item *warden.AppInstance) bool {
|
||||||
|
return item.Manifest.ID == c.Params("id")
|
||||||
|
}); !ok {
|
||||||
|
return fiber.NewError(fiber.StatusNotFound)
|
||||||
|
} else {
|
||||||
|
if err := instance.Stop(); err != nil {
|
||||||
|
return fiber.NewError(fiber.StatusInternalServerError, err.Error())
|
||||||
|
}
|
||||||
|
if err := instance.Start(); err != nil {
|
||||||
|
return fiber.NewError(fiber.StatusInternalServerError, err.Error())
|
||||||
|
}
|
||||||
|
return c.SendStatus(fiber.StatusOK)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
package sideload
|
package sideload
|
||||||
|
|
||||||
import (
|
import (
|
||||||
roadsign "code.smartsheep.studio/goatworks/roadsign/pkg"
|
roadsign "git.solsynth.dev/goatworks/roadsign/pkg"
|
||||||
"github.com/gofiber/fiber/v2"
|
"github.com/gofiber/fiber/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@@ -1,10 +1,14 @@
|
|||||||
package sideload
|
package sideload
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"code.smartsheep.studio/goatworks/roadsign/pkg/navi"
|
"git.solsynth.dev/goatworks/roadsign/pkg/navi"
|
||||||
"github.com/gofiber/fiber/v2"
|
"github.com/gofiber/fiber/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func getTraffic(c *fiber.Ctx) error {
|
||||||
|
return c.JSON(navi.R.Metrics)
|
||||||
|
}
|
||||||
|
|
||||||
func getTraces(c *fiber.Ctx) error {
|
func getTraces(c *fiber.Ctx) error {
|
||||||
return c.JSON(navi.R.Traces)
|
return c.JSON(navi.R.Metrics.Traces)
|
||||||
}
|
}
|
||||||
|
@@ -1,12 +1,12 @@
|
|||||||
package sideload
|
package sideload
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"code.smartsheep.studio/goatworks/roadsign/pkg/warden"
|
|
||||||
"context"
|
"context"
|
||||||
|
"git.solsynth.dev/goatworks/roadsign/pkg/warden"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"code.smartsheep.studio/goatworks/roadsign/pkg/navi"
|
"git.solsynth.dev/goatworks/roadsign/pkg/navi"
|
||||||
"github.com/gofiber/fiber/v2"
|
"github.com/gofiber/fiber/v2"
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"github.com/samber/lo"
|
"github.com/samber/lo"
|
||||||
@@ -42,11 +42,11 @@ func doPublish(c *fiber.Ctx) error {
|
|||||||
var instance *warden.AppInstance
|
var instance *warden.AppInstance
|
||||||
if application != nil {
|
if application != nil {
|
||||||
if instance = warden.GetFromPool(application.ID); instance != nil {
|
if instance = warden.GetFromPool(application.ID); instance != nil {
|
||||||
instance.Stop()
|
_ = instance.Stop()
|
||||||
}
|
}
|
||||||
} else if destination != nil && destination.GetType() != navi.DestinationStaticFile {
|
} else if destination != nil && destination.GetType() != navi.DestinationStaticFile {
|
||||||
return fiber.ErrUnprocessableEntity
|
return fiber.ErrUnprocessableEntity
|
||||||
} else {
|
} else if destination == nil {
|
||||||
return fiber.ErrNotFound
|
return fiber.ErrNotFound
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -84,7 +84,7 @@ func doPublish(c *fiber.Ctx) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if instance != nil {
|
if instance != nil {
|
||||||
instance.Wake()
|
_ = instance.Wake()
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.SendStatus(fiber.StatusOK)
|
return c.SendStatus(fiber.StatusOK)
|
||||||
|
@@ -5,8 +5,8 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"code.smartsheep.studio/goatworks/roadsign/pkg/navi"
|
"git.solsynth.dev/goatworks/roadsign/pkg/navi"
|
||||||
"code.smartsheep.studio/goatworks/roadsign/pkg/warden"
|
"git.solsynth.dev/goatworks/roadsign/pkg/warden"
|
||||||
"github.com/gofiber/fiber/v2"
|
"github.com/gofiber/fiber/v2"
|
||||||
"github.com/pelletier/go-toml/v2"
|
"github.com/pelletier/go-toml/v2"
|
||||||
"github.com/samber/lo"
|
"github.com/samber/lo"
|
||||||
@@ -38,29 +38,46 @@ func doSync(c *fiber.Ctx) error {
|
|||||||
if file, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0755); err != nil {
|
if file, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0755); err != nil {
|
||||||
return fiber.NewError(fiber.ErrInternalServerError.Code, err.Error())
|
return fiber.NewError(fiber.ErrInternalServerError.Code, err.Error())
|
||||||
} else {
|
} else {
|
||||||
raw, _ := toml.Marshal(req)
|
var testOut map[string]any
|
||||||
file.Write(raw)
|
if err := toml.Unmarshal([]byte(req), &testOut); err != nil {
|
||||||
|
return fiber.NewError(fiber.StatusBadRequest, fmt.Sprintf("invalid configuration: %v", err))
|
||||||
|
}
|
||||||
|
_, _ = file.Write([]byte(req))
|
||||||
defer file.Close()
|
defer file.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
var rebootQueue []*warden.AppInstance
|
var stopQueue, startQueue []*warden.AppInstance
|
||||||
|
// Getting things need to stop
|
||||||
if region, ok := lo.Find(navi.R.Regions, func(item *navi.Region) bool {
|
if region, ok := lo.Find(navi.R.Regions, func(item *navi.Region) bool {
|
||||||
return item.ID == id
|
return item.ID == id
|
||||||
}); ok {
|
}); ok {
|
||||||
for _, application := range region.Applications {
|
for _, application := range region.Applications {
|
||||||
if instance := warden.GetFromPool(application.ID); instance != nil {
|
if instance := warden.GetFromPool(application.ID); instance != nil {
|
||||||
instance.Stop()
|
stopQueue = append(stopQueue, instance)
|
||||||
rebootQueue = append(rebootQueue, instance)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reload
|
// Reload
|
||||||
navi.ReadInConfig(viper.GetString("paths.configs"))
|
_ = navi.ReadInConfig(viper.GetString("paths.configs"))
|
||||||
|
|
||||||
|
// Getting things need to start
|
||||||
|
if region, ok := lo.Find(navi.R.Regions, func(item *navi.Region) bool {
|
||||||
|
return item.ID == id
|
||||||
|
}); ok {
|
||||||
|
for _, application := range region.Applications {
|
||||||
|
if instance := warden.GetFromPool(application.ID); instance != nil {
|
||||||
|
startQueue = append(startQueue, instance)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Reboot
|
// Reboot
|
||||||
for _, instance := range rebootQueue {
|
for _, instance := range stopQueue {
|
||||||
instance.Wake()
|
_ = instance.Stop()
|
||||||
|
}
|
||||||
|
for _, instance := range startQueue {
|
||||||
|
_ = instance.Start()
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.SendStatus(fiber.StatusOK)
|
return c.SendStatus(fiber.StatusOK)
|
||||||
|
18
pkg/sideload/reload.go
Normal file
18
pkg/sideload/reload.go
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
package sideload
|
||||||
|
|
||||||
|
import (
|
||||||
|
"git.solsynth.dev/goatworks/roadsign/pkg/navi"
|
||||||
|
"github.com/gofiber/fiber/v2"
|
||||||
|
"github.com/spf13/viper"
|
||||||
|
)
|
||||||
|
|
||||||
|
func doReload(c *fiber.Ctx) error {
|
||||||
|
if err := navi.ReadInConfig(viper.GetString("paths.configs")); err != nil {
|
||||||
|
return fiber.NewError(fiber.StatusInternalServerError, err.Error())
|
||||||
|
}
|
||||||
|
if c.QueryBool("warden", false) {
|
||||||
|
navi.InitializeWarden(navi.R.Regions)
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.SendStatus(fiber.StatusOK)
|
||||||
|
}
|
@@ -2,16 +2,11 @@ package sideload
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
roadsign "git.solsynth.dev/goatworks/roadsign/pkg"
|
||||||
|
|
||||||
"code.smartsheep.studio/goatworks/roadsign/pkg/sideload/view"
|
|
||||||
"github.com/gofiber/fiber/v2/middleware/filesystem"
|
|
||||||
jsoniter "github.com/json-iterator/go"
|
|
||||||
|
|
||||||
roadsign "code.smartsheep.studio/goatworks/roadsign/pkg"
|
|
||||||
"github.com/gofiber/fiber/v2"
|
"github.com/gofiber/fiber/v2"
|
||||||
"github.com/gofiber/fiber/v2/middleware/basicauth"
|
"github.com/gofiber/fiber/v2/middleware/basicauth"
|
||||||
"github.com/gofiber/fiber/v2/middleware/logger"
|
"github.com/gofiber/fiber/v2/middleware/logger"
|
||||||
|
jsoniter "github.com/json-iterator/go"
|
||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
)
|
)
|
||||||
@@ -24,12 +19,13 @@ func InitSideload() *fiber.App {
|
|||||||
EnableIPValidation: true,
|
EnableIPValidation: true,
|
||||||
JSONDecoder: jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal,
|
JSONDecoder: jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal,
|
||||||
JSONEncoder: jsoniter.ConfigCompatibleWithStandardLibrary.Marshal,
|
JSONEncoder: jsoniter.ConfigCompatibleWithStandardLibrary.Marshal,
|
||||||
|
ProxyHeader: fiber.HeaderXForwardedFor,
|
||||||
EnablePrintRoutes: viper.GetBool("debug.print_routes"),
|
EnablePrintRoutes: viper.GetBool("debug.print_routes"),
|
||||||
TrustedProxies: viper.GetStringSlice("security.sideload_trusted_proxies"),
|
TrustedProxies: viper.GetStringSlice("sideload.trusted_proxies"),
|
||||||
BodyLimit: viper.GetInt("hypertext.limitation.max_body_size"),
|
BodyLimit: viper.GetInt("hypertext.limitation.max_body_size"),
|
||||||
})
|
})
|
||||||
|
|
||||||
if viper.GetBool("performance.request_logging") {
|
if viper.GetBool("telemetry.request_logging") {
|
||||||
app.Use(logger.New(logger.Config{
|
app.Use(logger.New(logger.Config{
|
||||||
Output: log.Logger,
|
Output: log.Logger,
|
||||||
Format: "[Sideload] [${time}] ${status} - ${latency} ${method} ${path}\n",
|
Format: "[Sideload] [${time}] ${status} - ${latency} ${method} ${path}\n",
|
||||||
@@ -43,22 +39,21 @@ func InitSideload() *fiber.App {
|
|||||||
},
|
},
|
||||||
}))
|
}))
|
||||||
|
|
||||||
app.Use("/", filesystem.New(filesystem.Config{
|
|
||||||
Root: http.FS(view.FS),
|
|
||||||
PathPrefix: "dist",
|
|
||||||
Index: "index.html",
|
|
||||||
NotFoundFile: "index.html",
|
|
||||||
}))
|
|
||||||
|
|
||||||
cgi := app.Group("/cgi").Name("CGI")
|
cgi := app.Group("/cgi").Name("CGI")
|
||||||
{
|
{
|
||||||
cgi.Get("/metadata", getMetadata)
|
cgi.Get("/metadata", getMetadata)
|
||||||
|
cgi.Get("/traffic", getTraffic)
|
||||||
cgi.Get("/traces", getTraces)
|
cgi.Get("/traces", getTraces)
|
||||||
cgi.Get("/stats", getStats)
|
cgi.Get("/stats", getStats)
|
||||||
cgi.Get("/regions", getRegions)
|
cgi.Get("/regions", getRegions)
|
||||||
cgi.Get("/regions/cfg/:id", getRegionConfig)
|
cgi.Get("/regions/cfg/:id", getRegionConfig)
|
||||||
cgi.Get("/applications", getApplications)
|
cgi.Get("/applications", getApplications)
|
||||||
cgi.Get("/applications/logs/:id", getApplicationLogs)
|
cgi.Get("/applications/:id/logs", getApplicationLogs)
|
||||||
|
cgi.Post("/applications/:id/start", letApplicationStart)
|
||||||
|
cgi.Post("/applications/:id/stop", letApplicationStop)
|
||||||
|
cgi.Post("/applications/:id/restart", letApplicationRestart)
|
||||||
|
|
||||||
|
cgi.Post("/reload", doReload)
|
||||||
}
|
}
|
||||||
|
|
||||||
webhooks := app.Group("/webhooks").Name("WebHooks")
|
webhooks := app.Group("/webhooks").Name("WebHooks")
|
||||||
|
@@ -1,10 +1,11 @@
|
|||||||
package sideload
|
package sideload
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"code.smartsheep.studio/goatworks/roadsign/pkg/navi"
|
"git.solsynth.dev/goatworks/roadsign/pkg/navi"
|
||||||
"code.smartsheep.studio/goatworks/roadsign/pkg/warden"
|
"git.solsynth.dev/goatworks/roadsign/pkg/warden"
|
||||||
"github.com/gofiber/fiber/v2"
|
"github.com/gofiber/fiber/v2"
|
||||||
"github.com/samber/lo"
|
"github.com/samber/lo"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func getStats(c *fiber.Ctx) error {
|
func getStats(c *fiber.Ctx) error {
|
||||||
@@ -23,5 +24,10 @@ func getStats(c *fiber.Ctx) error {
|
|||||||
"locations": len(locations),
|
"locations": len(locations),
|
||||||
"destinations": len(destinations),
|
"destinations": len(destinations),
|
||||||
"applications": len(applications),
|
"applications": len(applications),
|
||||||
|
"uptime": time.Since(navi.R.Metrics.StartupAt).Milliseconds(),
|
||||||
|
"traffic": fiber.Map{
|
||||||
|
"total": navi.R.Metrics.TotalTraffic,
|
||||||
|
"unique_client": len(navi.R.Metrics.TrafficFrom),
|
||||||
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
24
pkg/sideload/view/.gitignore
vendored
24
pkg/sideload/view/.gitignore
vendored
@@ -1,24 +0,0 @@
|
|||||||
# Logs
|
|
||||||
logs
|
|
||||||
*.log
|
|
||||||
npm-debug.log*
|
|
||||||
yarn-debug.log*
|
|
||||||
yarn-error.log*
|
|
||||||
pnpm-debug.log*
|
|
||||||
lerna-debug.log*
|
|
||||||
|
|
||||||
node_modules
|
|
||||||
dist
|
|
||||||
dist-ssr
|
|
||||||
*.local
|
|
||||||
|
|
||||||
# Editor directories and files
|
|
||||||
.vscode/*
|
|
||||||
!.vscode/extensions.json
|
|
||||||
.idea
|
|
||||||
.DS_Store
|
|
||||||
*.suo
|
|
||||||
*.ntvs*
|
|
||||||
*.njsproj
|
|
||||||
*.sln
|
|
||||||
*.sw?
|
|
@@ -1,6 +0,0 @@
|
|||||||
package view
|
|
||||||
|
|
||||||
import "embed"
|
|
||||||
|
|
||||||
//go:embed all:dist
|
|
||||||
var FS embed.FS
|
|
@@ -1,13 +0,0 @@
|
|||||||
<!doctype html>
|
|
||||||
<html lang="en">
|
|
||||||
<head>
|
|
||||||
<meta charset="UTF-8" />
|
|
||||||
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
||||||
<title>RoadSign Sideload</title>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<div id="root"></div>
|
|
||||||
<script type="module" src="/src/index.tsx"></script>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
@@ -1,24 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "roadsign-sideload",
|
|
||||||
"private": true,
|
|
||||||
"version": "0.0.0",
|
|
||||||
"type": "module",
|
|
||||||
"scripts": {
|
|
||||||
"dev": "vite",
|
|
||||||
"build": "tsc && vite build",
|
|
||||||
"preview": "vite preview"
|
|
||||||
},
|
|
||||||
"dependencies": {
|
|
||||||
"@solidjs/router": "^0.10.10",
|
|
||||||
"solid-js": "^1.8.7"
|
|
||||||
},
|
|
||||||
"devDependencies": {
|
|
||||||
"autoprefixer": "^10.4.17",
|
|
||||||
"daisyui": "^4.6.0",
|
|
||||||
"postcss": "^8.4.33",
|
|
||||||
"tailwindcss": "^3.4.1",
|
|
||||||
"typescript": "^5.2.2",
|
|
||||||
"vite": "^5.0.8",
|
|
||||||
"vite-plugin-solid": "^2.8.0"
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,6 +0,0 @@
|
|||||||
export default {
|
|
||||||
plugins: {
|
|
||||||
tailwindcss: {},
|
|
||||||
autoprefixer: {},
|
|
||||||
},
|
|
||||||
}
|
|
@@ -1,3 +0,0 @@
|
|||||||
@tailwind base;
|
|
||||||
@tailwind components;
|
|
||||||
@tailwind utilities;
|
|
@@ -1,17 +0,0 @@
|
|||||||
import "./index.css";
|
|
||||||
|
|
||||||
/* @refresh reload */
|
|
||||||
import { render } from "solid-js/web";
|
|
||||||
|
|
||||||
import { Route, Router } from "@solidjs/router";
|
|
||||||
|
|
||||||
import RootLayout from "./layouts/RootLayout";
|
|
||||||
import Dashboard from "./pages/dashboard";
|
|
||||||
|
|
||||||
const root = document.getElementById("root");
|
|
||||||
|
|
||||||
render(() => (
|
|
||||||
<Router root={RootLayout}>
|
|
||||||
<Route path="/" component={Dashboard} />
|
|
||||||
</Router>
|
|
||||||
), root!);
|
|
@@ -1,11 +0,0 @@
|
|||||||
import Navbar from "./shared/Navbar";
|
|
||||||
|
|
||||||
export default function RootLayout(props: any) {
|
|
||||||
return (
|
|
||||||
<div>
|
|
||||||
<Navbar />
|
|
||||||
|
|
||||||
<main class="h-[calc(100vh-64px)]">{props.children}</main>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
@@ -1,62 +0,0 @@
|
|||||||
import { For } from "solid-js";
|
|
||||||
|
|
||||||
interface MenuItem {
|
|
||||||
label: string;
|
|
||||||
href: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export default function Navbar() {
|
|
||||||
const nav: MenuItem[] = [{ label: "Dashboard", href: "/" }];
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div class="navbar bg-base-100 shadow-md">
|
|
||||||
<div class="navbar-start">
|
|
||||||
<div class="dropdown">
|
|
||||||
<div tabIndex={0} role="button" class="btn btn-ghost lg:hidden">
|
|
||||||
<svg
|
|
||||||
xmlns="http://www.w3.org/2000/svg"
|
|
||||||
class="h-5 w-5"
|
|
||||||
fill="none"
|
|
||||||
viewBox="0 0 24 24"
|
|
||||||
stroke="currentColor"
|
|
||||||
>
|
|
||||||
<path
|
|
||||||
stroke-linecap="round"
|
|
||||||
stroke-linejoin="round"
|
|
||||||
stroke-width="2"
|
|
||||||
d="M4 6h16M4 12h8m-8 6h16"
|
|
||||||
/>
|
|
||||||
</svg>
|
|
||||||
</div>
|
|
||||||
<ul
|
|
||||||
tabIndex={0}
|
|
||||||
class="menu menu-sm dropdown-content mt-3 z-[1] p-2 shadow bg-base-100 rounded-box w-52"
|
|
||||||
>
|
|
||||||
<For each={nav}>
|
|
||||||
{(item) => (
|
|
||||||
<li>
|
|
||||||
<a href={item.href}>{item.label}</a>
|
|
||||||
</li>
|
|
||||||
)}
|
|
||||||
</For>
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
<a href="/" class="btn btn-ghost text-xl">
|
|
||||||
RoadSign
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
<div class="navbar-center hidden lg:flex">
|
|
||||||
<ul class="menu menu-horizontal px-1">
|
|
||||||
<For each={nav}>
|
|
||||||
{(item) => (
|
|
||||||
<li>
|
|
||||||
<a href={item.href}>{item.label}</a>
|
|
||||||
</li>
|
|
||||||
)}
|
|
||||||
</For>
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
<div class="navbar-end"></div>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
@@ -1,10 +0,0 @@
|
|||||||
export default function Dashboard() {
|
|
||||||
return (
|
|
||||||
<div class="h-full w-full flex justify-center items-center">
|
|
||||||
<div class="max-w-96 text-center">
|
|
||||||
<h1 class="text-2xl font-bold">Hold on</h1>
|
|
||||||
<p>Our brand new sideload administration panel is still in progress. For now, you can use sideload api and roadsign cli.</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
1
pkg/sideload/view/src/vite-env.d.ts
vendored
1
pkg/sideload/view/src/vite-env.d.ts
vendored
@@ -1 +0,0 @@
|
|||||||
/// <reference types="vite/client" />
|
|
@@ -1,44 +0,0 @@
|
|||||||
/** @type {import('tailwindcss').Config} */
|
|
||||||
export default {
|
|
||||||
content: ["./src/**/*.{js,jsx,ts,tsx}"],
|
|
||||||
theme: {
|
|
||||||
extend: {},
|
|
||||||
},
|
|
||||||
daisyui: {
|
|
||||||
themes: [
|
|
||||||
{
|
|
||||||
light: {
|
|
||||||
...require("daisyui/src/theming/themes")["light"],
|
|
||||||
primary: "#4750a3",
|
|
||||||
secondary: "#93c5fd",
|
|
||||||
accent: "#0f766e",
|
|
||||||
info: "#67e8f9",
|
|
||||||
success: "#15803d",
|
|
||||||
warning: "#f97316",
|
|
||||||
error: "#dc2626",
|
|
||||||
"--rounded-box": "0",
|
|
||||||
"--rounded-btn": "0",
|
|
||||||
"--rounded-badge": "0",
|
|
||||||
"--tab-radius": "0",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
dark: {
|
|
||||||
...require("daisyui/src/theming/themes")["dark"],
|
|
||||||
primary: "#4750a3",
|
|
||||||
secondary: "#93c5fd",
|
|
||||||
accent: "#0f766e",
|
|
||||||
info: "#67e8f9",
|
|
||||||
success: "#15803d",
|
|
||||||
warning: "#f97316",
|
|
||||||
error: "#dc2626",
|
|
||||||
"--rounded-box": "0",
|
|
||||||
"--rounded-btn": "0",
|
|
||||||
"--rounded-badge": "0",
|
|
||||||
"--tab-radius": "0",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
plugins: [require("daisyui")],
|
|
||||||
};
|
|
@@ -1,26 +0,0 @@
|
|||||||
{
|
|
||||||
"compilerOptions": {
|
|
||||||
"target": "ES2020",
|
|
||||||
"useDefineForClassFields": true,
|
|
||||||
"module": "ESNext",
|
|
||||||
"lib": ["ES2020", "DOM", "DOM.Iterable"],
|
|
||||||
"skipLibCheck": true,
|
|
||||||
|
|
||||||
/* Bundler mode */
|
|
||||||
"moduleResolution": "bundler",
|
|
||||||
"allowImportingTsExtensions": true,
|
|
||||||
"resolveJsonModule": true,
|
|
||||||
"isolatedModules": true,
|
|
||||||
"noEmit": true,
|
|
||||||
"jsx": "preserve",
|
|
||||||
"jsxImportSource": "solid-js",
|
|
||||||
|
|
||||||
/* Linting */
|
|
||||||
"strict": true,
|
|
||||||
"noUnusedLocals": true,
|
|
||||||
"noUnusedParameters": true,
|
|
||||||
"noFallthroughCasesInSwitch": true
|
|
||||||
},
|
|
||||||
"include": ["src"],
|
|
||||||
"references": [{ "path": "./tsconfig.node.json" }]
|
|
||||||
}
|
|
@@ -1,10 +0,0 @@
|
|||||||
{
|
|
||||||
"compilerOptions": {
|
|
||||||
"composite": true,
|
|
||||||
"skipLibCheck": true,
|
|
||||||
"module": "ESNext",
|
|
||||||
"moduleResolution": "bundler",
|
|
||||||
"allowSyntheticDefaultImports": true
|
|
||||||
},
|
|
||||||
"include": ["vite.config.ts"]
|
|
||||||
}
|
|
@@ -1,6 +0,0 @@
|
|||||||
import { defineConfig } from 'vite'
|
|
||||||
import solid from 'vite-plugin-solid'
|
|
||||||
|
|
||||||
export default defineConfig({
|
|
||||||
plugins: [solid()],
|
|
||||||
})
|
|
File diff suppressed because it is too large
Load Diff
@@ -2,10 +2,11 @@ package warden
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"github.com/rs/zerolog/log"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/samber/lo"
|
"github.com/samber/lo"
|
||||||
@@ -87,15 +88,16 @@ func (v *AppInstance) Start() error {
|
|||||||
// Monitor
|
// Monitor
|
||||||
go func() {
|
go func() {
|
||||||
for {
|
for {
|
||||||
if v.Cmd.Process == nil || v.Cmd.ProcessState == nil {
|
if v.Cmd != nil && v.Cmd.Process == nil {
|
||||||
v.Status = AppStarting
|
v.Status = AppStarting
|
||||||
} else if !v.Cmd.ProcessState.Exited() {
|
} else if v.Cmd != nil && v.Cmd.ProcessState == nil {
|
||||||
v.Status = AppStarted
|
v.Status = AppStarted
|
||||||
} else {
|
} else {
|
||||||
v.Status = lo.Ternary(v.Cmd.ProcessState.Success(), AppExited, AppFailure)
|
v.Status = lo.Ternary(v.Cmd == nil, AppExited, AppFailure)
|
||||||
|
v.Cmd = nil
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
time.Sleep(100 * time.Millisecond)
|
time.Sleep(1000 * time.Millisecond)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
@@ -104,8 +106,13 @@ func (v *AppInstance) Start() error {
|
|||||||
|
|
||||||
func (v *AppInstance) Stop() error {
|
func (v *AppInstance) Stop() error {
|
||||||
if v.Cmd != nil && v.Cmd.Process != nil {
|
if v.Cmd != nil && v.Cmd.Process != nil {
|
||||||
if err := v.Cmd.Process.Signal(os.Interrupt); err != nil {
|
if err := v.Cmd.Process.Signal(syscall.SIGTERM); err != nil {
|
||||||
v.Cmd.Process.Kill()
|
log.Warn().Int("pid", v.Cmd.Process.Pid).Err(err).Msgf("Failed to send SIGTERM to process...")
|
||||||
|
if err = v.Cmd.Process.Kill(); err != nil {
|
||||||
|
log.Error().Int("pid", v.Cmd.Process.Pid).Err(err).Msgf("Failed to kill process...")
|
||||||
|
} else {
|
||||||
|
v.Cmd = nil
|
||||||
|
}
|
||||||
return err
|
return err
|
||||||
} else {
|
} else {
|
||||||
v.Cmd = nil
|
v.Cmd = nil
|
||||||
|
@@ -6,3 +6,8 @@ type Application struct {
|
|||||||
Command []string `json:"command" toml:"command"`
|
Command []string `json:"command" toml:"command"`
|
||||||
Environment []string `json:"environment" toml:"environment"`
|
Environment []string `json:"environment" toml:"environment"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ApplicationInfo struct {
|
||||||
|
Application
|
||||||
|
Status AppStatus `json:"status"`
|
||||||
|
}
|
||||||
|
@@ -1,18 +1,21 @@
|
|||||||
|
id = "central"
|
||||||
|
|
||||||
[debug]
|
[debug]
|
||||||
print_routes = false
|
print_routes = false
|
||||||
|
|
||||||
|
[sideload]
|
||||||
|
ports = [":81"]
|
||||||
|
secured_ports = []
|
||||||
|
trusted_proxies = ["localhost"]
|
||||||
|
|
||||||
[hypertext]
|
[hypertext]
|
||||||
sideload_ports = [":81"]
|
|
||||||
sideload_secured_ports = []
|
|
||||||
ports = [":8000"]
|
ports = [":8000"]
|
||||||
secured_ports = []
|
secured_ports = []
|
||||||
|
force_https = false
|
||||||
|
|
||||||
[hypertext.certificate]
|
# [[hypertext.certificate]]
|
||||||
redirect = false
|
# key = "./certs/privkey.pem"
|
||||||
sideload_key = "./cert.key"
|
# pem = "./certs/fullchain.pem"
|
||||||
sideload_pem = "./cert.pem"
|
|
||||||
key = "./cert.key"
|
|
||||||
pem = "./cert.pem"
|
|
||||||
|
|
||||||
[hypertext.limitation]
|
[hypertext.limitation]
|
||||||
max_body_size = 549_755_813_888 # 512 GiB
|
max_body_size = 549_755_813_888 # 512 GiB
|
||||||
@@ -27,9 +30,7 @@ capture_traces = true
|
|||||||
|
|
||||||
[performance]
|
[performance]
|
||||||
traces_limit = 256
|
traces_limit = 256
|
||||||
network_timeout = 3_000
|
|
||||||
prefork = false
|
prefork = false
|
||||||
|
|
||||||
[security]
|
[security]
|
||||||
sideload_trusted_proxies = ["localhost"]
|
|
||||||
credential = "e81f43f32d934271af6322e5376f5f59"
|
credential = "e81f43f32d934271af6322e5376f5f59"
|
||||||
|
5
test/data/.gitignore
vendored
5
test/data/.gitignore
vendored
@@ -1,3 +1,2 @@
|
|||||||
/ssr
|
/capital
|
||||||
/spa
|
/static-files
|
||||||
/congress
|
|
9
test/roadsign-spa/config/example.toml
Normal file
9
test/roadsign-spa/config/example.toml
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
id = "example"
|
||||||
|
|
||||||
|
[[locations]]
|
||||||
|
id = "example-location"
|
||||||
|
host = ["localhost:8000"]
|
||||||
|
path = ["/"]
|
||||||
|
[[locations.destinations]]
|
||||||
|
id = "example-destination"
|
||||||
|
uri = "files://../data/spa?fallback=index.html"
|
@@ -1,8 +0,0 @@
|
|||||||
name: Example Site
|
|
||||||
rules:
|
|
||||||
- host: ["localhost:8000"]
|
|
||||||
path: ["/"]
|
|
||||||
upstreams:
|
|
||||||
- id: example
|
|
||||||
name: Benchmarking Data
|
|
||||||
uri: files://../data/spa?fallback=index.html
|
|
15
test/roadsign-ssr/config/example.toml
Normal file
15
test/roadsign-ssr/config/example.toml
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
id = "capital"
|
||||||
|
|
||||||
|
[[locations]]
|
||||||
|
id = "capital"
|
||||||
|
hosts = ["localhost:8000"]
|
||||||
|
paths = ["/"]
|
||||||
|
[[locations.destinations]]
|
||||||
|
id = "capital-destination"
|
||||||
|
uri = "http://localhost:3000"
|
||||||
|
|
||||||
|
[[applications]]
|
||||||
|
id = "capital-app"
|
||||||
|
workdir = "../data/capital"
|
||||||
|
command = ["node", "server/index.mjs"]
|
||||||
|
environment = []
|
@@ -1,12 +0,0 @@
|
|||||||
name: Example Site
|
|
||||||
rules:
|
|
||||||
- host: ["localhost:8000"]
|
|
||||||
path: ["/"]
|
|
||||||
upstreams:
|
|
||||||
- id: example
|
|
||||||
name: Benchmarking Data
|
|
||||||
uri: http://localhost:3000
|
|
||||||
processes:
|
|
||||||
- id: nuxt-ssr
|
|
||||||
workdir: ../data/ssr
|
|
||||||
command: ["node", ".output/server/index.mjs"]
|
|
@@ -1,18 +1,21 @@
|
|||||||
|
id = "central-dc"
|
||||||
|
|
||||||
[debug]
|
[debug]
|
||||||
print_routes = true
|
print_routes = false
|
||||||
|
|
||||||
|
[sideload]
|
||||||
|
ports = [":81"]
|
||||||
|
secured_ports = []
|
||||||
|
trusted_proxies = ["localhost"]
|
||||||
|
|
||||||
[hypertext]
|
[hypertext]
|
||||||
sideload_ports = [":81"]
|
|
||||||
sideload_secured_ports = []
|
|
||||||
ports = [":8000"]
|
ports = [":8000"]
|
||||||
secured_ports = []
|
secured_ports = []
|
||||||
|
force_https = false
|
||||||
|
|
||||||
[hypertext.certificate]
|
# [[hypertext.certificate]]
|
||||||
redirect = false
|
# key = "./certs/privkey.pem"
|
||||||
sideload_key = "./cert.key"
|
# pem = "./certs/fullchain.pem"
|
||||||
sideload_pem = "./cert.pem"
|
|
||||||
key = "./cert.key"
|
|
||||||
pem = "./cert.pem"
|
|
||||||
|
|
||||||
[hypertext.limitation]
|
[hypertext.limitation]
|
||||||
max_body_size = 549_755_813_888 # 512 GiB
|
max_body_size = 549_755_813_888 # 512 GiB
|
||||||
@@ -21,11 +24,13 @@ max_qps = -1
|
|||||||
[paths]
|
[paths]
|
||||||
configs = "./config"
|
configs = "./config"
|
||||||
|
|
||||||
[performance]
|
[telemetry]
|
||||||
request_logging = true
|
request_logging = true
|
||||||
network_timeout = 3_000
|
capture_traces = true
|
||||||
|
|
||||||
|
[performance]
|
||||||
|
traces_limit = 256
|
||||||
prefork = false
|
prefork = false
|
||||||
|
|
||||||
[security]
|
[security]
|
||||||
sideload_trusted_proxies = ["localhost"]
|
|
||||||
credential = "e81f43f32d934271af6322e5376f5f59"
|
credential = "e81f43f32d934271af6322e5376f5f59"
|
||||||
|
9
test/roadsign-with-prefork/config/example.toml
Normal file
9
test/roadsign-with-prefork/config/example.toml
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
id = "example"
|
||||||
|
|
||||||
|
[[locations]]
|
||||||
|
id = "example-location"
|
||||||
|
host = ["localhost:8000"]
|
||||||
|
path = ["/"]
|
||||||
|
[[locations.destinations]]
|
||||||
|
id = "example-destination"
|
||||||
|
uri = "files://../data/spa?fallback=index.html"
|
@@ -1,8 +0,0 @@
|
|||||||
name: Example Site
|
|
||||||
rules:
|
|
||||||
- host: ["localhost:8000"]
|
|
||||||
path: ["/"]
|
|
||||||
upstreams:
|
|
||||||
- id: example
|
|
||||||
name: Benchmarking Data
|
|
||||||
uri: files://../data
|
|
9
test/roadsign/config/example.toml
Normal file
9
test/roadsign/config/example.toml
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
id = "static-files"
|
||||||
|
|
||||||
|
[[locations]]
|
||||||
|
id = "static-files-loc"
|
||||||
|
hosts = ["localhost:8000"]
|
||||||
|
paths = ["/"]
|
||||||
|
[[locations.destinations]]
|
||||||
|
id = "static-files-des"
|
||||||
|
uri = "files://../data/static-files"
|
@@ -1,8 +0,0 @@
|
|||||||
name: Example Site
|
|
||||||
rules:
|
|
||||||
- host: ["localhost:8000"]
|
|
||||||
path: ["/"]
|
|
||||||
upstreams:
|
|
||||||
- id: example
|
|
||||||
name: Benchmarking Data
|
|
||||||
uri: files://../data
|
|
@@ -1,18 +1,21 @@
|
|||||||
|
id = "central-dc"
|
||||||
|
|
||||||
[debug]
|
[debug]
|
||||||
print_routes = true
|
print_routes = false
|
||||||
|
|
||||||
|
[sideload]
|
||||||
|
ports = [":81"]
|
||||||
|
secured_ports = []
|
||||||
|
trusted_proxies = ["localhost"]
|
||||||
|
|
||||||
[hypertext]
|
[hypertext]
|
||||||
sideload_ports = [":81"]
|
|
||||||
sideload_secured_ports = []
|
|
||||||
ports = [":8000"]
|
ports = [":8000"]
|
||||||
secured_ports = []
|
secured_ports = []
|
||||||
|
force_https = false
|
||||||
|
|
||||||
[hypertext.certificate]
|
# [[hypertext.certificate]]
|
||||||
redirect = false
|
# key = "./certs/privkey.pem"
|
||||||
sideload_key = "./cert.key"
|
# pem = "./certs/fullchain.pem"
|
||||||
sideload_pem = "./cert.pem"
|
|
||||||
key = "./cert.key"
|
|
||||||
pem = "./cert.pem"
|
|
||||||
|
|
||||||
[hypertext.limitation]
|
[hypertext.limitation]
|
||||||
max_body_size = 549_755_813_888 # 512 GiB
|
max_body_size = 549_755_813_888 # 512 GiB
|
||||||
@@ -21,11 +24,13 @@ max_qps = -1
|
|||||||
[paths]
|
[paths]
|
||||||
configs = "./config"
|
configs = "./config"
|
||||||
|
|
||||||
[performance]
|
[telemetry]
|
||||||
request_logging = true
|
request_logging = true
|
||||||
network_timeout = 3_000
|
capture_traces = true
|
||||||
|
|
||||||
|
[performance]
|
||||||
|
traces_limit = 256
|
||||||
prefork = false
|
prefork = false
|
||||||
|
|
||||||
[security]
|
[security]
|
||||||
sideload_trusted_proxies = ["localhost"]
|
|
||||||
credential = "e81f43f32d934271af6322e5376f5f59"
|
credential = "e81f43f32d934271af6322e5376f5f59"
|
||||||
|
Reference in New Issue
Block a user