|
1 | 1 | /*
|
2 |
| - * This file is part of Cockpit. |
| 2 | + * This file is part of cockpit-aiscot |
3 | 3 | *
|
4 |
| - * Copyright (C) 2017 Red Hat, Inc. |
| 4 | + * Copyright Sensors & Signals LLC https://www.snstac.com/ |
5 | 5 | *
|
6 | 6 | * Cockpit is free software; you can redistribute it and/or modify it
|
7 | 7 | * under the terms of the GNU Lesser General Public License as published by
|
@@ -49,7 +49,6 @@ import { capitalize } from '@patternfly/react-core';
|
49 | 49 |
|
50 | 50 | const _ = cockpit.gettext;
|
51 | 51 |
|
52 |
| - |
53 | 52 | export const Application: React.FC = () => {
|
54 | 53 | // Configuration
|
55 | 54 | const SERVICE_NAME = 'aiscot'; // Change this to your service name
|
@@ -389,6 +388,38 @@ export const Application: React.FC = () => {
|
389 | 388 |
|
390 | 389 | const [formErrors, setFormErrors] = useState<Record<string, string>>({});
|
391 | 390 |
|
| 391 | + useEffect(() => { |
| 392 | + async function readConfigFileAndPopulateForm() { |
| 393 | + try { |
| 394 | + const content = await cockpit.file(CONFIG_FILE, { superuser: "try" }).read(); |
| 395 | + setConfigFileContents(content); |
| 396 | + |
| 397 | + // Parse config file lines |
| 398 | + const lines = content.split('\n'); |
| 399 | + const newForm: Record<string, string> = { ...envVarForm }; |
| 400 | + for (const line of lines) { |
| 401 | + // Ignore comments and empty lines |
| 402 | + const trimmed = line.trim(); |
| 403 | + if (!trimmed || trimmed.startsWith('#')) continue; |
| 404 | + const match = trimmed.match(/^([A-Za-z0-9_]+)=(.*)$/); |
| 405 | + if (match) { |
| 406 | + let [, key, value] = match; |
| 407 | + // Remove quotes if present |
| 408 | + value = value.replace(/^"(.*)"$/, '$1').replace(/^'(.*)'$/, '$1'); |
| 409 | + if (key in CONF_PARAMS) { |
| 410 | + newForm[key] = value; |
| 411 | + } |
| 412 | + } |
| 413 | + } |
| 414 | + setEnvVarForm(newForm); |
| 415 | + } catch (err) { |
| 416 | + // Ignore error, configFileContents already set by other effect |
| 417 | + } |
| 418 | + } |
| 419 | + readConfigFileAndPopulateForm(); |
| 420 | + // eslint-disable-next-line react-hooks/exhaustive-deps |
| 421 | + }, [configFileContents]); |
| 422 | + |
392 | 423 | // Validation helper
|
393 | 424 | function validateField(key: string, value: string): string {
|
394 | 425 | const def = CONF_PARAMS[key];
|
|
0 commit comments