Skip to content

Commit

Permalink
Merge pull request #326 from zowe/v3.x/feature/detectSshTelnet
Browse files Browse the repository at this point in the history
Read ssh/telnet port from /etc
  • Loading branch information
1000TurquoisePogs authored Nov 6, 2024
2 parents a09e53e + ab39464 commit 7fdd42f
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
All notable changes to the Zlux App Server package will be documented in this file.

## v3.1.0
- Enhancement: app-server tries to detect ssh and telnet ports (used by terminals) automatically. [(#326)](https://github.com/zowe/zlux-app-server/pull/326)
- Bugfix: app-server no longer causes Zowe to print "FSUM7422 node is not found" and "Node found in NODE_HOME" upon startup. This avoids confusion about if node requirements are met. (#325)

## v3.0.0
Expand Down
4 changes: 2 additions & 2 deletions defaults/serverConfig/defaults.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ zowe:
workspaceDirectory: ${{ process.env.HOME + '/.zowe/workspace' }}
externalDomains: ${{ function a() { if (process.env.ZWE_zowe_externalDomains) { return process.env.ZWE_zowe_externalDomains.split(','); } else { return [ os.hostname() ] } }; a() }}
environments:
ZWED_SSH_PORT: 22
ZWED_TN3270_PORT: 23
ZWED_SSH_PORT: "${{ process.env.ZWED_SSH_PORT ? process.env.ZWED_SSH_PORT : 22 }}"
ZWED_TN3270_PORT: "${{ process.env.ZWED_TN3270_PORT ? process.env.ZWED_TN3270_PORT : 23 }}"
ZWED_TN3270_SECURITY: telnet
ZWED_SSH_HOST: ${{ zowe.externalDomains[0] }}
ZWED_TN3270_HOST: ${{ zowe.externalDomains[0] }}
Expand Down
32 changes: 32 additions & 0 deletions lib/initUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -320,8 +320,34 @@ let registerBundledPlugin = function(pluginId, destination, oldPlugins, filePerm
}
module.exports.registerBundledPlugin = registerBundledPlugin;

function readPortFromUnixConfig(configFile, regex) {
let result = 0;
if (fs.fileExists(configFile)) {
const configContent = fs.readFileSync(configFile, 'utf8');
if (configContent) {
const configLines = configContent.split('\n');
for (let line in configLines) {
const matchLine = configLines[line].match(regex);
if (matchLine) {
const portNumber = parseInt(matchLine[0].replace(/\s+/g, " ").split(' ')[1]);
if (portNumber > 0 && portNumber < 65536) {
result = portNumber;
}
}
}
}
}
return result;
}

module.exports.setTerminalDefaults = function(configDestination, instanceItems) {
if (instanceItems.indexOf('org.zowe.terminal.vt.json') != -1) {
if (!process.env['ZWED_SSH_PORT']) {
const sshPort = readPortFromUnixConfig('/etc/ssh/sshd_config', /port[\s]+[0-9]{1,5}/i);
if (sshPort) {
process.env['ZWED_SSH_PORT'] = sshPort;
}
}
let defaultConfigDir = path.join(configDestination,'org.zowe.terminal.vt','sessions');
mkdirp(defaultConfigDir);
try {
Expand All @@ -334,6 +360,12 @@ module.exports.setTerminalDefaults = function(configDestination, instanceItems)
}
}
if (instanceItems.indexOf('org.zowe.terminal.tn3270.json') != -1) {
if (!process.env['ZWED_TN3270_PORT']) {
const telnetPort = readPortFromUnixConfig('/etc/services', /telnet[\s]+[0-9]{1,5}/i);
if (telnetPort) {
process.env['ZWED_TN3270_PORT'] = telnetPort;
}
}
let security = 'telnet';
if (process.env['ZWED_TN3270_SECURITY']) {
security = process.env['ZWED_TN3270_SECURITY'];
Expand Down

0 comments on commit 7fdd42f

Please sign in to comment.