Skip to content

Commit

Permalink
r0b08x [chore] 3/29/2024, 1:21:30 PM
Browse files Browse the repository at this point in the history
  • Loading branch information
p3x-robot committed Mar 29, 2024
1 parent 6be8110 commit 4ee4055
Show file tree
Hide file tree
Showing 8 changed files with 145 additions and 6 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ https://corifeus.com/redis-ui


---
# 🏍️ The p3x-redis-ui-server package motor that is connected to the p3x-redis-ui-material web user interface v2024.4.173
# 🏍️ The p3x-redis-ui-server package motor that is connected to the p3x-redis-ui-material web user interface v2024.4.174



Expand Down Expand Up @@ -112,7 +112,7 @@ All my domains ([patrikx3.com](https://patrikx3.com) and [corifeus.com](https://

---

[**P3X-REDIS-UI-SERVER**](https://corifeus.com/redis-ui-server) Build v2024.4.173
[**P3X-REDIS-UI-SERVER**](https://corifeus.com/redis-ui-server) Build v2024.4.174

[![NPM](https://img.shields.io/npm/v/p3x-redis-ui-server.svg)](https://www.npmjs.com/package/p3x-redis-ui-server) [![Donate for Corifeus / P3X](https://img.shields.io/badge/Donate-Corifeus-003087.svg)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=QZVM4V6HVZJW6) [![Contact Corifeus / P3X](https://img.shields.io/badge/Contact-P3X-ff9900.svg)](https://www.patrikx3.com/en/front/contact) [![Like Corifeus @ Facebook](https://img.shields.io/badge/LIKE-Corifeus-3b5998.svg)](https://www.facebook.com/corifeus.software)

Expand Down
2 changes: 1 addition & 1 deletion artifacts/cluster.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ All my domains ([patrikx3.com](https://patrikx3.com) and [corifeus.com](https://

---

[**P3X-REDIS-UI-SERVER**](https://corifeus.com/redis-ui-server) Build v2024.4.173
[**P3X-REDIS-UI-SERVER**](https://corifeus.com/redis-ui-server) Build v2024.4.174

[![NPM](https://img.shields.io/npm/v/p3x-redis-ui-server.svg)](https://www.npmjs.com/package/p3x-redis-ui-server) [![Donate for Corifeus / P3X](https://img.shields.io/badge/Donate-Corifeus-003087.svg)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=QZVM4V6HVZJW6) [![Contact Corifeus / P3X](https://img.shields.io/badge/Contact-P3X-ff9900.svg)](https://www.patrikx3.com/en/front/contact) [![Like Corifeus @ Facebook](https://img.shields.io/badge/LIKE-Corifeus-3b5998.svg)](https://www.facebook.com/corifeus.software)

Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "p3x-redis-ui-server",
"version": "2024.4.173",
"version": "2024.4.174",
"description": "🏍️ The p3x-redis-ui-server package motor that is connected to the p3x-redis-ui-material web user interface",
"corifeus": {
"icon": "fas fa-flag-checkered",
Expand Down Expand Up @@ -63,7 +63,8 @@
"koa-send": "^5.0.1",
"koa-static": "^5.0.0",
"lodash": "^4.17.21",
"socket.io": "^4.7.5"
"socket.io": "^4.7.5",
"tunnel-ssh": "^5.1.2"
},
"engines": {
"node": ">=12.13.0"
Expand Down
52 changes: 52 additions & 0 deletions src/service/socket.io/request/connection-connect.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,58 @@ module.exports = async (options) => {
}
}


if (!Array.isArray(redisConfig)) {
if (redisConfig.ssh === true) {

const tunnelOptions = {
autoClose: false
}
const sshOptions = {
host: redisConfig.sshHost,
port: redisConfig.sshPort,
username: redisConfig.sshUsername,
};
if (redisConfig.sshPrivateKey) {
sshOptions.privateKey = redisConfig.sshPrivateKey
} else {
sshOptions.password = redisConfig.sshPassword
}

const serverOptions = null

const forwardOptions = {
dstAddr: redisConfig.host,
dstPort: redisConfig.port,
}

const { createTunnel } = require('tunnel-ssh')
let [server, client] = await createTunnel(tunnelOptions, serverOptions, sshOptions, forwardOptions);


socket.p3xrs.tunnel = server

redisConfig.port = server.address().port

server.on('error',(e)=>{
console.error(e);
socket.p3xrs.tunnel.close()
socket.emit(options.responseEvent, {
status: 'error',
error: e.message
})
});

client.on('error',(e)=>{
console.error(e);
socket.p3xrs.tunnel.close()
socket.emit(options.responseEvent, {
status: 'error',
error: e.message
})
});
}
}
let redis = new Redis(redisConfig)
//console.warn('redis connection', redisConfig)
let redisSubscriber = new Redis(redisConfig)
Expand Down
10 changes: 10 additions & 0 deletions src/service/socket.io/request/connection-save.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@ module.exports = async (options) => {
if (p3xrs.connections.list[connectionIndexExisting].id === connectionSave.tlsCa) {
connectionSave.tlsCa = p3xrs.connections.list[connectionIndexExisting].tlsCa;
}
if (p3xrs.connections.list[connectionIndexExisting].id === connectionSave.tlsCa) {
connectionSave.tlsCa = p3xrs.connections.list[connectionIndexExisting].tlsCa;
}
if (p3xrs.connections.list[connectionIndexExisting].id === connectionSave.sshPassword) {
connectionSave.sshPassword = p3xrs.connections.list[connectionIndexExisting].sshPassword
}
if (p3xrs.connections.list[connectionIndexExisting].id === connectionSave.sshPrivateKey) {
connectionSave.sshPrivateKey = p3xrs.connections.list[connectionIndexExisting].sshPrivateKey
}


//TODO fix secured nodes password
if (Array.isArray(connectionSave.nodes)) {
Expand Down
71 changes: 70 additions & 1 deletion src/service/socket.io/request/redis-test-connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ module.exports = async (options) => {
if (redisConfig.tlsCa === actualConnection.id) {
redisConfig.tlsCa = actualConnection.tlsCa;
}
if (redisConfig.sshPassword === actualConnection.id) {
redisConfig.sshPassword = actualConnection.sshPassword;
}
if (redisConfig.sshPrivateKey === actualConnection.id) {
redisConfig.sshPrivateKey = actualConnection.sshPrivateKey;
}
}

const sentinelName = redisConfig.name
Expand Down Expand Up @@ -73,6 +79,64 @@ module.exports = async (options) => {
}
}
}

let ssh = {
server: undefined,
client: undefined,
}
if (!Array.isArray(redisConfig)) {
if (redisConfig.ssh === true) {

const tunnelOptions = {
autoClose: false
}
const sshOptions = {
host: redisConfig.sshHost,
port: redisConfig.sshPort,
username: redisConfig.sshUsername,
};
if (redisConfig.sshPrivateKey) {
sshOptions.privateKey = redisConfig.sshPrivateKey
} else {
sshOptions.password = redisConfig.sshPassword
}

const serverOptions = null

const forwardOptions = {
dstAddr: redisConfig.host,
dstPort: redisConfig.port,
}

const { createTunnel } = require('tunnel-ssh')
let [server, client] = await createTunnel(tunnelOptions, serverOptions, sshOptions, forwardOptions);


ssh.server = server
ssh.client = client

redisConfig.port = server.address().port

server.on('error',(e)=>{
console.error(e);
ssh.server.close()
socket.emit(options.responseEvent, {
status: 'error',
error: e.message
})
});

client.on('error',(e)=>{
console.error(e);
ssh.server.close()
socket.emit(options.responseEvent, {
status: 'error',
error: e.message
})
});
}
}

let redis = new Redis(redisConfig)
console.info('redis-test-connection', redisConfig)
redis.on('error', function (error) {
Expand All @@ -82,6 +146,9 @@ module.exports = async (options) => {
error: error.message
})
redis.disconnect()
if (ssh.server) {
ssh.server.close()
}
})
redis.on('connect', async function () {
try {
Expand All @@ -100,7 +167,9 @@ module.exports = async (options) => {
})
} finally {
redis.disconnect()

if (ssh.server) {
ssh.server.close()
}
}
})

Expand Down
6 changes: 6 additions & 0 deletions src/service/socket.io/shared.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ const sendConnections = (options) => {
delete connection.tlsCrt
delete connection.tlsKey
delete connection.tlsCa
delete connection.sshPassword
delete connection.sshPrivateKey

//TODO fix secured nodes password
if (Array.isArray(connection.nodes)) {
Expand Down Expand Up @@ -102,6 +104,10 @@ const disconnectRedisIo = (options) => {
socket.p3xrs.ioredisSubscriber.disconnect()
socket.p3xrs.ioredis = undefined
socket.p3xrs.ioredisSubscriber = undefined
if (socket.p3xrs.tunnel !== undefined) {
socket.p3xrs.tunnel.close()
socket.p3xrs.tunnel = undefined
}
}
}

Expand Down
1 change: 1 addition & 0 deletions src/service/socket.io/socket.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ module.exports = (io) => {
io: io,
ioredis: undefined,
ioredisSubscriber: undefined,
tunnel: undefined,
readonly: undefined,
// commands: undefined,
}
Expand Down

0 comments on commit 4ee4055

Please sign in to comment.