Skip to main content

Module utils

Module utils 

Source
Expand description

Utility functions for formatting and path management.

This module provides helper functions for common operations like formatting byte rates, durations, and managing configuration directories.

Structs§

ProfileMetadata
Profile metadata for persistence

Functions§

cleanup_openvpn_run_files
Cleans up OpenVPN runtime files (pid, log) for a given profile.
create_user_dir
Create a directory (and parents) owned by the real user.
delete_openvpn_auth_file
Deletes the saved OpenVPN auth credentials file for a profile.
delete_openvpn_scrv1_auth_file
Delete the static-challenge SCRV1 auth file for a profile if present.
format_bytes_speed
Formats bytes per second into a human-readable string.
format_local_time
Returns the current local time formatted as HH:MM:SS.
format_relative_time
Formats a SystemTime into a compact relative time string (e.g., 1s, 2m, 3h, 4d).
format_system_time_local
Converts any SystemTime into a local HH:MM:SS string.
get_app_config_dir
Returns the application configuration directory path.
get_openvpn_auth_path
Returns the path for an OpenVPN auth credentials file.
get_openvpn_run_paths
Returns (pid_path, log_path) for the given profile name.
get_openvpn_scrv1_auth_path
Path of the transient SCRV1 envelope auth file used for static-challenge connects (plan 2026-06-02-001 U3 / PF-2, #191).
get_profiles_dir
Returns the VPN profiles directory path.
get_tmp_config_dir
Returns the per-session temp config directory ${config_dir}/tmp/${session_id}/.
get_unique_path
Returns a unique path by appending (n) if the file already exists.
home_dir
Returns the user’s home directory.
is_private_ip
Checks if an IP address belongs to a private network range (RFC1918).
is_root
Check if the current process is running as root (UID 0)
load_profile_metadata
Load profile metadata from disk
openvpn_config_needs_auth
Checks whether an OpenVPN config file contains auth-user-pass without a file argument.
read_openvpn_pid
Reads the PID from an OpenVPN pid file.
read_openvpn_saved_auth
Reads saved OpenVPN credentials from the auth file.
read_openvpn_static_challenge_prompt
Read a .ovpn config and return the static-challenge prompt text if the directive is present.
sanitize_profile_name
Returns the OpenVPN runtime directory path for a given profile.
save_profile_metadata
Save profile metadata to disk
scrub_stale_scrv1_auth_files
Scan the OpenVPN auth directory and delete any leftover transient <safe>.scrv1.auth credentials bundle (plan 2026-06-02-001 U6, #191).
truncate
Truncates a string to a maximum number of characters.
write_openvpn_auth_file
Write the canonical <safe>.auth credentials file: line 1 username, line 2 password, both in plain text.
write_openvpn_scrv1_auth_file
Write a transient 3-line credentials bundle for the OpenVPN management-socket auth flow (plan 2026-06-02-001, #191, Approach B-minimal). The protocol layer reads this file, drives the --management socket dance with the embedded user/pass/otp, then deletes the file. Each line is <value> followed by \n:
write_user_file
Write a file owned by the real user.