Stop using config and toml as dependencies Stop passing around config variables through function calls Add config.ts and pull the values you need directly in the files Remove irc.js for incoming new IRC solution Rename controller to index because that was stupid Minor git bullshit with the config folder Change to yaml as a config formatmerge-requests/7/head
parent
681802dbaf
commit
f7733b9507
@ -1,8 +1,6 @@ |
||||
node_modules |
||||
site/live |
||||
config/local.toml |
||||
config/jwt.pem |
||||
config/generated.toml |
||||
config/bans.db |
||||
config/**/* |
||||
!config/.gitkeep |
||||
install/db_setup.sql |
||||
build/** |
||||
|
@ -1,58 +0,0 @@ |
||||
#DO NOT EDIT THIS FILE |
||||
#ALL CHANGES SHOULD GO IN LOCAL.TOML |
||||
[bcrypt] |
||||
saltRounds = 12 |
||||
|
||||
[satyr] |
||||
name = '' |
||||
domain = '' |
||||
registration = false |
||||
restrictedNames = ['live'] |
||||
rootredirect = '/users/live' |
||||
|
||||
[ircd] |
||||
enable = false |
||||
port = 6667 |
||||
sid = '' |
||||
server = '' |
||||
pass = '' |
||||
vhost = 'web.satyr.net' |
||||
|
||||
[database] |
||||
host = 'localhost' |
||||
user = 'satyr' |
||||
password = '' |
||||
database = 'satyr_db' |
||||
connectionLimit = '50' |
||||
connectionTimeout = '1000' |
||||
insecureAuth = false |
||||
debug = false |
||||
|
||||
[server] |
||||
logs = 0 |
||||
api = false |
||||
api_user = false |
||||
api_pass = false |
||||
|
||||
[server.rtmp] |
||||
port = 1935 |
||||
chunk_size = 6000 |
||||
gop_cache = true |
||||
ping = 30 |
||||
ping_timeout = 60 |
||||
|
||||
[server.http] |
||||
hsts = false |
||||
directory = './site' |
||||
port = 8000 |
||||
|
||||
[media] |
||||
record = false |
||||
publicEndpoint = 'live' |
||||
privateEndpoint = 'stream' |
||||
ffmpeg = '' |
||||
|
||||
[transcode] |
||||
adapative = false |
||||
variants = 3 |
||||
format = 'dash' |
@ -0,0 +1,24 @@ |
||||
satyr: |
||||
name: '<iname>' |
||||
domain: '<domain>' |
||||
email: '<email>' |
||||
registration: false |
||||
|
||||
media: |
||||
record: false |
||||
ffmpeg: '<ffmpeg>' |
||||
|
||||
http: |
||||
# uncomment to set HSTS when SSL is ready |
||||
#hsts: true |
||||
|
||||
database: |
||||
user: '<dbuser>' |
||||
password: '<dbpass>' |
||||
database: '<dbname>' |
||||
host: '<dbhost>' |
||||
|
||||
transcode: |
||||
adaptive: false |
||||
format: dash |
||||
variants: 3 |
@ -1,19 +0,0 @@ |
||||
[satyr] |
||||
name = '<iname>' |
||||
domain = '<domain>' |
||||
email = '<email>' |
||||
registration = false |
||||
|
||||
[media] |
||||
record = false |
||||
ffmpeg = '<ffmpeg>' |
||||
|
||||
[server.http] |
||||
# uncomment to set HSTS when SSL is enabled |
||||
# hsts = true |
||||
|
||||
[database] |
||||
user = '<dbuser>' |
||||
password = '<dbpass>' |
||||
database = '<dbname>' |
||||
host = '<dbhost>' |
@ -0,0 +1,49 @@ |
||||
import {parseAsYaml as parse} from "parse-yaml"; |
||||
import {readFileSync as read} from "fs"; |
||||
var localconfig: Object = parse(read('config/config.yml')); |
||||
const config: Object = { |
||||
crypto: Object.assign({
|
||||
saltRounds: 12
|
||||
}, localconfig['crypto']), |
||||
satyr: Object.assign({ |
||||
name: '', |
||||
domain: '', |
||||
registration: false, |
||||
restrictedNames: [ 'live' ], |
||||
rootredirect: '/users/live', |
||||
version: process.env.npm_package_version, |
||||
}, localconfig['satyr']), |
||||
ircd: Object.assign({ |
||||
port: 6667, |
||||
}, localconfig['ircd']), |
||||
database: Object.assign({ |
||||
host: 'localhost', |
||||
user: 'satyr', |
||||
password: '', |
||||
database: 'satyr_db', |
||||
connectionLimit: '50', |
||||
connectionTimeout: '1000', |
||||
insecureAuth: false, |
||||
debug: false }, localconfig['database']), |
||||
rtmp: Object.assign({ |
||||
port: 1935, |
||||
chunk_size: 6000, |
||||
gop_cache: true, |
||||
ping: 30, |
||||
ping_timeout: 60 }, localconfig['rtmp']), |
||||
http: Object.assign({
|
||||
hsts: false, directory: './site', port: 8000
|
||||
}, localconfig['http']), |
||||
media: Object.assign({ |
||||
record: false, |
||||
publicEndpoint: 'live', |
||||
privateEndpoint: 'stream', |
||||
ffmpeg: '' |
||||
}, localconfig['media']), |
||||
transcode: Object.assign({
|
||||
adapative: false,
|
||||
variants: 3,
|
||||
format: 'dash'
|
||||
}, localconfig['transcode']) |
||||
}; |
||||
export { config }; |
@ -1,67 +0,0 @@ |
||||
import * as mediaserver from "./server"; |
||||
import * as db from "./database"; |
||||
import * as api from "./api"; |
||||
import * as http from "./http"; |
||||
import * as cleanup from "./cleanup"; |
||||
import * as config from "config"; |
||||
|
||||
async function run() { |
||||
const dbcfg: object = config.database; |
||||
const bcryptcfg: object = config.bcrypt; |
||||
const satyr: object = { |
||||
privateEndpoint: config.media.privateEndpoint, |
||||
publicEndpoint: config.media.publicEndpoint, |
||||
record: config.media.record, |
||||
registration: config.satyr.registration, |
||||
webFormat: config.satyr.webFormat, |
||||
restrictedNames: config.satyr.restrictedNames, |
||||
name: config.satyr.name, |
||||
domain: config.satyr.domain, |
||||
email: config.satyr.email, |
||||
rootredirect: config.satyr.rootredirect, |
||||
version: process.env.npm_package_version, |
||||
directory: config.server.http.directory, |
||||
ffmpeg: config.media.ffmpeg |
||||
}; |
||||
const nms: object = { |
||||
logType: config.server.logs, |
||||
rtmp: { |
||||
port: config.server.rtmp.port, |
||||
chunk_size: config.server.rtmp.chunk_size, |
||||
gop_cache: config.server.rtmp.gop_cache, |
||||
ping: config.server.rtmp.ping, |
||||
ping_timeout: config.server.rtmp.ping_timeout, |
||||
}, |
||||
/*http: { |
||||
port: config.server.http.port + 1, |
||||
mediaroot: config.server.http.directory, |
||||
allow_origin: config.server.http.allow_origin |
||||
}, |
||||
trans: { |
||||
ffmpeg: config.media.ffmpeg, |
||||
tasks: [ |
||||
{ |
||||
app: config.media.publicEndpoint, |
||||
hls: config.transcode.hls, |
||||
hlsFlags: config.transcode.hlsFlags, |
||||
dash: config.transcode.dash, |
||||
dashFlags: config.transcode.dashFlags |
||||
} |
||||
] |
||||
},*/ |
||||
auth: { |
||||
api: config.server.api, |
||||
api_user: config.server.api_user, |
||||
api_pass: config.server.api_pass |
||||
}, |
||||
transcode: config.transcode |
||||
}; |
||||
db.init(dbcfg, bcryptcfg); |
||||
await cleanup.init(); |
||||
api.init(satyr); |
||||
http.init(satyr, config.server.http, config.ircd); |
||||
mediaserver.init(nms, satyr); |
||||
console.log(`Satyr v${process.env.npm_package_version} ready`); |
||||
} |
||||
run(); |
||||
export { run }; |
@ -0,0 +1,15 @@ |
||||
import * as mediaserver from "./server"; |
||||
import * as db from "./database"; |
||||
import * as http from "./http"; |
||||
import * as cleanup from "./cleanup"; |
||||
import { config } from "./config"; |
||||
|
||||
async function run() { |
||||
await db.init(); |
||||
await cleanup.init(); |
||||
await http.init(); |
||||
await mediaserver.init(); |
||||
console.log(`Satyr v${config['satyr']['version']} ready`); |
||||
} |
||||
run(); |
||||
export { run }; |
@ -1,212 +0,0 @@ |
||||
// written by crushv <nik@telekem.net>
|
||||
// thanks nikki
|
||||
|
||||
const net = require('net') |
||||
const EventEmitter = require('events') |
||||
|
||||
const socket = new net.Socket() |
||||
const emitter = new EventEmitter() |
||||
|
||||
socket.setEncoding('utf8') |
||||
|
||||
socket.on('error', console.error) |
||||
|
||||
function m (text) { |
||||
console.log('> ' + text) |
||||
socket.write(text + '\r\n') |
||||
} |
||||
|
||||
var config |
||||
|
||||
socket.once('connect', async () => { |
||||
console.log('Connected') |
||||
m(`PASS ${config.pass} TS 6 :${config.sid}`) |
||||
m('CAPAB QS ENCAP EX IE SAVE EUID') |
||||
m(`SERVER ${config.server} 1 satyr`) |
||||
}) |
||||
|
||||
function parseLine (l) { |
||||
const colIndex = l.lastIndexOf(':') |
||||
if (colIndex > -1) { |
||||
return { |
||||
params: l.substring(0, colIndex - 1).split(' '), |
||||
query: l.substring(colIndex + 1) |
||||
} |
||||
} else return { params: l.split(' ') } |
||||
} |
||||
|
||||
const servers = [] |
||||
const users = {} |
||||
const channels = {} |
||||
|
||||
const globalCommands = { |
||||
// PING :42X
|
||||
// params: SID
|
||||
PING: l => { |
||||
const { query } = parseLine(l) |
||||
m(`PONG :${query}`) |
||||
emitter.emit('ping') |
||||
}, |
||||
// PASS hunter2 TS 6 :42X
|
||||
// params: password, 'TS', TS version, SID
|
||||
PASS: l => { |
||||
const { query } = parseLine(l) |
||||
// adds a server
|
||||
servers.push(query) |
||||
} |
||||
} |
||||
|
||||
const serverCommands = { |
||||
// EUID nik 1 1569146316 +i ~nik localhost6.attlocal.net 0::1 42XAAAAAB * * :nik
|
||||
// params: nickname, hopcount, nickTS, umodes, username, visible hostname, IP address, UID, real hostname, account name, gecos
|
||||
EUID: l => { |
||||
const { params } = parseLine(l) |
||||
const user = { |
||||
nick: params[0], |
||||
nickTS: params[2], |
||||
modes: params[3], |
||||
username: params[4], |
||||
vhost: params[5], |
||||
ip: params[6], |
||||
uid: params[7] |
||||
} |
||||
users[user.uid] = user |
||||
}, |
||||
// SJOIN 1569142987 #test +nt :42XAAAAAB
|
||||
// params: channelTS, channel, simple modes, opt. mode parameters..., nicklist
|
||||
SJOIN: l => { |
||||
const { params, query } = parseLine(l) |
||||
const channel = { |
||||
timestamp: params[0], |
||||
name: params[1], |
||||
modes: params.slice(2).join(' '), |
||||
nicklist: query.split(' ').map(uid => { |
||||
if (/[^0-9a-zA-Z]/.test(uid[0])) return { uid: uid.slice(1), mode: uid[0] } |
||||
else return { uid: uid, mode: '' } |
||||
}) |
||||
} |
||||
channels[channel.name] = channel |
||||
} |
||||
} |
||||
|
||||
const userCommands = { |
||||
// :42XAAAAAC PRIVMSG #test :asd
|
||||
// params: target, msg
|
||||
PRIVMSG: (l, source) => { |
||||
const { params, query } = parseLine(l) |
||||
emitter.emit('message', users[source].nick, params[0], query) |
||||
}, |
||||
// :42XAAAAAC JOIN 1569149395 #test +
|
||||
JOIN: (l, source) => { |
||||
const { params } = parseLine(l) |
||||
channels[params[1]].nicklist.push({ |
||||
uid: source |
||||
}) |
||||
}, |
||||
// :42XAAAAAC PART #test :WeeChat 2.6
|
||||
PART: (l, source) => { |
||||
const { params } = parseLine(l) |
||||
for (let i = 0; i < channels[params[0]].nicklist.length; i++) { |
||||
if (channels[params[0]].nicklist[i].uid === source) { |
||||
channels[params[0]].nicklist.splice(i, 1) |
||||
return |
||||
} |
||||
} |
||||
}, |
||||
QUIT: (_l, source) => { |
||||
delete users[source] |
||||
} |
||||
} |
||||
|
||||
function parser (l) { |
||||
const split = l.split(' ') |
||||
const cmd = split[0] |
||||
const args = split.slice(1).join(' ') |
||||
if (globalCommands[cmd]) return globalCommands[cmd](args) |
||||
if (cmd[0] === ':') { |
||||
const source = cmd.slice(1) |
||||
const subcmd = split[1] |
||||
const subargs = split.slice(2).join(' ') |
||||
if (servers.indexOf(source) > -1 && serverCommands[subcmd]) serverCommands[subcmd](subargs) |
||||
if (users[source] && userCommands[subcmd]) userCommands[subcmd](subargs, source) |
||||
} |
||||
} |
||||
|
||||
socket.on('data', data => { |
||||
data.split('\r\n') |
||||
.filter(l => l !== '') |
||||
.forEach(l => { |
||||
console.log('< ' + l) |
||||
parser(l) |
||||
}) |
||||
}) |
||||
|
||||
module.exports.connect = conf => new Promise((resolve, reject) => { |
||||
emitter.once('ping', resolve) |
||||
config = conf |
||||
socket.connect(config.port) |
||||
process.on('SIGINT', () => { |
||||
socket.write('QUIT\r\n') |
||||
process.exit() |
||||
}) |
||||
}) |
||||
module.exports.events = emitter |
||||
|
||||
const genTS = () => Math.trunc((new Date()).getTime() / 1000) |
||||
const genUID = () => { |
||||
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' |
||||
var uid = '' |
||||
for (let i = 0; i < 6; i++) uid += chars.charAt(Math.floor(Math.random() * chars.length)) |
||||
if (users[uid]) return genUID() |
||||
return config.sid + uid |
||||
} |
||||
const getUID = nick => { |
||||
for (const key in users) if (users[key].nick === nick) return key |
||||
} |
||||
|
||||
module.exports.registerUser = nick => { |
||||
const user = { |
||||
nick: nick, |
||||
nickTS: genTS(), |
||||
modes: '+i', |
||||
username: '~' + nick, |
||||
vhost: config.vhost, |
||||
ip: '0::1', |
||||
uid: genUID() |
||||
} |
||||
users[user.uid] = user |
||||
m(`EUID ${user.nick} 1 ${user.nickTS} ${user.modes} ~${user.nick} ${user.vhost} 0::1 ${user.uid} * * :${user.nick}`) |
||||
} |
||||
module.exports.unregisterUser = nick => { |
||||
const uid = getUID(nick) |
||||
m(`:${uid} QUIT :Quit: satyr`) |
||||
delete users[uid] |
||||
} |
||||
module.exports.join = (nick, channelName) => { |
||||
const uid = getUID(nick) |
||||
if (!channels[channelName]) { |
||||
const channel = { |
||||
timestamp: genTS(), |
||||
name: channelName, |
||||
modes: '+nt', |
||||
nicklist: [{ uid: uid, mode: '' }] |
||||
} |
||||
channels[channel.name] = channel |
||||
} |
||||
m(`:${uid} JOIN ${channels[channelName].timestamp} ${channelName} +`) |
||||
} |
||||
module.exports.part = (nick, channelName) => { |
||||
const uid = getUID(nick) |
||||
m(`:${uid} PART ${channelName} :satyr`) |
||||
for (let i = 0; i < channels[channelName].nicklist.length; i++) { |
||||
if (channels[channelName].nicklist[i].uid === uid) { |
||||
channels[channelName].nicklist.splice(i, 1) |
||||
return |
||||
} |
||||
} |
||||
} |
||||
module.exports.send = (nick, channelName, message) => { |
||||
const uid = getUID(nick) |
||||
m(`:${uid} PRIVMSG ${channelName} :${message}`) |
||||
emitter.emit('message', nick, channelName, message) |
||||
} |
Reference in new issue