Skip to content

Commit

Permalink
Merge pull request #327 from zowe/v3.x/feature/detectSshTelnet
Browse files Browse the repository at this point in the history
Read ssh/telnet port from /etc: function and regex update
  • Loading branch information
timgerstel authored Nov 7, 2024
2 parents 7fdd42f + 609010e commit 0ffc640
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions lib/initUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ module.exports.registerBundledPlugin = registerBundledPlugin;

function readPortFromUnixConfig(configFile, regex) {
let result = 0;
if (fs.fileExists(configFile)) {
if (fileExists(configFile)) {
const configContent = fs.readFileSync(configFile, 'utf8');
if (configContent) {
const configLines = configContent.split('\n');
Expand All @@ -331,7 +331,8 @@ function readPortFromUnixConfig(configFile, regex) {
if (matchLine) {
const portNumber = parseInt(matchLine[0].replace(/\s+/g, " ").split(' ')[1]);
if (portNumber > 0 && portNumber < 65536) {
result = portNumber;
printFormattedDebug(`readPortFromUnixConfig: ${configFile} -> "${matchLine[0]}" -> ${portNumber}`);
result = portNumber;
}
}
}
Expand All @@ -343,7 +344,7 @@ function readPortFromUnixConfig(configFile, regex) {
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);
const sshPort = readPortFromUnixConfig('/etc/ssh/sshd_config', /^port[\s]+[0-9]{1,5}/i);
if (sshPort) {
process.env['ZWED_SSH_PORT'] = sshPort;
}
Expand All @@ -361,7 +362,7 @@ 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);
const telnetPort = readPortFromUnixConfig('/etc/services', /^telnet[\s]+[0-9]{1,5}/i);
if (telnetPort) {
process.env['ZWED_TN3270_PORT'] = telnetPort;
}
Expand Down

0 comments on commit 0ffc640

Please sign in to comment.