Skip to content

Commit

Permalink
Merge pull request #321 from wacki4/prompt-for-server-password
Browse files Browse the repository at this point in the history
Allow to select prompt for password on servers
  • Loading branch information
cschindl authored Aug 30, 2019
2 parents 1c088e0 + 4e9d160 commit a33470f
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 16 deletions.
4 changes: 2 additions & 2 deletions lib/dialogs/prompt-pass-dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ const atom = global.atom;

export default class PromptPassDialog extends Dialog {

constructor() {
constructor(prompt) {
super({
prompt: 'Enter password only for this session:',
prompt: prompt,
select: false,
});

Expand Down
8 changes: 4 additions & 4 deletions lib/ftp-remote-edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -366,9 +366,9 @@ class FtpRemoteEdit {
})
}

promtPassword() {
promptPassword() {
const self = this;
const dialog = new PromptPassDialog();
const dialog = new PromptPassDialog('Enter password only for this session:');

let promise = new Promise((resolve, reject) => {
dialog.on('dialog-done', (e, password) => {
Expand Down Expand Up @@ -464,7 +464,7 @@ class FtpRemoteEdit {
});
return;
} else {
self.promtPassword().then(() => {
self.promptPassword().then(() => {
if (Storage.load()) {
self.getTreeViewInstance().reload();
self.getTreeViewInstance().toggle();
Expand Down Expand Up @@ -524,7 +524,7 @@ class FtpRemoteEdit {
};

if (!Storage.hasPassword()) {
self.promtPassword().then(() => {
self.promptPassword().then(() => {
if (Storage.load()) {
self.getConfigurationViewInstance().reload(root);
self.getConfigurationViewInstance().attach();
Expand Down
4 changes: 3 additions & 1 deletion lib/helper/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ class Storage {
cleanconfig.logon = 'agent';
} else if (item.privatekeyfile) {
cleanconfig.logon = 'keyfile';
} else if (item.logon = 'passwordprompt') {
cleanconfig.logon = 'passwordprompt';
} else {
cleanconfig.logon = 'credentials';
}
Expand Down Expand Up @@ -384,7 +386,7 @@ class Storage {
// Fix error storing empty version
configArray.version = '0.14.2';
}

// since 0.15.0
if (compareVersions(configArray.version, '0.15.0') < 0) {
// backup current config
Expand Down
29 changes: 21 additions & 8 deletions lib/views/configuration-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,10 @@ export default class ConfigurationView extends View {
optionNormal.text = 'Username / Password';
optionNormal.value = 'credentials';
self.logonTypeSelect.add(optionNormal);
let optionPrompt = document.createElement("option");
optionPrompt.text = 'Username / Prompt for password';
optionPrompt.value = 'passwordprompt';
self.logonTypeSelect.add(optionPrompt);
let optionKeyFile = document.createElement("option");
optionKeyFile.text = 'Keyfile (OpenSSH format - PEM)';
optionKeyFile.value = 'keyfile';
Expand Down Expand Up @@ -452,6 +456,11 @@ export default class ConfigurationView extends View {
Storage.getServers()[index].logon = 'credentials';
Storage.getServers()[index].useAgent = false;
Storage.getServers()[index].privatekeyfile = '';
} else if (option.value == 'passwordprompt') {
Storage.getServers()[index].logon = 'passwordprompt';
Storage.getServers()[index].useAgent = false;
Storage.getServers()[index].privatekeyfile = '';
Storage.getServers()[index].password = '';
} else if (option.value == 'keyfile') {
Storage.getServers()[index].logon = 'keyfile';
Storage.getServers()[index].useAgent = false;
Expand Down Expand Up @@ -790,13 +799,13 @@ export default class ConfigurationView extends View {

self.protocolEncryptionSelect.selectedIndex = 0;

self.logonTypeSelect.options[1].disabled = false;
self.logonTypeSelect.options[2].disabled = false;
self.logonTypeSelect.options[3].disabled = false;

self.protocolEncryptionControl.setAttribute("style", "display:none;");
} else {
self.protocolSelect.selectedIndex = 0;

if (server.secure === 'implicit') {
self.protocolEncryptionSelect.selectedIndex = 2;
self.portInput.element.setAttribute('placeholder-text', '990');
Expand All @@ -809,18 +818,22 @@ export default class ConfigurationView extends View {
}

self.logonTypeSelect.selectedIndex = 0; // Username/Password
self.logonTypeSelect.options[1].disabled = true;
self.logonTypeSelect.options[2].disabled = true;
self.logonTypeSelect.options[3].disabled = true;

self.protocolEncryptionControl.removeAttribute("style");
}

if (server.logon == 'keyfile') {
self.logonTypeSelect.selectedIndex = 1; // Keyfile
self.logonTypeSelect.selectedIndex = 2; // Keyfile
self.passwordControl.removeAttribute("style");
self.privatekeyfileControl.removeAttribute("style");
} else if (server.logon == 'agent') {
self.logonTypeSelect.selectedIndex = 2; // SSH Agent
self.logonTypeSelect.selectedIndex = 3; // SSH Agent
self.passwordControl.setAttribute("style", "display:none;");
self.privatekeyfileControl.setAttribute("style", "display:none;");
} else if (server.logon == 'passwordprompt') {
self.logonTypeSelect.selectedIndex = 1; // SSH Agent
self.passwordControl.setAttribute("style", "display:none;");
self.privatekeyfileControl.setAttribute("style", "display:none;");
} else {
Expand Down Expand Up @@ -1013,14 +1026,14 @@ export default class ConfigurationView extends View {

connector.connect().then(() => {
showMessage('Connection could be established successfully')
connector.disconnect(null).catch(() => { });
connector.disconnect(null).catch(() => {});
connector.destroy();
}).catch((err) => {
showMessage(err, 'error');
connector.disconnect(null).catch(() => { });
connector.disconnect(null).catch(() => {});
connector.destroy();
});
} catch (e) { }
} catch (e) {}
}

new() {
Expand Down
29 changes: 28 additions & 1 deletion lib/views/server-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ import FileView from './file-view.js';
const shortHash = require('short-hash');
const md5 = require('md5');
const Path = require('path');
const Extend = require('util')._extend;
const tempDirectory = require('os').tmpdir();
const PromptPassDialog = require('./../dialogs/prompt-pass-dialog');

class ServerView extends View {

Expand Down Expand Up @@ -47,7 +49,7 @@ class ServerView extends View {
initialize(config) {
const self = this;

self.config = config;
self.config = Extend({}, config);
self.expanded = false;
self.finderItemsCache = null;

Expand Down Expand Up @@ -163,12 +165,37 @@ class ServerView extends View {
element.label.removeClass('icon-sync').removeClass('spin');
}

promptPassword() {
const self = this;
const dialog = new PromptPassDialog('Enter server password:');

let promise = new Promise((resolve, reject) => {
dialog.on('dialog-done', (e, password) => {
self.config.password = password;
dialog.close();
resolve(true);
});
dialog.attach();
});

return promise;
}

expand() {
const self = this;

let promise = new Promise((resolve, reject) => {
if (self.isExpanded()) return resolve(true);

if (self.config.logon == 'passwordprompt' && !self.config.password) {
self.promptPassword().then(() => {
self.expand().then(() => {}, () => {
self.config.password = "";
});
});
return resolve(false);
}

self.addSyncIcon();
self.getConnector().listDirectory(self.getPath()).then((list) => {
self.expanded = true;
Expand Down

0 comments on commit a33470f

Please sign in to comment.