3
0
mirror of https://github.com/cytodev/LightDMMock.git synced 2025-07-31 18:47:41 +02:00

35 Commits

Author SHA1 Message Date
8f623405f7 Modernize deprecation handling 2021-09-17 16:14:05 +02:00
c6f8b2da10 Rewrite LightDMMock class except methods
Also rewrite loadJSON and checkForUpdate,
and exported the class the ES6 way.
2021-09-02 00:58:04 +02:00
b23543e7c1 Update readme 2021-08-30 00:27:13 +02:00
968e6437ad Setup coding environment for VSCode and jsdoc 2021-08-17 13:38:59 +02:00
c3a1624aab Update repo location used in JS 2021-08-17 11:04:27 +02:00
512bad6a36 Update readme
...to my style
  ...for consistency
  ...to use ES6 modules (because I want my fork to be that)
2021-08-17 10:08:20 +02:00
0fb379a2f5 Update license 2021-08-17 10:04:33 +02:00
ba528cfbb7 Merge pull request 'Merge dev branch into master' (#1) from dev into master
Reviewed-on: EliasSchriefer/LightDMMock#1
2021-08-16 22:20:12 +00:00
05a6a29adb Merge branch 'master' into dev 2021-08-16 22:19:16 +00:00
Roel Walraven
1b941a68a3 Fix markdown headers 2017-05-31 16:42:51 +02:00
Roel Walraven
3d44e20d49 Fix missing char 2017-02-24 22:30:03 +01:00
Roel Walraven
a6cc68da3f Merged release/1.1.0 into master 2017-02-24 14:29:32 +01:00
Roel Walraven
75d13b9ae5 Merged release/1.1.0 into dev 2017-02-24 14:29:32 +01:00
Roel Walraven
1108263967 version.minor++; 2017-02-24 14:28:32 +01:00
Roel Walraven
a5c5a3b552 Add note for .face files 2017-02-24 14:27:49 +01:00
Roel Walraven
d6c24cd891 Merged feature/p3lim-suggested-cleanup into dev 2017-02-24 14:23:15 +01:00
Roel Walraven
f326ae92aa Update module loading 2017-02-24 14:22:31 +01:00
Roel Walraven
91667b64c2 Add link to original method definition 2017-02-24 14:21:58 +01:00
Roel Walraven
853995cb0e Update section headers 2017-02-24 14:21:41 +01:00
Roel Walraven
f2fe77a701 Fix alignment of equals symbol
Because reasons...
2017-02-24 14:21:07 +01:00
Roel Walraven
b083dafb7f Replace name with username
See issue #3
2017-02-24 14:20:33 +01:00
Roel Walraven
186fe137e1 Update autofill to fetch JSON 2017-02-24 14:14:16 +01:00
Roel Walraven
f3cd556099 Add method to load JSON from file 2017-02-24 14:10:16 +01:00
Roel Walraven
b127fd1d63 Add !== undefined check on update checking 2017-02-24 14:09:37 +01:00
Roel Walraven
5ceeaa7297 Move deprecated methods to own section 2017-02-24 14:08:47 +01:00
Roel Walraven
b7cb47d9c1 Move methods around and add start_session 2017-02-24 14:08:32 +01:00
Roel Walraven
0c01ee7933 Add deprecated properties and notifications 2017-02-24 14:04:48 +01:00
Roel Walraven
d6a7fabfd6 Move LightDMMock.js to src 2017-02-24 14:03:01 +01:00
Roel Walraven
c1d8cf2672 Add note on .face usage 2017-02-24 14:00:45 +01:00
Roel Walraven
e21f5bf05f Add link to C code this is based on 2017-02-24 14:00:31 +01:00
Roel Walraven
f9272107ef Move autofill data to JSON files instead of b64 encoded in the script 2017-02-24 14:00:10 +01:00
Roel Walraven
1217ccc0e1 Move mock home directories to src/home 2017-02-24 13:59:09 +01:00
Roel Walraven
2f87645e61 Merge pull request #1 from FallingSnow/patch-1
Add module exports
2017-02-24 10:25:32 +01:00
Ayrton Sparling
4e03335a28 Add require support 2016-12-14 16:22:03 -08:00
Roel Walraven
eeefc1152d Adds documentation for checkUpdate method 2016-08-04 18:35:28 +02:00
27 changed files with 3152 additions and 615 deletions

2
.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
# jsdoc-generated documentation
doc

23
.vscode/tasks.json vendored Normal file
View File

@@ -0,0 +1,23 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "jsdoc",
"type": "process",
"command": "jsdoc",
"args": ["src/LightDMMock.js", "-c", "jsdoc.json", "-d", "doc"],
"detail": "Generate documentation",
"presentation": {
"echo": false,
"reveal": "silent",
"showReuseMessage": false,
"panel": "dedicated",
"close": true,
},
"group": {
"kind": "build",
"isDefault": true,
},
}
]
}

3
jsdoc.json Normal file
View File

@@ -0,0 +1,3 @@
{
"plugins": ["plugins/markdown"]
}

View File

@@ -1,6 +1,6 @@
The MIT License (MIT)
Copyright (c) 2016 Roel Walraven <mail@cytodev.io>
Copyright (c) 2021 EliasSchriefer <elischriefer@gmail.com>
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in

File diff suppressed because one or more lines are too long

100
readme.md
View File

@@ -1,72 +1,74 @@
#LightDMMock
A LightDM Mock that is tightly based on the source C code of [Antergos](https://github.com/Antergos)' [lightdm-webkit2-greeter](https://github.com/Antergos/lightdm-webkit2-greeter). <font style="color:red">Please note that the deprecation errors are intrusive for a reason.</font>
# LightDMMock
A LightDM Mock that is written in modern JavaScript and based on [cytodev](https://github.com/cytodev)'s [LightDMMock](https://github.com/cytodev/LightDMMock), the lightdm-webkit2-greeter [manual](https://man.archlinux.org/man/community/lightdm-webkit2-greeter/lightdm-webkit2-greeter.1.en), the [LightDM API documentation](https://people.ubuntu.com/~robert-ancell/lightdm/reference/), and the latest version of [Antergos](https://github.com/Antergos)' lightdm-webkit2-greeter [source code](https://github.com/Antergos/web-greeter). <font style="color:red">Please note that the deprecation errors are intrusive for a reason.</font>
##Usage:
[1]. Clone the repo
````bash
git clone git@github.com:CytoDev/LightDMMock.git
````
[2]. Include the file in your theme that needs mocking<br>
````html
<script type="text/javascript" src="mock/LightDMMock.js"></script>
````
[3]. Create a new instance of LightDMMock
````javascript
if(!("lightdm" in window)) {
var LightDMMock = LightDMMock || {};
## Usage
1. Clone the repo
```bash
git clone https://git.sfs.ddnss.org/EliasSchriefer/LightDMMock
```
2. Set the type of your JavaScript to `module` in your theme that needs mocking
```html
<script type="module" src="main.js"></script>
```
```html
<script type="module">
...
</script>
```
3. Import `LightDMMock` and create a new instance
```javascript
import LightDMMock from "LightDMMock/src/LightDMMock.js";
window.lightdm = new LightDMMock(autofill, timeout, autoGuest);
}
````
```
##Parameters of LightDMMock()
####autofill
> **_`boolean`_**<br>
> Wether or not the arrays for users, languages, layouts, and sessions need to be filled with mock data. I advise to test both to make your theme less prone to crashing.
---
## Note
If you plan on using the `.face` files in the mock you have to include the path to `LightDMMock/src`. The `.face` files linked in `users.json` are absolute links to `/home/[username]/.face`.
####timeout
> **_`number`_**<br>
## Parameters of `LightDMMock()`
> **autofill**: `boolean`
>
> Whether or not the arrays for users, languages, layouts, and sessions need to be filled with mock data. I advise to test both to make your theme less prone to crashing.
>
> **timeout**: `number`
>
> Value to use for simulated autologin (this value is in seconds).
---
>
> **autoGuest**: `boolean`
>
> Whether or not to simulate automatic guest login. This will also enable a guest account in `lightdm.has_guest_account`.
---
####autoGuest
> **_`boolean`_**<br>
> Wether or not to simulate automatic guest login. This will also enable a guest account in `lightdm.has_guest_account`.
---
### A friendly reminder
The following functions **must** be provided by the custom greeter, which LightDM will call in the process of authenticating the user. This can be found in the original documentation (man pages) of the webkit-greeter, but I have posted them here for your convenience.
###A friendly reminder
The following functions __must__ be provided by the custom greeter, which LightDM will call in the process of authenticating the user. This can be found in the original documentation (man pages) of the webkit-greeter, but I have posted them here for your convenience.
> __show\_prompt(text, type)__<br>
> ````
> **show_prompt(text, type)**
>
> This will be called when LightDM needs to prompt the user for some reason, such
> as asking for a password. The "text" parameter will be the text of the prompt,
> and the "type" parameter will either be "text" for a visible prompt, or
> "password" for a prompt that the input should be hidden.
> ````
>
> __show\_message(text, type)__<br>
> ````
> **show_message(text, type)**
>
> This will be called when LightDM needs to display some info for the user. The
> "text" parameter will be the text of the message, and the "type" parameter will
> either be "info" for an information message, or "error" for an error message
> that LightDM has encountered.
> ````
>
> __authentication\_complete()__<br>
> ````
> **authentication_complete()**
>
> This function is called by LightDM when authentication has completed.
> ````
>
> __autologin\_timer\_expired()__<br>
> ````
> **autologin_timer_expired()**
>
> This function is called by LightDM when an autologin user's login timer has
> expired. The greeter should reset the authentication process.
> ````
###License:
This project is licensed under the MIT License. You can find a copy of the license [here](https://github.com/CytoDev/LightDMMock/license.md).
### License
This project is licensed under the MIT License. You can find a copy of the license [here](https://git.sfs.ddnss.org/EliasSchriefer/LightDMMock/license.md).
###Contributions:
You are more than welcome to submit issues as well as feature requests or just a 'how-ya-doin' in the [issue tracker](https://github.com/CytoDev/LightDMMock/issues/new). Contributing to the project can be done by forking it and submitting a pull request once it's all tested and tidy.
### Contributions
You are more than welcome to submit issues as well as feature requests or just a 'how-ya-doin' in the [issue tracker](https://git.sfs.ddnss.org/EliasSchriefer/LightDMMock/issues/new). Contributing to the project can be done by forking it and submitting a pull request once it's all tested and tidy.

909
src/LightDMMock.js Normal file
View File

@@ -0,0 +1,909 @@
/**
* @author Elias Schriefer <elischriefer@gmail.com>
* @alias lightdm
* @classdesc
* A LightDM Mock that is written in modern JavaScript and based on
* [cytodev](https://github.com/cytodev)'s
* [LightDMMock](https://github.com/cytodev/LightDMMock), the lightdm-webkit2-greeter
* [manual](https://man.archlinux.org/man/community/lightdm-webkit2-greeter/lightdm-webkit2-greeter.1.en),
* the [LightDM API documentation](https://people.ubuntu.com/~robert-ancell/lightdm/reference/),
* and the latest version of [Antergos](https://github.com/Antergos)'
* lightdm-webkit2-greeter [source code](https://github.com/Antergos/web-greeter).
* <font style="color:red">Please note that the deprecation errors are intrusive for a reason.</font>
*
* This is a rewrite in modern JavaScript.
*
* ##### Usage:
* 1. Set the type of your JavaScript to `module` in your theme that needs mocking
* ```html
* <script type="module" src="main.js"></script>
* ```
* ```html
* <script type="module">
* ...
* </script>
* ```
*
* 2. Import {@link LightDMMock} and create a new instance
* ```javascript
* import LightDMMock from "LightDMMock/src/LightDMMock.js";
*
* window.lightdm = new LightDMMock(autofill, timeout, autoGuest);
* ```
*
* If you want to use the `.face` images don't forget to add the path to
* `LightDMMock/src` to the image src. The `users.json` file has absolute paths
* like you would expect on a real filesystem.
*/
class LightDMMock {
// see <https://github.com/Antergos/web-greeter/blob/before-python/src/webkit2-extension.c#L1470-L1504>
// and <https://github.com/Antergos/web-greeter/blob/master/web-greeter/resources/js/docs/Greeter.js#L49-L240>
/**
* @type {?String}
* @desc
* The username of the authentication user being authenticated
* or null if no authentication is in progress.
*/
authentication_user = null;
/**
* @type {boolean}
* @desc
* Indicates the guest user should be used for autologin.
*/
autologin_guest = false;
/**
* @type {number}
* @desc
* The number of seconds to wait before automatically logging
* in. The older variable {@link lightdm.timed_user_delay} has
* been deprecated.
*/
autologin_timeout = 0;
/**
* @type {?String}
* @desc
* The name of the user account that should be logged into
* automatically after timed login delay has passed. The older
* variable {@link lightdm.timed_login_user} has been deprecated.
*/
autologin_user = null;
/**
* @type {boolean}
* @desc
* Whether or not the system can be made to hibernate by the
* greeter.
*/
can_hibernate = false;
/**
* @type {boolean}
* @desc
* Whether or not the system can be restarted by the greeter.
*/
can_restart = false;
/**
* @type {boolean}
* @desc
* Whether or not the system can be shutdown by the greeter.
*/
can_shutdown = false;
/**
* @type {boolean}
* @desc
* Whether or not the system can be suspended by the greeter.
*/
can_suspend = false;
/**
* @deprecated
*/
default_language = null;
/**
* @deprecated
*/
default_layout = null;
/**
* @type {?String}
* @desc
* The name of the default session (as configured in
* `lightdm.conf`).
*/
default_session = null;
/**
* @type {boolean}
* @desc
* A guest account is available for login.
*/
has_guest_account = false;
/**
* @type {boolean}
* @desc
* The whole list of users should not be displayed.
*/
hide_users = false;
/**
* @type {String}
* @desc
* The hostname of the system.
*/
hostname = null;
/**
* @type {boolean}
* @desc
* Indicates if the user has successfully authenticated.
*/
is_authenticated = false;
/**
* @type {boolean}
* @desc
* Indicates if lightdm is currently in the authentication
* phase.
*/
in_authentication = false;
/**
* @type {?String}
* @desc
* The currently selected language. The older variable name
* {@link lightdm.default_language} is deprecated.
*/
language = null;
/**
* @type {LightDMLanguage[]}
* @desc
* The languages that are available on the system.
*/
languages = null;
/**
* @type {String}
* @desc
* The name of the currently active keyboard layout. To change
* the layout, assign a valid layout name to this variable. The older
* variable name {@link lightdm.default_layout} is deprecated.
*/
layout = null;
/**
* @type {LightDMLayout[]}
* @desc
* The keyboard layouts that are available on the system.
*/
layouts = null;
/**
* @type {boolean}
* @desc
* `true` if the greeter was triggered by locking the seat.
*/
lock_hint = false;
/**
* @type {number}
* @desc
* The number of users able to log in.
*/
num_users = 0;
/**
* @deprecated
* @type {boolean}
* @desc
* The guest user should be selected by default for login.
*/
select_guest = null;
/**
* @type {boolean}
* @desc
* `true` if the guest account should be selected by default.
*/
select_guest_hint = false;
/**
* @deprecated
* @type {?String}
* @desc
* The username that should be selected by default for login.
*/
select_user = null;
/**
* @type {?String}
* @desc
* A username or `null` if no particular user should be selected.
*/
select_user_hint = null;
/**
* @type {LightDMSession[]}
* @desc
* The sessions that are available on the system.
*/
sessions = null;
/**
* @deprecated
*/
timed_login_delay = null;
/**
* @deprecated
*/
timed_login_user = null;
/**
* @type {LightDMUser[]}
* @desc
* The users that are able to log in.
*/
users = null;
/**
* @param {boolean} [autofill=false]
* Whether or not the arrays for users, languages, layouts, and sessions need to be filled with mock
* data. I advise to test both to make your theme less prone to crashing.
*
* @param {number} [timeout=0]
* Value to use for simulated autologin (this value is in seconds).
*
* @param {boolean} [autoGuest=false]
* Whether or not to simulate automatic guest login. This will also enable a guest account in
* {@link LightDMMock.has_guest_account lightdm.has_guest_account}
*/
constructor(autofill = false, timeout = 0, autoGuest = false) {
checkForUpdate("v1.1.0");
if (typeof autofill == "boolean" && autofill) {
let includePath = import.meta.url;
if (includePath == undefined) {
return console.error("Could not get module URL.");
}
includePath = includePath.substr(0, includePath.lastIndexOf("/"));
const rejectionHandler = response => {
console.warn(`${response.url.substr(response.url.lastIndexOf("/") + 1)} did not load correctly.`);
};
// see <https://github.com/Antergos/web-greeter/blob/master/web-greeter/resources/js/docs/LightDMObjects.js#L169-L253>
const usersJSON = loadJSON(`${includePath}/json/users.json`);
usersJSON
.then(json => {
this.users = json;
}, rejectionHandler)
// see <https://github.com/Antergos/web-greeter/blob/master/web-greeter/resources/js/docs/LightDMObjects.js#L85-L124>
const languagesJSON = loadJSON(`${includePath}/json/languages.json`);
languagesJSON
.then(json => {
this.languages = json;
}, rejectionHandler);
// see <https://github.com/Antergos/web-greeter/blob/master/web-greeter/resources/js/docs/LightDMObjects.js#L127-L166>
const layoutsJSON = loadJSON(`${includePath}/json/layouts.json`);
layoutsJSON
.then(json => {
this.layouts = json;
}, rejectionHandler);
// see <https://github.com/Antergos/web-greeter/blob/master/web-greeter/resources/js/docs/LightDMObjects.js#L43-L82>
const sessionsJSON = loadJSON(`${includePath}/json/sessions.json`);
sessionsJSON
.then(json => {
this.sessions = json;
}, rejectionHandler);
Promise.all([usersJSON, languagesJSON, layoutsJSON, sessionsJSON])
.then(() => {
this.default_session = this.sessions[0].name;
this.language = this.languages[0].name;
this.layout = this.layouts[0].name;
this.num_users = this.users.length;
if (typeof timeout == "number" && timeout > 0) {
if (typeof autoGuest == "boolean" && autoGuest) {
this.autologin_user = null;
this.autologin_guest = autoGuest;
} else {
this.autologin_user = this.users[0].username;
}
this.autologin_timeout = timeout * 1000;
setTimeout(() => {
if ((typeof autoGuest == "boolean" && autoGuest) || this.autologin_user != null)
window.autologin_timer_expired();
}, this.autologin_timeout);
}
for (let user of this.users) {
user.logged_in = Boolean(Math.floor(Math.random() * 2));
user.session = this.sessions[Math.floor((Math.random() * this.sessions.length))].name;
}
});
const deprecations = {
properties: [
{ deprecated: "default_language", alternative: "lightdm.language" },
{ deprecated: "default_layout", alternative: "lightdm.layout" },
{ deprecated: "select_guest", alternative: "lightdm.select_guest_hint" },
{ deprecated: "select_user", alternative: "lightdm.select_user_hint" },
{ deprecated: "timed_login_user", alternative: "lightdm.autologin_user" },
{ deprecated: "timed_login_delay", alternative: "lightdm.autologin_timeout" },
],
};
return new Proxy(this, {
get: (o, k, r) => {
if (deprecations.properties.map(o => o.deprecated).includes(k)) {
deprecationNotifier("property", k, deprecations.properties.alternative)
} else {
return Reflect.get(o, k, r);
}
}
});
}
}
}
/******************************************************************************
* Methods *
******************************************************************************/
// see <https://github.com/Antergos/web-greeter/blob/before-python/src/webkit2-extension.c#L1511-L1530>
/**
* Specifies the username of the user we'd like to start authenticating as.
* Note that if you call lightdm.authenticate with no argument, LightDM
* (via PAM) will issue a show_prompt() call to ask for the username. The
* older function lightdm.start_authentication() has been deprecated.
*
* @param {String} username [username to authenticate]
*/
LightDMMock.prototype.authenticate = function(username) {
window.logCall("authenticate", arguments);
window.checkArguments(arguments, 1, ["string"]);
if(this.in_authentication) {
window.show_message("Already authenticating " + this.authentication_user, "error");
return;
}
var exists = false;
for(var i = 0; i <= this.users.length -1; i++) {
if(this.users[i].username === username)
exists = true;
}
if(!exists) {
window.show_message("Invalid username", "error");
return;
}
this.authentication_user = username;
this.in_authentication = true;
window.show_prompt("Password:", "password");
};
/**
* Authenticates as the guest user.
*/
LightDMMock.prototype.authenticate_as_guest = function() {
window.logCall("authenticate_as_guest", arguments);
window.checkArguments(arguments, 0, []);
if(!this.has_guest_account)
throw new IlligalUsageException("Guest accounts are turned off. Make sure you check the value of 'lightdm.has_guest_account' before calling this function.");
if(this.in_authentication) {
window.show_message("Already authenticating" + this.authentication_user, "error");
return;
}
this.authentication_user = "guest";
this.in_authentication = true;
};
/**
* Cancels the authentication of any user currently in the
* process of authenticating.
*/
LightDMMock.prototype.cancel_authentication = function() {
window.logCall("cancel_authentication", arguments);
window.checkArguments(arguments, 0, []);
this.authentication_user = null;
this.in_authentication = false;
};
/**
* Cancels the authentication of the autologin user. The older function
* lightdm.cancel_timed_login() has been deprecated.
*/
LightDMMock.prototype.cancel_autologin = function() {
window.logCall("cancel_autologin", arguments);
window.checkArguments(arguments, 0, []);
this.autologin_user = null;
this.autologin_guest = false;
this.autologin_timeout = 0;
};
/**
* Returns the value of a named hint provided by LightDM.
*
* @param {String} hint_name [name of the hint to show]
*/
LightDMMock.prototype.get_hint = function(hint_name) {
window.logCall("get_hint", arguments);
window.checkArguments(arguments, 1, ["string"]);
// @fixme: I have no clue how to simulate this...
};
/**
* Hibernates the system, if the greeter has the authority to do so.
*/
LightDMMock.prototype.hibernate = function() {
window.logCall("hibernate", arguments);
window.checkArguments(arguments, 0, []);
if(!this.can_hibernate)
throw new IlligalUsageException("LightDM cannot hibernate the system. Make sure you check the value of 'lightdm.can_hibernate' before calling this function.");
window.alert("System hibernated.");
document.location.reload(true);
};
/**
* When LightDM has prompted for input, provide the response to LightDM. The
* deprecated function was "provide_secret". This is still available for
* backwards compatibility, but authors of greeters should move
* to using lightdm.respond().
*
* @param {String} text [the response to the challange, usually a password]
*/
LightDMMock.prototype.respond = function(text) {
window.logCall("respond", arguments);
window.checkArguments(arguments, 1, ["string"]);
if(!this.in_authentication)
throw new IlligalUsageException("LightDM is currently not in the authentication phase. Make sure to call 'lightdm.authenticate(username)' before calling this function.");
if(text === "password") {
this.is_authenticated = true;
window.authentication_complete();
} else {
window.show_message("Invalid password", "error");
}
};
/**
* Restarts the system, if the greeter has the authority to do so.
*/
LightDMMock.prototype.restart = function() {
window.logCall("restart", arguments);
window.checkArguments(arguments, 0, []);
if(!this.can_restart)
throw new IlligalUsageException("LightDM cannot restart the system. Make sure you check the value of 'lightdm.can_restart' before calling this function.");
window.alert("System restarted.");
document.location.reload(true);
};
/**
* Will set the language for the current LightDM session.
*
* @param {String} lang [the language to change to]
*/
LightDMMock.prototype.set_language = function(lang) {
window.logCall("set_language", arguments);
window.checkArguments(arguments, 1, ["string"]);
this.language = lang;
};
/**
* Shuts down the system, if the greeter has the authority to do so.
*/
LightDMMock.prototype.shutdown = function() {
window.logCall("shutdown", arguments);
window.checkArguments(arguments, 0, []);
if(!this.can_shutdown)
throw new IlligalUsageException("LightDM cannot shut down the system. Make sure you check the value of 'lightdm.can_shutdown' before calling this function.");
window.alert("System shut down.");
document.location.reload(true);
};
/**
* Once LightDM has successfully authenticated the user, start the user's
* session by calling this function. "session" is the authenticated user's
* session. If no session is passed, start the authenticated user with the
* system default session. The older function lightdm.login(user, session)
* has been deprecated.
*
* @param {String} session [the session name to start]
*/
LightDMMock.prototype.start_session = function(session) {
window.logCall("start_session_sync", arguments);
window.checkArguments(arguments, 1, ["string"]);
if(!this.in_authentication)
throw new IlligalUsageException("LightDM is currently not in the authentication phase. Make sure to call 'lightdm.authenticate(username)' before calling this function.");
if(!this.is_authenticated)
throw new IlligalUsageException("LightDM has no authenticated users to log in. Make sure to call 'lightdm.respond()' before calling this function.");
window.alert("LightDM has started a " + session + " session for " + this.authentication_user);
document.location.reload(true);
};
/**
* Suspends the system, if the greeter has the authority to do so.
*/
LightDMMock.prototype.suspend = function() {
window.logCall("suspend", arguments);
window.checkArguments(arguments, 0, []);
if(!this.can_suspend)
throw new IlligalUsageException("LightDM cannot suspend the system. Make sure you check the value of 'lightdm.can_suspend' before calling this function.");
window.alert("System suspended.");
document.location.reload(true);
};
/******************************************************************************
* Deprecated methods *
******************************************************************************/
LightDMMock.prototype.cancel_timed_login = function() {
window.logCall("cancel_timed_login", arguments);
window.deprecationNotifier("method", "lightdm.cancel_timed_login()", "lightdm.cancel_autologin()");
};
LightDMMock.prototype.start_authentication = function() {
window.logCall("start_authentication", arguments);
window.deprecationNotifier("method", "lightdm.start_authentication()", "lightdm.authenticate(username)");
};
LightDMMock.prototype.login = function() {
window.logCall("login", arguments);
window.deprecationNotifier("method", "lightdm.login()", "lightdm.start_session(session)");
};
LightDMMock.prototype.provide_secret = function() {
window.logCall("provide_secret", arguments);
window.deprecationNotifier("method", "lightdm.provide_secret(text)", "lightdm.respond(text)");
};
LightDMMock.prototype.start_session_sync = function() {
window.logCall("login", arguments);
window.deprecationNotifier("method", "lightdm.start_session_sync(session)", "lightdm.start_session(session)");
};
/******************************************************************************
* Throwables *
******************************************************************************/
/**
* Throwable IlligalUsageException
*
* @param {string} message [description of illigal usage]
*/
function IlligalUsageException(message) {
this.name = "IlligalUsageException";
this.message = message;
this.toString = function() {
return "[" + this.name + "] " + this.message;
};
}
/**
* Throwable DeprecationException
*
* @param {String} type [method||property]
* @param {String} depricated [deprecated method or property name]
* @param {String} alternative [alternative method or property to use]
*/
function DeprecationException(type, deprecated, alternative) {
this.name = "DeprecationException";
this.message = "The " + type + " '" + deprecated + "' is deprecated. Consider using '" + alternative + "' instead.";
this.toString = function() {
return "[" + this.name + "] " + this.message;
};
}
/**
* Throwable IncompatibleArgumentCountException
*
* @param {Number} expected [expected length of arguments]
* @param {Number} received [found length of arguments]
*/
function IncompatibleArgumentCountException(expected, received) {
this.name = "IncompatibleArgumentCountException";
this.message = "Incorrect number of arguments in function call. Expected " + expected + ", found " + received;
this.toString = function() {
return "[" + this.name + "] " + this.message;
};
}
/**
* Throwable IncompatibleArgumentTypesException
*
* @param {Number} type [argument number (non-zero)]
* @param {String} expected [expected type]
* @param {String} received [found type]
*/
function IncompatibleArgumentTypesException(number, expected, received) {
this.name = "IncompatibleArgumentTypesException";
this.message = "Argument " + number + " is of a wrong type. Expected '" + expected + "', found '" + received + "'";
this.toString = function() {
return "[" + this.name + "] " + this.message;
};
}
/******************************************************************************
* Helpers *
******************************************************************************/
/**
* @desc
* throws ~balls~ errors at users who use deprecated methods and properties.
*
* @param {String} type
* "method" or "property"
*
* @param {String} deprecated
* deprecated method or property name
*
* @param {String} alternative
* alternative method or property to use
*
* @throws {DeprecationException}
*/
export const deprecationNotifier = (type, deprecated, alternative) => {
throw new DeprecationException(type, deprecated, alternative);
};
/**
* global helper checkArguments
* throws ~tables~ errors at users who call methods
* with erroneous arguments.
*
* @param {Array} args [the arguments passed to the original method]
* @param {Number} length [the expected amount of arguments]
* @param {Arrray} types [the expected types of the arguments]
*
* @throws {IncompatibleArgumentTypesException}
*/
window.checkArguments = function(args, length, types) {
if(args.length !== length)
throw new IncompatibleArgumentCountException(length, args.length);
for(var i = 1; i <= types.length; i++) {
if(typeof args[i-1] !== types[i-1])
throw new IncompatibleArgumentTypesException(i, types[i-1], typeof args[i-1]);
}
};
/**
* global helper logCall
* logs a function call with the arguments provided to help with debugging a
* lightdm js script.
*
* @param {String} name [called function name]
* @param {Array} args [called function arguments]
*
* @return {window.console.info}
*/
window.logCall = function(name, args) {
var argv = [];
if(args !== undefined && args.length !== 0) {
for(var i = 0; i <= args.length; i++) {
if(args[i] !== undefined)
argv.push({type: typeof args[i], value: args[i]});
}
}
if(argv.length > 0)
return window.console.info("[lightdm." + name + "] called with " + argv.length + " argument(s)", argv);
return window.console.info("[lightdm." + name + "] called with 0 arguments");
};
/**
* @desc
* Compares `curentVersion` with the tag name of Gitea's latest release and
* prompts the user to download a new version if it is available.
*
* @param {String} currentVersion
* the current tag version
*/
export const checkForUpdate = async currentVersion => {
const errMessage = "Could not check for new version of LightDMMock. Please check for a new version manually by visiting https://git.sfs.ddnss.org/EliasSchriefer/LightDMMock/releases/latest";
const response = await fetch("https://git.sfs.ddnss.org/api/v1/repos/EliasSchriefer/LightDMMock/releases");
if (response.ok) {
try {
const request = (await request.json())?.[0]?.tag_name;
if (currentVersion != latest) {
console.warn(`You are using an outdated version of LightDMMock. Please download the new version from https://git.sfs.ddnss.org/EliasSchriefer/LightDMMock/releases/tag/${latest}`);
}
} catch (err) {
console.error(err.toString());
console.warn(errMessage);
}
} else if (response.status == 404) {
console.warn(errMessage);
}
};
/**
* @desc
* Loads JSON from a path. Removes the need to b64 encode them in this file.
*
* @param {String} url
* path to JSON file
*
* @throws {Response} Response with status code other than 200 Ok
*/
export const loadJSON = async url => {
let response = await fetch(url);
if (response.ok) {
return await response.json();
} else {
console.error(response.statusText);
throw response;
}
};
/******************************************************************************
* External global functions *
******************************************************************************/
/**
* @namespace window
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Window/window}
*/
/**
* @function show_prompt
* @memberof window
* @desc
* This will be called when LightDM needs to prompt the user for some
* reason, such as asking for a password.
*
* @param {String} text
* Will be the text of the prompt
*
* @param {String} type
* Will either be
* - "text" for a visible prompt, or
* - "password" for a prompt that the input should be hidden.
*/
/**
* @function show_message
* @memberof window
* @desc
* This will be called when LightDM needs to display some info for the
* user.
*
* @param {String} text
* Will be the text of the message
*
* @param {String} type
* Will either be
* - "info" for an information message, or
* - "error" for an error message that LightDM has encountered.
*/
/**
* @function authentication_complete
* @memberof window
* @desc
* This function is called by LightDM when authentication has
* completed.
*/
/**
* @function autologin_timer_expired
* @memberof window
* @desc
* This function is called by LightDM when an autologin user's login
* timer has expired. The greeter should reset the authentication
* process.
*/
/******************************************************************************
* Object.watch shim *
******************************************************************************/
/*
* object.watch polyfill
*
* 2012-04-03
*
* By Eli Grey, http://eligrey.com
* Public Domain.
* NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.
*/
// object.watch
if (!Object.prototype.watch) {
Object.defineProperty(Object.prototype, "watch", {
enumerable: false,
configurable: true,
writable: false,
value: function(prop, handler) {
var oldval = this[prop],
newval = oldval,
getter = function () {
return newval;
},
setter = function (val) {
oldval = newval;
newval = handler.call(this, prop, oldval, val);
return newval;
};
if(delete this[prop]) { // can't watch constants
Object.defineProperty(this, prop, {
get: getter,
set: setter,
enumerable: true,
configurable: true
});
}
}
});
}
// object.unwatch
if(!Object.prototype.unwatch) {
Object.defineProperty(Object.prototype, "unwatch", {
enumerable: false,
configurable: true,
writable: false,
value: function (prop) {
var val = this[prop];
delete this[prop]; // remove accessors
this[prop] = val;
}
});
}
/******************************************************************************
* Module loading *
******************************************************************************/
export default LightDMMock;

View File

Before

Width:  |  Height:  |  Size: 3.2 KiB

After

Width:  |  Height:  |  Size: 3.2 KiB

View File

Before

Width:  |  Height:  |  Size: 2.7 KiB

After

Width:  |  Height:  |  Size: 2.7 KiB

View File

Before

Width:  |  Height:  |  Size: 3.9 KiB

After

Width:  |  Height:  |  Size: 3.9 KiB

View File

Before

Width:  |  Height:  |  Size: 3.0 KiB

After

Width:  |  Height:  |  Size: 3.0 KiB

View File

Before

Width:  |  Height:  |  Size: 4.2 KiB

After

Width:  |  Height:  |  Size: 4.2 KiB

View File

Before

Width:  |  Height:  |  Size: 2.9 KiB

After

Width:  |  Height:  |  Size: 2.9 KiB

View File

Before

Width:  |  Height:  |  Size: 2.8 KiB

After

Width:  |  Height:  |  Size: 2.8 KiB

View File

Before

Width:  |  Height:  |  Size: 3.1 KiB

After

Width:  |  Height:  |  Size: 3.1 KiB

View File

Before

Width:  |  Height:  |  Size: 3.0 KiB

After

Width:  |  Height:  |  Size: 3.0 KiB

View File

Before

Width:  |  Height:  |  Size: 4.0 KiB

After

Width:  |  Height:  |  Size: 4.0 KiB

View File

Before

Width:  |  Height:  |  Size: 2.7 KiB

After

Width:  |  Height:  |  Size: 2.7 KiB

View File

Before

Width:  |  Height:  |  Size: 3.9 KiB

After

Width:  |  Height:  |  Size: 3.9 KiB

View File

Before

Width:  |  Height:  |  Size: 4.4 KiB

After

Width:  |  Height:  |  Size: 4.4 KiB

View File

Before

Width:  |  Height:  |  Size: 4.6 KiB

After

Width:  |  Height:  |  Size: 4.6 KiB

View File

Before

Width:  |  Height:  |  Size: 3.2 KiB

After

Width:  |  Height:  |  Size: 3.2 KiB

View File

Before

Width:  |  Height:  |  Size: 3.1 KiB

After

Width:  |  Height:  |  Size: 3.1 KiB

7
src/json/languages.json Normal file
View File

@@ -0,0 +1,7 @@
[
{
"name":"English",
"code":"en",
"territory":null
}
]

1999
src/json/layouts.json Normal file

File diff suppressed because it is too large Load Diff

19
src/json/sessions.json Normal file
View File

@@ -0,0 +1,19 @@
[
{
"key" : "LXDE",
"name" : "LXDE",
"comment" : "LXDE - Lightweight X11 desktop environment"
}, {
"key" : "openbox",
"name" : "Openbox",
"comment" : "Log in using the Openbox window manager (without a session manager)"
}, {
"key" : "twm",
"name" : "TWM",
"comment" : "The Tab Window Manager"
}, {
"key" : "tinywm",
"name" : "Tinywm",
"comment" : "Ridiculously tiny window manager"
}
]

138
src/json/users.json Normal file
View File

@@ -0,0 +1,138 @@
[
{
"display_name" : "Alexander the Great",
"home_directory" : "/home/basileusalex",
"image" : "/home/basileusalex/.face",
"language" : "gr_GR",
"layout" : null,
"logged_in" : false,
"session" : null,
"username" : "basileusalex"
}, {
"display_name" : "Napoleon Bonaparte",
"home_directory" : "/home/napoleonib",
"image" : "/home/napoleonib/.face",
"language" : "fr_FR",
"layout" : null,
"logged_in" : false,
"session" : null,
"username" : "napoleonib"
},{
"display_name" : "Gaius Octavius",
"home_directory" : "/home/imperatoraugustus",
"image" : "/home/imperatoraugustus/.face",
"language" : "it_IT",
"layout" : null,
"logged_in" : false,
"session" : null,
"username" : "imperatoraugustus"
},{
"display_name" : "Sir Winston Leonard Spencer-Churchill",
"home_directory" : "/home/honourablewinston",
"image" : "/home/honourablewinston/.face",
"language" : "en_GB",
"layout" : null,
"logged_in" : false,
"session" : null,
"username" : "honourablewinston"
},{
"display_name" : "Peter Alekseyevich Romanov",
"home_directory" : "/home/peteralexeyevich",
"image" : "/home/peteralexeyevich/.face",
"language" : "ru_RU",
"layout" : null,
"logged_in" : false,
"session" : null,
"username" : "peteralexeyevich"
},{
"display_name" : "John Fitzgerald Kennedy",
"home_directory" : "/home/jackkennedy",
"image" : "/home/jackkennedy/.face",
"language" : "en_US",
"layout" : null,
"logged_in" : false,
"session" : null,
"username" : "jackkennedy"
},{
"display_name" : "Muhammed bin Murad",
"home_directory" : "/home/mehmedisani",
"image" : "/home/mehmedisani/.face",
"language" : "tr_TR",
"layout" : null,
"logged_in" : false,
"session" : null,
"username" : "mehmedisani"
},{
"display_name" : "Gustavus Adolphus",
"home_directory" : "/home/gustav2",
"image" : "/home/gustav2/.face",
"language" : "sv_SE",
"layout" : null,
"logged_in" : false,
"session" : null,
"username" : "gustav2"
},{
"display_name" : "Mao Zedong",
"home_directory" : "/home/chairmanzedong",
"image" : "/home/chairmanzedong/.face",
"language" : "tr_TR",
"layout" : null,
"logged_in" : false,
"session" : null,
"username" : "chairmanzedong"
},{
"display_name" : "Erik Thorvaldsson",
"home_directory" : "/home/redthorvald",
"image" : "/home/redthorvald/.face",
"language" : "no_NO",
"layout" : null,
"logged_in" : false,
"session" : null,
"username" : "redthorvald"
},{
"display_name" : "Cristoforo Colombo",
"home_directory" : "/home/cristocolombo",
"image" : "/home/cristocolombo/.face",
"language" : "it_IT",
"layout" : null,
"logged_in" : false,
"session" : null,
"username" : "cristocolombo"
},{
"display_name" : "Willem van Oranje",
"home_directory" : "/home/silentwill",
"image" : "/home/silentwill/.face",
"language" : "nl_NL",
"layout" : null,
"logged_in" : false,
"session" : null,
"username" : "silentwill"
},{
"display_name" : "Genghis Khan",
"home_directory" : "/home/khagantemujin",
"image" : "/home/khagantemujin/.face",
"language" : "mn_MN",
"layout" : null,
"logged_in" : false,
"session" : null,
"username" : "khagantemujin"
},{
"display_name" : "Mikhail Sergeyevich Gorbachev",
"home_directory" : "/home/gorbachev",
"image" : "/home/gorbachev/.face",
"language" : "ru_RU",
"layout" : null,
"logged_in" : false,
"session" : null,
"username" : "gorbachev"
},{
"display_name" : "Meiji",
"home_directory" : "/home/meijitaitei",
"image" : "/home/meijitaitei/.face",
"language" : "jp_JP",
"layout" : null,
"logged_in" : false,
"session" : null,
"username" : "meijitaitei"
}
]