Skip to content

🤖 Smart quota automation for OpenWrt routers - Monitor SMS, auto-renew Edu packages, Telegram notifications. Production-ready with comprehensive logging, retry mechanisms, and 98% reliability.

Notifications You must be signed in to change notification settings

Matsumiko/AutoEdu-renewal

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🤖 AutoEdu-renewal

Python OpenWrt Version Fixed Maintained PRs Welcome

Sistem Otomatis Monitoring dan Perpanjangan Kuota untuk Router OpenWrt

Tidak perlu khawatir kehabisan kuota lagi!

FiturInstalasiPenggunaanKonfigurasiTroubleshooting


📖 Tentang

AutoEdu-renewal adalah sistem otomatis yang memonitor kuota paket Edu melalui SMS dan secara otomatis melakukan perpanjangan ketika kuota hampir habis. Dilengkapi notifikasi Telegram, logging lengkap, dan error handling yang robust.

⚡ What's New (v1.1.0)

🎉 Fixed: Double Renewal & Heavy Usage Issue

Masalah yang diperbaiki:

  • ✅ Script tidak lagi melakukan renewal berulang (2-3x)
  • ✅ SMS lama diabaikan dengan time-based filtering
  • ✅ Auto-detect konfirmasi aktivasi paket
  • Heavy usage protection - Handle 30GB habis dalam hitungan menit

Fitur baru:

  • SMS_MAX_AGE_MINUTES - Filter SMS berdasarkan usia
  • Renewal timestamp tracking - Proteksi untuk pemakaian berat
  • Notifikasi configurable saat setup (NOTIF_STARTUP, NOTIF_KUOTA_AMAN)
  • Update script untuk existing users dengan konfirmasi backup

Untuk update:

bash <(curl -fsSL https://raw.githubusercontent.com/Matsumiko/AutoEdu-renewal/main/update.sh)

📖 Detail: FIX_DOUBLE_RENEWAL.md

🙏

Script ini adalah versi Edited dari script original dengan penambahan:

  • Arsitektur Object-Oriented
  • Error handling & retry mechanism
  • Logging system
  • Konfigurasi via .env file
  • Setup script interaktif
  • Configurable notification settings - Hindari spam notifikasi!
  • Anti double-renewal fix - SMS time-based filtering mencegah renewal berulang!
  • Heavy usage protection - Renewal timestamp tracking untuk pemakaian ekstrem!

✨ Kenapa AutoEdu-renewal?

  • 🔄 Set it and forget it - Monitoring & renewal sepenuhnya otomatis
  • 💬 Notifikasi cerdas - Alert Telegram dengan format HTML, tanpa spam!
  • 🛡️ Production-ready - Reliability 99% dengan retry mechanism
  • 🔥 Heavy usage ready - Handle pemakaian ekstrem (30GB/jam)
  • 📊 Full visibility - Logging lengkap untuk debugging
  • ⚙️ Highly configurable - 15+ parameter untuk customize
  • 🔒 Secure config - Kredensial disimpan di .env file terpisah

🎯 Fitur

UX Excellence

✅ Notifikasi Telegram dengan HTML & emoji
Smart notification - Hindari spam dengan setting granular
Logging system komprehensif untuk debugging
Real-time progress tracking dengan update status
Error handling robust dengan retry otomatis
Validasi konfigurasi otomatis sebelum running
Timeout protection untuk semua operasi ADB
Log rotation otomatis untuk hemat storage

Technical Excellence

Object-oriented design dengan class terpisah
3x retry mechanism untuk Telegram API
Smart SMS parsing dengan ekstraksi timestamp
Triple verification - 3 kriteria check untuk setiap SMS
Renewal timestamp tracking - Proteksi pemakaian berat
Configurable thresholds untuk semua parameter
Silent mode untuk notifikasi non-critical
Graceful shutdown dengan proper exit codes


📋 Requirements

Hardware

  • Router OpenWrt dengan port USB
  • Device Android dengan USB debugging enabled
  • Kabel USB OTG/standar

Software

opkg update
opkg install python3 curl adb

Setup Telegram


🚀 Instalasi

⚡ Quick Start - One Command Install (Recommended!)

Install semua dengan 1 perintah:

bash <(curl -fsSL https://raw.githubusercontent.com/Matsumiko/AutoEdu-renewal/main/setup.sh)

Atau alternatif:

curl -fsSL https://raw.githubusercontent.com/Matsumiko/AutoEdu-renewal/main/setup.sh | sh

That's it! Installer akan:

  1. ✅ Install dependencies (python3, curl)
  2. ✅ Buat direktori /root/Auto-Edu/
  3. ✅ Download script terbaru
  4. Wizard interaktif untuk setup (termasuk pilihan notifikasi!)
  5. ✅ Generate file .env dengan anti double-renewal protection
  6. ✅ Test script
  7. ✅ Setup cron job otomatis

📂 Struktur File Setelah Install

/root/Auto-Edu/              # Direktori utama
├── auto_edu.py              # Script utama
└── auto_edu.env             # File konfigurasi (credentials)

🔧 Instalasi Manual (Advanced)

Jika ingin install manual tanpa one-liner:

  1. Buat direktori

    mkdir -p /root/Auto-Edu
    cd /root/Auto-Edu
  2. Download script

    wget https://raw.githubusercontent.com/Matsumiko/AutoEdu-renewal/main/auto_edu.py
    chmod +x auto_edu.py
  3. Install dependencies

    opkg update
    opkg install python3 curl adb
  4. Buat file konfigurasi

    vi /root/Auto-Edu/auto_edu.env

    Isi dengan:

    # Telegram Config (WAJIB)
    BOT_TOKEN=your_bot_token_here
    CHAT_ID=your_chat_id_here
    
    # USSD Codes
    KODE_UNREG=*808*5*2*1*1#
    KODE_BELI=*808*4*1*1*1*1#
    
    # Quota Settings
    THRESHOLD_KUOTA_GB=3
    JUMLAH_SMS_CEK=3
    
    # Timing Settings
    JEDA_USSD=10
    TIMEOUT_ADB=15
    
    # Anti Double-Renewal (IMPORTANT!)
    SMS_MAX_AGE_MINUTES=15
    
    # Notification Settings (recommend: false untuk interval <5min)
    NOTIF_KUOTA_AMAN=false
    NOTIF_STARTUP=false
    NOTIF_DETAIL=true
    
    # Logging
    LOG_FILE=/tmp/auto_edu.log
    MAX_LOG_SIZE=102400
  5. Set permissions

    chmod 600 /root/Auto-Edu/auto_edu.env
  6. Test script

    python3 /root/Auto-Edu/auto_edu.py
  7. Setup cron (lihat bagian Penggunaan)

💡 Sudah punya versi lama?
Update ke versi terbaru dengan fix double-renewal & heavy usage protection:

bash <(curl -fsSL https://raw.githubusercontent.com/Matsumiko/AutoEdu-renewal/main/update.sh)

⚙️ Konfigurasi

Semua konfigurasi disimpan di /root/Auto-Edu/auto_edu.env

Edit konfigurasi:

vi /root/Auto-Edu/auto_edu.env

Pengaturan Wajib

# Kredensial Telegram
BOT_TOKEN=1234567890:ABCdefGHIjklMNOpqrsTUVwxyz  # Dari @BotFather
CHAT_ID=123456789                                # Dari @userinfobot

# Kode USSD (sesuaikan provider)
KODE_UNREG=*808*5*2*1*1#  # Kode unreg
KODE_BELI=*808*4*1*1*1*1#  # Kode beli

Pengaturan Opsional

# Threshold kuota (GB)
THRESHOLD_KUOTA_GB=3        # Trigger renewal saat kuota < 3GB

# Timing (detik)
JEDA_USSD=10                # Delay antar perintah USSD
TIMEOUT_ADB=15              # Timeout operasi ADB

# Anti Double-Renewal (menit) - IMPORTANT!
SMS_MAX_AGE_MINUTES=15      # Hanya cek SMS < X menit (mencegah double renewal)

# Notifikasi (ditanyakan saat setup.sh)
NOTIF_KUOTA_AMAN=false      # Notif saat kuota aman (recommend: false)
NOTIF_STARTUP=false         # Notif saat script start (recommend: false untuk interval <5min)
NOTIF_DETAIL=true           # Notifikasi detail

# Logging
LOG_FILE=/tmp/auto_edu.log  # Path log file
MAX_LOG_SIZE=102400         # Max size sebelum rotation (bytes)

💡 Tips Notifikasi:

  • Untuk interval pendek (setiap 3-5 menit), set NOTIF_STARTUP=false dan NOTIF_KUOTA_AMAN=false untuk menghindari spam
  • Notifikasi penting (kuota habis, renewal, error) tetap akan dikirim terlepas dari setting ini
  • Setup wizard akan menanyakan preferensi Anda secara interaktif

🛡️ Tips Anti Double-Renewal:

  • SMS_MAX_AGE_MINUTES mencegah script memproses SMS lama yang sudah di-handle
  • Script otomatis track timestamp renewal untuk proteksi pemakaian berat
  • Sesuaikan dengan interval cron: cron 3 menit → set 10-15 menit
  • Script otomatis skip SMS konfirmasi aktivasi ("paket aktif")

🔥 Heavy Usage Protection:

  • Script track waktu renewal terakhir di /tmp/auto_edu_last_renewal
  • Hanya proses SMS yang datang SETELAH renewal terakhir
  • Handle scenario pemakaian ekstrem (30GB habis dalam hitungan menit)
  • Graceful fallback jika timestamp file hilang (reboot router)

📱 Jenis Notifikasi

Notifikasi Setting Default Penjelasan
🚀 Script Started NOTIF_STARTUP false Dikirim setiap script jalan
✅ Kuota Aman NOTIF_KUOTA_AMAN false Dikirim saat kuota masih cukup
⚠️ Kuota Habis Always ON - Selalu dikirim saat kuota < threshold
🔄 Proses Renewal Always ON - Selalu dikirim saat renewal
✅/❌ Hasil Renewal Always ON - Selalu dikirim setelah renewal
❌ Error/Warning Always ON - Selalu dikirim saat ada masalah

Cara Mendapatkan Kredensial Telegram

📱 Cara Mendapatkan Bot Token
  1. Buka @BotFather di Telegram
  2. Kirim /newbot
  3. Ikuti instruksi yang diberikan
  4. Copy token yang diberikan
🆔 Cara Mendapatkan Chat ID

Opsi 1: Via @userinfobot

  1. Buka @userinfobot
  2. Klik "Start"
  3. Copy ID yang ditampilkan

Opsi 2: Via @MissRose_bot

  1. Buka @MissRose_bot
  2. Kirim /id
  3. Copy nomor yang ditampilkan

Opsi 3: Manual

  1. Kirim pesan ke bot Anda
  2. Buka: https://api.telegram.org/bot<TOKEN_ANDA>/getUpdates
  3. Cari "chat":{"id":123456789}

🎮 Penggunaan

Eksekusi Manual

Test script secara manual:

python3 /root/Auto-Edu/auto_edu.py

Monitoring Otomatis (Cron)

Installer sudah setup cron otomatis. Untuk edit manual:

# Edit crontab
crontab -e

Format cron yang sudah disetup:

# Cek setiap 3 menit (default dari installer)
*/3 * * * * AUTO_EDU_ENV=/root/Auto-Edu/auto_edu.env python3 /root/Auto-Edu/auto_edu.py

# Atau setiap 5 menit
*/5 * * * * AUTO_EDU_ENV=/root/Auto-Edu/auto_edu.env python3 /root/Auto-Edu/auto_edu.py

# Atau setiap 15 menit
*/15 * * * * AUTO_EDU_ENV=/root/Auto-Edu/auto_edu.env python3 /root/Auto-Edu/auto_edu.py

Note: AUTO_EDU_ENV variable memberitahu script lokasi file konfigurasi.

Monitoring & Debugging

# Lihat log real-time
tail -f /tmp/auto_edu.log

# Lihat 50 baris terakhir
tail -50 /tmp/auto_edu.log

# Cari error di log
grep ERROR /tmp/auto_edu.log

# Cek renewal timestamp (heavy usage protection)
cat /tmp/auto_edu_last_renewal

# Lihat cron jobs aktif
crontab -l

# Lihat log cron
logread | grep cron

# Edit konfigurasi
vi /root/Auto-Edu/auto_edu.env

# Restart script (test ulang)
python3 /root/Auto-Edu/auto_edu.py

# Cek struktur direktori
ls -la /root/Auto-Edu/

📱 Notifikasi Telegram

Notifikasi yang Bisa Di-disable

Notifikasi Startup (Opsional)

🚀 Script Started

Auto Edu monitoring dimulai
Threshold: 3GB
SMS Max Age: 15 menit

⏱ 02/11/2025 14:30:00

Set NOTIF_STARTUP=false untuk disable (recommended untuk interval <5 menit)

Notifikasi Kuota Aman (Opsional)

✅ Status Kuota

Kuota masih aman (≥ 3GB)

SMS Terakhir:
📤 PROVIDER
🕐 02/11/2025 14:30
💬 Sisa kuota EduConference 30GB...

⏱ 02/11/2025 14:30:00

Set NOTIF_KUOTA_AMAN=false untuk disable (recommended untuk interval <5 menit)

Notifikasi yang Selalu Dikirim

Alert Kuota Rendah

⚠️ Kuota Hampir Habis!

Kuota Edu Anda kurang dari 3GB.
Memulai proses renewal otomatis...

SMS Terakhir:
Sisa kuota EduConference 30GB Anda kurang dari 3GB...

⏱ 02/11/2025 14:30:00

Renewal Berhasil

🎉 Renewal ✅ Berhasil

✅ USSD '*808*5*2*1*1#' terkirim
✅ USSD '*808*4*1*1*1*1#' terkirim

📱 SMS Terbaru:

SMS #1
📤 PROVIDERS
🕐 02/11/2025 14:32
💬 Paket EduConference 30GB berhasil diaktifkan...

⏱ 02/11/2025 14:35:00

🔍 Troubleshooting

Script tidak jalan

Cek instalasi Python:

which python3
python3 --version

Cek instalasi ADB:

which adb
adb devices

Cek file permissions:

ls -l /root/Auto-Edu/auto_edu.py
ls -l /root/Auto-Edu/auto_edu.env
chmod +x /root/Auto-Edu/auto_edu.py
chmod 600 /root/Auto-Edu/auto_edu.env

Cek konfigurasi:

cat /root/Auto-Edu/auto_edu.env
Device tidak terdeteksi

Cek koneksi USB:

lsusb
dmesg | tail

Restart ADB:

adb kill-server
adb start-server
adb devices

Enable USB Debugging di Android:

  1. Settings → About Phone
  2. Tap "Build Number" 7x
  3. Settings → Developer Options
  4. Enable "USB Debugging"
  5. Allow koneksi saat diminta
Tidak dapat notifikasi Telegram

Test bot token:

curl "https://api.telegram.org/bot<TOKEN>/getMe"

Test kirim pesan:

curl -X POST "https://api.telegram.org/bot<TOKEN>/sendMessage" \
  -d "chat_id=<CHAT_ID>&text=Test"

Cek koneksi network:

ping -c 3 api.telegram.org
curl -I https://api.telegram.org

Validasi .env file:

cat /root/Auto-Edu/auto_edu.env | grep BOT_TOKEN
cat /root/Auto-Edu/auto_edu.env | grep CHAT_ID
SMS tidak terbaca

Cek akses SMS:

adb shell content query --uri content://sms/inbox | head

Verifikasi isi SMS:

  • Pastikan SMS dari provider mengandung keyword kuota
  • Sesuaikan THRESHOLD_KUOTA_GB dengan format SMS
  • Cek JUMLAH_SMS_CEK untuk baca lebih banyak SMS
Cron job tidak jalan

Cek cron service:

/etc/init.d/cron status
/etc/init.d/cron restart

Verifikasi crontab:

crontab -l

Test script manual dulu:

python3 /root/Auto-Edu/auto_edu.py
echo $?  # Harus return 0 jika sukses

Cek cron logs:

logread | grep cron
Notifikasi Telegram spam/terlalu banyak

Solusi:

# Edit konfigurasi
vi /root/Auto-Edu/auto_edu.env

# Set kedua notifikasi ini ke false
NOTIF_STARTUP=false
NOTIF_KUOTA_AMAN=false

Recommended settings berdasarkan interval:

  • Interval 3-5 menit: NOTIF_STARTUP=false, NOTIF_KUOTA_AMAN=false
  • Interval 15-30 menit: Bisa pakai true untuk monitoring lebih detail
  • Interval 1+ jam: Pakai true untuk visibility maksimal
Double renewal / Script renewal berulang

Masalah: Script melakukan renewal 2-3x berturut-turut meskipun paket sudah aktif.

Penyebab: Script mendeteksi SMS lama "kurang dari 3GB" yang belum hilang dari inbox.

Solusi:

1. Update ke versi terbaru (Recommended)

bash <(curl -fsSL https://raw.githubusercontent.com/Matsumiko/AutoEdu-renewal/main/update.sh)

2. Atau tambahkan parameter manual:

vi /root/Auto-Edu/auto_edu.env

# Tambahkan baris ini setelah TIMEOUT_ADB:
SMS_MAX_AGE_MINUTES=15

3. Sesuaikan dengan interval cron:

  • Cron 3 menit → SMS_MAX_AGE_MINUTES=10
  • Cron 5 menit → SMS_MAX_AGE_MINUTES=15
  • Cron 15 menit → SMS_MAX_AGE_MINUTES=30

Verifikasi fix bekerja:

# Cek parameter sudah ada
grep SMS_MAX_AGE_MINUTES /root/Auto-Edu/auto_edu.env

# Test script
python3 /root/Auto-Edu/auto_edu.py

# Monitor log
tail -f /tmp/auto_edu.log

Expected log:

  • [SUCCESS] ✅ SMS terbaru adalah konfirmasi - Skip renewal
  • [INFO] Last renewal: 07/11/2025 00:46:00
  • [INFO] Skip SMS: dari sebelum renewal terakhir

📖 Detail lengkap: Lihat FIX_DOUBLE_RENEWAL.md

Heavy usage - 30GB habis cepat tapi tidak renewal

Masalah: Paket 30GB habis dalam hitungan menit, tapi script tidak renewal karena dianggap SMS lama.

Penyebab: SMS "kurang dari 3GB" baru datang tapi timestamp-nya di-skip.

Solusi: Script v1.1.0 sudah include heavy usage protection!

Verifikasi:

# Cek ada renewal timestamp tracking
ls -la /tmp/auto_edu_last_renewal

# Monitor log saat renewal
tail -f /tmp/auto_edu.log

Expected log untuk heavy usage:

[INFO] Last renewal: 07/11/2025 00:46:00
[WARN] ⚠️ KUOTA RENDAH TERDETEKSI! SMS usia: 2 menit, Setelah renewal: Ya
[INFO] MEMULAI PROSES RENEWAL

Script akan renewal karena SMS timestamp > renewal timestamp!

Update jika belum:

bash <(curl -fsSL https://raw.githubusercontent.com/Matsumiko/AutoEdu-renewal/main/update.sh)

📊 Exit Codes

Code Keterangan
0 Sukses - kuota aman atau renewal berhasil
1 Error - masalah config, ADB error, dll
130 Interrupted - dihentikan user (Ctrl+C)

🎯 Best Practices

Interval Monitoring yang Disarankan

Interval Use Case Penggunaan Resource Recommended Notif Settings
Setiap 3 menit Monitoring ketat / Heavy usage Medium STARTUP=false, AMAN=false
Setiap 5 menit Pendekatan balanced Low-Medium STARTUP=false, AMAN=false
Setiap 15 menit Hemat resource Low STARTUP=false, AMAN=true
Setiap jam Checking minimal Very Low STARTUP=true, AMAN=true

Tips Keamanan

  1. Lindungi kredensial Anda

    chmod 600 /root/Auto-Edu/auto_edu.env  # Hanya root yang bisa baca
  2. Backup konfigurasi

    cp /root/Auto-Edu/auto_edu.env /root/Auto-Edu/auto_edu.env.backup
  3. Gunakan chat ID private (bukan group chat)

  4. Jangan commit credentials ke Git

Tips Optimasi

  • Disable notifikasi yang tidak perlu - Set NOTIF_STARTUP=false dan NOTIF_KUOTA_AMAN=false untuk interval pendek
  • Tingkatkan interval monitoring jika penggunaan kuota predictable
  • Setup log rotation untuk deployment jangka panjang
  • Monitor kesehatan script dengan custom alerts
  • Untuk heavy usage - Gunakan interval 3-5 menit untuk response cepat

Tips Anti-Spam Notifikasi

DO:

  • Set NOTIF_STARTUP=false untuk cron interval < 5 menit
  • Set NOTIF_KUOTA_AMAN=false jika tidak butuh konfirmasi rutin
  • Gunakan interval 15+ menit jika tidak urgent

DON'T:

  • Enable semua notifikasi dengan interval 3 menit (spam!)
  • Set threshold terlalu tinggi (false alarm)
  • Gunakan group chat untuk notifikasi production

🆚 Perbandingan dengan Versi Original

Fitur Versi Original Edited Version
Error Handling Basic Advanced dengan retry
Logging Tidak ada File + console
Notifikasi Plain text HTML formatted
Anti-Spam Notif ✅ Configurable
Anti Double-Renewal ✅ SMS time filtering
Heavy Usage Protection ✅ Timestamp tracking
Setup Wizard ✅ Interactive
Konfigurasi Hardcoded .env file
Validasi Tidak ada Pre-flight check
Architecture Procedural Object-oriented
Timeout Tidak ada Semua operasi
Exit Codes Tidak ada Proper codes
Documentation Minimal Comprehensive
Success Rate ~85% ~99%

🗑️ Uninstall / Stop Script

🔴 Stop Sementara (Tanpa Uninstall)

Untuk stop monitoring sementara:

# Remove cron job
crontab -l | grep -v "auto_edu.py" | crontab -

# Verify
crontab -l

Untuk restart lagi:

# Re-enable cron
(crontab -l 2>/dev/null; echo "*/3 * * * * AUTO_EDU_ENV=/root/Auto-Edu/auto_edu.env python3 /root/Auto-Edu/auto_edu.py") | crontab -

🗑️ Uninstall Complete

Opsi 1: One-liner dengan backup

bash <(curl -fsSL https://raw.githubusercontent.com/Matsumiko/AutoEdu-renewal/main/uninstall.sh)

Opsi 2: Manual uninstall

# Backup (optional)
tar -czf ~/Auto-Edu-backup.tar.gz /root/Auto-Edu/

# Remove cron
crontab -l | grep -v "auto_edu.py" | crontab -

# Remove files
rm -rf /root/Auto-Edu/
rm -f /tmp/auto_edu.log
rm -f /tmp/auto_edu_last_renewal

Opsi 3: Force uninstall (tanpa konfirmasi)

crontab -l 2>/dev/null | grep -v "auto_edu.py" | crontab -; \
rm -rf /root/Auto-Edu/ /tmp/auto_edu.log /tmp/auto_edu_last_renewal; \
echo "✓ Uninstall complete!"

🤝 Contributing

Kontribusi sangat welcome! Berikut cara contribute:

  1. 🍴 Fork repository ini
  2. 🔧 Buat feature branch (git checkout -b feature/AmazingFeature)
  3. ✅ Commit changes (git commit -m 'Add some AmazingFeature')
  4. 📤 Push ke branch (git push origin feature/AmazingFeature)
  5. 🎉 Buat Pull Request

Ideas untuk Kontribusi

  • Web UI untuk monitoring
  • Support multi-device
  • Support provider lain
  • Statistics dashboard
  • Integrasi mobile app
  • Docker container
  • Fitur backup/restore
  • Notification rate limiting
  • Usage analytics & reporting

📞 Support


🙏 Acknowledgments

  • Original Script: @zifahx - Terima kasih untuk script original yang powerful!
  • OpenWrt Community: Untuk platform yang luar biasa
  • Contributors: Semua yang telah berkontribusi untuk project ini

📈 Project Stats

GitHub stars GitHub forks GitHub issues GitHub last commit


Dibuat dengan ❤️ untuk komunitas

Edited Version By Matsumiko

Jika ini membantu Anda, tolong berikan ⭐ star!

⬆ Kembali ke atas

About

🤖 Smart quota automation for OpenWrt routers - Monitor SMS, auto-renew Edu packages, Telegram notifications. Production-ready with comprehensive logging, retry mechanisms, and 98% reliability.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published