Commit 5b1713b7 authored by Côme Chilliet's avatar Côme Chilliet

feat(fai) Add support for cryptsetup configuration

issue #5821
parent 7223f3ac
......@@ -119,7 +119,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 +133,12 @@ class DiskPartitionsAttribute extends DialogOrderedArrayAttribute
$list[preg_replace('/:.*$/', '', $partname)][] = $disk;
}
}
} elseif ($disk['FAIdiskType'] == 'cryptsetup') {
foreach ($disk['partitions'] as $part) {
foreach (explode(',', $part['FAIpartitionSize']) as $partname) {
$list[preg_replace('/:.*$/', '', $partname)][] = $disk;
}
}
}
}
......@@ -187,6 +193,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;
......@@ -290,6 +299,10 @@ class faiDiskEntry extends simplePlugin
$this->attributesAccess['disklabel']->setDisabled(TRUE);
$this->attributesAccess['disklabel']->setVisible(FALSE);
}
if ($this->FAIdiskType == 'cryptsetup') {
$this->attributesAccess['fstabkey']->setDisabled(TRUE);
$this->attributesAccess['fstabkey']->setVisible(FALSE);
}
if ($disk) {
$this->is_edit = TRUE;
......@@ -423,6 +436,8 @@ class faiDiskEntry extends simplePlugin
/* Assemble flags */
if ($this->FAIdiskType == 'disk') {
$tmp['FAIdiskOption'] = array('fstabkey:'.$this->fstabkey, 'disklabel:'.$this->disklabel);
} elseif ($this->FAIdiskType == 'cryptsetup') {
$tmp['FAIdiskOption'] = array();
} else {
$tmp['FAIdiskOption'] = array('fstabkey:'.$this->fstabkey);
}
......@@ -463,7 +478,7 @@ class faiDiskEntry extends simplePlugin
}
}
/* Assembe disk flags */
/* Assemble disk flags */
if (!empty($bootable)) {
$tmp['FAIdiskOption'][] = 'bootable:'.trim($bootable, ',');
}
......@@ -501,14 +516,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);
}
}
} elseif ($disk['FAIdiskType'] == 'disk') {
// Collect all available disks
if ($disk['FAIdiskType'] == 'disk') {
$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,7 +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'))
array(_('swap'),_('ext2'),_('ext3'),_('ext4'),_('reiser fs'),_('xfs'),_('btrfs'),_('LVM/RAID'))
),
new BooleanAttribute (
_('Encrypted'), _('Wether or not this partition is encrypted'),
......@@ -382,6 +390,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,6 +410,13 @@ 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])) {
......@@ -415,6 +436,25 @@ class faiPartition extends simplePlugin
if ($this->FAIdiskType != 'lvm') {
$this->attributesAccess['cn']->setDisabled(TRUE);
}
if ($this->FAIdiskType == 'cryptsetup') {
$this->attributesAccess['cryptsetupPartition']->setChoices($this->getPartitionList());
$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);
......@@ -498,6 +538,13 @@ class faiPartition extends simplePlugin
} elseif ($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 +577,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'];
}
}
}
......
......@@ -113,6 +113,10 @@ class PartitionTableAttribute extends DialogOrderedArrayAttribute
'submit',
'add'.$id.'_dialog_lvm',
array('value' => _('Add LVM'))
).$this->renderInputField(
'submit',
'add'.$id.'_dialog_cryptsetup',
array('value' => _('Add cryptsetup'))
);
}
......@@ -128,6 +132,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'));
}
}
}
......
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