diff --git a/emhttp/plugins/dynamix/DiskSettings.page b/emhttp/plugins/dynamix/DiskSettings.page index 409e794e3..5bb7d4e6d 100644 --- a/emhttp/plugins/dynamix/DiskSettings.page +++ b/emhttp/plugins/dynamix/DiskSettings.page @@ -19,6 +19,11 @@ Tag="icon-disk" require_once "$docroot/webGui/include/Preselect.php"; $events = explode('|',$var['smEvents'] ?? $numbers); +$reply = '/var/tmp/luks.reply'; +$keyfile = is_file($var['luksKeyfile']); +$encrypt = false; +foreach ($disks as $disk) if (isset($disk['fsType']) && strncmp($disk['fsType'],'luks:',5)===0) $encrypt = true; + function displayTemp($temp) { global $display; return (is_numeric($temp) && _var($display,'unit')=='F') ? round(9/5*$temp)+32 : $temp; @@ -27,7 +32,11 @@ function displayTemp($temp) { +
_(Enable auto start)_: -: @@ -67,7 +131,7 @@ _(Enable auto start)_: :disk_enable_autostart_help: _(Default spin down delay)_: -: @@ -86,7 +150,7 @@ _(Default spin down delay)_: :disk_spindown_delay_help: _(Enable spinup groups)_: -: @@ -94,7 +158,7 @@ _(Enable spinup groups)_: :disk_spinup_groups_help: _(Default file system)_: -: @@ -118,7 +182,7 @@ _(Tunable (poll_attributes))_: :disk_tunable_poll_attributes_help: _(Tunable (enable NCQ))_: -: @@ -131,7 +195,7 @@ _(Tunable (nr_requests))_: :disk_tunable_nr_requests_help: _(Tunable (scheduler))_: -: @@ -157,7 +221,7 @@ _(Tunable (md_sync_limit))_: :disk_tunable_md_sync_limit_help: _(Tunable (md_write_method))_: -: @@ -189,6 +253,63 @@ _(Default critical disk temperature threshold)_ (°
+ +

+
+ + + + + + + + + +  +:   + + +_(Existing encryption key)_: +:
+ +
+_(Enter existing passphrase)_: +: _(show passphrase)_ + +
+ + +_(Change encryption key)_: +:
+ +
+_(Type new passphrase)_: +: _(show passphrase)_ + +_(Retype new passphrase)_: +: + +
+ +  +: +
+ +
_(Global SMART Settings)_
@@ -199,7 +320,7 @@ _(Default critical disk temperature threshold)_ (° _(Default SMART notification value)_: -: @@ -207,7 +328,7 @@ _(Default SMART notification value)_: :disk_default_smart_notification_help: _(Default SMART notification tolerance level)_: -: @@ -220,7 +341,7 @@ _(Default SMART notification tolerance level)_: :disk_default_smart_tolerance_help: _(Default SMART controller type)_: -: diff --git a/emhttp/plugins/dynamix/include/update.encryption.php b/emhttp/plugins/dynamix/include/update.encryption.php new file mode 100644 index 000000000..98461a676 --- /dev/null +++ b/emhttp/plugins/dynamix/include/update.encryption.php @@ -0,0 +1,111 @@ + + 1) exec("cryptsetup luksRemoveKey /dev/$disk $key 1>/dev/null 2>&1"); +} +function diskname($name) { + global $disks; + foreach ($disks as $disk) if (strncmp($name,$disk['device'],strlen(disk['device']))==0) return $disk['name']; + return $name; +} +function reply($text,$type) { + global $oldkey,$newkey,$delkey; + $reply = $_POST['#reply']; + if (realpath(dirname($reply))=='/var/tmp') file_put_contents($reply,$text."\0".$type); + delete_file($oldkey); + if ($_POST['newinput']=='text' || $delkey) delete_file($newkey); + die(); +} + +if (isset($_POST['oldinput'])) { + switch ($_POST['oldinput']) { + case 'text': + file_put_contents($oldkey,base64_decode($_POST['oldluks'])); + break; + case 'file': + file_put_contents($oldkey,base64_decode(explode(';base64,',$_POST['olddata'])[1])); + break; + } +} else { + if (is_file($newkey)) copy($newkey,$oldkey); +} + +if (is_file($oldkey)) { + $disk = $crypto[0]; // check first disk only (key is the same for all disks) + exec("cryptsetup luksOpen --test-passphrase --key-file $oldkey /dev/$disk 1>/dev/null 2>&1",$none,$error); +} else $error = 1; + +if ($error > 0) reply(_('Incorrect existing key'),'warning'); + +if (isset($_POST['newinput'])) { + switch ($_POST['newinput']) { + case 'text': + file_put_contents($newkey,base64_decode($_POST['newluks'])); + break; + case 'file': + file_put_contents($newkey,base64_decode(explode(';base64,',$_POST['newdata'])[1])); + break; + } + $good = $bad = []; + foreach ($crypto as $disk) { + exec("cryptsetup luksAddKey --key-file $oldkey /dev/$disk $newkey 1>/dev/null 2>&1",$none,$error); + if ($error==0) $good[] = $disk; else $bad[] = diskname($disk); + } + if (count($bad)==0) { + // all okay, remove the old key + foreach ($good as $disk) removeKey($oldkey,$disk); + reply(_('Key successfully changed'),'success'); + } else { + // something went wrong, restore key + foreach ($good as $disk) removeKey($newkey,$disk); + reply(_('Changing key failed for disks').': '.implode(' ',$bad),'error'); + } +} +reply(_('Missing new key'),'warning'); +?>