Commit 503588e5 authored by Côme Chilliet's avatar Côme Chilliet
Browse files

:sparkles: feat(opsi): Allow to add products directly on systems

This allows to configure localboot products action directly in the OPSI
 client tab of a system

issue #5596
Showing with 93 additions and 2 deletions
+93 -2
...@@ -26,6 +26,7 @@ class opsiClient extends simplePlugin ...@@ -26,6 +26,7 @@ class opsiClient extends simplePlugin
var $inheritance = array('gosaGroupOfNames' => 'member'); var $inheritance = array('gosaGroupOfNames' => 'member');
var $initialMembers; var $initialMembers;
var $products;
static function plInfo () static function plInfo ()
{ {
...@@ -56,7 +57,33 @@ class opsiClient extends simplePlugin ...@@ -56,7 +57,33 @@ class opsiClient extends simplePlugin
'fdOpsiProfileDn', FALSE 'fdOpsiProfileDn', FALSE
), ),
) )
) ),
'products' => array(
'name' => _('Softwares'),
'attrs' => array(
new OrderedArrayAttribute(
new CharSeparatedCompositeAttribute(
_('The localboot products to setup on this host'),
'fdOpsiLocalbootProduct',
array(
new SelectAttribute(
'', '',
'fdOpsiLocalbootProduct_product', TRUE
),
new SelectAttribute(
'', '',
'fdOpsiLocalbootProduct_action', TRUE,
array('setup', 'always', 'once', 'custom', 'userlogin', 'update')
)
),
'|', '', _('Localboot products')
),
FALSE, // non-ordered
array(),
TRUE // edition
),
)
),
); );
} }
...@@ -72,6 +99,7 @@ class opsiClient extends simplePlugin ...@@ -72,6 +99,7 @@ class opsiClient extends simplePlugin
} }
} }
} }
$this->attributesAccess['fdOpsiLocalbootProduct']->attribute->attributes[0]->setSubmitForm('product_changed');
} }
function save() function save()
...@@ -213,6 +241,69 @@ class opsiClient extends simplePlugin ...@@ -213,6 +241,69 @@ class opsiClient extends simplePlugin
$profileslabel[] = $attrs['cn'][0]; $profileslabel[] = $attrs['cn'][0];
} }
$this->attributesAccess['fdOpsiProfileDn']->setChoices($profilesdn, $profileslabel); $this->attributesAccess['fdOpsiProfileDn']->setChoices($profilesdn, $profileslabel);
$opsi_args = array('id','name','setupScript','alwaysScript','onceScript','customScript','userLoginScript','updateScript','productVersion','packageVersion');
if (!isset($this->products[$this->fdOpsiServerDn])) {
$s_daemon = new supportDaemon();
if (!$s_daemon->is_available()) {
msg_dialog::display(
_("Could not contact argonaut server"),
msgPool::siError($s_daemon->get_error()), ERROR_DIALOG
);
return;
}
$ldap->cat($this->fdOpsiServerDn);
if ($attrs = $ldap->fetch()) {
if (isset($attrs['macAddress'])) {
$macAddress = $attrs['macAddress'][0];
} else {
msg_dialog::display(
_("No mac address"),
sprintf(_("Server %s has no mac address configured in the LDAP"), $this->fdOpsiServerDn), ERROR_DIALOG
);
return FALSE;
}
} else {
msg_dialog::display(
sprintf(_("Could not find %s in the LDAP"), $this->fdOpsiServerDn),
msgPool::ldaperror($ldap->get_error()), ERROR_DIALOG
);
return FALSE;
}
$localboots = $s_daemon->append_call('OPSI.get_localboots', $macAddress, array('args' => array($opsi_args)));
if ($s_daemon->is_error()) {
msg_dialog::display(
_('Failed to contact OPSI server'),
msgPool::siError($s_daemon->get_error()), ERROR_DIALOG
);
return;
}
$this->products[$this->fdOpsiServerDn]['localboots'] = array();
foreach ($localboots as $localboot) {
$this->products[$this->fdOpsiServerDn]['localboots'][$localboot['id']] = $localboot;
}
}
$choices = array();
foreach ($this->products[$this->fdOpsiServerDn]['localboots'] as $id => $infos) {
$choices[$id] = sprintf(_('%s (%s-%s)'), $infos['id'], $infos['productVersion'], $infos['packageVersion']);
}
$this->attributesAccess['fdOpsiLocalbootProduct']->attribute->attributes[0]->setChoices(
array_keys($choices),
array_values($choices)
);
}
public function product_changed ()
{
$localboot = $this->attributesAccess['fdOpsiLocalbootProduct']->attribute->attributes[0]->getValue();
$actions = array();
foreach (array('setup', 'always', 'once', 'custom', 'userLogin', 'update') as $action) {
if (!empty($this->products[$this->fdOpsiServerDn]['localboots'][$localboot][$action.'Script'])) {
$actions[] = strtolower($action);
}
}
$this->attributesAccess['fdOpsiLocalbootProduct']->attribute->attributes[1]->setChoices($actions);
} }
} }
......
...@@ -72,7 +72,7 @@ objectclass ( 1.3.6.1.4.1.38414.20.2.1 NAME 'opsiServer' SUP top AUXILIARY ...@@ -72,7 +72,7 @@ objectclass ( 1.3.6.1.4.1.38414.20.2.1 NAME 'opsiServer' SUP top AUXILIARY
objectclass ( 1.3.6.1.4.1.38414.20.2.2 NAME 'opsiClient' SUP top AUXILIARY objectclass ( 1.3.6.1.4.1.38414.20.2.2 NAME 'opsiClient' SUP top AUXILIARY
DESC 'FusionDirectory - OPSI client' DESC 'FusionDirectory - OPSI client'
MUST ( cn $ fdOpsiServerDn ) MUST ( cn $ fdOpsiServerDn )
MAY ( fdOpsiProfileDn ) ) MAY ( fdOpsiProfileDn $ fdOpsiLocalbootProduct ) )
objectclass ( 1.3.6.1.4.1.38414.20.2.3 NAME 'opsiProfile' objectclass ( 1.3.6.1.4.1.38414.20.2.3 NAME 'opsiProfile'
DESC 'FusionDirectory - OPSI profile' DESC 'FusionDirectory - OPSI profile'
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment