Skip to content
This repository has been archived by the owner on Nov 12, 2023. It is now read-only.

Commit

Permalink
autodiscover settings
Browse files Browse the repository at this point in the history
  • Loading branch information
schorschii committed Sep 25, 2020
1 parent 3f6fbc4 commit 95f1381
Showing 1 changed file with 64 additions and 4 deletions.
68 changes: 64 additions & 4 deletions ldappwd@schorschii/desklet.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,19 @@ MyDesklet.prototype = {

// initialize settings
this.settings = new Settings.DeskletSettings(this, this.metadata["uuid"], desklet_id);
this.settings.bindProperty(Settings.BindingDirection.IN, "hide-decorations", "hide_decorations", this.on_setting_changed);
this.settings.bindProperty(Settings.BindingDirection.IN, "server-address", "serverAddress", this.on_setting_changed);
this.settings.bindProperty(Settings.BindingDirection.IN, "server-username", "serverUsername", this.on_setting_changed);
this.settings.bindProperty(Settings.BindingDirection.IN, "server-domain", "serverDomain", this.on_setting_changed);
this.settings.bindProperty(Settings.BindingDirection.BIDIRECTIONAL, "server-address", "serverAddress", this.on_setting_changed);
this.settings.bindProperty(Settings.BindingDirection.BIDIRECTIONAL, "server-username", "serverUsername", this.on_setting_changed);
this.settings.bindProperty(Settings.BindingDirection.BIDIRECTIONAL, "server-domain", "serverDomain", this.on_setting_changed);
this.settings.bindProperty(Settings.BindingDirection.IN, "show-notifications", "showNotifications", this.on_setting_changed);
this.settings.bindProperty(Settings.BindingDirection.IN, "show-buttons", "showButtons", this.on_setting_changed);
this.settings.bindProperty(Settings.BindingDirection.IN, "hide-decorations", "hide_decorations", this.on_setting_changed);
this.settings.bindProperty(Settings.BindingDirection.BIDIRECTIONAL, "last-pwdExpiry", "lastPwdExpiry", this.on_setting_changed);

// try to get useful values if settings are empty
if(this.serverAddress == "" && this.serverUsername == "" && this.serverDomain == "") {
this.tryGetSettingsFromSystem();
}

// initialize desklet gui
this.setupUI();
},
Expand All @@ -78,6 +83,61 @@ MyDesklet.prototype = {
this.refreshDesklet(true);
},

tryGetSettingsFromSystem: function() {
try {
// user name
let subprocess = new Gio.Subprocess({
argv: ["/usr/bin/whoami"],
flags: Gio.SubprocessFlags.STDOUT_PIPE,
});
subprocess.init(null);
subprocess.wait_async(null, (sourceObject, res) => {
let [, out] = sourceObject.communicate_utf8(null, null);
this.serverUsername = out.trim();
});

// domain name
let fileDomain = Gio.file_new_for_path("/etc/resolv.conf");
fileDomain.load_contents_async(null, (file, response) => {
try {
let [success, contents, tag] = file.load_contents_finish(response);
if(success) {
let lines = contents.toString().split("\n");
for(var i = 0; i < lines.length; i++) {
if(lines[i].trim().startsWith("search ")) {
this.serverDomain = lines[i].split(" ")[1].trim()
}
}
}
GLib.free(contents);
} catch(err) {
this.currentError = 1;
}
this.refreshDesklet();
});

// ldap server (domain controller)
let fileSmbConf = Gio.file_new_for_path("/etc/samba/smb.conf");
fileSmbConf.load_contents_async(null, (file, response) => {
try {
let [success, contents, tag] = file.load_contents_finish(response);
if(success) {
let lines = contents.toString().split("\n");
for(var i = 0; i < lines.length; i++) {
if(lines[i].trim().startsWith("password server = ")) {
this.serverAddress = lines[i].split(" ")[3].trim().split(",")[0].trim();
}
}
}
GLib.free(contents);
} catch(err) {
this.currentError = 1;
}
this.refreshDesklet();
});
} catch(ex) {}
},

populateContextMenu: function() {
this.refreshMenuItem = new PopupMenu.PopupMenuItem(_("Refresh Expiry Date"));
this._menu.addMenuItem(this.refreshMenuItem);
Expand Down

0 comments on commit 95f1381

Please sign in to comment.