Skip to content

Commit

Permalink
initial state
Browse files Browse the repository at this point in the history
  • Loading branch information
Spookerton committed Aug 28, 2022
0 parents commit 14ed992
Show file tree
Hide file tree
Showing 16 changed files with 337 additions and 0 deletions.
Empty file added .codebeatignore
Empty file.
3 changes: 3 additions & 0 deletions .codebeatsettings
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"BLOCK_NESTING": [5, 6, 7, 8]
}
9 changes: 9 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
indent_style = space
indent_size = 2
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.js text eol=lf
14 changes: 14 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Require reviews Core for changes to configuration, license, etc

.github/ @Baystation12/Core
.vscode/ @Baystation12/Core

.codebeatsettings @Baystation12/Core
.codebeatignore @Baystation12/Core
.editorconfig @Baystation12/Core
.gitattributes @Baystation12/Core
.gitignore @Baystation12/Core

/LICENSE.md @Baystation12/Core
/README.md @Baystation12/Core
/package.json @Baystation12/Core
6 changes: 6 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: 2
updates:
- package-ecosystem: "npm"
directory: "/"
schedule:
interval: "daily"
37 changes: 37 additions & 0 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: CodeQL
on:
push:
branches:
- main
pull_request:
branches:
- main
schedule:
- cron: 22 2 * * 0
jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
permissions:
security-events: write
strategy:
fail-fast: false
matrix:
language:
- javascript
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Setup Node.js environment
uses: actions/[email protected]
with:
node-version: 18.x
architecture: x64
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}
- name: Autobuild
uses: github/codeql-action/autobuild@v2
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
104 changes: 104 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# 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/

# TypeScript v1 declaration files
typings/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# 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 variables file
.env
.env.test

# parcel-bundler cache (https://parceljs.org/)
.cache

# Next.js build output
.next

# Nuxt.js build / generate output
.nuxt
dist

# Gatsby files
.cache/
# 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

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port
6 changes: 6 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"recommendations": [
"rome.rome",
"eamodio.gitlens"
]
}
9 changes: 9 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"files.eol": "\n",
"files.encoding": "utf8",
"files.insertFinalNewline": true,
"files.trimFinalNewlines": true,
"files.trimTrailingWhitespace": true,
"editor.insertSpaces": true,
"editor.tabSize": 2
}
7 changes: 7 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
ISC License (ISC) <https://opensource.org/licenses/ISC>

Copyright (c) 2022 Baystation <https://github.com/baystation12>

Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Warden [![License: ISC v3](https://img.shields.io/badge/License-ISC-informational.svg)](https://opensource.org/licenses/ISC) [![CodeQL](https://github.com/Baystation12/warden/workflows/CodeQL/badge.svg)](https://github.com/baystation12/warden/actions) [![codebeat badge](https://codebeat.co/badges/aff3ecf7-e0a9-42c8-864b-ed8c4106f9de)](https://codebeat.co/projects/github-com-baystation12-warden-main)

[Website](https://bay.ss13.me) - [Discord](https://bay.ss13.me/discord)

A simple front proxy that will permit payload inspection and connection bans.
4 changes: 4 additions & 0 deletions config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const port = 0
export const host = '0.0.0.0'
export const game_port = 0
export const game_host = '127.0.0.1'
16 changes: 16 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "warden",
"license": "ISC",
"version": "0.1.0",
"repository": "https://github.com/baystation12/warden",
"bugs": "https://github.com/baystation12/warden/issues",
"private": true,
"type": "module",
"main": "src/index.js",
"engines": {
"node": ">=16"
},
"contributors": [
"spookerton <[email protected]> (https://github.com/spookerton)"
]
}
3 changes: 3 additions & 0 deletions rome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{

}
113 changes: 113 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
import * as net from 'node:net'
import * as readline from 'node:readline'
import * as config from '../config.js'

process.on('uncaughtException', function (error) {
console.error('Uncaught Error', error)
})

let connections = {}

let blockedAddresses = {}

let listener = new net.Server({
allowHalfOpen: false,
noDelay: true
}).on('error', function (error) {
console.error('listener error', error)
listener.close()
}).on('close', function () {
for (let address in connections)
connections[address].remote.close()
console.log('listener closed')
}).on('connection', function (remote) {
const address = remote.remoteAddress
if (blockedAddresses[address])
return remote.destroy()
console.log('new connection from', address)
let local = new net.Socket({
allowHalfOpen: false,
}).on('error', function (error) {
remote.end()
local.end()
}).on('close', function () {
remote.end()
}).on('data', function (data) {
remote.write(data)
})
connections[address] = { remote, local }
remote.on('error', function (error) {
remote.end()
local.end()
}).on('close', function () {
delete connections[address]
local.end()
}).on('data', function (data) {
if (inspect(data, local))
return remote.end()
local.write(data)
})
local.connect({
port: config.game_port,
host: config.game_host,
family: 4,
noDelay: true
})
}).listen(config.port, config.host, function () {
console.log('Listener ready on', listener.address().port)
readline.createInterface({
input: process.stdin,
output: process.stdout,
prompt: '%> '
}).on('close', function () {
listener.close()
process.exit(0)
}).on('line', function (line) {
let [command, ...params] = line.trim().split(/\s+/)
command = commands[command.toLowerCase()]
if (!command)
console.log('No such command, try "help"')
else
command(params, this)
this.prompt()
}).prompt()
}).unref()

let commands = {
'help': function () {
let result = []
for (let command in commands)
result.push(command)
console.log(result.join('\n'))
},
'exit': function (params, con) {
con.close()
},
'connections': function (params, con) {
let result = []
for (let address in connections)
result.push(address)
console.log(result.join('\n'))
},
'block': function (params, con) {
const address = params.join('')
if (blockedAddresses[address])
return console.log('address already blocked')
blockedAddresses[address] = true
if (!connections[address])
return console.log('blocked')
connections[address].remote.end()
console.log('blocked & kicked')
},
'allow': function (params, con) {
const address = params.join('')
if (!blockedAddresses[address])
return console.log('address already allowed')
delete blockedAddresses[address]
console.log('allowed')
}
}

function inspect (data, local) {
return false
}

0 comments on commit 14ed992

Please sign in to comment.