# Termux Flask Development Setup Guide ## SMS Campaign Manager on Android ### Prerequisites - Termux installed on Android - Termux:API app installed (for Android API access) - SSH access configured (optional, for remote development) ### Initial Setup #### 1. Update Termux Packages ```bash pkg update && pkg upgrade ``` #### 2. Install Required System Packages ```bash # Install Python and development tools pkg install python python-pip # Install Node.js (if needed for npm packages) pkg install nodejs # Install which command (useful for debugging) pkg install which # Install Termux API package pkg install termux-api ``` ### Project Setup #### 1. Create Project Directory Structure ```bash mkdir -p ~/projects/sms-campaign-manager cd ~/projects/sms-campaign-manager ``` #### 2. Install Python Dependencies ```bash pip install flask werkzeug requests ``` #### 3. Create the Flask Application Create `app.py` with the following content: ```python from flask import Flask, jsonify, render_template_string import subprocess import json app = Flask(__name__) @app.route('/') def index(): return render_template_string(''' SMS Campaign Manager - Termux

🚀 SMS Campaign Manager

Running on Termux!

✅ Flask Server Status: Active

Server IP: 10.0.0.193:5000

Environment: Termux on Android

🔋 Termux API Tests

📱 Battery Status

🔔 Send Test Notification

''') @app.route('/battery') def battery(): try: result = subprocess.run(['termux-battery-status'], capture_output=True, text=True) battery_data = json.loads(result.stdout) return f"""

🔋 Battery Status

{json.dumps(battery_data, indent=2)}

← Back

""" except Exception as e: return f"

Error

{str(e)}

← Back

" @app.route('/notification') def notification(): try: subprocess.run(['termux-notification', '--title', 'Flask Test', '--content', 'Hello from SMS Campaign Manager!'], capture_output=True, text=True) return f"""

🔔 Notification Sent!

Check your Android notifications.

← Back

""" except Exception as e: return f"

Error

{str(e)}

← Back

" if __name__ == '__main__': print("🚀 Starting SMS Campaign Manager on Termux...") print("📱 Device IP: 10.0.0.193") print("🌐 Access from Ubuntu: http://10.0.0.193:5000") app.run(host='0.0.0.0', port=5000, debug=True) ``` ### Running the Application #### 1. Start the Flask Server ```bash cd ~/projects/sms-campaign-manager python app.py ``` #### 2. Access the Application - **From Android device:** http://127.0.0.1:5000 - **From Ubuntu/network:** http://10.0.0.193:5000 (replace with your device IP) - **From SSH:** Access via the device's network IP ### Features Implemented 1. **Web Interface**: Clean, responsive HTML interface 2. **Battery Status API**: Uses `termux-battery-status` to display device battery info 3. **Notification API**: Sends test notifications using `termux-notification` 4. **Network Access**: Configured to accept connections from any IP (0.0.0.0) ### Useful Commands #### Check if server is running ```bash ps aux | grep python ``` #### Find your device IP ```bash ifconfig wlan0 | grep inet # or ip addr show wlan0 ``` #### Kill existing Flask processes ```bash pkill -f "python app.py" ``` #### Run in background with nohup ```bash nohup python app.py > flask.log 2>&1 & ``` #### View logs ```bash tail -f flask.log ``` ### SSH Access from Ubuntu If you want to develop from your Ubuntu machine: ```bash # From Ubuntu, SSH into Termux ssh android-dev # Navigate to project cd ~/projects/sms-campaign-manager # Edit files with nano or vim nano app.py ``` ### Troubleshooting #### Port Already in Use ```bash # Find process using port 5000 lsof -i :5000 # Kill the process kill -9 ``` #### Permission Issues with Termux API Make sure you've granted permissions to Termux:API app in Android settings. #### Network Access Issues Ensure your device and Ubuntu machine are on the same network. ### Next Steps for SMS Campaign Manager 1. **Add SMS functionality**: ```python # Send SMS using Termux API subprocess.run(['termux-sms-send', '-n', phone_number, message]) ``` 2. **Add contact list management**: ```python # Get contacts subprocess.run(['termux-contact-list']) ``` 3. **Add database support**: ```bash pip install flask-sqlalchemy ``` 4. **Add authentication**: ```bash pip install flask-login ``` ### Code-Server Alternative (Failed Attempt) **Note:** Installing code-server on Termux proved problematic due to: - Missing native module `argon2.node` - Node version incompatibilities - Architecture issues (ARM64) **Recommendation:** Use SSH with nano/vim for editing, or use a mobile code editor app like Acode or Termux:Widget for quick edits. ### Quick Restart Script Create `restart_server.sh`: ```bash #!/data/data/com.termux/files/usr/bin/bash pkill -f "python app.py" cd ~/projects/sms-campaign-manager python app.py ``` Make it executable: ```bash chmod +x restart_server.sh ``` ### Backup Your Work ```bash # Create backup tar -czf sms-campaign-backup.tar.gz ~/projects/sms-campaign-manager # Copy to Ubuntu via SCP scp sms-campaign-backup.tar.gz bunker-admin@10.0.0.9:~/backups/ ``` --- ## Summary You successfully: 1. ✅ Installed Flask and dependencies on Termux 2. ✅ Created a working Flask web application 3. ✅ Integrated Termux API for Android features 4. ✅ Made it accessible from your Ubuntu machine 5. ✅ Tested battery status and notification APIs The server was running successfully and accepting connections from your Ubuntu machine (10.0.0.9) as shown in the logs.