Disable otomatis pelanggan yang telat bayar

 

skrip disable otomatis pelanggan yang telat bayar. Jadi kalau lewat jatuh tempo, speed mereka diturunkan jadi 512Kbps/512Kbps (bisa disesuaikan).

Cek Jatuh Tempo dari due:DD/MM/YYYY

contoh Comment winbox "nama:Bu Dedeh; paket:Unlimited; harga:100000; due:01/08/2025; no_hp:0123456789; iface:pppoe-brige3-3; Usage:2.35 GB"



🔧 Skrip Cek Jatuh Tempo + Potong Speed

/system script

add name=cek_jatuh_tempo source={


    :log info "📆 Cek jatuh tempo pelanggan (format due)..."


    # === Ambil tanggal hari ini ===

    :local d [/system clock get date]

    :local bulan [:pick $d 0 3]

    :local hari [:pick $d 4 6]

    :local tahun [:pick $d 7 11]


    :local bln ("jan","feb","mar","apr","may","jun","jul","aug","sep","oct","nov","dec")

    :local bulan_num ([:find $bln $bulan] + 1)

    :if ($bulan_num < 10) do={ :set bulan_num ("0".$bulan_num) }


    :local today ($hari."/".$bulan_num."/".$tahun)


    /queue simple

    :foreach i in=[find] do={


        :local cmt [get $i comment]

        :if ([:len $cmt] = 0) do={ :continue }


        :local p [:find $cmt "due:"]

        :if ($p = nil) do={ :continue }


        # Ambil tanggal due (DD/MM/YYYY)

        :local due [:pick $cmt ($p + 4) ($p + 14)]


        :if ($due = $today) do={


            :log warning ("⏰ JATUH TEMPO: ".$cmt)


            # Potong speed

            :if ([get $i max-limit] != "512k/512k") do={

                set $i max-limit=512k/512k

            }

        }

    }

}



⏰ SCHEDULER (WAJIB BIAR OTOMATIS)

/system scheduler add name=cek_jatuh_tempo \ interval=1d \ start-time=00:05:00 \ on-event=cek_jatuh_tempo

🔄 Restore Speed Setelah Bayar

Kalau pelanggan sudah bayar:

  1. Edit queue pelanggan.
  2. Kembalikan max-limit sesuai paket (misalnya 20M/20M).
  3. Ubah juga jatuh_tempo ke bulan berikutnya di comment.

Contoh update comment setelah bayar:

/queue simple

set Bu Dedeh_192.168.88.10 comment="nama:Bu Dedeh; paket:Unlimited; harga:100000; due:01/08/2025; no_hp:087762046511; iface:pppoe-brige3-3; Usage:2.35"

set Bu Dedeh_192.168.88.10 max-limit=20M/20M


Jadi alurnya:

  • Hari H jatuh tempo → speed otomatis dipotong ke 512Kbps.
  • Setelah bayar → admin update tanggal + restore speed normal.

Opsi auto-disable koneksi (block access total) selain dipotong speed, supaya bisa pilih model hukuman pelanggan yang telat bayar.

 

Oke 👍, saya buatkan 2 opsi hukuman pelanggan di Mikrotik kalau lewat jatuh tempo bulanan:


🔧 1. Opsi Potong Speed (sudah ada)

Speed diturunkan jadi 512K/512K. (sudah saya kasih skrip ).


🔧 2. Opsi Block Total Internet

Kalau lewat jatuh tempo → akses internet diputus, diarahkan ke halaman informasi (misalnya portal lokal atau pesan bayar tagihan).

Skrip Block Total:

/system script

add name=cek_jatuh_tempo_block source={


    :log info "🚫 Cek jatuh tempo (BLOCK TOTAL)..."


    # === Ambil tanggal hari ini ===

    :local d [/system clock get date]

    :local bulan [:pick $d 0 3]

    :local hari [:pick $d 4 6]

    :local tahun [:pick $d 7 11]


    :local bln ("jan","feb","mar","apr","may","jun","jul","aug","sep","oct","nov","dec")

    :local bulan_num ([:find $bln $bulan] + 1)

    :if ($bulan_num < 10) do={ :set bulan_num ("0".$bulan_num) }


    :local today ($hari."/".$bulan_num."/".$tahun)


    # Bersihkan list blokir lama

    /ip firewall address-list remove [find list="blokir"]


    /queue simple

    :foreach i in=[find] do={


        :local cmt [get $i comment]

        :if ([:len $cmt] = 0) do={ :continue }


        :local p [:find $cmt "due:"]

        :if ($p = nil) do={ :continue }


        :local due [:pick $cmt ($p + 4) ($p + 14)]


        :if ($due = $today) do={


            :local target [get $i target]


            :log warning ("🚫 TELAT BAYAR → BLOCK: ".$cmt)


            /ip firewall address-list add \

                list=blokir \

                address=$target \

                timeout=0

        }

    }

}


🔥 FIREWALL RULE (WAJIB)

Pasang di atas rule allow internet:

/ip firewall filter add chain=forward \ src-address-list=blokir \ action=reject \ reject-with=icmp-admin-prohibited \ comment="🚫 Pelanggan Telat Bayar"

📌 Efek:

  • Internet mati total

  • WhatsApp & browser langsung nggak jalan

  • Bikin pelanggan cepat sadar 😅


⏰ SCHEDULER (BIAR OTOMATIS)

/system scheduler add name=cek_jatuh_tempo_block \ interval=1d \ start-time=00:05:00 \ on-event=cek_jatuh_tempo_block

🔁 FIREWALL NAT (REDIRECT)

Misal halaman tagihan ada di:

http://192.168.88.2/tagihan.html
/ip firewall nat add chain=dstnat protocol=tcp dst-port=80 \ src-address-list=blokir \ action=dst-nat to-addresses=192.168.88.2 to-ports=5000

👉 192.168.88.2 itu IP SERVER FLASK (admin/aplikasi), BUKAN IP pelanggan dan BUKAN IP Mikrotik.
✅ 192.168.88.2 = KOMPUTER / SERVER ADMIN

🔧 Cara Pastikan IP 192.168.88.2 BENAR

Di PC admin / server Flask:

Windows

ipconfig

Cari:

IPv4 Address . . . . . : 192.168.88.2

🔄 Restore Setelah Bayar

  1. Hapus IP pelanggan dari address-list=blokir.
  2. Update comment jatuh_tempo ke bulan depan.

SCRIPT RESTORE SETELAH BAYAR

Script ini:

  • Cari queue berdasarkan IP / target

  • Hapus dari address-list blokir

  • Ganti due: ke bulan depan

  • Log biar kelihatan di Winbox

📜 Script MikroTik

/system script add name=restore_setelah_bayar source={ :log info "🔄 Restore pelanggan setelah bayar"; :local targetIP $1 :local today [/system clock get date] # Hapus dari address-list blokir /ip firewall address-list remove [find list=blokir address=$targetIP] /queue simple :foreach i in=[find where target~$targetIP] do={ :local cmt [get $i comment] # Ambil due lama :local pos1 [:find $cmt "due:"] :local pos2 [:find $cmt ";no_hp:"] :if ($pos1 != -1 && $pos2 != -1) do={ :local dueLama [:pick $cmt ($pos1+4) $pos2] # Hitung bulan depan (manual simpel) :local d [:pick $dueLama 0 2] :local m [:pick $dueLama 3 5] :local y [:pick $dueLama 6 10] :set m ($m + 1) :if ($m > 12) do={ :set m 1 :set y ($y + 1) } :if ([:len $m] = 1) do={ :set m ("0".$m) } :local dueBaru ($d."/".$m."/".$y) # Ganti due di comment :local cmtBaru [:replace $cmt $dueLama $dueBaru] set $i comment=$cmtBaru :log info ("✅ Restore sukses: ".$cmtBaru) } } }

 🎯 TUJUAN AKHIR

Dari Flask (web admin):

  • klik “Bayar”

  • Flask:

    1. Hapus IP dari address-list=blokir

    2. Update due di comment queue

  • MikroTik eksekusi real-time


1️⃣ AKTIFKAN API DI MIKROTIK (WAJIB)

Masuk Winbox → IP → Services

Pastikan:

api ENABLED port: 8728

Boleh juga pakai api-ssl (8729), tapi kita mulai yang simpel dulu.


2️⃣ BUAT USER KHUSUS API (AMAN)

Di Winbox → System → Users

Buat user baru:

name: flaskapi group: full (atau custom) password: kuat


Komentar

Postingan Populer