2011-09-28 13:16:26 +00:00
|
|
|
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
2019-01-31 14:07:06 +00:00
|
|
|
/* exported Component */
|
2011-08-19 18:29:39 +00:00
|
|
|
|
2019-05-23 20:45:44 +00:00
|
|
|
const { Clutter, Gio, GLib, GObject, NM, Pango, Shell, St } = imports.gi;
|
2017-12-06 15:55:15 +00:00
|
|
|
const Signals = imports.signals;
|
2011-08-19 18:29:39 +00:00
|
|
|
|
2011-11-03 20:57:33 +00:00
|
|
|
const Config = imports.misc.config;
|
2017-07-15 04:03:55 +00:00
|
|
|
const Dialog = imports.ui.dialog;
|
2012-06-14 17:53:52 +00:00
|
|
|
const Main = imports.ui.main;
|
|
|
|
const MessageTray = imports.ui.messageTray;
|
2011-08-19 18:29:39 +00:00
|
|
|
const ModalDialog = imports.ui.modalDialog;
|
2011-10-11 22:38:24 +00:00
|
|
|
const ShellEntry = imports.ui.shellEntry;
|
2011-08-19 18:29:39 +00:00
|
|
|
|
2011-11-03 20:57:33 +00:00
|
|
|
const VPN_UI_GROUP = 'VPN Plugin UI';
|
|
|
|
|
2019-05-23 20:45:44 +00:00
|
|
|
var NetworkSecretDialog = GObject.registerClass(
|
|
|
|
class NetworkSecretDialog extends ModalDialog.ModalDialog {
|
|
|
|
_init(agent, requestId, connection, settingName, hints, flags, contentOverride) {
|
|
|
|
super._init({ styleClass: 'prompt-dialog' });
|
2011-08-19 18:29:39 +00:00
|
|
|
|
|
|
|
this._agent = agent;
|
|
|
|
this._requestId = requestId;
|
|
|
|
this._connection = connection;
|
|
|
|
this._settingName = settingName;
|
|
|
|
this._hints = hints;
|
|
|
|
|
2011-11-03 20:57:33 +00:00
|
|
|
if (contentOverride)
|
|
|
|
this._content = contentOverride;
|
|
|
|
else
|
|
|
|
this._content = this._getContent();
|
2011-08-19 18:29:39 +00:00
|
|
|
|
2017-07-15 04:03:55 +00:00
|
|
|
let icon = new Gio.ThemedIcon({ name: 'dialog-password-symbolic' });
|
|
|
|
let contentParams = { icon,
|
|
|
|
title: this._content.title,
|
|
|
|
body: this._content.message };
|
|
|
|
let contentBox = new Dialog.MessageDialogContent(contentParams);
|
|
|
|
this.contentLayout.add_actor(contentBox);
|
2011-08-19 18:29:39 +00:00
|
|
|
|
2014-08-06 13:16:39 +00:00
|
|
|
let layout = new Clutter.GridLayout({ orientation: Clutter.Orientation.VERTICAL });
|
2013-07-09 01:08:47 +00:00
|
|
|
let secretTable = new St.Widget({ style_class: 'network-dialog-secret-table',
|
|
|
|
layout_manager: layout });
|
|
|
|
layout.hookup_style(secretTable);
|
|
|
|
|
2014-06-20 14:41:22 +00:00
|
|
|
let rtl = secretTable.get_text_direction() == Clutter.TextDirection.RTL;
|
2011-09-14 23:22:29 +00:00
|
|
|
let initialFocusSet = false;
|
2011-08-19 18:29:39 +00:00
|
|
|
let pos = 0;
|
|
|
|
for (let i = 0; i < this._content.secrets.length; i++) {
|
|
|
|
let secret = this._content.secrets[i];
|
2012-02-09 20:52:21 +00:00
|
|
|
let label = new St.Label({ style_class: 'prompt-dialog-password-label',
|
2014-08-06 13:16:39 +00:00
|
|
|
text: secret.label,
|
|
|
|
x_align: Clutter.ActorAlign.START,
|
|
|
|
y_align: Clutter.ActorAlign.CENTER });
|
2013-09-18 20:36:17 +00:00
|
|
|
label.clutter_text.ellipsize = Pango.EllipsizeMode.NONE;
|
2011-08-19 18:29:39 +00:00
|
|
|
|
|
|
|
let reactive = secret.key != null;
|
|
|
|
|
2019-12-12 09:32:53 +00:00
|
|
|
let entryParams = {
|
|
|
|
style_class: 'prompt-dialog-password-entry',
|
|
|
|
text: secret.value,
|
|
|
|
can_focus: reactive,
|
|
|
|
reactive,
|
|
|
|
x_expand: true,
|
|
|
|
};
|
|
|
|
if (secret.password)
|
|
|
|
secret.entry = new St.PasswordEntry(entryParams);
|
|
|
|
else
|
|
|
|
secret.entry = new St.Entry(entryParams);
|
|
|
|
ShellEntry.addContextMenu(secret.entry);
|
2011-08-19 18:29:39 +00:00
|
|
|
|
|
|
|
if (secret.validate)
|
|
|
|
secret.valid = secret.validate(secret);
|
|
|
|
else // no special validation, just ensure it's not empty
|
|
|
|
secret.valid = secret.value.length > 0;
|
|
|
|
|
|
|
|
if (reactive) {
|
2011-09-14 23:22:29 +00:00
|
|
|
if (!initialFocusSet) {
|
|
|
|
this.setInitialKeyFocus(secret.entry);
|
|
|
|
initialFocusSet = true;
|
|
|
|
}
|
|
|
|
|
2017-12-02 00:27:35 +00:00
|
|
|
secret.entry.clutter_text.connect('activate', this._onOk.bind(this));
|
2017-10-31 00:38:18 +00:00
|
|
|
secret.entry.clutter_text.connect('text-changed', () => {
|
2011-08-19 18:29:39 +00:00
|
|
|
secret.value = secret.entry.get_text();
|
|
|
|
if (secret.validate)
|
|
|
|
secret.valid = secret.validate(secret);
|
|
|
|
else
|
|
|
|
secret.valid = secret.value.length > 0;
|
|
|
|
this._updateOkButton();
|
2017-10-31 00:38:18 +00:00
|
|
|
});
|
2019-01-29 21:02:57 +00:00
|
|
|
} else {
|
2011-08-19 18:29:39 +00:00
|
|
|
secret.valid = true;
|
2019-01-29 21:02:57 +00:00
|
|
|
}
|
2011-08-19 18:29:39 +00:00
|
|
|
|
2014-06-20 14:41:22 +00:00
|
|
|
if (rtl) {
|
2014-08-06 13:16:39 +00:00
|
|
|
layout.attach(secret.entry, 0, pos, 1, 1);
|
|
|
|
layout.attach(label, 1, pos, 1, 1);
|
2014-06-20 14:41:22 +00:00
|
|
|
} else {
|
2014-08-06 13:16:39 +00:00
|
|
|
layout.attach(label, 0, pos, 1, 1);
|
|
|
|
layout.attach(secret.entry, 1, pos, 1, 1);
|
2014-06-20 14:41:22 +00:00
|
|
|
}
|
2011-08-19 18:29:39 +00:00
|
|
|
pos++;
|
|
|
|
}
|
2011-09-08 15:53:22 +00:00
|
|
|
|
2019-12-17 20:03:45 +00:00
|
|
|
if (this._content.secrets.some(s => s.password)) {
|
|
|
|
this._capsLockWarningLabel = new ShellEntry.CapsLockWarning();
|
|
|
|
if (rtl)
|
|
|
|
layout.attach(this._capsLockWarningLabel, 0, pos, 1, 1);
|
|
|
|
else
|
|
|
|
layout.attach(this._capsLockWarningLabel, 1, pos, 1, 1);
|
|
|
|
}
|
|
|
|
|
2017-07-15 04:03:55 +00:00
|
|
|
contentBox.messageBox.add(secretTable);
|
2011-08-19 18:29:39 +00:00
|
|
|
|
2017-07-27 10:15:29 +00:00
|
|
|
if (flags & NM.SecretAgentGetSecretsFlags.WPS_PBC_ACTIVE) {
|
|
|
|
let descriptionLabel = new St.Label({ style_class: 'prompt-dialog-description',
|
|
|
|
text: _("Alternatively you can connect by pushing the “WPS” button on your router.") });
|
|
|
|
descriptionLabel.clutter_text.line_wrap = true;
|
|
|
|
descriptionLabel.clutter_text.ellipsize = Pango.EllipsizeMode.NONE;
|
|
|
|
|
2019-10-21 18:44:00 +00:00
|
|
|
contentBox.messageBox.add_child(descriptionLabel);
|
2017-07-27 10:15:29 +00:00
|
|
|
}
|
|
|
|
|
2019-02-12 14:02:09 +00:00
|
|
|
this._okButton = {
|
|
|
|
label: _("Connect"),
|
|
|
|
action: this._onOk.bind(this),
|
|
|
|
default: true,
|
|
|
|
};
|
|
|
|
|
|
|
|
this.setButtons([{
|
|
|
|
label: _("Cancel"),
|
|
|
|
action: this.cancel.bind(this),
|
|
|
|
key: Clutter.KEY_Escape,
|
|
|
|
}, this._okButton]);
|
2013-11-03 21:10:11 +00:00
|
|
|
|
|
|
|
this._updateOkButton();
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2011-08-19 18:29:39 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_updateOkButton() {
|
2011-08-19 18:29:39 +00:00
|
|
|
let valid = true;
|
|
|
|
for (let i = 0; i < this._content.secrets.length; i++) {
|
|
|
|
let secret = this._content.secrets[i];
|
|
|
|
valid = valid && secret.valid;
|
|
|
|
}
|
|
|
|
|
|
|
|
this._okButton.button.reactive = valid;
|
2012-08-20 01:40:09 +00:00
|
|
|
this._okButton.button.can_focus = valid;
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2011-08-19 18:29:39 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_onOk() {
|
2011-08-19 18:29:39 +00:00
|
|
|
let valid = true;
|
|
|
|
for (let i = 0; i < this._content.secrets.length; i++) {
|
|
|
|
let secret = this._content.secrets[i];
|
|
|
|
valid = valid && secret.valid;
|
|
|
|
if (secret.key != null)
|
|
|
|
this._agent.set_password(this._requestId, secret.key, secret.value);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (valid) {
|
2011-11-03 20:57:33 +00:00
|
|
|
this._agent.respond(this._requestId, Shell.NetworkAgentResponse.CONFIRMED);
|
2011-08-19 18:29:39 +00:00
|
|
|
this.close(global.get_current_time());
|
|
|
|
}
|
|
|
|
// do nothing if not valid
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2011-08-19 18:29:39 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
cancel() {
|
2011-11-03 20:57:33 +00:00
|
|
|
this._agent.respond(this._requestId, Shell.NetworkAgentResponse.USER_CANCELED);
|
2011-08-19 18:29:39 +00:00
|
|
|
this.close(global.get_current_time());
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2011-08-19 18:29:39 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_validateWpaPsk(secret) {
|
2011-08-19 18:29:39 +00:00
|
|
|
let value = secret.value;
|
|
|
|
if (value.length == 64) {
|
|
|
|
// must be composed of hexadecimal digits only
|
|
|
|
for (let i = 0; i < 64; i++) {
|
2019-08-19 19:33:15 +00:00
|
|
|
if (!((value[i] >= 'a' && value[i] <= 'f') ||
|
|
|
|
(value[i] >= 'A' && value[i] <= 'F') ||
|
|
|
|
(value[i] >= '0' && value[i] <= '9')))
|
2011-08-19 18:29:39 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-08-19 19:38:51 +00:00
|
|
|
return value.length >= 8 && value.length <= 63;
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2011-08-19 18:29:39 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_validateStaticWep(secret) {
|
2011-08-19 18:29:39 +00:00
|
|
|
let value = secret.value;
|
2017-10-31 10:38:20 +00:00
|
|
|
if (secret.wep_key_type == NM.WepKeyType.KEY) {
|
2011-08-19 18:29:39 +00:00
|
|
|
if (value.length == 10 || value.length == 26) {
|
2019-01-29 20:18:46 +00:00
|
|
|
for (let i = 0; i < value.length; i++) {
|
2019-08-19 19:33:15 +00:00
|
|
|
if (!((value[i] >= 'a' && value[i] <= 'f') ||
|
|
|
|
(value[i] >= 'A' && value[i] <= 'F') ||
|
|
|
|
(value[i] >= '0' && value[i] <= '9')))
|
2011-08-19 18:29:39 +00:00
|
|
|
return false;
|
2019-01-29 20:18:46 +00:00
|
|
|
}
|
|
|
|
} else if (value.length == 5 || value.length == 13) {
|
|
|
|
for (let i = 0; i < value.length; i++) {
|
2019-08-19 19:33:15 +00:00
|
|
|
if (!((value[i] >= 'a' && value[i] <= 'z') ||
|
|
|
|
(value[i] >= 'A' && value[i] <= 'Z')))
|
2011-08-19 18:29:39 +00:00
|
|
|
return false;
|
|
|
|
}
|
2019-01-29 21:02:57 +00:00
|
|
|
} else {
|
2011-08-19 18:29:39 +00:00
|
|
|
return false;
|
2019-01-29 21:02:57 +00:00
|
|
|
}
|
2019-01-29 20:18:46 +00:00
|
|
|
} else if (secret.wep_key_type == NM.WepKeyType.PASSPHRASE) {
|
|
|
|
if (value.length < 0 || value.length > 64)
|
|
|
|
return false;
|
|
|
|
}
|
2011-08-19 18:29:39 +00:00
|
|
|
return true;
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2011-08-19 18:29:39 +00:00
|
|
|
|
2019-01-31 14:08:10 +00:00
|
|
|
_getWirelessSecrets(secrets, _wirelessSetting) {
|
2011-08-19 18:29:39 +00:00
|
|
|
let wirelessSecuritySetting = this._connection.get_setting_wireless_security();
|
2018-09-18 03:47:43 +00:00
|
|
|
|
|
|
|
if (this._settingName == '802-1x') {
|
|
|
|
this._get8021xSecrets(secrets);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-08-19 18:29:39 +00:00
|
|
|
switch (wirelessSecuritySetting.key_mgmt) {
|
|
|
|
// First the easy ones
|
|
|
|
case 'wpa-none':
|
|
|
|
case 'wpa-psk':
|
2019-10-04 12:21:25 +00:00
|
|
|
case 'sae':
|
2011-08-19 18:29:39 +00:00
|
|
|
secrets.push({ label: _("Password: "), key: 'psk',
|
|
|
|
value: wirelessSecuritySetting.psk || '',
|
|
|
|
validate: this._validateWpaPsk, password: true });
|
|
|
|
break;
|
|
|
|
case 'none': // static WEP
|
2019-01-30 00:18:24 +00:00
|
|
|
secrets.push({ label: _("Key: "), key: `wep-key${wirelessSecuritySetting.wep_tx_keyidx}`,
|
2011-08-19 18:29:39 +00:00
|
|
|
value: wirelessSecuritySetting.get_wep_key(wirelessSecuritySetting.wep_tx_keyidx) || '',
|
|
|
|
wep_key_type: wirelessSecuritySetting.wep_key_type,
|
|
|
|
validate: this._validateStaticWep, password: true });
|
|
|
|
break;
|
|
|
|
case 'ieee8021x':
|
2019-08-20 00:51:42 +00:00
|
|
|
if (wirelessSecuritySetting.auth_alg == 'leap') { // Cisco LEAP
|
2011-08-19 18:29:39 +00:00
|
|
|
secrets.push({ label: _("Password: "), key: 'leap-password',
|
|
|
|
value: wirelessSecuritySetting.leap_password || '', password: true });
|
2019-08-20 00:51:42 +00:00
|
|
|
} else { // Dynamic (IEEE 802.1x) WEP
|
2011-08-19 18:29:39 +00:00
|
|
|
this._get8021xSecrets(secrets);
|
2019-08-20 00:51:42 +00:00
|
|
|
}
|
2011-08-19 18:29:39 +00:00
|
|
|
break;
|
|
|
|
case 'wpa-eap':
|
|
|
|
this._get8021xSecrets(secrets);
|
|
|
|
break;
|
|
|
|
default:
|
2019-01-30 00:18:24 +00:00
|
|
|
log(`Invalid wireless key management: ${wirelessSecuritySetting.key_mgmt}`);
|
2011-08-19 18:29:39 +00:00
|
|
|
}
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2011-08-19 18:29:39 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_get8021xSecrets(secrets) {
|
2011-08-19 18:29:39 +00:00
|
|
|
let ieee8021xSetting = this._connection.get_setting_802_1x();
|
|
|
|
|
2018-09-18 03:47:43 +00:00
|
|
|
/* If hints were given we know exactly what we need to ask */
|
|
|
|
if (this._settingName == "802-1x" && this._hints.length) {
|
2019-08-20 00:51:42 +00:00
|
|
|
if (this._hints.includes('identity')) {
|
2018-09-18 03:47:43 +00:00
|
|
|
secrets.push({ label: _("Username: "), key: 'identity',
|
|
|
|
value: ieee8021xSetting.identity || '', password: false });
|
2019-08-20 00:51:42 +00:00
|
|
|
}
|
|
|
|
if (this._hints.includes('password')) {
|
2018-09-18 03:47:43 +00:00
|
|
|
secrets.push({ label: _("Password: "), key: 'password',
|
|
|
|
value: ieee8021xSetting.password || '', password: true });
|
2019-08-20 00:51:42 +00:00
|
|
|
}
|
|
|
|
if (this._hints.includes('private-key-password')) {
|
2018-09-18 03:47:43 +00:00
|
|
|
secrets.push({ label: _("Private key password: "), key: 'private-key-password',
|
|
|
|
value: ieee8021xSetting.private_key_password || '', password: true });
|
2019-08-20 00:51:42 +00:00
|
|
|
}
|
2018-09-18 03:47:43 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-08-19 18:29:39 +00:00
|
|
|
switch (ieee8021xSetting.get_eap_method(0)) {
|
|
|
|
case 'md5':
|
|
|
|
case 'leap':
|
|
|
|
case 'ttls':
|
|
|
|
case 'peap':
|
2013-12-03 23:33:20 +00:00
|
|
|
case 'fast':
|
2011-08-19 18:29:39 +00:00
|
|
|
// TTLS and PEAP are actually much more complicated, but this complication
|
|
|
|
// is not visible here since we only care about phase2 authentication
|
|
|
|
// (and don't even care of which one)
|
|
|
|
secrets.push({ label: _("Username: "), key: null,
|
|
|
|
value: ieee8021xSetting.identity || '', password: false });
|
|
|
|
secrets.push({ label: _("Password: "), key: 'password',
|
|
|
|
value: ieee8021xSetting.password || '', password: true });
|
|
|
|
break;
|
|
|
|
case 'tls':
|
|
|
|
secrets.push({ label: _("Identity: "), key: null,
|
|
|
|
value: ieee8021xSetting.identity || '', password: false });
|
|
|
|
secrets.push({ label: _("Private key password: "), key: 'private-key-password',
|
|
|
|
value: ieee8021xSetting.private_key_password || '', password: true });
|
|
|
|
break;
|
|
|
|
default:
|
2019-01-30 00:18:24 +00:00
|
|
|
log(`Invalid EAP/IEEE802.1x method: ${ieee8021xSetting.get_eap_method(0)}`);
|
2011-08-19 18:29:39 +00:00
|
|
|
}
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2011-08-19 18:29:39 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_getPPPoESecrets(secrets) {
|
2011-08-19 18:29:39 +00:00
|
|
|
let pppoeSetting = this._connection.get_setting_pppoe();
|
|
|
|
secrets.push({ label: _("Username: "), key: 'username',
|
|
|
|
value: pppoeSetting.username || '', password: false });
|
|
|
|
secrets.push({ label: _("Service: "), key: 'service',
|
|
|
|
value: pppoeSetting.service || '', password: false });
|
|
|
|
secrets.push({ label: _("Password: "), key: 'password',
|
|
|
|
value: pppoeSetting.password || '', password: true });
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2011-08-19 18:29:39 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_getMobileSecrets(secrets, connectionType) {
|
2011-08-19 18:29:39 +00:00
|
|
|
let setting;
|
|
|
|
if (connectionType == 'bluetooth')
|
|
|
|
setting = this._connection.get_setting_cdma() || this._connection.get_setting_gsm();
|
|
|
|
else
|
|
|
|
setting = this._connection.get_setting_by_name(connectionType);
|
|
|
|
secrets.push({ label: _("Password: "), key: 'password',
|
|
|
|
value: setting.value || '', password: true });
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2011-08-19 18:29:39 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_getContent() {
|
2011-08-19 18:29:39 +00:00
|
|
|
let connectionSetting = this._connection.get_setting_connection();
|
|
|
|
let connectionType = connectionSetting.get_connection_type();
|
|
|
|
let wirelessSetting;
|
|
|
|
let ssid;
|
|
|
|
|
|
|
|
let content = { };
|
2019-01-29 01:27:05 +00:00
|
|
|
content.secrets = [];
|
2011-08-19 18:29:39 +00:00
|
|
|
|
|
|
|
switch (connectionType) {
|
|
|
|
case '802-11-wireless':
|
|
|
|
wirelessSetting = this._connection.get_setting_wireless();
|
2017-10-31 10:38:20 +00:00
|
|
|
ssid = NM.utils_ssid_to_utf8(wirelessSetting.get_ssid().get_data());
|
2011-08-19 18:29:39 +00:00
|
|
|
content.title = _("Authentication required by wireless network");
|
2014-01-17 21:30:49 +00:00
|
|
|
content.message = _("Passwords or encryption keys are required to access the wireless network “%s”.").format(ssid);
|
2011-08-19 18:29:39 +00:00
|
|
|
this._getWirelessSecrets(content.secrets, wirelessSetting);
|
|
|
|
break;
|
|
|
|
case '802-3-ethernet':
|
|
|
|
content.title = _("Wired 802.1X authentication");
|
|
|
|
content.message = null;
|
|
|
|
content.secrets.push({ label: _("Network name: "), key: null,
|
|
|
|
value: connectionSetting.get_id(), password: false });
|
|
|
|
this._get8021xSecrets(content.secrets);
|
|
|
|
break;
|
|
|
|
case 'pppoe':
|
|
|
|
content.title = _("DSL authentication");
|
|
|
|
content.message = null;
|
|
|
|
this._getPPPoESecrets(content.secrets);
|
|
|
|
break;
|
|
|
|
case 'gsm':
|
2018-07-14 20:56:22 +00:00
|
|
|
if (this._hints.includes('pin')) {
|
2011-08-19 18:29:39 +00:00
|
|
|
let gsmSetting = this._connection.get_setting_gsm();
|
|
|
|
content.title = _("PIN code required");
|
|
|
|
content.message = _("PIN code is needed for the mobile broadband device");
|
|
|
|
content.secrets.push({ label: _("PIN: "), key: 'pin',
|
|
|
|
value: gsmSetting.pin || '', password: true });
|
2012-06-14 17:53:52 +00:00
|
|
|
break;
|
2011-08-19 18:29:39 +00:00
|
|
|
}
|
|
|
|
// fall through
|
|
|
|
case 'cdma':
|
|
|
|
case 'bluetooth':
|
|
|
|
content.title = _("Mobile broadband network password");
|
2014-01-17 21:30:49 +00:00
|
|
|
content.message = _("A password is required to connect to “%s”.").format(connectionSetting.get_id());
|
2011-09-07 17:16:01 +00:00
|
|
|
this._getMobileSecrets(content.secrets, connectionType);
|
2011-08-19 18:29:39 +00:00
|
|
|
break;
|
|
|
|
default:
|
2019-01-30 00:18:24 +00:00
|
|
|
log(`Invalid connection type: ${connectionType}`);
|
2019-01-29 01:18:52 +00:00
|
|
|
}
|
2011-08-19 18:29:39 +00:00
|
|
|
|
|
|
|
return content;
|
|
|
|
}
|
2019-05-23 20:45:44 +00:00
|
|
|
});
|
2011-11-03 20:57:33 +00:00
|
|
|
|
2017-10-31 01:19:44 +00:00
|
|
|
var VPNRequestHandler = class {
|
|
|
|
constructor(agent, requestId, authHelper, serviceType, connection, hints, flags) {
|
2011-11-03 20:57:33 +00:00
|
|
|
this._agent = agent;
|
|
|
|
this._requestId = requestId;
|
|
|
|
this._connection = connection;
|
2017-07-27 10:15:29 +00:00
|
|
|
this._flags = flags;
|
2011-11-03 20:57:33 +00:00
|
|
|
this._pluginOutBuffer = [];
|
|
|
|
this._title = null;
|
|
|
|
this._description = null;
|
2019-01-29 01:27:05 +00:00
|
|
|
this._content = [];
|
2011-11-03 20:57:33 +00:00
|
|
|
this._shellDialog = null;
|
|
|
|
|
|
|
|
let connectionSetting = connection.get_setting_connection();
|
|
|
|
|
2019-01-29 01:27:05 +00:00
|
|
|
let argv = [authHelper.fileName,
|
2019-01-29 19:36:54 +00:00
|
|
|
'-u', connectionSetting.uuid,
|
|
|
|
'-n', connectionSetting.id,
|
|
|
|
'-s', serviceType];
|
2011-11-03 20:57:33 +00:00
|
|
|
if (authHelper.externalUIMode)
|
|
|
|
argv.push('--external-ui-mode');
|
2017-10-31 10:38:20 +00:00
|
|
|
if (flags & NM.SecretAgentGetSecretsFlags.ALLOW_INTERACTION)
|
2011-11-03 20:57:33 +00:00
|
|
|
argv.push('-i');
|
2017-10-31 10:38:20 +00:00
|
|
|
if (flags & NM.SecretAgentGetSecretsFlags.REQUEST_NEW)
|
2011-11-03 20:57:33 +00:00
|
|
|
argv.push('-r');
|
2014-07-07 21:44:44 +00:00
|
|
|
if (authHelper.supportsHints) {
|
|
|
|
for (let i = 0; i < hints.length; i++) {
|
|
|
|
argv.push('-t');
|
|
|
|
argv.push(hints[i]);
|
|
|
|
}
|
|
|
|
}
|
2011-11-03 20:57:33 +00:00
|
|
|
|
|
|
|
this._newStylePlugin = authHelper.externalUIMode;
|
|
|
|
|
|
|
|
try {
|
2019-01-31 14:08:00 +00:00
|
|
|
let [success_, pid, stdin, stdout, stderr] =
|
2011-11-03 20:57:33 +00:00
|
|
|
GLib.spawn_async_with_pipes(null, /* pwd */
|
|
|
|
argv,
|
|
|
|
null, /* envp */
|
|
|
|
GLib.SpawnFlags.DO_NOT_REAP_CHILD,
|
|
|
|
null /* child_setup */);
|
|
|
|
|
|
|
|
this._childPid = pid;
|
|
|
|
this._stdin = new Gio.UnixOutputStream({ fd: stdin, close_fd: true });
|
|
|
|
this._stdout = new Gio.UnixInputStream({ fd: stdout, close_fd: true });
|
2013-09-02 07:59:01 +00:00
|
|
|
GLib.close(stderr);
|
2011-11-03 20:57:33 +00:00
|
|
|
this._dataStdout = new Gio.DataInputStream({ base_stream: this._stdout });
|
|
|
|
|
|
|
|
if (this._newStylePlugin)
|
|
|
|
this._readStdoutNewStyle();
|
|
|
|
else
|
|
|
|
this._readStdoutOldStyle();
|
|
|
|
|
|
|
|
this._childWatch = GLib.child_watch_add(GLib.PRIORITY_DEFAULT, pid,
|
2017-12-02 00:27:35 +00:00
|
|
|
this._vpnChildFinished.bind(this));
|
2011-11-03 20:57:33 +00:00
|
|
|
|
|
|
|
this._writeConnection();
|
2019-01-29 01:26:39 +00:00
|
|
|
} catch (e) {
|
2011-11-03 20:57:33 +00:00
|
|
|
logError(e, 'error while spawning VPN auth helper');
|
|
|
|
|
|
|
|
this._agent.respond(requestId, Shell.NetworkAgentResponse.INTERNAL_ERROR);
|
|
|
|
}
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2011-11-03 20:57:33 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
cancel(respond) {
|
2012-10-22 21:13:45 +00:00
|
|
|
if (respond)
|
|
|
|
this._agent.respond(this._requestId, Shell.NetworkAgentResponse.USER_CANCELED);
|
|
|
|
|
2011-11-03 20:57:33 +00:00
|
|
|
if (this._newStylePlugin && this._shellDialog) {
|
|
|
|
this._shellDialog.close(global.get_current_time());
|
|
|
|
this._shellDialog.destroy();
|
|
|
|
} else {
|
|
|
|
try {
|
|
|
|
this._stdin.write('QUIT\n\n', null);
|
2019-01-29 01:26:39 +00:00
|
|
|
} catch (e) { /* ignore broken pipe errors */ }
|
2011-11-03 20:57:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
this.destroy();
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2011-11-03 20:57:33 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
destroy() {
|
2011-11-03 20:57:33 +00:00
|
|
|
if (this._destroyed)
|
|
|
|
return;
|
|
|
|
|
2017-12-06 15:55:15 +00:00
|
|
|
this.emit('destroy');
|
|
|
|
if (this._childWatch)
|
|
|
|
GLib.source_remove(this._childWatch);
|
2011-11-03 20:57:33 +00:00
|
|
|
|
|
|
|
this._stdin.close(null);
|
|
|
|
// Stdout is closed when we finish reading from it
|
|
|
|
|
|
|
|
this._destroyed = true;
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2011-11-03 20:57:33 +00:00
|
|
|
|
2019-01-31 14:08:10 +00:00
|
|
|
_vpnChildFinished(pid, status, _requestObj) {
|
2013-11-08 03:48:51 +00:00
|
|
|
this._childWatch = 0;
|
2011-11-03 20:57:33 +00:00
|
|
|
if (this._newStylePlugin) {
|
|
|
|
// For new style plugin, all work is done in the async reading functions
|
|
|
|
// Just reap the process here
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let [exited, exitStatus] = Shell.util_wifexited(status);
|
|
|
|
|
|
|
|
if (exited) {
|
|
|
|
if (exitStatus != 0)
|
|
|
|
this._agent.respond(this._requestId, Shell.NetworkAgentResponse.USER_CANCELED);
|
|
|
|
else
|
|
|
|
this._agent.respond(this._requestId, Shell.NetworkAgentResponse.CONFIRMED);
|
2019-01-29 21:02:57 +00:00
|
|
|
} else {
|
2011-11-03 20:57:33 +00:00
|
|
|
this._agent.respond(this._requestId, Shell.NetworkAgentResponse.INTERNAL_ERROR);
|
2019-01-29 21:02:57 +00:00
|
|
|
}
|
2011-11-03 20:57:33 +00:00
|
|
|
|
|
|
|
this.destroy();
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2011-11-03 20:57:33 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_vpnChildProcessLineOldStyle(line) {
|
2011-11-03 20:57:33 +00:00
|
|
|
if (this._previousLine != undefined) {
|
|
|
|
// Two consecutive newlines mean that the child should be closed
|
|
|
|
// (the actual newlines are eaten by Gio.DataInputStream)
|
|
|
|
// Send a termination message
|
|
|
|
if (line == '' && this._previousLine == '') {
|
|
|
|
try {
|
|
|
|
this._stdin.write('QUIT\n\n', null);
|
2019-01-29 01:26:39 +00:00
|
|
|
} catch (e) { /* ignore broken pipe errors */ }
|
2011-11-03 20:57:33 +00:00
|
|
|
} else {
|
|
|
|
this._agent.set_password(this._requestId, this._previousLine, line);
|
|
|
|
this._previousLine = undefined;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
this._previousLine = line;
|
|
|
|
}
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2011-11-03 20:57:33 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_readStdoutOldStyle() {
|
2017-10-31 00:38:18 +00:00
|
|
|
this._dataStdout.read_line_async(GLib.PRIORITY_DEFAULT, null, (stream, result) => {
|
2019-01-31 14:08:00 +00:00
|
|
|
let [line, len_] = this._dataStdout.read_line_finish_utf8(result);
|
2011-11-03 20:57:33 +00:00
|
|
|
|
|
|
|
if (line == null) {
|
|
|
|
// end of file
|
|
|
|
this._stdout.close(null);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this._vpnChildProcessLineOldStyle(line);
|
|
|
|
|
|
|
|
// try to read more!
|
|
|
|
this._readStdoutOldStyle();
|
2017-10-31 00:38:18 +00:00
|
|
|
});
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2011-11-03 20:57:33 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_readStdoutNewStyle() {
|
2017-10-31 00:38:18 +00:00
|
|
|
this._dataStdout.fill_async(-1, GLib.PRIORITY_DEFAULT, null, (stream, result) => {
|
2011-11-03 20:57:33 +00:00
|
|
|
let cnt = this._dataStdout.fill_finish(result);
|
|
|
|
|
|
|
|
if (cnt == 0) {
|
|
|
|
// end of file
|
|
|
|
this._showNewStyleDialog();
|
|
|
|
|
|
|
|
this._stdout.close(null);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Try to read more
|
|
|
|
this._dataStdout.set_buffer_size(2 * this._dataStdout.get_buffer_size());
|
|
|
|
this._readStdoutNewStyle();
|
2017-10-31 00:38:18 +00:00
|
|
|
});
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2011-11-03 20:57:33 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_showNewStyleDialog() {
|
2011-11-03 20:57:33 +00:00
|
|
|
let keyfile = new GLib.KeyFile();
|
2014-04-23 06:52:37 +00:00
|
|
|
let data;
|
2011-11-03 20:57:33 +00:00
|
|
|
let contentOverride;
|
|
|
|
|
|
|
|
try {
|
2014-04-23 06:52:37 +00:00
|
|
|
data = this._dataStdout.peek_buffer();
|
|
|
|
|
2018-08-02 21:54:08 +00:00
|
|
|
if (data instanceof Uint8Array)
|
|
|
|
data = imports.byteArray.toGBytes(data);
|
|
|
|
else
|
|
|
|
data = data.toGBytes();
|
|
|
|
|
|
|
|
keyfile.load_from_bytes(data, GLib.KeyFileFlags.NONE);
|
2011-11-03 20:57:33 +00:00
|
|
|
|
|
|
|
if (keyfile.get_integer(VPN_UI_GROUP, 'Version') != 2)
|
|
|
|
throw new Error('Invalid plugin keyfile version, is %d');
|
|
|
|
|
|
|
|
contentOverride = { title: keyfile.get_string(VPN_UI_GROUP, 'Title'),
|
|
|
|
message: keyfile.get_string(VPN_UI_GROUP, 'Description'),
|
|
|
|
secrets: [] };
|
|
|
|
|
2019-01-31 14:08:00 +00:00
|
|
|
let [groups, len_] = keyfile.get_groups();
|
2011-11-03 20:57:33 +00:00
|
|
|
for (let i = 0; i < groups.length; i++) {
|
|
|
|
if (groups[i] == VPN_UI_GROUP)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
let value = keyfile.get_string(groups[i], 'Value');
|
|
|
|
let shouldAsk = keyfile.get_boolean(groups[i], 'ShouldAsk');
|
|
|
|
|
|
|
|
if (shouldAsk) {
|
2019-02-12 14:02:09 +00:00
|
|
|
contentOverride.secrets.push({
|
|
|
|
label: keyfile.get_string(groups[i], 'Label'),
|
|
|
|
key: groups[i],
|
2019-08-19 19:06:04 +00:00
|
|
|
value,
|
2019-02-12 14:02:09 +00:00
|
|
|
password: keyfile.get_boolean(groups[i], 'IsSecret'),
|
|
|
|
});
|
2011-11-03 20:57:33 +00:00
|
|
|
} else {
|
|
|
|
if (!value.length) // Ignore empty secrets
|
|
|
|
continue;
|
|
|
|
|
|
|
|
this._agent.set_password(this._requestId, groups[i], value);
|
|
|
|
}
|
|
|
|
}
|
2019-01-29 01:26:39 +00:00
|
|
|
} catch (e) {
|
2014-04-23 06:52:37 +00:00
|
|
|
// No output is a valid case it means "both secrets are stored"
|
|
|
|
if (data.length > 0) {
|
|
|
|
logError(e, 'error while reading VPN plugin output keyfile');
|
2011-11-03 20:57:33 +00:00
|
|
|
|
2014-04-23 06:52:37 +00:00
|
|
|
this._agent.respond(this._requestId, Shell.NetworkAgentResponse.INTERNAL_ERROR);
|
2017-12-06 15:55:15 +00:00
|
|
|
this.destroy();
|
2014-04-23 06:52:37 +00:00
|
|
|
return;
|
|
|
|
}
|
2011-11-03 20:57:33 +00:00
|
|
|
}
|
|
|
|
|
2014-04-23 06:52:37 +00:00
|
|
|
if (contentOverride && contentOverride.secrets.length) {
|
2011-11-03 20:57:33 +00:00
|
|
|
// Only show the dialog if we actually have something to ask
|
2017-07-27 10:15:29 +00:00
|
|
|
this._shellDialog = new NetworkSecretDialog(this._agent, this._requestId, this._connection, 'vpn', [], this._flags, contentOverride);
|
2011-11-03 20:57:33 +00:00
|
|
|
this._shellDialog.open(global.get_current_time());
|
|
|
|
} else {
|
|
|
|
this._agent.respond(this._requestId, Shell.NetworkAgentResponse.CONFIRMED);
|
2017-12-06 15:55:15 +00:00
|
|
|
this.destroy();
|
2011-11-03 20:57:33 +00:00
|
|
|
}
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2011-11-03 20:57:33 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_writeConnection() {
|
2011-11-03 20:57:33 +00:00
|
|
|
let vpnSetting = this._connection.get_setting_vpn();
|
|
|
|
|
|
|
|
try {
|
2017-10-31 00:38:18 +00:00
|
|
|
vpnSetting.foreach_data_item((key, value) => {
|
2019-01-30 00:18:24 +00:00
|
|
|
this._stdin.write(`DATA_KEY=${key}\n`, null);
|
|
|
|
this._stdin.write(`DATA_VAL=${value || ''}\n\n`, null);
|
2017-10-31 00:38:18 +00:00
|
|
|
});
|
|
|
|
vpnSetting.foreach_secret((key, value) => {
|
2019-01-30 00:18:24 +00:00
|
|
|
this._stdin.write(`SECRET_KEY=${key}\n`, null);
|
|
|
|
this._stdin.write(`SECRET_VAL=${value || ''}\n\n`, null);
|
2017-10-31 00:38:18 +00:00
|
|
|
});
|
2011-11-03 20:57:33 +00:00
|
|
|
this._stdin.write('DONE\n\n', null);
|
2019-01-29 01:26:39 +00:00
|
|
|
} catch (e) {
|
2011-11-03 20:57:33 +00:00
|
|
|
logError(e, 'internal error while writing connection to helper');
|
|
|
|
|
|
|
|
this._agent.respond(this._requestId, Shell.NetworkAgentResponse.INTERNAL_ERROR);
|
2017-12-06 15:55:15 +00:00
|
|
|
this.destroy();
|
2011-11-03 20:57:33 +00:00
|
|
|
}
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
|
|
|
};
|
2017-12-06 15:55:15 +00:00
|
|
|
Signals.addSignalMethods(VPNRequestHandler.prototype);
|
2011-11-03 20:57:33 +00:00
|
|
|
|
2017-10-31 01:19:44 +00:00
|
|
|
var NetworkAgent = class {
|
|
|
|
constructor() {
|
2019-02-12 14:02:09 +00:00
|
|
|
this._native = new Shell.NetworkAgent({
|
|
|
|
identifier: 'org.gnome.Shell.NetworkAgent',
|
|
|
|
capabilities: NM.SecretAgentCapabilities.VPN_HINTS,
|
|
|
|
auto_register: false,
|
|
|
|
});
|
2011-08-19 18:29:39 +00:00
|
|
|
|
|
|
|
this._dialogs = { };
|
2011-11-03 20:57:33 +00:00
|
|
|
this._vpnRequests = { };
|
2012-06-14 17:53:52 +00:00
|
|
|
this._notifications = { };
|
2011-11-03 20:57:33 +00:00
|
|
|
|
2018-01-21 20:04:37 +00:00
|
|
|
this._pluginDir = Gio.file_new_for_path(Config.VPNDIR);
|
2016-11-03 12:32:40 +00:00
|
|
|
try {
|
|
|
|
let monitor = this._pluginDir.monitor(Gio.FileMonitorFlags.NONE, null);
|
2019-08-19 20:20:35 +00:00
|
|
|
monitor.connect('changed', () => (this._vpnCacheBuilt = false));
|
2019-01-29 01:26:39 +00:00
|
|
|
} catch (e) {
|
2019-01-30 00:18:24 +00:00
|
|
|
log(`Failed to create monitor for VPN plugin dir: ${e.message}`);
|
2016-11-03 12:32:40 +00:00
|
|
|
}
|
|
|
|
|
2017-12-02 00:27:35 +00:00
|
|
|
this._native.connect('new-request', this._newRequest.bind(this));
|
|
|
|
this._native.connect('cancel-request', this._cancelRequest.bind(this));
|
2018-01-11 09:50:45 +00:00
|
|
|
|
|
|
|
this._initialized = false;
|
|
|
|
this._native.init_async(GLib.PRIORITY_DEFAULT, null, (o, res) => {
|
|
|
|
try {
|
|
|
|
this._native.init_finish(res);
|
|
|
|
this._initialized = true;
|
2019-01-29 01:26:39 +00:00
|
|
|
} catch (e) {
|
2018-01-11 09:50:45 +00:00
|
|
|
this._native = null;
|
|
|
|
logError(e, 'error initializing the NetworkManager Agent');
|
|
|
|
}
|
|
|
|
});
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2011-08-19 18:29:39 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
enable() {
|
2017-12-06 15:55:20 +00:00
|
|
|
if (!this._native)
|
|
|
|
return;
|
|
|
|
|
|
|
|
this._native.auto_register = true;
|
2018-01-11 09:50:45 +00:00
|
|
|
if (this._initialized && !this._native.registered)
|
2017-12-06 15:55:20 +00:00
|
|
|
this._native.register_async(null, null);
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2012-09-03 01:23:50 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
disable() {
|
2012-10-22 21:13:45 +00:00
|
|
|
let requestId;
|
|
|
|
|
|
|
|
for (requestId in this._dialogs)
|
|
|
|
this._dialogs[requestId].cancel();
|
|
|
|
this._dialogs = { };
|
|
|
|
|
|
|
|
for (requestId in this._vpnRequests)
|
|
|
|
this._vpnRequests[requestId].cancel(true);
|
|
|
|
this._vpnRequests = { };
|
|
|
|
|
2012-06-14 17:53:52 +00:00
|
|
|
for (requestId in this._notifications)
|
|
|
|
this._notifications[requestId].destroy();
|
|
|
|
this._notifications = { };
|
|
|
|
|
2017-12-06 15:55:20 +00:00
|
|
|
if (!this._native)
|
|
|
|
return;
|
|
|
|
|
|
|
|
this._native.auto_register = false;
|
2018-01-11 09:50:45 +00:00
|
|
|
if (this._initialized && this._native.registered)
|
2017-12-06 15:55:20 +00:00
|
|
|
this._native.unregister_async(null, null);
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2012-09-03 01:23:50 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_showNotification(requestId, connection, settingName, hints, flags) {
|
2012-06-14 17:53:52 +00:00
|
|
|
let source = new MessageTray.Source(_("Network Manager"), 'network-transmit-receive');
|
|
|
|
source.policy = new MessageTray.NotificationApplicationPolicy('gnome-network-panel');
|
|
|
|
|
|
|
|
let title, body;
|
|
|
|
|
|
|
|
let connectionSetting = connection.get_setting_connection();
|
|
|
|
let connectionType = connectionSetting.get_connection_type();
|
|
|
|
switch (connectionType) {
|
2019-01-29 23:22:10 +00:00
|
|
|
case '802-11-wireless': {
|
2012-06-14 17:53:52 +00:00
|
|
|
let wirelessSetting = connection.get_setting_wireless();
|
2018-05-09 14:17:17 +00:00
|
|
|
let ssid = NM.utils_ssid_to_utf8(wirelessSetting.get_ssid().get_data());
|
2012-06-14 17:53:52 +00:00
|
|
|
title = _("Authentication required by wireless network");
|
2015-03-12 21:23:57 +00:00
|
|
|
body = _("Passwords or encryption keys are required to access the wireless network “%s”.").format(ssid);
|
2012-06-14 17:53:52 +00:00
|
|
|
break;
|
2019-01-29 23:22:10 +00:00
|
|
|
}
|
2012-06-14 17:53:52 +00:00
|
|
|
case '802-3-ethernet':
|
|
|
|
title = _("Wired 802.1X authentication");
|
2015-03-12 21:23:57 +00:00
|
|
|
body = _("A password is required to connect to “%s”.".format(connection.get_id()));
|
2012-06-14 17:53:52 +00:00
|
|
|
break;
|
|
|
|
case 'pppoe':
|
|
|
|
title = _("DSL authentication");
|
2015-03-12 21:23:57 +00:00
|
|
|
body = _("A password is required to connect to “%s”.".format(connection.get_id()));
|
2012-06-14 17:53:52 +00:00
|
|
|
break;
|
|
|
|
case 'gsm':
|
2018-07-14 20:56:22 +00:00
|
|
|
if (hints.includes('pin')) {
|
2012-06-14 17:53:52 +00:00
|
|
|
title = _("PIN code required");
|
2019-01-29 21:53:55 +00:00
|
|
|
body = _("PIN code is needed for the mobile broadband device");
|
2012-06-14 17:53:52 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
// fall through
|
|
|
|
case 'cdma':
|
|
|
|
case 'bluetooth':
|
|
|
|
title = _("Mobile broadband network password");
|
2019-01-29 21:53:55 +00:00
|
|
|
body = _("A password is required to connect to “%s”.").format(connectionSetting.get_id());
|
2019-12-16 23:21:46 +00:00
|
|
|
break;
|
|
|
|
case 'vpn':
|
|
|
|
title = _("VPN password");
|
|
|
|
body = _("A password is required to connect to “%s”.").format(connectionSetting.get_id());
|
2012-06-14 17:53:52 +00:00
|
|
|
break;
|
|
|
|
default:
|
2019-01-30 00:18:24 +00:00
|
|
|
log(`Invalid connection type: ${connectionType}`);
|
2012-06-14 17:53:52 +00:00
|
|
|
this._native.respond(requestId, Shell.NetworkAgentResponse.INTERNAL_ERROR);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let notification = new MessageTray.Notification(source, title, body);
|
|
|
|
|
2017-10-31 00:38:18 +00:00
|
|
|
notification.connect('activated', () => {
|
2012-06-14 17:53:52 +00:00
|
|
|
notification.answered = true;
|
|
|
|
this._handleRequest(requestId, connection, settingName, hints, flags);
|
2017-10-31 00:38:18 +00:00
|
|
|
});
|
2012-06-14 17:53:52 +00:00
|
|
|
|
|
|
|
this._notifications[requestId] = notification;
|
2017-10-31 00:38:18 +00:00
|
|
|
notification.connect('destroy', () => {
|
2012-06-14 17:53:52 +00:00
|
|
|
if (!notification.answered)
|
|
|
|
this._native.respond(requestId, Shell.NetworkAgentResponse.USER_CANCELED);
|
|
|
|
delete this._notifications[requestId];
|
2017-10-31 00:38:18 +00:00
|
|
|
});
|
2012-06-14 17:53:52 +00:00
|
|
|
|
|
|
|
Main.messageTray.add(source);
|
2019-05-13 21:32:31 +00:00
|
|
|
source.showNotification(notification);
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2012-06-14 17:53:52 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_newRequest(agent, requestId, connection, settingName, hints, flags) {
|
2017-10-31 10:38:20 +00:00
|
|
|
if (!(flags & NM.SecretAgentGetSecretsFlags.USER_REQUESTED))
|
2012-06-14 17:53:52 +00:00
|
|
|
this._showNotification(requestId, connection, settingName, hints, flags);
|
|
|
|
else
|
|
|
|
this._handleRequest(requestId, connection, settingName, hints, flags);
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2012-06-14 17:53:52 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_handleRequest(requestId, connection, settingName, hints, flags) {
|
2011-11-03 20:57:33 +00:00
|
|
|
if (settingName == 'vpn') {
|
|
|
|
this._vpnRequest(requestId, connection, hints, flags);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-07-27 10:15:29 +00:00
|
|
|
let dialog = new NetworkSecretDialog(this._native, requestId, connection, settingName, hints, flags);
|
2017-10-31 00:38:18 +00:00
|
|
|
dialog.connect('destroy', () => {
|
2011-08-19 18:29:39 +00:00
|
|
|
delete this._dialogs[requestId];
|
2017-10-31 00:38:18 +00:00
|
|
|
});
|
2011-08-19 18:29:39 +00:00
|
|
|
this._dialogs[requestId] = dialog;
|
|
|
|
dialog.open(global.get_current_time());
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2011-08-19 18:29:39 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_cancelRequest(agent, requestId) {
|
2011-11-03 20:57:33 +00:00
|
|
|
if (this._dialogs[requestId]) {
|
|
|
|
this._dialogs[requestId].close(global.get_current_time());
|
|
|
|
this._dialogs[requestId].destroy();
|
|
|
|
delete this._dialogs[requestId];
|
|
|
|
} else if (this._vpnRequests[requestId]) {
|
2012-10-22 21:13:45 +00:00
|
|
|
this._vpnRequests[requestId].cancel(false);
|
2011-11-03 20:57:33 +00:00
|
|
|
delete this._vpnRequests[requestId];
|
|
|
|
}
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2011-11-03 20:57:33 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_vpnRequest(requestId, connection, hints, flags) {
|
2011-11-03 20:57:33 +00:00
|
|
|
let vpnSetting = connection.get_setting_vpn();
|
|
|
|
let serviceType = vpnSetting.service_type;
|
|
|
|
|
|
|
|
this._buildVPNServiceCache();
|
|
|
|
|
|
|
|
let binary = this._vpnBinaries[serviceType];
|
|
|
|
if (!binary) {
|
|
|
|
log('Invalid VPN service type (cannot find authentication binary)');
|
|
|
|
|
|
|
|
/* cancel the auth process */
|
|
|
|
this._native.respond(requestId, Shell.NetworkAgentResponse.INTERNAL_ERROR);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-12-06 15:55:15 +00:00
|
|
|
let vpnRequest = new VPNRequestHandler(this._native, requestId, binary, serviceType, connection, hints, flags);
|
2017-10-31 00:38:18 +00:00
|
|
|
vpnRequest.connect('destroy', () => {
|
2017-12-06 15:55:15 +00:00
|
|
|
delete this._vpnRequests[requestId];
|
2017-10-31 00:38:18 +00:00
|
|
|
});
|
2017-12-06 15:55:15 +00:00
|
|
|
this._vpnRequests[requestId] = vpnRequest;
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2011-11-03 20:57:33 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_buildVPNServiceCache() {
|
2011-11-03 20:57:33 +00:00
|
|
|
if (this._vpnCacheBuilt)
|
|
|
|
return;
|
|
|
|
|
|
|
|
this._vpnCacheBuilt = true;
|
|
|
|
this._vpnBinaries = { };
|
|
|
|
|
2016-11-03 14:25:49 +00:00
|
|
|
NM.VpnPluginInfo.list_load().forEach(plugin => {
|
|
|
|
let service = plugin.get_service();
|
|
|
|
let fileName = plugin.get_auth_dialog();
|
|
|
|
let supportsHints = plugin.supports_hints();
|
|
|
|
let externalUIMode = false;
|
|
|
|
|
|
|
|
let prop = plugin.lookup_property('GNOME', 'supports-external-ui-mode');
|
|
|
|
if (prop) {
|
|
|
|
prop = prop.trim().toLowerCase();
|
|
|
|
externalUIMode = ['true', 'yes', 'on', '1'].includes(prop);
|
|
|
|
}
|
2011-11-03 20:57:33 +00:00
|
|
|
|
2016-11-03 14:25:49 +00:00
|
|
|
if (GLib.file_test(fileName, GLib.FileTest.IS_EXECUTABLE)) {
|
|
|
|
let binary = { fileName, externalUIMode, supportsHints };
|
|
|
|
this._vpnBinaries[service] = binary;
|
2011-11-03 20:57:33 +00:00
|
|
|
|
2016-11-03 14:25:49 +00:00
|
|
|
plugin.get_aliases().forEach(alias => {
|
|
|
|
this._vpnBinaries[alias] = binary;
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
log('VPN plugin at %s is not executable'.format(fileName));
|
2011-11-03 20:57:33 +00:00
|
|
|
}
|
2016-11-03 14:25:49 +00:00
|
|
|
});
|
2011-08-19 18:29:39 +00:00
|
|
|
}
|
2017-10-31 01:19:44 +00:00
|
|
|
};
|
2017-07-18 17:47:27 +00:00
|
|
|
var Component = NetworkAgent;
|