How index-null/snaf works
Project Type and Purpose
• This is a single‐process, standalone Windows background utility written in Python.
• It periodically (via a scheduler) checks campus‐network connectivity, automatically re‐authenticates via the Portal when disconnected, logs activity, and sends email notifications.
• It is distributed as a PyInstaller‐bundled executable; there is no separate frontend.
File Structure Analysis
• Top level:
• config.ini – user‐editable settings (credentials, email, intervals, log level)
• requirements.txt – Python dependencies
• src/ – core Python modules
– main.py – orchestrator (entry point)
– network_utils.py – connectivity checks and login routines (requests to Portal)
– email_utils.py – SMTP client (smtplib) for notifications
– logger_config.py – log setup (logging module)
• Assets directory and logs/app.log (created at runtime)
• No web UI or database—state is ephemeral, stored in memory and logs.
Key Components
a. Config Manager
• Reads config.ini (configparser) at startup.
b. Scheduler
• schedule library triggers “check” jobs at configured interval.
c. Network Checker
• network_utils → HTTP GET/HEAD to external site (e.g., httpbin.org or school portal)
d. Portal Authenticator
• network_utils → POST credentials to campus portal (requests)
e. Logger
• logger_config → writes to console and logs/app.log (file sink)
f. Email Notifier
• email_utils → SMTP session to external mail server (smtp.qq.com)
g. External Services
• Campus Portal Server (authentication endpoint)
• SMTP Server (QQ or other)
• External Internet Endpoint (for connectivity check)
h. OS Network Stack
• Underlying Windows networking, ipconfig invoked for diagnostics
Relationships & Data Flows
• On launch, main.py loads Config → init Logger → start Scheduler
• Scheduler → every “interval”:
1. Scheduler invokes Network Checker
2. If connectivity OK and first run or state changed → log status → maybe send “first success” email
3. If connectivity DOWN → Portal Authenticator attempts login
• On success/failure → log outcome → Email Notifier (with ipconfig output if needed)
• All modules share the same process; they interact via function calls and share the Logger instance.
• Config Manager is read‐only after startup; changes require restart.
Architectural Patterns & Principles
• Single responsibility modules (SRP): scheduling, network I/O, email, logging, config
• Observer pattern (Scheduler triggers subscribers)
• Stateless reconnection logic (state in memory only)
• Dependency injection via config object passed into modules (e.g., credentials, SMTP settings)