Re: client.ip_address != bbs.atcode("IP") while using ftelnet
By: Codefenix to All on Thu Mar 09 2023 18:19:59
I learned today that if someone is connected to the BBS from ftelnet, and ftelnet is configured with SendLocation=true, the IP message variable accurately displays the user's IP address, but the client.ip_address property does not. This seems to be the case whether running the WS/WSS services built into SBBS or running Rick Parrish's standalone ftelnetproxy service.
client.ip_address is the address seen by whatever server. In this case it's either going to be the address of Rick's proxy server or the address of your own websocket proxy (probably the same as your BBS).
I recently found that websocketservice.js breaks TTYLOC and probably other telnet commands due to UTF-8 decoding. I can't recall if this applies at every stage of the connection.
TTYLOC (send location) seems to work fine when using Rick's proxy, but not when using websocketservice.js. (There's also websocket_proxy_service.js which is another story.)
I altered websocketservice.js to write the client.ip_address that *it* sees to a file in the OS temp directory, and remove the file afterward. The filename format is: sbbs-ws-<local-port>.ip.
A consuming script can do this:
```js
// Returns string or undefined
function getIP() {
const fn = system.temp_path+'sbbs-ws-'+client.socket.remote_port+'.ip';
const f = new File(fn);
if (!f.exists) return;
if (f.date < client.connect_time) return; // Avoid stale ws ip files
if (f.date - client.connect_time > 5) return; // (5 seconds arbitrary)
if (!f.open('r')) return;
const addr = f.read();
f.close();
}
```
This is not a perfect method and there's a slim chance of incorrect results, but mostly fine.
For that reason, I'm using bbs.atcode("IP") in place of client.ip_address
I'm not sure where that value comes from, but it won't be any more reliable in the case of a client coming from websocketservice.js.
---
echicken
electronic chicken bbs - bbs.electronicchicken.com
---
þ Synchronet þ electronic chicken bbs - bbs.electronicchicken.com