<html>
  <head>
    <meta content="text/html; charset=windows-1252"
      http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    Hello,<br>
    <br>
    I think auth_check() returns a particular code if the user doesn't
    exits -- see the readme and add the return code to the switch along
    with the -2 value.<br>
    <br>
    Alternative, you can use the function is_subscriber() from auth_db
    module to detect if the user exists or not, and if not, ban it
    directly without <br>
    <br>
    Cheers,<br>
    Daniel<br>
    <br>
    <div class="moz-cite-prefix">On 15/03/16 12:55, meres gr wrote:<br>
    </div>
    <blockquote
cite="mid:CAL5gj2ZC5mw9TQmdheznTfjFz6kPiJTb_JNkotwPfOaZKu3FRQ@mail.gmail.com"
      type="cite">
      <div dir="ltr">I am using the following script to ban users
        failing to authenticate with fail2ban:
        <div>My problem is that it logs attempts of users only existing
          to the database</div>
        <div>I would like to modify it in order to log all FAILED
          authentication attempts</div>
        <div>Is this possible?</div>
        <div> </div>
        <div>
          <div># Authentication route</div>
          <div>route[AUTH] {</div>
          <div>#!ifdef WITH_AUTH</div>
          <div><br>
          </div>
          <div>  if(is_present_hf("Authorization"))</div>
          <div>  {</div>
          <div>    if($sht(a=>$au::auth_count)==3)</div>
          <div>    {</div>
          <div>     <span class="" style="white-space:pre">     </span>$var(exp)
            = $Ts - 900;</div>
          <div>        if($sht(a=>$au::last_auth) > $var(exp))</div>
          <div>        {</div>
          <div>            sl_send_reply("403", "Try later");</div>
          <div>            exit;</div>
          <div>        } else {</div>
          <div>            $sht(a=>$au::auth_count) = 0;</div>
          <div>        }</div>
          <div>    }</div>
          <div>    if(!www_authenticate("$td", "subscriber"))</div>
          <div>    {</div>
          <div>     <span class="" style="white-space:pre">     </span>switch
            ($retcode) {</div>
          <div>            case -1:</div>
          <div>                sl_send_reply("403", "Forbidden");</div>
          <div>            exit;</div>
          <div>            case -2:</div>
          <div>#fixed null -> $null:</div>
          <div>                if($sht(a=>$au::auth_count) == $null)</div>
          <div>                    $sht(a=>$au::auth_count) = 0;</div>
          <div>                $sht(a=>$au::auth_count) =
            $sht(a=>$au::auth_count) + 1;</div>
          <div>xlog("User $fu Authenticating from ip $si\n");</div>
          <div>                if($sht(a=>$au::auth_count) == 3)</div>
          <div>xlog("User $fU Authenticating for the 3d time from ip
            $si\n");</div>
          <div>                $sht(a=>$au::last_auth) = $Ts;</div>
          <div>            break;</div>
          <div>        }</div>
          <div><span class="" style="white-space:pre">  </span>www_challenge("$td"/*realm*/,"0"/*qop*/);</div>
          <div>        exit;</div>
          <div>    }</div>
          <div>    $sht(a=>$au::auth_count) = 0;</div>
          <div>  } else {</div>
          <div>    www_challenge("$td","0");</div>
          <div>    exit;</div>
          <div>  }</div>
          <div>}</div>
          <div>#!endif<br>
          </div>
        </div>
      </div>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <br>
      <pre wrap="">_______________________________________________
SIP Express Router (SER) and Kamailio (OpenSER) - sr-users mailing list
<a class="moz-txt-link-abbreviated" href="mailto:sr-users@lists.sip-router.org">sr-users@lists.sip-router.org</a>
<a class="moz-txt-link-freetext" href="http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users">http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users</a>
</pre>
    </blockquote>
    <br>
    <pre class="moz-signature" cols="72">-- 
Daniel-Constantin Mierla
<a class="moz-txt-link-freetext" href="http://www.asipto.com">http://www.asipto.com</a>
<a class="moz-txt-link-freetext" href="http://twitter.com/#!/miconda">http://twitter.com/#!/miconda</a> - <a class="moz-txt-link-freetext" href="http://www.linkedin.com/in/miconda">http://www.linkedin.com/in/miconda</a>
Kamailio World Conference, Berlin, May 18-20, 2016 - <a class="moz-txt-link-freetext" href="http://www.kamailioworld.com">http://www.kamailioworld.com</a></pre>
  </body>
</html>