1 <?php
3 class InstallRecipe extends plugin
4 {
6 public $installBootstrapMethod = '';
7 public $installBootstrapMethodList = NULL;
9 public $installConfigManagement = '';
10 public $installConfigManagementList = NULL;
12 public $installTemplateDN = "";
13 public $installTemplateDNList = array(
14 'dc=intranet,dc=gonicus,dc=de' => 'Intranet-Tpl',
15 'ou=systems,dc=intranet,dc=gonicus,dc=de' => 'System-Tpl');
17 public $installMirrorDN = "";
18 public $installMirrorDNList = array(
19 'dc=intranet,dc=gonicus,dc=de' => 'Intranet',
20 'ou=systems,dc=intranet,dc=gonicus,dc=de' => 'System');
21 public $installKernelPackage = "";
22 public $installKernelPackageList = array('kernel1','kk1');
23 public $installKeyboardlayout = "";
24 public $installKeyboardlayoutList = array("104","105");
25 public $installSystemLocale = "";
26 public $installSystemLocaleList = array('de','en_EN.UTF-8');
27 public $installTimezone = "";
28 public $installTimeUTC = "";
29 public $installNTPServer = array();
30 public $installRootEnabled = "";
31 public $installRootPasswordHash = "";
32 public $installPartitionTable = "";
34 public $objectclasses = array('installRecipe');
35 public $attributes = array("installTemplateDN","installKeyboardlayout","installSystemLocale",
36 "installTimezone","installTimeUTC","installNTPServer","installMirrorDN",
37 "installRootEnabled","installRootPasswordHash","installKernelPackage",
38 "installPartitionTable","installConfigManagement","installBootstrapMethod");
40 public $setKickstartRootPasswordHash = FALSE;
42 private $installNTPServerList = NULL;
44 function __construct(&$config, $dn)
45 {
46 plugin::plugin($config, $dn);
48 // Preset some values for new accounts
49 if(!$this->is_account){
51 // Preset the device timezone
52 $tz = timezone::get_default_timezone();
53 $this->installTimezone = $tz['name'];
54 }
56 // Prepare list of timezones
57 $tmp = timezone::_get_tz_zones();
58 $list = array();
59 foreach($tmp['TIMEZONES'] as $name => $offset){
60 if($offset >= 0){
61 $list[$name] = $name." ( + ".sprintf("%0.2f",$offset/(60*60))." "._("hours").")";
62 }else{
63 $offset = $offset * -1;
64 $list[$name] = $name." ( - ".sprintf("%0.2f",($offset/(60*60)))." "._("hours").")";
65 }
66 }
67 uksort($list, 'strnatcasecmp');
68 $this->timezones = $list;
70 // Get list of password hashes
71 $tmp = passwordMethod::get_available_methods();
72 $this->hashes = array();
73 foreach($tmp['name'] as $name){
74 $this->hashes[$name] = $name;
75 }
76 $this->hash = $this->config->get_cfg_value("core","passwordDefaultHash");
78 // Get list of NTP servers
79 $this->installNTPServer = array();
80 if(isset($this->attrs['installNTPServer']['count'])){
81 for($i = 0; $i < $this->attrs['installNTPServer']['count']; $i++){
82 $this->installNTPServer[] = $this->attrs['installNTPServer'][$i];
83 }
84 }
86 // Prepare NTP servers list
87 $this->installNTPServerList= new sortableListing($this->installNTPServer);
88 $this->installNTPServerList->setDeleteable(true);
89 $this->installNTPServerList->setEditable(false);
90 $this->installNTPServerList->setColspecs(array('*'));
91 $this->installNTPServerList->setWidth("100%");
92 $this->installNTPServerList->setHeight("70px");
94 // Load list of bootstrap methods.
95 $this->loadInstallationMethods();
96 }
99 function loadInstallationMethods()
100 {
101 $this->installBootstrapMethodList = array();
102 $this->installConfigManagementList = array();
103 $rpc = $this->config->getRpcHandle();
104 $res = $rpc->getSupportedBaseInstallMethods();
105 foreach($res as $name => $method){
106 $this->installBootstrapMethodList[$name] = $method['name'];
107 foreach($method['methods'] as $m){
108 $this->installConfigManagementList[$name][$m] = $m;
109 }
110 }
112 if(empty($this->installBootstrapMethod)){
113 $this->installBootstrapMethod = key($this->installBootstrapMethodList);
114 }
115 if(empty($this->installConfigManagement)){
116 $this->installConfigManagement = key($this->installConfigManagementList[$this->installBootstrapMethod]);
117 }
118 }
121 function execute()
122 {
123 if($this->setKickstartRootPasswordHash){
124 $this->dialog = TRUE;
125 $smarty = get_smarty();
126 $smarty->assign('hashes', set_post($this->hashes));
127 $smarty->assign('hash', set_post($this->hash));
128 return($smarty->fetch(get_template_path('goto/Device/SetPassword.tpl', TRUE)));
129 }
131 $this->installNTPServerList->setAcl($this->getacl('installNTPServer'));
132 $this->installNTPServerList->update();
134 plugin::execute();
135 $smarty = get_smarty();
136 $smarty->assign('timezones', $this->timezones);
137 $smarty->assign('installKeyboardlayoutList', $this->installKeyboardlayoutList);
138 $smarty->assign('installKernelPackageList', $this->installKernelPackageList);
139 $smarty->assign('installTemplateDNList', $this->installTemplateDNList);
140 $smarty->assign('installMirrorDNList', $this->installMirrorDNList);
141 $smarty->assign('installSystemLocaleList', $this->installSystemLocaleList);
142 $smarty->assign('installNTPServerList', $this->installNTPServerList->render());
144 $smarty->assign('installBootstrapMethod', $this->installBootstrapMethod);
145 $smarty->assign('installBootstrapMethodList', $this->installBootstrapMethodList);
146 $smarty->assign('installConfigManagement', $this->installConfigManagement);
148 $cfgList = $this->installConfigManagementList[$this->installBootstrapMethod];
149 $smarty->assign('installConfigManagementList', $cfgList);
150 foreach($this->attributes as $attr){
151 $smarty->assign($attr, $this->$attr);
152 }
153 $this->dialog = false;
154 return($smarty->fetch(get_template_path('goto/Device/InstallRecipe.tpl', TRUE)));
155 }
158 function save_object()
159 {
162 if(isset($_POST['InstallRecipePosted'])){
164 $currentInstallMethod = $this->installConfigManagement;
165 plugin::save_object();
166 $this->installRootEnabled = isset($_POST['installRootEnabled']);
167 $this->installTimeUTC = isset($_POST['installTimeUTC']);
170 if(isset($_POST['setKickstartRootPasswordHash'])){
171 $this->setKickstartRootPasswordHash = true;
172 }
174 $this->installNTPServerList->save_object();
175 $this->installNTPServer = $this->installNTPServerList->getMaintainedData();
176 if(isset($_POST['installNTPServer_Input']) && isset($_POST['installNTPServer_Add'])){
177 $add = get_post('installNTPServer_Input');
178 if(!in_array($add, $this->installNTPServer) && !empty($add)){
179 $this->installNTPServer[] = $add;
180 }
181 }
182 $this->installNTPServerList->setListData($this->installNTPServer);
184 if($currentInstallMethod != $this->installConfigManagement){
185 $this->updateRecipeTab();
186 }
187 }
188 if(isset($_POST['cancelPassword'])) $this->setKickstartRootPasswordHash =false;
189 if(isset($_POST['setPassword'])) {
190 $this->setKickstartRootPasswordHash =false;
191 $hash = get_post('passwordHash');
193 // Not sure, why this is here, but maybe some encryption methods require it.
194 mt_srand((double) microtime()*1000000);
196 // Generate the requested hash
197 $methods = new passwordMethod($this->config, $this->dn);
198 $available = $methods->get_available_methods();
199 $test = new $available[$hash]($this->config,$this->dn);
200 $this->installRootPasswordHash = @$test->generate_hash(get_post('rootPassword'));
201 }
203 }
206 function updateRecipeTab()
207 {
208 $mode = $this->installConfigManagement;
209 if(!isset($this->recipeTabs[$mode])){
210 $this->recipeTabs[$mode] = new DeviceConfig($this->config, $this->dn);
211 $this->recipeTabs[$mode]->parent = &$this->parent;
213 if($this->recipeTabs[$mode]->setInstallMethod($mode)){
215 $class= &$this->recipeTabs[$mode];
217 // Add some dummy entries for testing.
218 if($mode == 'puppet'){
219 $id = $class->addItem('PuppetModule','test1',
220 array(
221 'dependency' => array('stulle','Wurst'),
222 'version' => '2.4-f',
223 'name' => 'Thundebird',
224 'description' => 'Mozilla mail client')
225 );
226 $id = $class->addItem('PuppetModule','test2',
227 array(
228 'dependency' => array('Leipnitz','Dose'),
229 'version' => 1,
230 'name' => 'Firefox',
231 'description' => 'Test Module')
232 );
233 $class->setCurrentItem($id);
234 $id = $class->addItem('PuppetTemplate','temp1',
235 array(
236 'name' => 'temp1',
237 'data' => 'kekse.tpl')
238 );
239 $class->setCurrentItem($id);
240 $id = $class->addItem('PuppetTemplate','tep1',
241 array(
242 'name' => 'tep1',
243 'data' => 'kekse.tpl')
244 );
246 $class->setCurrentItem($class->getRootItemID());
247 }
248 }else{
249 unset($this->recipeTabs[$mode]);
250 }
251 }
253 // Update the recipe tab to match the selected installation method.
254 if($this->is_account && isset($this->recipeTabs[$mode])){
256 if(isset($this->parent->by_object['DeviceConfig']) &&
257 $this->recipeTabs[$mode] === $this->parent->by_object['DeviceConfig']){
258 return;
259 }
261 $this->parent->by_name['DeviceConfig'] = $mode ;
262 $this->parent->by_object['DeviceConfig'] = &$this->recipeTabs[$mode];
263 }else{
264 if(isset($this->parent->by_name['DeviceConfig'])){
265 unset($this->parent->by_name['DeviceConfig']);
266 unset($this->parent->by_object['DeviceConfig']);
267 }
268 }
269 }
272 function save()
273 {
274 //
275 if(!$this->installRootEnabled) $this->installRootPasswordHash = "";
276 $this->installRootEnabled = ($this->installRootEnabled)?'TRUE':'FALSE';
277 $this->installTimeUTC = ($this->installTimeUTC)?'TRUE':'FALSE';
280 plugin::save();
282 $this->cleanup();
283 $ldap=$this->config->get_ldap_link();
284 $ldap->cd($this->config->current['BASE']);
285 $ldap->cd($this->dn);
286 $ldap->modify($this->attrs);
287 new log("modify","Device/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
288 if (!$ldap->success()){
289 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
290 }else{
291 $this->handle_post_events("modify");
292 }
293 }
295 static function plInfo()
296 {
297 return (array(
298 "plShortName" => _("Device"),
299 "plDescription" => _("Registered device"),
300 "plSelfModify" => FALSE,
301 "plDepends" => array(),
302 "plPriority" => 1,
303 "plSection" => array("administration"),
304 "plCategory" => array("Device"),
305 "plProvidedAcls" => array(
306 "member" => _("Member"),
307 "installTemplateDN" => _("Template"),
308 "installBootstrapMethod" => _("Bootstrap method"),
309 "installConfigManagement" => _("Config management"),
310 "installKeyboardlayout" => _("Keyboard layout"),
311 "installSystemLocale" => _("System locale"),
312 "installTimezone" => _("Timezone"),
313 "installTimeUTC" => _("Time"),
314 "installNTPServer" => _("NTP-Server"),
315 "installMirrorDN" => _("Kickstart mirror"),
316 "installRootEnabled" => _("Root login enabled"),
317 "installRootPasswordHash" => _("Root password hash"),
318 "installKernelPackage" => _("Kernal package"),
319 "installPartitionTable" => _("Partition table")
320 )
321 )
322 );
323 }
324 }
326 ?>