summaryrefslogblamecommitdiffstats
path: root/modules-available/sysconfig/addmodule_sshkey.inc.php
blob: 9f5bd1d3e161a165c47a2254f0bcded22db32904 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11










                                                 

                                                                   























                                                                                                                                   
                                           











                                                                                                      
                                           





                                                                                           
                                                                                


                                                                                           
                                           









                                                                                   
<?php

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

class SshKey_Start extends AddModule_Base
{

	protected function renderInternal()
	{
		if ($this->edit !== null) {
			$data = $this->edit->getData(null) + 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 === null) {
			$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 !== null) {
			$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 === null, NULL, 200)) {
			Util::redirect('?do=SysConfig&action=addmodule&step=SshKey_Start');
		}
		// Yay
		if ($this->edit !== null) {
			Message::addSuccess('module-edited');
		} else {
			Message::addSuccess('module-added');
			AddModule_Base::setStep('AddModule_Assign', $module->id());
			return;
		}
		Util::redirect('?do=SysConfig');
	}

}