toritoesinocente

telegram.php

Oct 14th, 2021
724
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/php -q
  2. <?php
  3. $canal = "CANAL O CHATID";
  4. $token = "EL TOKEN DEL BOT";
  5. @$cmd = $argv[1];
  6. @$arg = $argv[2];
  7. if($cmd == 'start') $msg = "inicio de fail2ban";
  8. elseif($cmd == 'stop') $msg = "fin de fail2ban";
  9. elseif($cmd == 'ban') $msg = "nuevo ip <strong>bloqueado</strong> ".$arg;
  10. elseif($cmd == 'unban') $msg = "nuevo ip desbloqueado ".$arg;
  11. if(!empty($msg)) chat($msg);
  12. /* chat(para, mensaje) {{{ */
  13. function chat($m) {
  14.         global $token, $canal;
  15.         $datos = [ "text" => $m, "chat_id" => $canal, 'parse_mode'=>'html'];
  16.         if(empty($m)) { echo "intenta enviar un mensaje vacio\n"; return; }
  17.         $metodo = "POST"; //cambiar a "POST" en caso de que sea post
  18.         $url    = "https://api.telegram.org/bot".$token."/sendMessage";
  19.         $ch = curl_init();
  20.         curl_setopt($ch,CURLOPT_URL,$url);
  21.         curl_setopt($ch,CURLOPT_POSTFIELDS, http_build_query($datos));
  22.         curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
  23.         $tmp = curl_exec($ch);
  24.         $k = json_decode($tmp);
  25.         curl_close($ch);
  26. }
  27. /* }}} */
RAW Paste Data