Telegram Bot mikrotik

:local CHID “-xxxx699”;
:local BotID “1361xxxxx:AAGrj3Kn8shgsZd5XwrodBUZX0xxxxxxxx”;
:local HostStatus “INET HO UP”;

:local message “Ping $host $HostStatus”;

/tool fetch url=”https://api.telegram.org/bot$BotID/sendmessage\?chat_id=$CHID&text=$message”

By yans008 Posted in Uncategorized

Refresh Slave replication mysql

  1. Slave: stop slave;
  2. Master: flush logs
  3. Master: show master status; — take note of the master log file and master log position
  4. Slave: CHANGE MASTER TO MASTER_LOG_FILE='log-bin.00000X', MASTER_LOG_POS=106;
  5. Slave: start slave;
By yans008 Posted in Mysql

Urutan import ssl di mikrotik

Pertama Upload 3 file berikut ke mikrotik :

  1. Upload root-ca-bundle.crt
  2. Upload namadomain.crt
  3. Uplod mycomodo.key

Setelah di upload, masuk ke menu system –> certificate –> import file yang telah di upload dengan urutan sbb :

  1. Import root-ca-bundle.crt
  2. import namadomain.crt
  3. import mycomodo.key

 

By yans008 Posted in Uncategorized

Membatasi trafik ketika sudah mencapai Daily quota pada hotspot mikrotik

JALANKAN TIAP MENIT CEK JIKA SUDAH 1 GB, SPEED DIRUBAH KE 512.

:foreach i in=[/ip hotspot user find ] do={
local outboundnya ([/ip hotspot user get $i bytes-out]);
local profilenya ([/ip hotspot user get $i profile]);
local usernya ([/ip hotspot user get $i name]);
:if ($outboundnya > “1073741824”) do={
:if ($profilenya = “1M”) do={
/ip hotspot user set [find name=$usernya] profile=512k;
/ip hotspot host remove [find mac-address=$usernya]
}
}
}

JALAN TIAP JAM 00:00:01, UNTUK RESET JADI 1 GB dan Speed 1 M
:foreach i in=[/ip hotspot user find ] do={
local profilenya ([/ip hotspot user get $i profile]);
:if ($profilenya = “512k”) do={
/ip hotspot user set [find name=$usernya] profile=1M;
/ip hotspot host remove [find mac-address=$usernya]
/ip hotspot user reset-counters [find mac-address=$usernya]
}
}

monitor antrian email dan simpan ke database

#!/usr/bin/perl
#!/usr/bin/env perl
# Script for update IP and system name using nbtscan
# Requirement : perl
# By : s.suyanto@gmail.com

use DBI;
use strict;
use warnings;
use Symbol;
# require “Konfig.pl”;
# print “content-type: text/html \n\n”;

my $hostsms = “serversms”;
my $databasesms = “sms”;
my $usersms = “usersms”;
my $pwsms = “passwordsms”;

my $dbh = DBI->connect(“dbi:mysql:$databasesms:$hostsms:3306”, $usersms, $pwsms);

sub count {
my ($dir) = @_;
my $dh = gensym();
my $c = 0;
opendir($dh, $dir) or die “$0: opendir: $dir: $!\n”;
while (my $f = readdir($dh)) {
if ($f =~ m{^[A-F0-9]{5,}$}) {
++$c;
} elsif ($f =~ m{^[A-F0-9]$}) {
$c += count(“$dir/$f”);
}
}
closedir($dh) or die “closedir: $dir: $!\n”;
return $c;
}
my $qdir = `postconf -h queue_directory`;
chomp($qdir);
chdir($qdir) or die “$0: chdir: $qdir: $!\n”;

my $Masuk = count(“incoming”);
my $Aktif= count(“active”);
my $Ditangguhkan= count(“deferred”);

my $TotalAntrian = $Masuk+$Aktif+$Ditangguhkan;

printf “Incoming: %d\n”, count(“incoming”);
printf “Active: %d\n”, count(“active”);
printf “Deferred: %d\n”, count(“deferred”);
printf “Bounced: %d\n”, count(“bounce”);
printf “Hold: %d\n”, count(“hold”);

if ($TotalAntrian >= 500) {
my $Alert = “Total MailRekind : $TotalAntrian (In : $Masuk, Act: $Aktif, Def: $Ditangguhkan)”;
my $sth = $dbh->prepare(“INSERT INTO `outbox` (`UpdatedInDB`, `InsertIntoDB`, `SendingDateTime`, `SendBefore`, `SendAfter`, `Text`, `DestinationNumber`, `Coding`, `UDH`, `Class`, `TextDecoded`, `MultiPart`, `RelativeValidity`, `SenderID`, `SendingTimeOut`, `DeliveryReport`, `CreatorID`) VALUES (NOW(), NOW(), NOW(), ’23:59:59′, ’00:00:00′, NULL, ‘01111111’, ‘Default_No_Compression’, NULL, 1, ‘$Alert’, ‘false’, -1, NULL, NOW(), ‘default’, ”)”);
$sth->execute();
}

printf “Incoming : $Masuk, Active : $Aktif, Deffered: $Ditangguhkan\n”;

$dbh->disconnect();

By yans008 Posted in Uncategorized

Men-Disable global forwarding pada bind untuk delegasi subdomain

options {

forwarders {1.1.1.1 ; 2.2.2.2}; // ip dns provider.

}

zone “contoh.com” {
type master;
file “zone.contoh.com”;
forwarders {};
};

forwarders {};  Tujuannya agar sub-domain yang ada di sub-domain contoh.com tidak diforward ke ip dns di forwarder. (ip dns provider)

By yans008 Posted in Uncategorized

Perl Tail and sendmail

#!/usr/bin/perl
# Butuh libfile-tail-perl
# dibuat oleh : yanto
use File::Tail;
use Mail::Sendmail;

$file=File::Tail->new(name=>”/var/log/messages”,maxinterval=>2, adjustafter=>2);
while (defined($line=$file->read)) {
$needToFind = “DENY:”;
$_ = $line;
# print “$line\n” if m/$needToFind/;

if (m/$needToFind/)
{

%mail = ( To => ‘xxxx@xxxxx.com’,
From => ‘xxxx@xxxxx.com’,
Subject => “vmps : New user”,
Message => “$line”
);

sendmail(%mail) or die $Mail::Sendmail::error;

}
}
exit 0;

By yans008 Posted in Uncategorized

ssh

yanto@local-host$ ssh-keygen
yanto@local-host$ ssh-copy-id -i ~/.ssh/id_rsa.pub remote-host

By yans008 Posted in Uncategorized