Commit eedc9916 authored by Côme Chilliet's avatar Côme Chilliet

Merge branch '5821-add-luks-section-to-fai-disk-entry' into '1.3-dev'

Resolve "Add LUKS section to FAI disk entry"

See merge request fusiondirectory/fd-plugins!232
parents cde8f903 0461d118
......@@ -97,9 +97,6 @@ class DiskPartitionsAttribute extends DialogOrderedArrayAttribute
protected function getAttributeArrayValue($key, $value)
{
$opt = array();
if (isset($value['encrypted']) && $value['encrypted']) {
$opt[] = _('encrypted');
}
if (isset($value['bootable']) && $value['bootable']) {
$opt[] = _('bootable');
}
......@@ -119,7 +116,7 @@ class DiskPartitionsAttribute extends DialogOrderedArrayAttribute
function delPostValue ($key)
{
/* Create a list of all partitions that are used in
* lvm or raid compilations.
* lvm, raid or cryptsetup compilations.
*/
$list = array();
foreach ($this->plugin->parent->disks as $disk) {
......@@ -133,6 +130,10 @@ class DiskPartitionsAttribute extends DialogOrderedArrayAttribute
$list[preg_replace('/:.*$/', '', $partname)][] = $disk;
}
}
} elseif ($disk['FAIdiskType'] == 'cryptsetup') {
foreach ($disk['partitions'] as $part) {
$list[$part['FAIpartitionSize']][] = $disk;
}
}
}
......@@ -167,7 +168,11 @@ class DiskPartitionsAttribute extends DialogOrderedArrayAttribute
}
if ($this->plugin->FAIdiskType == 'disk') {
$part['cn'] = $this->plugin->cn.$part['FAIpartitionNr'];
if (preg_match('/^disk(\d+)$/', $this->plugin->cn)) {
$part['cn'] = $this->plugin->cn.'.'.$part['FAIpartitionNr'];
} else {
$part['cn'] = $this->plugin->cn.$part['FAIpartitionNr'];
}
} elseif ($this->plugin->FAIdiskType == 'lvm') {
/* Check if we need to update partition names of lvm compilations */
if (isset($this->value[$part['FAIpartitionNr']])) {
......@@ -183,6 +188,9 @@ class DiskPartitionsAttribute extends DialogOrderedArrayAttribute
} elseif ($this->plugin->FAIdiskType == 'raid') {
/* Set raid names to md# */
$part['cn'] = 'md'.$part['FAIpartitionNr'];
} elseif ($this->plugin->FAIdiskType == 'cryptsetup') {
/* Set cryptsetup names to luks# */
$part['cn'] = 'luks'.$part['FAIpartitionNr'];
}
$this->value[$part['FAIpartitionNr']] = $part;
......@@ -251,6 +259,10 @@ class faiDiskEntry extends simplePlugin
array('msdos', 'gpt'), '',
array('MSDOS', 'GPT')
),
new BooleanAttribute (
_('Random init'), _('Initialise all encrypted partitions with random data'),
'randinit', FALSE
),
new HiddenAttribute ('FAIdiskType')
)
),
......@@ -282,6 +294,19 @@ class faiDiskEntry extends simplePlugin
$this->attributesAccess['lvmDevices']->setDisabled(TRUE);
$this->attributesAccess['lvmDevices']->setVisible(FALSE);
}
if ($this->FAIdiskType != 'disk') {
$this->attributesAccess['disklabel']->setDisabled(TRUE);
$this->attributesAccess['disklabel']->setVisible(FALSE);
$this->attributesAccess['cn']->setDisabled(TRUE);
$this->attributesAccess['cn']->setValue($this->FAIdiskType);
}
if ($this->FAIdiskType == 'cryptsetup') {
$this->attributesAccess['fstabkey']->setDisabled(TRUE);
$this->attributesAccess['fstabkey']->setVisible(FALSE);
} else {
$this->attributesAccess['randinit']->setDisabled(TRUE);
$this->attributesAccess['randinit']->setVisible(FALSE);
}
if ($disk) {
$this->is_edit = TRUE;
......@@ -348,6 +373,11 @@ class faiDiskEntry extends simplePlugin
}
continue;
}
if ($option == 'randinit') {
$this->randinit = TRUE;
continue;
}
}
}
......@@ -396,7 +426,11 @@ class faiDiskEntry extends simplePlugin
foreach ($partitions as $key => $val) {
$partitions[$key]['FAIpartitionNr'] = $key;
if ($this->FAIdiskType == 'disk') {
$partitions[$key]['cn'] = $this->cn.$key;
if (preg_match('/^disk(\d+)$/', $this->cn)) {
$partitions[$key]['cn'] = $this->cn.'.'.$key;
} else {
$partitions[$key]['cn'] = $this->cn.$key;
}
} elseif ($this->FAIdiskType == 'lvm') {
$partitions[$key]['FAIpartitionType'] = 'lvm';
}
......@@ -411,6 +445,12 @@ class faiDiskEntry extends simplePlugin
/* Assemble flags */
if ($this->FAIdiskType == 'disk') {
$tmp['FAIdiskOption'] = array('fstabkey:'.$this->fstabkey, 'disklabel:'.$this->disklabel);
} elseif ($this->FAIdiskType == 'cryptsetup') {
if ($this->randinit) {
$tmp['FAIdiskOption'] = array('randinit');
} else {
$tmp['FAIdiskOption'] = array();
}
} else {
$tmp['FAIdiskOption'] = array('fstabkey:'.$this->fstabkey);
}
......@@ -444,14 +484,14 @@ class faiDiskEntry extends simplePlugin
}
/* Unset non valid attributes */
foreach (array('bootable','encrypted','preserve','resize','FAIdiskType') as $attr) {
foreach (array('bootable','preserve','resize','FAIdiskType') as $attr) {
if (isset($tmp['partitions'][$id][$attr])) {
unset($tmp['partitions'][$id][$attr]);
}
}
}
/* Assembe disk flags */
/* Assemble disk flags */
if (!empty($bootable)) {
$tmp['FAIdiskOption'][] = 'bootable:'.trim($bootable, ',');
}
......@@ -489,14 +529,12 @@ class faiDiskEntry extends simplePlugin
foreach ($disk['partitions'] as $part) {
// Add disks of raid arrays, to the used list.
if ($disk['FAIdiskType'] == 'raid') {
if (in_array($disk['FAIdiskType'], array('raid','cryptsetup'))) {
foreach (explode(',', $part['FAIpartitionSize']) as $rDevice) {
$used[] = preg_replace('/:.*$/i', '', $rDevice);
}
}
// Collect all available disks
if ($disk['FAIdiskType'] == 'disk') {
} elseif ($disk['FAIdiskType'] == 'disk') {
// Collect all available disks
$name = $part['cn'];
if (!in_array($name, $this->lvmDevices)) {
$may[] = $name;
......
......@@ -288,6 +288,14 @@ class faiPartition extends simplePlugin
TRUE
)
),
new SelectAttribute(
_('Partition'), _('Partition to encrypt'),
'cryptsetupPartition', FALSE
),
new StringAttribute(
_('Password'), _('Password to use for encryption. Leave empty to use a encryption key file instead.'),
'cryptsetupPassword', FALSE
),
new BooleanAttribute (
_('Resize'), _('Resize existing partition'),
'resize', FALSE
......@@ -311,11 +319,7 @@ class faiPartition extends simplePlugin
_('Filesystem'), _('The filesystem this partition should be formatted with'),
'FAIfsType', TRUE,
array('swap','ext2','ext3','ext4','reiserfs','xfs','btrfs','-'), 'ext4',
array(_('swap space'),_('ext2'),_('ext3'),_('ext4'),_('reiser fs'),_('xfs'),_('btrfs'),_('LVM/RAID'))
),
new BooleanAttribute (
_('Encrypted'), _('Wether or not this partition is encrypted'),
'encrypted', FALSE
array(_('swap'),_('ext2'),_('ext3'),_('ext4'),_('reiser fs'),_('xfs'),_('btrfs'),_('LVM/RAID'))
),
new FaiMountPointAttribute (
_('Mount point'), _('Mount point for this partition'),
......@@ -326,6 +330,11 @@ class faiPartition extends simplePlugin
'options' => array(
'name' => _('Options'),
'attrs' => array(
new StringAttribute (
_('Mount options'), _('Filesystem mount options'),
'FAImountOptions', FALSE,
'defaults'
),
new StringAttribute (
_('Create options'), _('Filesystem create options'),
'FAIfsCreateOptions', FALSE
......@@ -334,10 +343,6 @@ class faiPartition extends simplePlugin
_('Tune options'), _('Filesystem tune options'),
'FAIfsTuneOptions', FALSE
),
new StringAttribute (
_('Mount options'), _('Filesystem mount options'),
'FAIfsOptions', FALSE
),
)
)
);
......@@ -382,6 +387,12 @@ class faiPartition extends simplePlugin
'raid5' => _('RAID 5'),
'raid6' => _('RAID 6')
);
} elseif ($this->FAIdiskType == 'cryptsetup') {
$types = array(
'luks' => _('LUKS'),
'swap' => _('Swap'),
'tmp' => _('tmp'),
);
} else {
$types = array();
}
......@@ -396,25 +407,44 @@ class faiPartition extends simplePlugin
if ($type == 'raid') {
$object['raidDevices'] = $object['FAIpartitionSize'];
unset($object['FAIpartitionSize']);
} elseif ($type == 'cryptsetup') {
$object['cryptsetupPartition'] = $object['FAIpartitionSize'];
unset($object['FAIpartitionSize']);
if (preg_match('/^luks:"(.+)"$/', $object['FAIpartitionType'], $m)) {
$object['FAIpartitionType'] = 'luks';
$object['cryptsetupPassword'] = $m[1];
}
}
foreach ($this->attributes as $attr) {
if (isset($object[$attr])) {
$this->$attr = $object[$attr];
}
}
if (($this->FAIdiskType == 'disk') || ($this->FAIdiskType == 'lvm')) {
/* Check for encrypted partitions */
if (preg_match('/:encrypt$/', $this->FAImountPoint)) {
$this->FAImountPoint = preg_replace('/:encrypt/', '', $this->FAImountPoint);
$this->encrypted = TRUE;
}
}
}
if ($this->FAIdiskType != 'lvm') {
$this->attributesAccess['cn']->setDisabled(TRUE);
}
if ($this->FAIdiskType == 'cryptsetup') {
$this->attributesAccess['cryptsetupPartition']->setChoices($this->getPartitionList());
$this->attributesAccess['cryptsetupPartition']->setRequired(TRUE);
$this->attributesAccess['FAIpartitionSize']->setDisabled(TRUE);
$this->attributesAccess['FAIpartitionSize']->setVisible(FALSE);
$this->attributesInfo['flags']['name'] = _('Encryption settings');
$this->attributesAccess['resize']->setDisabled(TRUE);
$this->attributesAccess['resize']->setVisible(FALSE);
$this->attributesAccess['preserve']->setDisabled(TRUE);
$this->attributesAccess['preserve']->setVisible(FALSE);
$this->attributesAccess['bootable']->setDisabled(TRUE);
$this->attributesAccess['bootable']->setVisible(FALSE);
} else {
$this->attributesAccess['cryptsetupPartition']->setDisabled(TRUE);
$this->attributesAccess['cryptsetupPartition']->setVisible(FALSE);
$this->attributesAccess['cryptsetupPassword']->setDisabled(TRUE);
$this->attributesAccess['cryptsetupPassword']->setVisible(FALSE);
}
if ($this->FAIdiskType == 'raid') {
$this->attributesAccess['raidDevices']->attributes[0]->attribute->attributes[0]->setChoices($this->getPartitionList());
$this->attributesAccess['FAIpartitionSize']->setDisabled(TRUE);
......@@ -490,14 +520,16 @@ class faiPartition extends simplePlugin
$ret[$attr] = $this->$attr;
}
if (($this->FAIdiskType == 'disk') || ($this->FAIdiskType == 'lvm')) {
/* Add encryption flag to partition mount point */
if ($this->encrypted) {
$ret['FAImountPoint'] .= ':encrypt';
}
} elseif ($this->FAIdiskType == 'raid') {
if ($this->FAIdiskType == 'raid') {
$ret['FAIpartitionSize'] = $ret['raidDevices'];
unset($ret['raidDevices']);
} elseif ($this->FAIdiskType == 'cryptsetup') {
$ret['FAIpartitionSize'] = $ret['cryptsetupPartition'];
unset($ret['cryptsetupPartition']);
if (!empty($ret['cryptsetupPassword'])) {
$ret['FAIpartitionType'] .= ':"'.$ret['cryptsetupPassword'].'"';
}
unset($ret['cryptsetupPassword']);
}
return $ret;
......@@ -530,10 +562,7 @@ class faiPartition extends simplePlugin
// Collect all available disks
if ($disk['FAIdiskType'] == 'disk') {
$name = $part['cn'];
if (!isset($this->raidDevices[$name])) {
$may[] = $name;
}
$may[] = $part['cn'];
}
}
}
......
......@@ -80,10 +80,11 @@ class PartitionTableAttribute extends DialogOrderedArrayAttribute
protected $dialogClass = 'DiskEntryDialog';
protected $partitionAttributes = array(
'cn','description',
'FAIpartitionNr', 'FAIpartitionSize', 'FAImountPoint',
'FAIfsType', 'FAIpartitionType', 'FAImountOptions',
'FAIfsOptions', 'FAIpartitionFlags', 'FAIfsCreateOptions',
'FAIfsTuneOptions', 'FAIfsOptions', 'FAIpartitionFlags',
'FAIpartitionNr', 'FAIpartitionSize',
'FAIpartitionType', 'FAIpartitionFlags',
'FAImountPoint', 'FAImountOptions',
'FAIfsType',
'FAIfsCreateOptions', 'FAIfsTuneOptions',
'FAIlvmDevice'
);
......@@ -101,19 +102,37 @@ class PartitionTableAttribute extends DialogOrderedArrayAttribute
function renderButtons ()
{
$id = $this->getHtmlId();
return $this->renderInputField(
$buttons = $this->renderInputField(
'submit',
'add'.$id.'_dialog',
array('value' => '{msgPool type=addButton}')
).$this->renderInputField(
'submit',
'add'.$id.'_dialog_raid',
array('value' => _('Add RAID'))
).$this->renderInputField(
'submit',
'add'.$id.'_dialog_lvm',
array('value' => _('Add LVM'))
array('value' => _('Add disk'))
);
if (!isset($this->value['raid'])) {
$buttons .= $this->renderInputField(
'submit',
'add'.$id.'_dialog_raid',
array('value' => _('Add RAID'))
);
}
if (!isset($this->value['lvm'])) {
$buttons .= $this->renderInputField(
'submit',
'add'.$id.'_dialog_lvm',
array('value' => _('Add LVM'))
);
}
if (!isset($this->value['cryptsetup'])) {
$buttons .= $this->renderInputField(
'submit',
'add'.$id.'_dialog_cryptsetup',
array('value' => _('Add cryptsetup'))
);
}
return $buttons;
}
function loadPostValue ()
......@@ -128,6 +147,8 @@ class PartitionTableAttribute extends DialogOrderedArrayAttribute
$this->plugin->openDialog(new $this->dialogClass($this->plugin, $this, array(), 'raid'));
} elseif (isset($_POST['add'.$id.'_dialog_lvm'])) {
$this->plugin->openDialog(new $this->dialogClass($this->plugin, $this, array(), 'lvm'));
} elseif (isset($_POST['add'.$id.'_dialog_cryptsetup'])) {
$this->plugin->openDialog(new $this->dialogClass($this->plugin, $this, array(), 'cryptsetup'));
}
}
}
......@@ -151,6 +172,9 @@ class PartitionTableAttribute extends DialogOrderedArrayAttribute
$diskInfos[$attr] = $subattrs[$attr][0];
}
}
if ($diskInfos['FAIdiskType'] != 'disk') {
$diskInfos['cn'] = $diskInfos['FAIdiskType'];
}
// Get disk options, without 'count' index.
$diskInfos['FAIdiskOption'] = array();
......@@ -169,8 +193,8 @@ class PartitionTableAttribute extends DialogOrderedArrayAttribute
}
$diskInfos['dn'] = $subattrs['dn'];
$this->value[$diskInfos['dn']] = $diskInfos;
$this->value[$diskInfos['dn']]['partitions'] = array();
$this->value[$diskInfos['cn']] = $diskInfos;
$this->value[$diskInfos['cn']]['partitions'] = array();
}
/* Fetch partitions */
foreach ($this->value as $name => $disk) {
......@@ -270,8 +294,6 @@ class PartitionTableAttribute extends DialogOrderedArrayAttribute
function diskConfigured ($disk)
{
if (isset($disk['rename'])) {
unset($this->value[$disk['rename']['from']]);
$disk['cn'] = $disk['rename']['to'];
unset($disk['rename']);
}
......
......@@ -313,21 +313,21 @@ attributetype ( 1.3.6.1.4.1.10098.1.1.5.30 NAME 'FAIpartitionMethod'
# Name : FAIdiskOption
# Description: Store new disk options like preserve_always, etc.
attributetype ( 1.3.6.1.4.1.10098.1.1.5.31 NAME 'FAIdiskOption'
DESC 'Options for the disk creation'
DESC 'Options for the disk like preserve_always, etc.'
EQUALITY caseIgnoreIA5Match
SUBSTR caseIgnoreIA5SubstringsMatch
SYNTAX 1.3.6.1.4.1.1466.115.121.1.26)
# Name : FAIdiskType
# Description: Differenciate between lvm, raid and disk
# Description: Differenciate between lvm, raid, cryptsetup and disk
attributetype ( 1.3.6.1.4.1.10098.1.1.5.32 NAME 'FAIdiskType'
DESC 'Options for the disk creation'
DESC 'disk_config type. May be lvm, raid, cryptsetup or disk.'
SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 SINGLE-VALUE)
# Name : FAIlvmDevice
# Description: For lvm disk definitions, store the physical devices
attributetype ( 1.3.6.1.4.1.10098.1.1.5.33 NAME 'FAIlvmDevice'
DESC 'Options for the disk creation'
DESC 'For lvm disk definitions, store the physical devices'
EQUALITY caseIgnoreIA5Match
SUBSTR caseIgnoreIA5SubstringsMatch
SYNTAX 1.3.6.1.4.1.1466.115.121.1.26)
......@@ -335,13 +335,13 @@ attributetype ( 1.3.6.1.4.1.10098.1.1.5.33 NAME 'FAIlvmDevice'
# Name : FAIfsCreateOptions
# Description: New option field to pass FS creation options
attributetype ( 1.3.6.1.4.1.10098.1.1.5.34 NAME 'FAIfsCreateOptions'
DESC 'Options for the disk creation'
DESC 'Option field to pass FS creation options'
SYNTAX 1.3.6.1.4.1.1466.115.121.1.26)
# Name : FAIfsTuneOptions
# Description: New option field to pass FS tuning options
attributetype ( 1.3.6.1.4.1.10098.1.1.5.35 NAME 'FAIfsTuneOptions'
DESC 'Options for the disk creation'
DESC 'Option field to pass FS tuning options'
SYNTAX 1.3.6.1.4.1.1466.115.121.1.26)
##
......
Markdown is supported
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