Commit Graph

139 Commits

Author SHA1 Message Date
7b9f66b0c8 Merge pull request 'fix: handle missing server_permissions table gracefully' (#57) from feat/dashboard-aggregated-chart into master
Reviewed-on: #57
2026-06-13 11:23:12 -04:00
bb1192c164 fix: handle missing server_permissions table gracefully
- Wrap ServerPermission queries in try-catch so show/edit don't 500
  when the migration hasn't been run yet
- Same protection for save calls in store/update (both web and API)
2026-06-13 10:55:14 -04:00
81c8626df5 Merge pull request 'feat: validate required SSH permissions before creating server' (#56) from feat/dashboard-aggregated-chart into master
Reviewed-on: #56
Reviewed-by: rafaga21 <rafaelminaya20@hotmail.com>
2026-06-13 10:44:21 -04:00
0cfed5bf27 feat: validate required SSH permissions before creating server
- New server_permissions table (migration 007) stores required SSH permissions per server
- PermissionValidator service connects via SSH and validates each permission before save
- ServerPermission model for CRUD on server_permissions table
- Web flow: create/edit forms include dynamic permission rows with quick-add presets
- API flow: serverAdd/serverUpdate accept permissions array, return 400 on failure
- Show view displays required permissions on server detail page
- Form input preserved on validation failure (credentials excluded)
- AGENTS.md updated with new conventions
2026-06-13 10:41:18 -04:00
c916ed175c Merge pull request 'feat: add aggregated resource usage chart to dashboard' (#55) from feat/dashboard-aggregated-chart into master
Reviewed-on: #55
2026-06-11 21:46:57 -04:00
8f3b5bd7ce feat: add aggregated resource usage chart to dashboard 2026-06-11 21:46:33 -04:00
957d4494b1 Merge pull request 'fix: remove bottom nav padding on server detail screen' (#54) from feat/push-monitoring-agent-v2 into master
Reviewed-on: #54
2026-06-11 21:33:04 -04:00
ae09af3e02 Bump app version to 1.7.2 (versionCode 11) and rebuild APK 2026-06-11 21:31:39 -04:00
c88b46ec80 fix: remove bottom nav padding on server detail screen
Scaffold's innerPadding reserved NavigationBar height even when the
bar was hidden (on detail screens). Content like the services list
had extra empty space at the bottom.

Fix: build custom PaddingValues that only includes bottom padding
when inLoggedInArea is true.
2026-06-11 21:26:34 -04:00
3f95b061d3 Merge pull request 'fix: 401 logout loop — sync state update, prevent re-navigation' (#53) from feat/push-monitoring-agent-v2 into master
Reviewed-on: #53
2026-06-11 21:13:27 -04:00
1885693f8d fix: 401 logout loop — sync state update, prevent re-navigation
Root cause: LoginViewModel.logout() was async (viewModelScope.launch),
so _uiState.isConnected remained true after navigating to login.
LoginScreen's LaunchedEffect immediately navigated back to dashboard,
where APIs failed with 401 again → infinite loop.

Fixes:
- SessionManager: add _invalidating flag to prevent concurrent 401 handling
- AuthInterceptor: check isSessionValid before invalidating
- LoginViewModel: update _uiState synchronously in logout(), clear token
  before launching coroutine for prefs.clear()
- LoginViewModel: call SessionManager.restoreSession() after successful login
- MainActivity: remove restoreSession() from logout handler (was incorrectly
  re-validating session right after invalidation)

Bump to v1.7.1 (versionCode 10)
2026-06-11 21:12:39 -04:00
3f80f2c484 Merge pull request 'feat: start agent immediately in background after user-mode install' (#52) from feat/push-monitoring-agent-v2 into master
Reviewed-on: #52
2026-06-11 20:56:19 -04:00
4bb383f127 feat: start agent immediately in background after user-mode install
After installing cron, the agent now starts right away via
nohup ... & disown instead of waiting for the next boot.
2026-06-11 20:55:15 -04:00
ab9e5d9cf3 Merge pull request 'fix: force LC_ALL=C for metric commands to avoid comma decimal separator' (#51) from feat/push-monitoring-agent-v2 into master
Reviewed-on: #51
2026-06-11 20:50:31 -04:00
552e30751d fix: force LC_ALL=C for metric commands to avoid comma decimal separator
Some locales use comma as decimal separator (e.g., es_DO.UTF-8).
This caused invalid JSON like "cpu": 2,4 instead of "cpu": 2.4.
Prefixed CPU and RAM commands with LC_ALL=C to force dot decimals.

Also removed debug logging from pushMetrics endpoint.
2026-06-11 20:49:14 -04:00
50f1574954 Merge pull request 'feat/push-monitoring-agent-v2' (#50) from feat/push-monitoring-agent-v2 into master
Reviewed-on: #50
2026-06-11 20:43:53 -04:00
2340fce8f8 fix: use warning level for push metrics log 2026-06-11 20:39:28 -04:00
ef23dd0b08 fix: add logging to pushMetrics endpoint for debugging 401 2026-06-11 20:39:14 -04:00
b90c600573 Merge pull request 'fix: unquote PAYLOAD heredoc so runtime vars are expanded' (#49) from feat/push-monitoring-agent-v2 into master
Reviewed-on: #49
2026-06-11 20:35:58 -04:00
ddf4d744c6 fix: unquote PAYLOAD heredoc so runtime vars are expanded
The inner PAYLOAD heredoc had a quoted delimiter ('PAYLOAD') which
prevented runtime variable expansion. Changed to unquoted (PAYLOAD)
so $AGENT_KEY, $CPU, etc. are correctly expanded at runtime.

The double-escaping works as:
  install time (outer EOF):  $AGENT_KEY  →   (in file)
  runtime (inner PAYLOAD):     →  abc123... (actual value)
2026-06-11 20:35:24 -04:00
1d99bff390 Merge pull request 'fix: escape runtime vars in unquoted heredoc, eliminate sed dependency' (#48) from feat/push-monitoring-agent-v2 into master
Reviewed-on: #48
2026-06-11 20:34:06 -04:00
a1e3723a97 fix: escape runtime vars in unquoted heredoc, eliminate sed dependency
The unquoted EOF heredoc expands all $ at install time. Runtime
variables inside functions (CPU, RAM, AGENT_KEY, etc.) must be
escaped with $ to prevent premature expansion.

Also removed the fragile sed replace step entirely — values are now
embedded directly when the heredoc is expanded.
2026-06-11 20:33:11 -04:00
2373e2b227 Merge pull request 'fix: use correct server URL instead of localhost' (#47) from feat/push-monitoring-agent-v2 into master
Reviewed-on: #47
2026-06-11 20:29:39 -04:00
26e35c6bc7 fix: use ['HTTP_HOST'] dynamically for agent URL 2026-06-11 20:28:35 -04:00
4d3a7e4d65 fix: use correct server URL instead of localhost
AgentService now replaces 'localhost' in the server URL with
sysadmin.lan before sending to the remote agent. Also added
URL/hostname debug output to the agent startup log.
2026-06-11 20:26:37 -04:00
db29f5b50b Merge pull request 'fix: remove set -e from agent, guard all commands with || true' (#46) from feat/push-monitoring-agent-v2 into master
Reviewed-on: #46
2026-06-11 20:22:21 -04:00
cc0a0c0644 fix: remove set -e from agent, guard all commands with || true
- Removed 'set -e' so a failing metric collection command doesn't kill
  the agent process
- Added '|| true' to every command in collect_metrics() to prevent
  pipeline failures
- Fixed push_metrics() to capture curl exit code with 'local code; code=$(...) || code=0'
- The agent now keeps running even if individual metrics or push fail
2026-06-11 20:21:24 -04:00
b5ebeb7ba6 Merge pull request 'fix: embed config directly in agent script, remove external config file' (#45) from feat/push-monitoring-agent-v2 into master
Reviewed-on: #45
2026-06-11 19:45:30 -04:00
b27e1392ca fix: embed config directly in agent script, remove external config file
The values SERVER_URL, AGENT_KEY, INTERVAL are now written directly
into the agent bash script using @placeholder@ substitution with sed.
No config file lookup needed — eliminates the 'not configured' error.

Config file directory (/etc/servermanager, ~/.config/servermanager)
is no longer created or referenced.
2026-06-11 19:44:30 -04:00
05cf026867 Merge pull request 'fix: agent config search order — 1st arg > /etc/ > ~/.config/' (#44) from feat/push-monitoring-agent-v2 into master
Reviewed-on: #44
2026-06-11 19:39:13 -04:00
93d5f24d0f fix: agent config search order — 1st arg > /etc/ > ~/.config/
The systemd service runs as root so /root is /root, but config is
written to /etc/servermanager/agent.conf. The agent now tries:
1. Path from command-line argument
2. /etc/servermanager/agent.conf (system mode)
3. $HOME/.config/servermanager/agent.conf (user mode)

Service ExecStart and cron job both pass the config path explicitly.
2026-06-11 19:38:10 -04:00
589524b1d0 Merge pull request 'feat: push-based monitoring with remote agent (v2)' (#43) from feat/push-monitoring-agent-v2 into master
Reviewed-on: #43
Reviewed-by: rafaga21 <rafaelminaya20@hotmail.com>
2026-06-11 19:34:41 -04:00
4ae9443016 Revert "fix: agent now searches both /etc/servermanager and ~/.config for config"
This reverts commit fe997750ff.
2026-06-11 19:33:29 -04:00
3a263a692f Merge pull request 'fix: agent now searches both /etc/servermanager and ~/.config for config' (#42) from feat/push-monitoring-agent into master
Reviewed-on: #42
2026-06-11 19:27:27 -04:00
fe997750ff fix: agent now searches both /etc/servermanager and ~/.config for config
The embedded agent binary checks /etc/servermanager/agent.conf first
(system mode), then falls back to ~/.config/servermanager/agent.conf
(user mode).
2026-06-11 19:24:25 -04:00
20e3a6926f Merge pull request 'fix: dual-mode installer — works with or without sudo' (#41) from feat/push-monitoring-agent into master
Reviewed-on: #41
2026-06-11 19:14:59 -04:00
fd3cc6825c fix: dual-mode installer — works with or without sudo
Installer now detects at runtime if it can get root access:
- Root/NOPASSWD sudo: installs to system directories with systemd
- No root: installs to ~/.local/bin with @reboot cron job

Self-elevation uses 'script -qc sudo bash' for requiretty, or falls
back to user mode without hanging on password prompts.

Uninstaller checks both system and user paths.
2026-06-11 19:12:57 -04:00
76180271ce Merge pull request 'feat: push-based monitoring with remote agent (self-elevating installer)' (#40) from feat/push-monitoring-agent into master
Reviewed-on: #40
Reviewed-by: rafaga21 <rafaelminaya20@hotmail.com>
2026-06-11 19:09:09 -04:00
0edc882f2e fix: installer self-elevates with script PTY instead of external sudo chain
- agent-install.sh and agent-uninstall.sh now detect if running as root
  at startup and re-execute via 'script -qc sudo bash' if needed
- AgentService commands simplified: just write to /tmp and run bash,
  the scripts handle privilege escalation internally
- Fixes exit code propagation: the script's exit code now correctly
  flows back through exec -> script -> sudo -> bash -> SSH
2026-06-11 19:07:14 -04:00
08ee59663b Merge pull request 'fix: use script command for PTY instead of modifying SSHService' (#39) from feat/push-monitoring-agent into master
Reviewed-on: #39
2026-06-11 19:02:34 -04:00
0ce24c4b8f fix: use script command for PTY instead of modifying SSHService
- Revert SSHService exec() back to original (remove PTY parameter)
- AgentService now writes installer to /tmp/ first, then runs via
  script -q -c to create a PTY for sudo (handles requiretty)
- Falls back to direct sudo bash if script is unavailable
- Cleans up temp files after execution
- Added mkdir -p for /usr/local/bin in installer
- Added file verification and byte-count after writing agent binary
2026-06-11 19:01:27 -04:00
00062e4d4a Merge pull request 'fix: allocate PTY for agent install to work with sudo requiretty' (#38) from feat/push-monitoring-agent into master
Reviewed-on: #38
2026-06-11 18:53:19 -04:00
63bf125420 fix: allocate PTY for agent install to work with sudo requiretty
The remote server has 'Defaults requiretty' in sudoers, which prevents
sudo from running without a TTY. Modified SSHService::exec() to accept
an optional  parameter that allocates a pseudo-terminal, and
extracts the exit status from output when PTY is used (since phpseclib
doesn't return exit status in PTY mode).
2026-06-11 18:52:40 -04:00
5f6788970f Merge pull request 'feat: push-based monitoring with remote agent' (#37) from feat/push-monitoring-agent into master
Reviewed-on: #37
Reviewed-by: rafaga21 <rafaelminaya20@hotmail.com>
2026-06-11 18:50:21 -04:00
f4c534c020 fix: always use sudo for agent install (remove fallback check)
The sudo -n check was incorrectly detecting that sudo required a
password, causing fallback to plain bash without root permissions.
Now we always run the installer via sudo bash, consistent with how
all other SSH commands work (systemctl, reboot, etc.).
2026-06-11 18:48:23 -04:00
28d2dfecce Merge pull request 'fix: add sudo fallback to agent installer + improve error output' (#36) from feat/push-monitoring-agent into master
Reviewed-on: #36
2026-06-11 18:46:13 -04:00
85bb70fe0f fix: add sudo fallback to agent installer + improve error output
- AgentService: try sudo -n first, fall back to bash without sudo
- AgentService: add sudo to uninstall command
- AgentService: trim error output to last 20 lines for readability
- View: show SSH output inline in error toast
- Fix undefined $path variable in success path
2026-06-11 18:45:14 -04:00
16044445d4 Merge pull request 'feat: push-based monitoring with remote agent' (#35) from feat/push-monitoring-agent into master
Reviewed-on: #35
2026-06-11 18:31:47 -04:00
bfa102cf97 feat: push-based monitoring with remote agent
- Add database migration 006 for agent_key, agent_installed, agent_install_path, agent_last_seen_at columns
- Add Server model methods: findByAgentKey, generateAgentKey, regenerateAgentKey, updateAgentLastSeen, setAgentInstalled
- Auto-generate agent_key on server creation
- Create AgentService for SSH-based install/uninstall of remote agent
- Create bin/agent.sh - bash agent script for remote servers
- Create install/agent-install.sh and install/agent-uninstall.sh
- Create install/servermanager-agent.service systemd unit
- Add POST /api/metrics/push endpoint (auth via agent_key)
- Add web routes for agent install/uninstall/regenerate-key
- Add agent status section to server detail view with install/uninstall modals
- Make MonitoringService::saveMetrics() public for reuse
2026-06-11 18:28:22 -04:00
fcd8565890 Merge pull request 'fix: filtrar servidores por usuario/equipo segun rol' (#34) from fix/server-access-filtering into master
Reviewed-on: #34
Reviewed-by: rafaga21 <rafaelminaya20@hotmail.com>
2026-06-11 17:27:23 -04:00