Skip to content

Commit

Permalink
feat(api): add option to select the used network interface
Browse files Browse the repository at this point in the history
fixes #117
  • Loading branch information
MauriceNino committed Jun 15, 2022
1 parent d4b1f69 commit 8b6a78d
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/CONFIGURATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ in the [INSTALL.md](./INSTALL.md).

| Variable | Description | Type | Default Value |
| ---------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------ | ------------------------------------------ |
| `DASHDOT_USE_NETWORK_INTERFACE` | If dashdot detects the wrong gateway as your default interface, you can provide a name here that is used instead | string | |
| `DASHDOT_SPEED_TEST_INTERVAL` | At which interval the network speed-test should be rerun (in minutes) | number | `60` |
| `DASHDOT_NETWORK_LABEL_LIST` | Change the order of the labels in the list, to change the position in the widget, or remove an item from the list, to remove it from the widget (The available options are: `type`, `speed_up`, `speed_down`, `interface_speed`, `public_ip`) | string | `type,speed_up,speed_down,interface_speed` |
| `DASHDOT_NETWORK_WIDGET_GROW` | To adjust the relative size of the Network widget | number | `6` |
Expand Down
1 change: 1 addition & 0 deletions apps/api/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export const CONFIG: Config = {
ram_shown_datapoints: numNull(penv('RAM_SHOWN_DATAPOINTS')) ?? 20,
ram_poll_interval: numNull(penv('RAM_POLL_INTERVAL')) ?? 1000,

use_network_interface: penv('USE_NETWORK_INTERFACE') ?? '',
speed_test_interval: numNull(penv('SPEED_TEST_INTERVAL')) ?? 60,
network_label_list: lst(
penv('NETWORK_LABEL_LIST') ?? 'type,speed_up,speed_down,interface_speed'
Expand Down
18 changes: 18 additions & 0 deletions apps/api/src/setup-networking.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { exec as exaca } from 'child_process';
import * as fs from 'fs';
import { promisify } from 'util';
import { CONFIG } from './config';

const exec = promisify(exaca);

Expand All @@ -18,6 +19,23 @@ export const setupNetworking = async () => {
}

try {
if (CONFIG.use_network_interface !== '') {
if (
fs.existsSync(
`/internal_mnt/host_sys/class/net/${CONFIG.use_network_interface}`
)
) {
NET_INTERFACE = CONFIG.use_network_interface;
console.log(`Using network interface from config "${NET_INTERFACE}"`);

return;
} else {
console.warn(
`Network interface "${CONFIG.use_network_interface}" not found, using first available interface`
);
}
}

const { stdout } = await exec(
"nsenter --net=/mnt/host_ns_net route | grep default | awk '{print $8}'"
);
Expand Down
1 change: 1 addition & 0 deletions libs/common/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ export type Config = {
ram_poll_interval: number;

// Network Widget
use_network_interface: string;
speed_test_interval: number;
network_label_list: (
| 'type'
Expand Down

0 comments on commit 8b6a78d

Please sign in to comment.