fix(db): broke remote connection (security purposes)
also fix starting on used ports of db
This commit is contained in:
@ -171,8 +171,8 @@ autoUpdater.on('update-downloaded', () => {
|
||||
|
||||
let tray = undefined
|
||||
|
||||
app.on("ready", () => {
|
||||
sphinx = startSphinx(() => {
|
||||
app.on("ready", async () => {
|
||||
sphinx = await startSphinx(() => {
|
||||
|
||||
mainWindow = createWindow("main", {
|
||||
width: 1000,
|
||||
|
@ -28,6 +28,7 @@ let config = {
|
||||
sphinx: {
|
||||
host : '127.0.0.1',
|
||||
port : 9306,
|
||||
interfacePort: 9312,
|
||||
connectionLimit: 10
|
||||
},
|
||||
|
||||
@ -107,7 +108,7 @@ const configProxy = new Proxy(config, {
|
||||
})
|
||||
|
||||
config.load = () => {
|
||||
debug('loading configuration')
|
||||
debug('loading configuration', configPath)
|
||||
if(fs.existsSync(configPath))
|
||||
{
|
||||
debug('finded configuration', configPath)
|
||||
@ -133,4 +134,9 @@ config.load = () => {
|
||||
return configProxy
|
||||
}
|
||||
|
||||
config.reload = (path) => {
|
||||
configPath = path + '/rats.json'
|
||||
return config.load()
|
||||
}
|
||||
|
||||
module.exports = configProxy.load()
|
@ -246,9 +246,9 @@ module.exports = async (callback, mainWindow, sphinxApp) => {
|
||||
|
||||
logT('patcher', 'cleaned torrents db structure, rectreating again')
|
||||
i = 1
|
||||
await new Promise((resolve) => {
|
||||
await new Promise(async (resolve) => {
|
||||
// reopen sphinx
|
||||
sphinxApp = sphinxApp.start(async () => {
|
||||
sphinxApp = await sphinxApp.start(async () => {
|
||||
sphinx = await single().waitConnection()
|
||||
resolve()
|
||||
}) // same args
|
||||
|
11
src/background/portCheck.js
Normal file
11
src/background/portCheck.js
Normal file
@ -0,0 +1,11 @@
|
||||
const net = require('net')
|
||||
|
||||
module.exports = (port, host = '127.0.0.1') => new Promise((resolve, reject) => {
|
||||
const tester = net.createServer()
|
||||
.once('error', err => (err.code === 'EADDRINUSE' ? resolve(false) : reject(err)))
|
||||
.once('listening', () => tester.once('close', () => resolve(true)).close())
|
||||
.listen({
|
||||
host,
|
||||
port
|
||||
})
|
||||
})
|
@ -68,14 +68,17 @@ io.on('connection', (socket) =>
|
||||
}
|
||||
})
|
||||
|
||||
sphinx = startSphinx(() => {
|
||||
dbPatcher(() => {
|
||||
spider = new spiderCall((...data) => io.sockets.emit(...data), (message, callback) => {
|
||||
socketMessages[message] = callback
|
||||
}, path.resolve(packageJson.serverDataDirectory), packageJson.version, 'production')
|
||||
}, null, sphinx)
|
||||
}, path.resolve(packageJson.serverDataDirectory), () => {})
|
||||
|
||||
const start = async () =>
|
||||
{
|
||||
sphinx = await startSphinx(() => {
|
||||
dbPatcher(() => {
|
||||
spider = new spiderCall((...data) => io.sockets.emit(...data), (message, callback) => {
|
||||
socketMessages[message] = callback
|
||||
}, path.resolve(packageJson.serverDataDirectory), packageJson.version, 'production')
|
||||
}, null, sphinx)
|
||||
}, path.resolve(packageJson.serverDataDirectory), () => {})
|
||||
}
|
||||
start()
|
||||
|
||||
var rl = require("readline").createInterface({
|
||||
input: process.stdin,
|
||||
@ -92,8 +95,12 @@ process.on("SIGINT", () => {
|
||||
{
|
||||
spider.stop(() => sphinx.stop(() => process.exit()))
|
||||
}
|
||||
else
|
||||
else if(sphinx)
|
||||
{
|
||||
sphinx.stop(() => process.exit())
|
||||
}
|
||||
else
|
||||
{
|
||||
process.exit()
|
||||
}
|
||||
});
|
@ -11,8 +11,21 @@ const appConfig = require('./config')
|
||||
const findFiles = require('./findFiles')
|
||||
const _ = require('lodash')
|
||||
const isRunning = require('is-running')
|
||||
const portCheck = require('./portCheck')
|
||||
|
||||
const findGoodPort = async (port, host) => {
|
||||
while (!(await portCheck(port, host))) {
|
||||
port++
|
||||
logT('sphinx', 'port is busy, listen on', port)
|
||||
}
|
||||
return port
|
||||
}
|
||||
|
||||
const writeSphinxConfig = async (path, dbPath) => {
|
||||
appConfig.sphinx.port = await findGoodPort(appConfig.sphinx.port)
|
||||
appConfig.sphinx.interfacePort = await findGoodPort(appConfig.sphinx.interfacePort)
|
||||
appConfig.sphinx = appConfig.sphinx
|
||||
|
||||
const writeSphinxConfig = (path, dbPath) => {
|
||||
let config = `
|
||||
index torrents
|
||||
{
|
||||
@ -83,8 +96,8 @@ const writeSphinxConfig = (path, dbPath) => {
|
||||
|
||||
searchd
|
||||
{
|
||||
listen = 9312
|
||||
listen = 9306:mysql41
|
||||
listen = 127.0.0.1:${appConfig.sphinx.interfacePort}
|
||||
listen = 127.0.0.1:${appConfig.sphinx.port}:mysql41
|
||||
read_timeout = 5
|
||||
max_children = 30
|
||||
seamless_rotate = 1
|
||||
@ -143,8 +156,8 @@ const writeSphinxConfig = (path, dbPath) => {
|
||||
return {isInitDb}
|
||||
}
|
||||
|
||||
module.exports = (callback, dataDirectory, onClose) => {
|
||||
const start = (callback) => {
|
||||
module.exports = async (callback, dataDirectory, onClose) => {
|
||||
const start = async (callback) => {
|
||||
|
||||
const sphinxPath = path.resolve(appPath('searchd'))
|
||||
logT('sphinx', 'Sphinx Path:', sphinxPath)
|
||||
@ -163,7 +176,7 @@ module.exports = (callback, dataDirectory, onClose) => {
|
||||
if(isSphinxExternal)
|
||||
logT('sphinx', `founded running sphinx instance in ${sphinxPid}, using it`)
|
||||
|
||||
const { isInitDb } = isSphinxExternal ? {isInitDb: false} : writeSphinxConfig(sphinxConfigDirectory, appConfig.dbPath)
|
||||
const { isInitDb } = isSphinxExternal ? {isInitDb: false} : await writeSphinxConfig(sphinxConfigDirectory, appConfig.dbPath)
|
||||
|
||||
const config = `${sphinxConfigDirectory}/sphinx.conf`
|
||||
const options = ['--config', config]
|
||||
@ -288,7 +301,7 @@ module.exports = (callback, dataDirectory, onClose) => {
|
||||
|
||||
sphinx.fixing = false
|
||||
|
||||
_.merge(sphinx, sphinx.start(callback));
|
||||
_.merge(sphinx, await sphinx.start(callback));
|
||||
}
|
||||
|
||||
if (isSphinxExternal && callback) setTimeout(()=>{logT('sphinx', 'external sphinx signalled');callback()}, 0);
|
||||
@ -296,5 +309,5 @@ module.exports = (callback, dataDirectory, onClose) => {
|
||||
return sphinx
|
||||
}
|
||||
|
||||
return start(callback)
|
||||
return await start(callback)
|
||||
}
|
Reference in New Issue
Block a user