2012-08-20 01:37:54 +00:00
|
|
|
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
|
|
|
|
|
|
|
const Gio = imports.gi.Gio;
|
|
|
|
const Lang = imports.lang;
|
|
|
|
const Shell = imports.gi.Shell;
|
|
|
|
const Signals = imports.signals;
|
|
|
|
|
2018-08-23 00:55:02 +00:00
|
|
|
const ProviderIface = `
|
|
|
|
<node>
|
|
|
|
<interface name="org.freedesktop.realmd.Provider">
|
|
|
|
<property name="Name" type="s" access="read"/>
|
|
|
|
<property name="Version" type="s" access="read"/>
|
|
|
|
<property name="Realms" type="ao" access="read"/>
|
|
|
|
<method name="Discover">
|
|
|
|
<arg name="string" type="s" direction="in"/>
|
|
|
|
<arg name="options" type="a{sv}" direction="in"/>
|
|
|
|
<arg name="relevance" type="i" direction="out"/>
|
|
|
|
<arg name="realm" type="ao" direction="out"/>
|
|
|
|
</method>
|
|
|
|
</interface>
|
|
|
|
</node>`;
|
2012-08-20 01:37:54 +00:00
|
|
|
const Provider = Gio.DBusProxy.makeProxyWrapper(ProviderIface);
|
|
|
|
|
2018-08-23 00:55:02 +00:00
|
|
|
const ServiceIface = `
|
|
|
|
<node>
|
|
|
|
<interface name="org.freedesktop.realmd.Service">
|
|
|
|
<method name="Cancel">
|
|
|
|
<arg name="operation" type="s" direction="in"/>
|
|
|
|
</method>
|
|
|
|
<method name="Release" />
|
|
|
|
<method name="SetLocale">
|
|
|
|
<arg name="locale" type="s" direction="in"/>
|
|
|
|
</method>
|
|
|
|
<signal name="Diagnostics">
|
|
|
|
<arg name="data" type="s"/>
|
|
|
|
<arg name="operation" type="s"/>
|
|
|
|
</signal>
|
|
|
|
</interface>
|
|
|
|
</node>`;
|
2012-08-20 01:37:54 +00:00
|
|
|
const Service = Gio.DBusProxy.makeProxyWrapper(ServiceIface);
|
|
|
|
|
2018-08-23 00:55:02 +00:00
|
|
|
const RealmIface = `
|
|
|
|
<node>
|
|
|
|
<interface name="org.freedesktop.realmd.Realm">
|
|
|
|
<property name="Name" type="s" access="read"/>
|
|
|
|
<property name="Configured" type="s" access="read"/>
|
|
|
|
<property name="Details" type="a(ss)" access="read"/>
|
|
|
|
<property name="LoginFormats" type="as" access="read"/>
|
|
|
|
<property name="LoginPolicy" type="s" access="read"/>
|
|
|
|
<property name="PermittedLogins" type="as" access="read"/>
|
|
|
|
<property name="SupportedInterfaces" type="as" access="read"/>
|
|
|
|
<method name="ChangeLoginPolicy">
|
|
|
|
<arg name="login_policy" type="s" direction="in"/>
|
|
|
|
<arg name="permitted_add" type="as" direction="in"/>
|
|
|
|
<arg name="permitted_remove" type="as" direction="in"/>
|
|
|
|
<arg name="options" type="a{sv}" direction="in"/>
|
|
|
|
</method>
|
|
|
|
<method name="Deconfigure">
|
|
|
|
<arg name="options" type="a{sv}" direction="in"/>
|
|
|
|
</method>
|
|
|
|
</interface>
|
|
|
|
</node>`;
|
2012-08-20 01:37:54 +00:00
|
|
|
const Realm = Gio.DBusProxy.makeProxyWrapper(RealmIface);
|
|
|
|
|
2017-07-18 17:41:25 +00:00
|
|
|
var Manager = new Lang.Class({
|
2012-08-20 01:37:54 +00:00
|
|
|
Name: 'Manager',
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_init(parentActor) {
|
2012-08-20 01:37:54 +00:00
|
|
|
this._aggregateProvider = Provider(Gio.DBus.system,
|
|
|
|
'org.freedesktop.realmd',
|
|
|
|
'/org/freedesktop/realmd',
|
2017-12-02 00:27:35 +00:00
|
|
|
this._reloadRealms.bind(this))
|
2012-08-20 01:37:54 +00:00
|
|
|
this._realms = {};
|
|
|
|
|
2013-04-19 07:07:04 +00:00
|
|
|
this._signalId = this._aggregateProvider.connect('g-properties-changed',
|
2017-10-31 00:38:18 +00:00
|
|
|
(proxy, properties) => {
|
|
|
|
if ('Realms' in properties.deep_unpack())
|
|
|
|
this._reloadRealms();
|
|
|
|
});
|
2012-08-20 01:37:54 +00:00
|
|
|
},
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_reloadRealms() {
|
2012-08-20 01:37:54 +00:00
|
|
|
let realmPaths = this._aggregateProvider.Realms;
|
|
|
|
|
|
|
|
if (!realmPaths)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (let i = 0; i < realmPaths.length; i++) {
|
|
|
|
let realm = Realm(Gio.DBus.system,
|
|
|
|
'org.freedesktop.realmd',
|
|
|
|
realmPaths[i],
|
2017-12-02 00:27:35 +00:00
|
|
|
this._onRealmLoaded.bind(this));
|
2012-08-20 01:37:54 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_reloadRealm(realm) {
|
2012-08-20 01:37:54 +00:00
|
|
|
if (!realm.Configured) {
|
|
|
|
if (this._realms[realm.get_object_path()])
|
|
|
|
delete this._realms[realm.get_object_path()];
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this._realms[realm.get_object_path()] = realm;
|
|
|
|
|
|
|
|
this._updateLoginFormat();
|
|
|
|
},
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_onRealmLoaded(realm, error) {
|
2012-08-20 01:37:54 +00:00
|
|
|
if (error)
|
|
|
|
return;
|
|
|
|
|
|
|
|
this._reloadRealm(realm);
|
|
|
|
|
2017-10-31 00:38:18 +00:00
|
|
|
realm.connect('g-properties-changed', (proxy, properties) => {
|
|
|
|
if ('Configured' in properties.deep_unpack())
|
|
|
|
this._reloadRealm(realm);
|
|
|
|
});
|
2012-08-20 01:37:54 +00:00
|
|
|
},
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_updateLoginFormat() {
|
2012-08-20 01:37:54 +00:00
|
|
|
let newLoginFormat;
|
|
|
|
|
|
|
|
for (let realmPath in this._realms) {
|
|
|
|
let realm = this._realms[realmPath];
|
|
|
|
if (realm.LoginFormats && realm.LoginFormats.length > 0) {
|
|
|
|
newLoginFormat = realm.LoginFormats[0];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this._loginFormat != newLoginFormat) {
|
|
|
|
this._loginFormat = newLoginFormat;
|
|
|
|
this.emit('login-format-changed', newLoginFormat);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
get loginFormat() {
|
|
|
|
if (this._loginFormat !== undefined)
|
|
|
|
return this._loginFormat;
|
|
|
|
|
|
|
|
this._updateLoginFormat();
|
|
|
|
|
|
|
|
return this._loginFormat;
|
2013-04-19 07:07:04 +00:00
|
|
|
},
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
release() {
|
2013-04-19 07:07:04 +00:00
|
|
|
Service(Gio.DBus.system,
|
|
|
|
'org.freedesktop.realmd',
|
|
|
|
'/org/freedesktop/realmd',
|
2017-10-31 00:38:18 +00:00
|
|
|
service => { service.ReleaseRemote(); });
|
2013-04-19 07:07:04 +00:00
|
|
|
this._aggregateProvider.disconnect(this._signalId);
|
|
|
|
this._realms = { };
|
|
|
|
this._updateLoginFormat();
|
2012-08-20 01:37:54 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
Signals.addSignalMethods(Manager.prototype)
|