summaryrefslogblamecommitdiffstats
path: root/modules/sysconfig/addmodule_ad.inc.php
blob: a85c5d06aa2feefb9c5b34927a152a25e02203c3 (plain) (tree)
1
2
3
4
5
6
7
8





                                                                         

                                                                                                      






                                           

                                                
                                                                                                                     




                                                                    
                                                       






                                                     

                         







                                                                             
                                                                                                                

                               





                                                                      
                   
                                                



                                                                                                                
                                                        
                  



                                           
                                                                                                                         




                                                                            
                                                                













                                                           



                                                                                        

                                                    


                                                                      
                                         



                                                                                                                
                                                  
                  

         

                                           
                                                                                                                




                                      
<?php

/*
 * Wizard for setting up active directory integration for authentication.
 */

Page_SysConfig::addModule('AD_AUTH', 'AdModule_Start', Dictionary::translate('lang_adAuthentication'),
	Dictionary::translate('lang_adModule'),	Dictionary::translate('lang_authentication'), true
);

class AdModule_Start extends AddModule_Base
{

	protected function renderInternal()
	{
		Session::set('ad_check', false);
		Session::save();
		Render::addDialog(Dictionary::translate('lang_adAuthentication'), false, 'sysconfig/ad-start', array(
			'step' => 'AdModule_CheckConnection',
			'server' => Request::post('server'),
			'searchbase' => Request::post('searchbase'),
			'binddn' => Request::post('binddn'),
			'bindpw' => Request::post('bindpw'),
			'home' => Request::post('home')
		));
	}

}

class AdModule_CheckConnection extends AddModule_Base
{
	private $taskIds;

	protected function preprocessInternal()
	{
		$server = Request::post('server');
		$searchbase = Request::post('searchbase');
		$binddn = Request::post('binddn');
		$bindpw = Request::post('bindpw');
		if (empty($server) || empty($searchbase) || empty($binddn)) {
			Message::addError('empty-field');
			AddModule_Base::setStep('AdModule_Start'); // Continues with AdModule_Start for render()
			return;
		}
		$ldapSearch = Taskmanager::submit('LdapSearch', array(
			'home' => Request::post('home'),
			'server' => $server,
			'searchbase' => $searchbase,
			'binddn' => $binddn,
			'bindpw' => $bindpw
		));
		if (!isset($ldapSearch['id'])) {
			AddModule_Base::setStep('AdModule_Start'); // Continues with AdModule_Start for render()
			return;
		}
		$this->taskIds = array(
			'tm-search' => $ldapSearch['id']
		);
	}
	
	protected function renderInternal()
	{
		Render::addDialog(Dictionary::translate('lang_adAuthentication'), false, 'sysconfig/ad-checkconnection', 
			array_merge($this->taskIds, array(
				'server' => Request::post('server'),
				'searchbase' => Request::post('searchbase'),
				'binddn' => Request::post('binddn'),
				'bindpw' => Request::post('bindpw'),
				'home' => Request::post('home'),
				'step' => 'AdModule_Finish'
			))
		);
	}

}

class AdModule_Finish extends AddModule_Base
{

	private $taskIds;

	protected function preprocessInternal()
	{
		$config = ConfigModule::insertAdConfig('AD: ' . Request::post('server'),
			Request::post('server'),
			Request::post('searchbase'),
			Request::post('binddn'),
			Request::post('bindpw', ''),
			Request::post('home', '')
		);
		$config['proxyip'] = Property::getServerIp();
		$tgz = Taskmanager::submit('CreateAdConfig', $config);
		if (!isset($tgz['id'])) {
			AddModule_Base::setStep('AdModule_Start'); // Continues with AdModule_Start for render()
			return;
		}
		$this->taskIds = array(
			'tm-config' => $tgz['id'],
		);
	}
	
	protected function renderInternal()
	{
		Render::addDialog(Dictionary::translate('lang_adAuthentication'), false, 'sysconfig/ad-finish', 
			$this->taskIds
		);
	}

}