Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fixed passive mode address when connecting from localhost #160

Closed
wants to merge 1 commit into from
Closed

Conversation

dmkng
Copy link

@dmkng dmkng commented Apr 12, 2019

No description provided.

@trs
Copy link
Contributor

trs commented Jun 21, 2019

I'd rather see this expanded into if blocks instead of ternary operators.
And a function to test if a given IP is "local" would make it clear.

function isLocalIP(ip) {
  return ip === '127.0.0.1' || ip === 'localhost' || ip == '::1'
}

...

let address = this.server.options.pasv_url;
if (isLocalIP(this.ip)) {
  address = this.ip;
}

@dmkng
Copy link
Author

dmkng commented Jun 21, 2019

I think that IP can never be localhost because it's hostname. So it can be done like that:

function isLocalIP(ip) {
  return ip === '127.0.0.1' || ip == '::1';
}

...

let address = (isLocalIP(this.ip) ? this.ip : this.server.options.pasv_url);
// or
let address = this.server.options.pasv_url;
if (isLocalIP(this.ip)) {
  address = this.ip;
}

or maybe make pasv_url option as callback called every time when someone sends PASV command to the server? Connected user's IP will be passed to the callback parameters and server developer will handle connecting from localhost by itself.

@trs
Copy link
Contributor

trs commented Jun 21, 2019

If there becomes a need to make it a callback it can be. The only reason I see to make it a callback would be for this exact case.

That looks good to me. I'd rather the if block only because it's clearer to me at a glance.

@trs
Copy link
Contributor

trs commented Jun 21, 2019

That method can go in https://github.com/trs/ftp-srv/tree/master/src/helpers

@trs trs mentioned this pull request Jul 22, 2019
@trs
Copy link
Contributor

trs commented Jul 22, 2019

Added to: #168

@trs trs closed this Jul 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants