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

Try to detect ssh and telnet port #313

Closed
wants to merge 5 commits into from

Conversation

Martin-Zeithaml
Copy link
Contributor

@Martin-Zeithaml Martin-Zeithaml commented Aug 15, 2024

Proposed changes

Try to detect ssh and telnet port by looking into /etc/ssh/sshd_config and /etc/services. If such check fails, set the default port 22 and 23 (same as now).

This PR addresses Issue:

Type of change

  • New feature (non-breaking change which adds functionality)

PR Checklist

Please delete options that are not relevant.

  • If the changes in this PR are meant for the next release / mainline, this PR targets the "staging" branch.
  • My code follows the style guidelines of this project (see: Contributing guideline)
  • I have commented my code, particularly in hard-to-understand areas
  • Relevant update to CHANGELOG.md
  • My changes generate no new warnings

Testing

Small unit test

Test for checking if the logic works as expected:

Input='' -> SSH_PORT=22
Input=' ' -> SSH_PORT=22
Input='123 ' -> SSH_PORT=22
Input='0' -> SSH_PORT=22
Input='asdf' -> SSH_PORT=22
Input='99999' -> SSH_PORT=22
Input='file not found' -> SSH_PORT=22
Input='C:\' -> SSH_PORT=22
Input='1' -> SSH_PORT=1
Input='23' -> SSH_PORT=23
Input='144' -> SSH_PORT=144
Input='65535' -> SSH_PORT=65535

Running without variables

In the log:

ZWED_SSH_PORT=22
ZWED_TN3270_PORT=23

Running with preset ZWED_SSH_PORT

In the log:

ZWED_SSH_PORT=123
ZWED_TN3270_PORT=23

Further comments

I keep the setting in defaults.yaml. It should work without that, because those variables are exported. But in the future, there might be a way how to do it in JavaScript, keep it as reference.

Signed-off-by: Martin Zeithaml <[email protected]>
Signed-off-by: Martin Zeithaml <[email protected]>
@Martin-Zeithaml Martin-Zeithaml changed the base branch from v2.x/staging to v3.x/staging August 16, 2024 14:11
Signed-off-by: Martin Zeithaml <[email protected]>
Signed-off-by: Martin Zeithaml <[email protected]>
Signed-off-by: Martin Zeithaml <[email protected]>
# Check ssh and telnet port
if [ -z "${ZWED_SSH_PORT}" ]; then
if [ -e "/etc/ssh/sshd_config" ]; then
ssh_port=$(cat "/etc/ssh/sshd_config" | grep '^Port.*' | awk -F\ '{print $2}')
Copy link
Member

@1000TurquoisePogs 1000TurquoisePogs Nov 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regarding the reading of these here:
Just did a lot of work in v2.15-v2.18 to remove as much shell as possible for performance.

  1. start.sh gets read every time the server starts, including crash restarts. configure.sh does not get read during crash restarts so its a little better...

  2. configure.sh still gets read every fresh start. can we do this in JS instead? - read the file, line split and search for term.... we already have "initInstance.js". It could be made more intelligent.

initUtils.js takes these env vars and writes out JSON in workspace dir.
If it would instead do pretty much this logic when the env vars were missing, we wouldn't need to put this code into shell and the performance impact would be much less.

@Martin-Zeithaml
Copy link
Contributor Author

Replaced by #326.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Closed
Development

Successfully merging this pull request may close these issues.

2 participants