Okay, this is a common challenge with embedded devices that primarily offer a web interface for configuration. The goal is to find the underlying mechanism the Web-Based Management (WBM) uses.
Disclaimer:
Modifying system files directly can be risky if you don't know exactly what you're doing. Always back up configurations if possible. Test thoroughly on a non-production device first. The exact files and commands might differ based on the specific firmware version of your Wago CC100.
Here's a general approach and specific things to investigate:
Phase 1: Investigation (The "Reverse Engineering" Part)
You'll need SSH access to the Wago CC100. You'll likely need root privileges for most of these operations (sudo -i or logging in as root if allowed).
-
Connect via SSH:
ssh your_user@wago_cc100_ip
-
Baseline Snapshot (Before WBM Change):
- Docker:
- NTP:
- Identify the NTP client. Common ones:
systemd-timesyncd: systemctl status systemd-timesyncd
chrony: systemctl status chronyd (or chronyc sources)
ntp (ntpd): systemctl status ntp (or ntpq -p)
- Check its status and configuration file. Common locations:
systemd-timesyncd: /etc/systemd/timesyncd.conf
chrony: /etc/chrony/chrony.conf or /etc/chrony.conf
ntp: /etc/ntp.conf
- Again, Wago might have custom paths.
- Copy the config:
cp /path/to/ntp_config /path/to/ntp_config.before
-
Make the Change via WBM:
- Go to your Wago CC100's WBM.
- Enable Docker. Apply/Save.
- Wait for it to take effect.
-
Post-Change Analysis (Docker):
- SSH back in.
- Check Docker service status again. Is it active and enabled?
systemctl is-active docker
systemctl is-enabled docker
- Compare the Docker configuration files (if they existed) with your
.before copies:
diff /path/to/docker_config.before /path/to/docker_config
- Look for newly created Docker configuration files.
- Crucially, find recently modified files:
find /etc -mmin -5 -ls # Files in /etc modified in the last 5 minutes
find /usr/local/etc -mmin -5 -ls # Or other potential Wago config dirs
find /opt -mmin -5 -ls
This will show you what files the WBM likely touched.
- Check system logs for clues:
journalctl -u docker -n 50 --no-pager # Last 50 log entries for docker unit
dmesg | tail -n 50
-
Repeat for NTP:
- Disable Docker (if you want a clean slate for NTP investigation, or just proceed).
- Enable NTP via WBM. Apply/Save.
- SSH back in.
- Check NTP service status (e.g.,
systemctl is-active systemd-timesyncd).
- Compare NTP config files with
.before copies.
- Use
find /etc -mmin -5 -ls etc., to see what changed.
- Check logs related to the NTP service (e.g.,
journalctl -u systemd-timesyncd).
Phase 2: Hypothesizing and Testing
Based on your findings:
-
Docker:
- Common scenario: The WBM might simply run
systemctl enable docker and systemctl start docker.
- It might also create or modify
/etc/docker/daemon.json. For example, to enable Docker, it might ensure the file exists, even if empty {}.
- Script action:
- Ensure
/etc/docker/daemon.json exists and has the correct content (if any specific content is set by WBM).
# Example: Ensure daemon.json exists (can be empty if no specific opts)
sudo mkdir -p /etc/docker
sudo touch /etc/docker/daemon.json
# Or if specific content is needed:
# echo '{"some-key": "some-value"}' | sudo tee /etc/docker/daemon.json
- Enable and start the service:
sudo systemctl enable docker
sudo systemctl start docker
# Or to do both and wait:
# sudo systemctl enable --now docker
-
NTP:
- If
systemd-timesyncd:
- If
chrony:
- The WBM modifies
/etc/chrony/chrony.conf (e.g., adding server your_ntp_server_ip iburst).
- Then:
sudo systemctl enable chronyd && sudo systemctl start chronyd.
- Similar to , edit the config and restart/enable the service.
Wago-Specific Configuration Tools:
Some embedded systems have their own command-line configuration utilities that the WBM calls.
This is speculative, but worth looking for.
Phase 3: Scripting
Once you've identified the commands and file modifications:
#!/bin/bash
# --- Configuration ---
WAGO_HOST="your_wago_cc100_ip"
WAGO_USER="your_ssh_user"
# For password-less SSH, ensure your public key is in ~/.ssh/authorized_keys on the Wago
# Otherwise, you might need sshpass (not recommended for production) or expect.
# --- Helper Function for Remote Commands ---
run_remote() {
echo "Executing on $WAGO_HOST: $@"
ssh "$WAGO_USER@$WAGO_HOST" "sudo $@"
# Add error checking here if needed
if [ $? -ne 0 ]; then
echo "ERROR: Command failed: $@" >&2
# exit 1 # Or handle error differently
fi
}
# --- Enable Docker ---
enable_docker() {
echo "--- Enabling Docker ---"
# 1. Check if already enabled/active (optional, for idempotency)
# if ssh "$WAGO_USER@$WAGO_HOST" "systemctl is-active docker && systemctl is-enabled docker"; then
# echo "Docker already active and enabled."
# return 0
# fi
# Based on your investigation, this might be:
# Example: Create/ensure daemon.json if needed (often not needed just to enable)
# run_remote "mkdir -p /etc/docker && touch /etc/docker/daemon.json"
# Example: Enable and start Docker service
run_remote "systemctl enable docker"
run_remote "systemctl start docker"
# Or combined: run_remote "systemctl enable --now docker"
# Add a small delay and check status
sleep 5
if ssh "$WAGO_USER@$WAGO_HOST" "systemctl is-active docker"; then
echo "Docker enabled and active successfully."
else
echo "ERROR: Docker failed to start."
# ssh "$WAGO_USER@$WAGO_HOST" "journalctl -u docker -n 20 --no-pager" # Show logs
fi
echo ""
}
# --- Enable NTP ---
enable_ntp() {
echo "--- Enabling NTP ---"
# Assuming systemd-timesyncd. Adjust if it's chrony or ntpd.
# 1. Configure NTP servers in /etc/systemd/timesyncd.conf
# This is a simplistic way to ensure the NTP line is present and uncommented.
# A more robust method would use sed or awk to modify specific lines.
# IMPORTANT: This example overwrites the [Time] section. Be careful.
# Better: use sed to uncomment/replace existing NTP= line
# run_remote "sed -i -E 's/^#?(NTP=).*/NTP=0.pool.ntp.org 1.pool.ntp.org 2.pool.ntp.org/' /etc/systemd/timesyncd.conf"
# run_remote "sed -i -E 's/^#?(FallbackNTP=).*/FallbackNTP=time.cloudflare.com/' /etc/systemd/timesyncd.conf"
# If the file or section doesn't exist, these sed commands might not work as expected.
# A safer approach might be to tee a known-good configuration snippet:
NTP_CONFIG_SNIPPET="[Time]\nNTP=0.pool.ntp.org 1.pool.ntp.org\nFallbackNTP=time.cloudflare.com"
run_remote "bash -c \"echo -e '${NTP_CONFIG_SNIPPET}' > /etc/systemd/timesyncd.conf.new && mv /etc/systemd/timesyncd.conf.new /etc/systemd/timesyncd.conf\""
# 2. Enable and restart systemd-timesyncd
run_remote "systemctl enable systemd-timesyncd"
run_remote "systemctl restart systemd-timesyncd"
# Alternative for systemd-timesyncd:
# run_remote "timedatectl set-ntp true" # This often handles config and restart
# Add a small delay and check status
sleep 5
if ssh "$WAGO_USER@$WAGO_HOST" "systemctl is-active systemd-timesyncd && timedatectl status | grep 'NTP service: active'"; then
echo "NTP (systemd-timesyncd) enabled and active successfully."
ssh "$WAGO_USER@$WAGO_HOST" "timedatectl status" # Show status
else
echo "ERROR: NTP (systemd-timesyncd) failed to start or sync."
# ssh "$WAGO_USER@$WAGO_HOST" "journalctl -u systemd-timesyncd -n 20 --no-pager" # Show logs
fi
echo ""
}
# --- Deploy Docker Images/Containers ---
deploy_containers() {
echo "--- Deploying Docker Containers ---"
# Ensure Docker is running before proceeding
if ! ssh "$WAGO_USER@$WAGO_HOST" "systemctl is-active docker"; then
echo "ERROR: Docker is not active. Cannot deploy containers."
return 1
fi
# Example: Pull an image
run_remote "docker pull alpine:latest"
# Example: Run a container
# Make sure container names are unique or use --rm
run_remote "docker run -d --name my_alpine_container alpine:latest sleep infinity"
# Example: Copy a docker-compose.yml file and run it
# scp my-docker-compose.yml "$WAGO_USER@$WAGO_HOST:/opt/myapp/docker-compose.yml"
# run_remote "mkdir -p /opt/myapp"
# run_remote "docker-compose -f /opt/myapp/docker-compose.yml up -d"
echo "Container deployment tasks initiated."
# Add checks to see if containers are running
sleep 5
run_remote "docker ps"
echo ""
}
# --- Main Execution ---
echo "Starting Wago CC100 Configuration..."
enable_docker
enable_ntp
# Optional: Wait for NTP to sync if critical, though services usually start fine without perfect time immediately
# echo "Waiting a bit for NTP to potentially sync..."
# sleep 30 # Adjust as needed
deploy_containers
echo "Wago CC100 configuration script finished."
Key things for the script:
Start with the investigation phase. It's the most important. Good luck!