*/
/**
* Manages SSH public keys.
*
* @package modules
*/
class ldapPublicKey extends baseModule {
/**
* Returns meta data that is interpreted by parent class
*
* @return array array with meta data
*
* @see baseModule::get_metaData()
*/
function get_metaData() {
$return = array();
// icon
$return['icon'] = 'keyBig.png';
// manages host accounts
$return["account_types"] = array("user");
// alias name
$return["alias"] = _("SSH public key");
// module dependencies
$return['dependencies'] = array('depends' => array(), 'conflicts' => array());
// managed object classes
$return['objectClasses'] = array('ldapPublicKey');
// managed attributes
$return['attributes'] = array('sshPublicKey');
// help Entries
$return['help'] = array(
'key' => array(
"Headline" => _("SSH public key"), 'attr' => 'sshPublicKey',
"Text" => _("Please enter your public SSH key.")
),
'keyList' => array(
"Headline" => _("SSH public key"), 'attr' => 'sshPublicKey',
"Text" => _("Please a comma separated list of your public SSH keys.")
)
);
// upload fields
$return['upload_columns'] = array(
array(
'name' => 'ldapPublicKey_sshPublicKey',
'description' => _('SSH public key'),
'help' => 'keyList',
'example' => _('ssh-dss 234234 user@host')
)
);
// available PDF fields
$return['PDF_fields'] = array(
'sshPublicKey' => _('SSH public keys')
);
return $return;
}
/**
* Returns the HTML meta data for the main account page.
*
* @return htmlElement HTML meta data
*/
function display_html_attributes() {
$return = new htmlTable();
$keyCount = 0;
// list current keys
if (isset($this->attributes['sshPublicKey'])) {
$keyCount = sizeof($this->attributes['sshPublicKey']);
for ($i = 0; $i < sizeof($this->attributes['sshPublicKey']); $i++) {
$return->addElement(new htmlOutputText(_('SSH public key')));
$sshInput = new htmlInputField('sshPublicKey' . $i, $this->attributes['sshPublicKey'][$i]);
$sshInput->setFieldSize(50);
$sshInput->setFieldMaxLength(4096);
$return->addElement($sshInput);
$return->addElement(new htmlButton('delKey' . $i, 'del.png', true));
$return->addElement(new htmlHelpLink('key'), true);
}
}
// input box for new key
$return->addElement(new htmlOutputText(_('New SSH public key')));
$sshNewKey = new htmlInputField('sshPublicKey');
$sshNewKey->setFieldSize(50);
$sshNewKey->setFieldMaxLength(4096);
$return->addElement($sshNewKey);
$return->addElement(new htmlButton('addKey', 'add.png', true));
$return->addElement(new htmlHelpLink('key'));
$return->addElement(new htmlHiddenInput('key_number', $keyCount));
return $return;
}
/**
* Processes user input of the primary module page.
* It checks if all input values are correct and updates the associated LDAP attributes.
*
* @return array list of info/error messages
*/
function process_attributes() {
$this->attributes['sshPublicKey'] = array();
// check old keys
if (isset($_POST['key_number'])) {
for ($i = 0; $i < $_POST['key_number']; $i++) {
if (isset($_POST['delKey' . $i])) continue;
if (isset($_POST['sshPublicKey' . $i]) && ($_POST['sshPublicKey' . $i] != "")) {
$this->attributes['sshPublicKey'][] = $_POST['sshPublicKey' . $i];
}
}
}
// check new key
if (isset($_POST['sshPublicKey']) && ($_POST['sshPublicKey'] != "")) {
$this->attributes['sshPublicKey'][] = $_POST['sshPublicKey'];
}
$this->attributes['sshPublicKey'] = array_unique($this->attributes['sshPublicKey']);
return array();
}
/**
* In this function the LDAP account is built up.
*
* @param array $rawAccounts list of hash arrays (name => value) from user input
* @param array $partialAccounts list of hash arrays (name => value) which are later added to LDAP
* @param array $ids list of IDs for column position (e.g. "posixAccount_uid" => 5)
* @param array $selectedModules list of selected account modules
* @return array list of error messages if any
*/
function build_uploadAccounts($rawAccounts, $ids, &$partialAccounts, $selectedModules) {
$messages = array();
for ($i = 0; $i < sizeof($rawAccounts); $i++) {
// add object class
if (!in_array("ldapPublicKey", $partialAccounts[$i]['objectClass'])) $partialAccounts[$i]['objectClass'][] = "ldapPublicKey";
// add keys
if ($rawAccounts[$i][$ids['ldapPublicKey_sshPublicKey']] != "") {
$keys = explode(',', $rawAccounts[$i][$ids['ldapPublicKey_sshPublicKey']]);
// check format
for ($m = 0; $m < sizeof($keys); $m++) {
$partialAccounts[$i]['sshPublicKey'][] = $keys[$m];
}
}
}
return $messages;
}
/**
* Returns a list of PDF entries
*/
function get_pdfEntries() {
$return = array();
if (sizeof($this->attributes['sshPublicKey']) > 0) {
$return['ldapPublicKey_sshPublicKey'][0] = '' . _('SSH public keys') . '