summaryrefslogtreecommitdiffstats
path: root/modules-available/sysconfig/addmodule_sshkey.inc.php
blob: b5ab4ad6f7f9f65f0439fd315a69624720a53e20 (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
<?php

/*
 * Wizard for configuring the sshd (client side).
 */

class SshKey_Start extends AddModule_Base
{

	protected function renderInternal()
	{
		if ($this->edit !== false) {
			$data = $this->edit->getData(false) + array(
					'title' => $this->edit->title(),
					'edit' => $this->edit->id(),
				);
		} else {
			$data = array();
		}
		Render::addDialog(Dictionary::translateFile('config-module', 'sshkey_title'), false, 'sshkey-start', $data + array(
				'step' => 'SshKey_Finish',
			));
	}

}

class SshKey_Finish extends AddModule_Base
{

	protected function preprocessInternal()
	{
		$title = Request::post('title');
		if (empty($title)) {
			Message::addError('missing-title');
			return;
		}
		// Seems ok, create entry
		if ($this->edit === false) {
			$module = ConfigModule::getInstance('SshKey');
		} else {
			$module = $this->edit;
		}
		if ($module === false) {
			Message::addError('main.error-read', 'sshkey.inc.php');
			Util::redirect('?do=SysConfig&action=addmodule&step=SshKey_Start');
		}
		if (!$module->setData('publicKey', Request::post('publicKey'))) {
			Message::addError('main.value-invalid', 'pubkey', Request::post('publicKey'));
			Util::redirect('?do=SysConfig&action=addmodule&step=SshKey_Start');
		}
		if ($this->edit !== false) {
			$ret = $module->update($title);
		} else {
			$ret = $module->insert($title);
		}
		if (!$ret) {
			Util::redirect('?do=SysConfig&action=addmodule&step=SshKey_Start');
		} elseif (!$module->generate($this->edit === false, NULL, 200)) {
			Util::redirect('?do=SysConfig&action=addmodule&step=SshKey_Start');
		}
		// Yay
		if ($this->edit !== false) {
			Message::addSuccess('module-edited');
		} else {
			Message::addSuccess('module-added');
			AddModule_Base::setStep('AddModule_Assign', $module->id());
			return;
		}
		Util::redirect('?do=SysConfig');
	}

}