summaryrefslogtreecommitdiffstats
path: root/modules-available/sysconfig/inc/configmodulebaseldap.inc.php
blob: ad3d32c561b347d72e3a6e52271cde1fe78790b9 (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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<?php

abstract class ConfigModuleBaseLdap extends ConfigModule
{

	const VERSION = 3;

	private static $REQUIRED_FIELDS = array('server', 'searchbase');
	private static $OPTIONAL_FIELDS = array('binddn', 'bindpw', 'home', 'ssl', 'fixnumeric', 'fingerprint', 'certificate', 'homeattr',
		'shareRemapMode', 'shareRemapCreate', 'shareDocuments', 'shareDownloads', 'shareDesktop', 'shareMedia',
		'shareOther', 'shareHomeDrive', 'shareDomain', 'credentialPassthrough', 'mapping', 'genuid',
		'ldapAttrMountOpts', 'shareHomeMountOpts', 'nohomewarn');

	public static function getMapping($config = false, &$empty = true)
	{
		$list = array(
			['name' => 'uid', 'field' => 'uid', 'ad' => 'sAMAccountName'],
			['name' => 'uidnumber', 'field' => 'uidnumber', 'ad' => false],
			['name' => 'uncHomePath', 'field' => 'homemount', 'ad' => 'homeDirectory'],
			['name' => 'homeDirectory', 'field' => 'localhome', 'ad' => false],
			['name' => 'posixAccount', 'field' => 'posixAccount', 'ad' => 'user'],
			//['name' => 'shadowAccount', 'field' => 'shadowAccount'],
		);
		if (is_array($config)) {
			foreach ($list as &$item) {
				if (!empty($config[$item['field']])) {
					$item['value'] = $config[$item['field']];
					$empty = false;
				}
			}
		}
		return $list;
	}

	protected function generateInternal($tgz, $parent)
	{
		$np = Trigger::ldadp($this->id(), $parent);
		if ($np !== false) {
			$parent = $np;
		}
		$config = $this->moduleData;
		if (isset($config['certificate']) && !is_string($config['certificate'])) {
			unset($config['certificate']);
		}
		if (preg_match('/^([^\:]+)\:(\d+)$/', $config['server'], $out)) {
			$config['server'] = $out[1];
			$config['adport'] = $out[2];
		} else {
			if (isset($config['certificate'])) {
				$config['adport'] = 636;
			} else {
				$config['adport'] = 389;
			}
		}
		$config['parentTask'] = $parent;
		$config['failOnParentFail'] = false;
		$config['proxyip'] = Property::getServerIp();
		$config['proxyport'] = 3100 + $this->id();
		$config['filename'] = $tgz;
		$config['moduleid'] = $this->id();
		if (!isset($config['shareRemapMode'])) {
			$config['shareRemapMode'] = 3;
		}
		if (!isset($config['shareHomeDrive'])) {
			$config['shareHomeDrive'] = 'H:';
		}
		if (!isset($config['fixnumeric'])) {
			$config['fixnumeric'] = 's';
		}
		$config['genuid'] = isset($config['genuid']) && !empty($config['genuid']);
		$config['nohomewarn'] = isset($config['nohomewarn']) ? (int)$config['nohomewarn'] : 0;
		$this->preTaskmanagerHook($config);
		$task = Taskmanager::submit('CreateLdapConfig', $config);
		if (is_array($task) && isset($task['id'])) {
			Trigger::ldadp(null, $task['id']);
		}
		return $task;
	}

	/**
	 * Hook called before running CreateLdapConfig task with the
	 * configuration to be passed to the task. Passed by reference
	 * so it can be modified.
	 *
	 * @param array $config
	 */
	protected function preTaskmanagerHook(&$config)
	{
	}

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

	protected function validateConfig()
	{
		// Check if required fields are filled
		return Util::hasAllKeys($this->moduleData, self::$REQUIRED_FIELDS);
	}

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

	// ############## Callbacks #############################

	/**
	 * Server IP changed - rebuild all AD modules.
	 */
	public function event_serverIpChanged()
	{
		$this->generate(false);
	}

}