3
class InstallRecipe extends plugin
6
/* This has to be replaced by valid attributes, currently they are just
7
* fake variables. #FIXME: I do not know the real attribute names yet.
9
public $installBootstrapMethod = '';
10
public $installBootstrapMethodList = NULL;
12
public $installConfigManagement = '';
13
public $installConfigManagementList = NULL;
17
public $installTemplateDN = "";
18
public $installTemplateDNList = array();
20
public $installMirrorDN = "";
21
public $installMirrorDNList = array();
23
public $installKernelPackage = "";
24
public $installKernelPackageList = array();
26
public $installKeyboardlayout = "";
27
public $installKeyboardlayoutList = array();
29
public $installSystemLocale = "";
30
public $installSystemLocaleList = array();
32
public $installTimezone = "";
33
public $installTimeUTC = "";
35
public $installNTPServer = array();
36
public $installRootEnabled = "";
37
public $installRootPasswordHash = "";
39
public $setKickstartRootPasswordHash = FALSE;
40
public $installPartitionTable = "";
41
private $installNTPServerList = NULL;
43
public $objectclasses = array('installRecipe');
44
public $attributes = array("installTemplateDN","installKeyboardlayout","installSystemLocale",
45
"installTimezone","installTimeUTC","installNTPServer","installMirrorDN",
46
"installRootEnabled","installRootPasswordHash","installKernelPackage",
47
"installPartitionTable","installConfigManagement","installBootstrapMethod");
49
private $map = array('puppet' => array('objectClass' => 'puppetClient', 'type' => 'puppet', 'bootstrap' => 'preseed'));
51
/* Some plugin management related attributes
52
* See class plugin for details.
54
public $view_logged = FALSE;
55
public $ignore_account = FALSE;
58
/*! \brief Initialize the plugin and its widgets.
59
* Finally call init() to load values from the backend.
61
function __construct(&$config, $dn)
63
plugin::plugin($config, $dn);
65
// Set default password hash
66
$this->hash = $this->config->get_cfg_value("core","passwordDefaultHash");
68
// Prepare list of timezones
69
$this->timezones = $this->getTimezones();
71
// Get list of password hashes
72
$tmp = passwordMethod::get_available_methods();
73
$this->hashes = array();
74
foreach($tmp['name'] as $name){
75
$this->hashes[$name] = $name;
78
// Prepare NTP servers list
79
$this->installNTPServerList= new sortableListing($this->installNTPServer);
80
$this->installNTPServerList->setDeleteable(true);
81
$this->installNTPServerList->setEditable(false);
82
$this->installNTPServerList->setColspecs(array('*'));
83
$this->installNTPServerList->setWidth("100%");
84
$this->installNTPServerList->setHeight("70px");
86
// Init the object values.
91
/*! \brief Load attribute values from the GOsa-backend using jsonRPC
95
// Detect account status by checking the used objectClasses
96
$this->is_account = FALSE;
97
foreach($this->map as $type){
98
if(in_array($type['objectClass'], $this->attrs['objectClass'])){
99
$this->installBootstrapMethod = $type['bootstrap'];
100
$this->installConfigManagement = $type['type'];
101
$this->is_account = TRUE;
105
// Start without error.
106
$this->initFailed = FALSE;
108
// Get list of NTP servers
109
$this->installNTPServer = array();
110
if(isset($this->attrs['installNTPServer']['count'])){
111
for($i = 0; $i < $this->attrs['installNTPServer']['count']; $i++){
112
$this->installNTPServer[] = $this->attrs['installNTPServer'][$i];
116
// Load list of bootstrap methods.
117
$res = $this->loadInstallationMethods();
119
$this->initFailed = TRUE;
120
msg_dialog(_("Error"), msgPool::rpcError($this->rpcErrorMessage), ERROR_DIALOG);
123
$this->installBootstrapMethodList = $res['installBootstrapMethodList'];
124
$this->installConfigManagementList = $res['installConfigManagementList'];
127
// Load system locales
128
$locales = $this->getSystemLocales();
129
if($locales == NULL){
130
$this->initFailed = TRUE;
131
msg_dialog(_("Error"), msgPool::rpcError($this->rpcErrorMessage), ERROR_DIALOG);
134
$this->installSystemLocaleList = $locales;
137
// Load installation templates
138
$res = $this->loadInstallationTemplates();
140
$this->initFailed = TRUE;
141
msg_dialog(_("Error"), msgPool::rpcError($this->rpcErrorMessage), ERROR_DIALOG);
144
$this->installTemplateDNList = $res;
147
// Load installation keyboard layouts
148
$res = $this->loadInstallationKeyboardLayouts();
150
$this->initFailed = TRUE;
151
msg_dialog(_("Error"), msgPool::rpcError($this->rpcErrorMessage), ERROR_DIALOG);
154
$this->installKeyboardlayoutList = $res;
157
// Load kernel package list
158
$res = $this->loadInstallationKernelPackages();
160
$this->initFailed = TRUE;
161
msg_dialog(_("Error"), msgPool::rpcError($this->rpcErrorMessage), ERROR_DIALOG);
164
$this->installKernelPackageList = $res;
167
// Load installation mirrors
168
$res = $this->loadInstallationMirrors();
170
$this->initFailed = TRUE;
171
msg_dialog(_("Error"), msgPool::rpcError($this->rpcErrorMessage), ERROR_DIALOG);
174
$this->installMirrorDNList = $res;
177
// Preset some values for new accounts
178
if(!$this->is_account){
180
// Preset the device timezone
181
$tz = timezone::get_default_timezone();
182
$this->installTimezone = $tz['name'];
184
// Set initial bootstrap and install method.
185
$this->installBootstrapMethod = key($this->installBootstrapMethodList);
186
$this->installConfigManagement = key($this->installConfigManagementList[$this->installBootstrapMethod]);
190
// Check if we've a valid bootstrap and configMangement method selected
191
if(!isset($this->installConfigManagementList[$this->installBootstrapMethod])){
192
$newMethod = key($this->installBootstrapMethodList);
193
msg_dialog::display(_("Error"),
194
sprintf(_("The selected bootstrap method %s is invalid. Using %s instead!"),
195
bold($this->installBootstrapMethod), bold($newMethod)), ERROR_DIALOG);
196
$this->installBootstrapMethod = $newMethod;
198
if(!isset($this->installConfigManagementList[$this->installBootstrapMethod][$this->installConfigManagement])){
199
$newMethod = key($this->installConfigManagementList[$this->installBootstrapMethod]);
200
msg_dialog::display(_("Error"),
201
sprintf(_("The selected config management method %s is invalid. Using %s instead!"),
202
bold($this->installConfigManagement),bold($newMethod)), ERROR_DIALOG);
203
$this->installConfigManagement = $newMethod;
208
function getTimezones()
210
$tmp = timezone::_get_tz_zones();
212
foreach($tmp['TIMEZONES'] as $name => $offset){
214
$list[$name] = $name." ( + ".sprintf("%0.2f",$offset/(60*60))." "._("hours").")";
216
$offset = $offset * -1;
217
$list[$name] = $name." ( - ".sprintf("%0.2f",($offset/(60*60)))." "._("hours").")";
220
uksort($list, 'strnatcasecmp');
225
function loadInstallationKernelPackages()
227
return(array('kernel1','kk1'));
231
function loadInstallationMirrors()
234
'dc=intranet,dc=gonicus,dc=de' => 'Intranet',
235
'ou=systems,dc=intranet,dc=gonicus,dc=de' => 'System');
239
function loadInstallationTemplates()
242
'dc=intranet,dc=gonicus,dc=de' => 'Intranet-Tpl',
243
'ou=systems,dc=intranet,dc=gonicus,dc=de' => 'System-Tpl');
247
function loadInstallationKeyboardLayouts()
249
return(array('104','105'));
252
function getSystemLocales()
254
$locales = json_decode('{"hu_HU.UTF-8": "Hungarian",
255
"es_DO.UTF-8": "Spanish (Dominican Republic)",
256
"es_CL.UTF-8": "Spanish (Chile)"}');
262
/*! \brief Try to load install and bootstrap methods from the GOsa-backend
263
* This is done via jsonRPC, if calling the backend method fails,
264
* this method returns FALSE, in case of success it return TRUE;
266
function loadInstallationMethods()
268
$rpc = $this->config->getRpcHandle();
269
$res = $rpc->getSupportedBaseInstallMethods();
271
// Failed to load backend values, keep reported error and return with FALSE;
272
$this->rpcError = !$rpc->success();
273
if(!$rpc->success()){
274
$this->rpcErrorMessage = $rpc->get_error();
278
// Walk through result and set bootstrap methods.
279
foreach($res as $name => $method){
280
$res['installBootstrapMethodList'][$name] = $method['name'];
281
foreach($method['methods'] as $m){
282
$res['installConfigManagementList'][$name][$m] = $m;
291
// Log account access
292
if($this->is_account && !$this->view_logged){
293
$this->view_logged = TRUE;
294
new log("view","Device/".get_class($this),$this->dn);
301
// Allow to add or remove the distribution list extension
302
if(isset($_POST['modify_state'])){
303
if($this->is_account && $this->acl_is_removeable()){
304
$this->is_account= FALSE;
305
}elseif(!$this->is_account && $this->acl_is_createable()){
306
$this->is_account= TRUE;
310
// Show account status-changer
312
if ($this->parent !== NULL){
313
if ($this->is_account){
314
$display= $this->show_disable_header(_("Remove install profile"),
315
msgPool::featuresEnabled(_("Install profile")));
317
$display= $this->show_enable_header(_("Add install profile"),
318
msgPool::featuresDisabled(_("Install profile")));
324
Root password hash dialog
327
if($this->setKickstartRootPasswordHash){
328
$this->dialog = TRUE;
329
$smarty = get_smarty();
330
$smarty->assign('hashes', set_post($this->hashes));
331
$smarty->assign('hash', set_post($this->hash));
332
return($smarty->fetch(get_template_path('goto/Device/SetPassword.tpl', TRUE)));
336
Generate HTML content
339
$this->installNTPServerList->setAcl($this->getacl('installNTPServer'));
340
$this->installNTPServerList->update();
343
$smarty = get_smarty();
344
$smarty->assign('timezones', $this->timezones);
345
$smarty->assign('installKeyboardlayoutList', $this->installKeyboardlayoutList);
346
$smarty->assign('installKernelPackageList', $this->installKernelPackageList);
347
$smarty->assign('installTemplateDNList', $this->installTemplateDNList);
348
$smarty->assign('installMirrorDNList', $this->installMirrorDNList);
349
$smarty->assign('installSystemLocaleList', $this->installSystemLocaleList);
350
$smarty->assign('installNTPServerList', $this->installNTPServerList->render());
352
$smarty->assign('installBootstrapMethod', $this->installBootstrapMethod);
353
$smarty->assign('installBootstrapMethodList', $this->installBootstrapMethodList);
354
$smarty->assign('installConfigManagement', $this->installConfigManagement);
356
$cfgList = $this->installConfigManagementList[$this->installBootstrapMethod];
357
$smarty->assign('installConfigManagementList', $cfgList);
358
foreach($this->attributes as $attr){
359
$smarty->assign($attr, $this->$attr);
361
$this->dialog = false;
362
return($display.$smarty->fetch(get_template_path('goto/Device/InstallRecipe.tpl', TRUE)));
366
function save_object()
368
if(isset($_POST['InstallRecipePosted'])){
370
$currentInstallMethod = $this->installConfigManagement;
371
plugin::save_object();
372
$this->installRootEnabled = isset($_POST['installRootEnabled']);
373
$this->installTimeUTC = isset($_POST['installTimeUTC']);
376
if(isset($_POST['setKickstartRootPasswordHash'])){
377
$this->setKickstartRootPasswordHash = true;
380
$this->installNTPServerList->save_object();
381
$this->installNTPServer = $this->installNTPServerList->getMaintainedData();
382
if(isset($_POST['installNTPServer_Input']) && isset($_POST['installNTPServer_Add'])){
383
$add = get_post('installNTPServer_Input');
384
if(!in_array($add, $this->installNTPServer) && !empty($add)){
385
$this->installNTPServer[] = $add;
388
$this->installNTPServerList->setListData($this->installNTPServer);
390
if(isset($_POST['cancelPassword'])) $this->setKickstartRootPasswordHash =false;
391
if(isset($_POST['setPassword'])) {
392
$this->setKickstartRootPasswordHash =false;
393
$hash = get_post('passwordHash');
395
// Not sure, why this is here, but maybe some encryption methods require it.
396
mt_srand((double) microtime()*1000000);
398
// Generate the requested hash
399
$methods = new passwordMethod($this->config, $this->dn);
400
$available = $methods->get_available_methods();
401
$test = new $available[$hash]($this->config,$this->dn);
402
$this->installRootPasswordHash = @$test->generate_hash(get_post('rootPassword'));
411
if(!$this->installRootEnabled) $this->installRootPasswordHash = "";
412
$this->installRootEnabled = ($this->installRootEnabled)?'TRUE':'FALSE';
413
$this->installTimeUTC = ($this->installTimeUTC)?'TRUE':'FALSE';
417
unset($this->attrs['installConfigManagement']);
418
unset($this->attrs['installBootstrapMethod']);
419
echo "Skipp saving of 'installConfigManagement' and 'installBootstrapMethod', i've no idea where to store them.";
421
// Remove all objectClasses which belongs to a bootstrap method,
422
// and then add the selected one.
423
foreach($this->map as $type){
424
$this->attrs['objectClass'] = array_remove_entries_ics(array($type['objectClass']), $this->attrs['objectClass']);
426
$this->attrs['objectClass'][] = $this->map[$this->installConfigManagement]['objectClass'];
428
print_a($this->attrs);
431
$ldap=$this->config->get_ldap_link();
432
$ldap->cd($this->config->current['BASE']);
433
$ldap->cd($this->dn);
434
$ldap->modify($this->attrs);
435
new log("modify","Device/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
436
if (!$ldap->success()){
437
msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
439
$this->handle_post_events("modify");
444
function remove_from_parent()
446
plugin::remove_from_parent();
447
unset($this->attrs['installConfigManagement']);
448
unset($this->attrs['installBootstrapMethod']);
449
echo "Skipp saving of 'installConfigManagement' and 'installBootstrapMethod', i've no idea where to store them.";
451
$ldap=$this->config->get_ldap_link();
452
$ldap->cd($this->config->current['BASE']);
453
$ldap->cd($this->dn);
454
$ldap->modify($this->attrs);
455
new log("remove","Device/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
456
if (!$ldap->success()){
457
msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_DEL, get_class()));
459
$this->handle_post_events("remove");
465
static function plInfo()
468
"plShortName" => _("Device"),
469
"plDescription" => _("Registered device"),
470
"plSelfModify" => FALSE,
471
"plDepends" => array(),
473
"plSection" => array("administration"),
474
"plCategory" => array("Device"),
475
"plProvidedAcls" => array(
476
"member" => _("Member"),
477
"installTemplateDN" => _("Template"),
478
"installBootstrapMethod" => _("Bootstrap method"),
479
"installConfigManagement" => _("Config management"),
480
"installKeyboardlayout" => _("Keyboard layout"),
481
"installSystemLocale" => _("System locale"),
482
"installTimezone" => _("Timezone"),
483
"installTimeUTC" => _("Time"),
484
"installNTPServer" => _("NTP-Server"),
485
"installMirrorDN" => _("Kickstart mirror"),
486
"installRootEnabled" => _("Root login enabled"),
487
"installRootPasswordHash" => _("Root password hash"),
488
"installKernelPackage" => _("Kernel package"),
489
"installPartitionTable" => _("Partition table")