Skip to content

Commit

Permalink
WIP - redesign
Browse files Browse the repository at this point in the history
  • Loading branch information
mvollmer committed Oct 19, 2023
1 parent f7c7193 commit ca6006e
Show file tree
Hide file tree
Showing 65 changed files with 6,602 additions and 1,316 deletions.
74 changes: 74 additions & 0 deletions pkg/storaged/actions.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* This file is part of Cockpit.
*
* Copyright (C) 2023 Red Hat, Inc.
*
* Cockpit is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* Cockpit is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Cockpit; If not, see <http://www.gnu.org/licenses/>.
*/

import cockpit from "cockpit";
import client from "./client";

import { get_existing_passphrase, unlock_with_type } from "./crypto-keyslots.jsx"; // XXX
import { set_crypto_auto_option } from "./utils.js";
import { dialog_open, PassInput } from "./dialog.jsx";

const _ = cockpit.gettext;

export function unlock(block) {
const crypto = client.blocks_crypto[block.path];
if (!crypto)
return;

function unlock_with_passphrase() {
const crypto = client.blocks_crypto[block.path];
if (!crypto)
return;

dialog_open({
Title: _("Unlock"),
Fields: [
PassInput("passphrase", _("Passphrase"), {})
],
Action: {
Title: _("Unlock"),
action: function (vals) {
return (crypto.Unlock(vals.passphrase, {})
.then(() => set_crypto_auto_option(block, true)));
}
}
});
}

return get_existing_passphrase(block, true).then(type => {
return (unlock_with_type(client, block, null, type)
.then(() => set_crypto_auto_option(block, true))
.catch(() => unlock_with_passphrase()));
});
}

export function lock(block) {
const crypto = client.blocks_crypto[block.path];
if (!crypto)
return;

return crypto.Lock({}).then(() => set_crypto_auto_option(block, false));
}

export function std_lock_action(backing_block, content_block) {
if (backing_block == content_block)
return null;

return { title: _("Lock"), action: () => lock(backing_block) };
}
42 changes: 34 additions & 8 deletions pkg/storaged/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ import vdo_monitor_py from "./vdo-monitor.py";
import stratis2_set_key_py from "./stratis2-set-key.py";
import stratis3_set_key_py from "./stratis3-set-key.py";

import { create_pages } from "./create-pages.jsx";

/* STORAGED CLIENT
*/

Expand Down Expand Up @@ -544,6 +546,25 @@ function update_indices() {
client.blocks_partitions[path].sort(function (a, b) { return a.Offset - b.Offset });
}

client.iscsi_sessions_drives = { };
client.drives_iscsi_session = { };
for (path in client.drives) {
const block = client.drives_block[path];
if (!block)
continue;
for (const session_path in client.iscsi_sessions) {
const session = client.iscsi_sessions[session_path];
for (i = 0; i < block.Symlinks.length; i++) {
if (utils.decode_filename(block.Symlinks[i]).includes(session.data.target_name)) {
client.drives_iscsi_session[path] = session;
if (!client.iscsi_sessions_drives[session_path])
client.iscsi_sessions_drives[session_path] = [];
client.iscsi_sessions_drives[session_path].push(client.drives[path]);
}
}
}
}

client.path_jobs = { };
function enter_job(job) {
if (!job.Objects || !job.Objects.length)
Expand All @@ -563,10 +584,15 @@ function update_indices() {
}
}

client.update = () => {
update_indices();
client.path_warnings = find_warnings(client);
client.dispatchEvent("changed");
client.update = (first_time) => {
if (first_time)
client.ready = true;
if (client.ready) {
update_indices();
client.path_warnings = find_warnings(client);
create_pages();
client.dispatchEvent("changed");
}
};

function init_model(callback) {
Expand Down Expand Up @@ -705,7 +731,7 @@ function init_model(callback) {

client.storaged_client.addEventListener('notify', () => client.update());

client.update();
client.update(true);
callback();
});
});
Expand Down Expand Up @@ -801,7 +827,7 @@ function nfs_mounts() {
if (lines.length >= 2) {
self.entries = JSON.parse(lines[lines.length - 2]);
self.fsys_sizes = { };
client.dispatchEvent('changed');
client.update();
}
})
.catch(function (error) {
Expand All @@ -824,11 +850,11 @@ function nfs_mounts() {
.then(function (output) {
const data = JSON.parse(output);
self.fsys_sizes[path] = [(data[2] - data[1]) * data[0], data[2] * data[0]];
client.dispatchEvent('changed');
client.update();
})
.catch(function () {
self.fsys_sizes[path] = [0, 0];
client.dispatchEvent('changed');
client.update();
});

return null;
Expand Down
Loading

0 comments on commit ca6006e

Please sign in to comment.