summaryrefslogtreecommitdiffstats
path: root/modules-available/sysconfig/inc/configmodule/loginscreen.inc.php
blob: ed99fcd5b43b0f5c355f5d42299d5aee169bc25e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?php

ConfigModule::registerModule(
	ConfigModule_LoginScreen::MODID, // ID
	Dictionary::translateFile('config-module', 'loginscreen_title'), // Title
	Dictionary::translateFile('config-module', 'loginscreen_description'), // Description
	Dictionary::translateFile('config-module', 'group_loginscreen'), // Group
	true, // Only one per config?
	610 // Sort order
);

class ConfigModule_LoginScreen extends ConfigModule
{
	const MODID = 'LoginScreen';
	const VERSION = 1;

	const VALID_FIELDS = [
		'clock-text-style',
		'clock-background-style',
		'clock-shadow',
		'username-placeholder',
		'password-placeholder',
		'shib-session-button-text',
		'qr-session-button-text',
		'user-session-button-text',
		'guest-session-button-text',
		'guest-session-start-text',
		'guest-session-start-button-text',
		'reset-timeout',
	];

	protected function generateInternal(string $tgz, ?string $parent)
	{
		/* Validate if all data are available */
		if (!$this->validateConfig())
			return false;

		return Taskmanager::submit('MakeTarball', array(
			'files' => $this->getFileArray(),
			'destination' => $tgz,
			'parentTask' => $parent,
		), false);
	}

	protected function moduleVersion(): int
	{
		return self::VERSION;
	}

	protected function validateConfig(): bool
	{
		return true;
	}

	public function setData(string $key, $value): bool
	{
		if (!in_array($key, self::VALID_FIELDS))
			return false;
		$this->moduleData[$key] = $value;
		return true;
	}

	public function allowDownload(): bool
	{
		return false;
	}

	/**
	 * Creates a map with filepath => file content
	 * @return array{"/etc/lightdm/qt-lightdm-greeter.conf.d/80-$id-customization.conf": string}
	 */
	private function getFileArray(): array
	{
		$id = $this->id();
		$content = "[General]\n";
		foreach (self::VALID_FIELDS as $field) {
			if (!isset($this->moduleData[$field]))
				continue;
			$content .= $field . '=' . $this->escapeString($this->moduleData[$field]) . "\n";
		}
		return [
			"/etc/lightdm/qt-lightdm-greeter.conf.d/80-$id-customization.conf" => $content,
		];
	}

	private function escapeString(string $str)
	{
		if (strpos($str, '\\') !== false) {
			$str = str_replace('\\', '\\\\', $str);
		}
		if (strpos($str, '"') !== false) {
			$str = str_replace('"', '\\"', $str);
		}
		if (strpos($str, ';') !== false) {
			$str = '"' . $str. '"';
		}
		return $str;
	}

}