Ignore:
Timestamp:
Jul 30, 2009, 7:36:50 PM (15 years ago)
Author:
grum
Message:

Update AStat 2.1.0 - new features
See main.inc.php file for details

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/AStat/admin/astat_config.tpl

    r3394 r3706  
    2020  }
    2121
     22  function isAValidIP(ip, strict)
     23  {
     24    returnedip=ip;
     25    re = /^(\d{1,3}){1}(\.\d{1,3}){0,3}$/i;
     26    if(re.test(ip))
     27    {
     28      num = ip.split('.');
     29      for(i=0;i<num.length;i++)
     30      {
     31        if(num[i]>255) return(false);
     32      }
     33      if(!strict)
     34      {
     35        returnedip+="%";
     36      }
     37      for(j=4-i;j>0;j--)
     38      {
     39        returnedip+=".%";
     40      }
     41      return(returnedip);
     42    }
     43    else
     44    {
     45      return(false);
     46    }
     47  }
     48
     49  function makeOptionsFromList(list, options)
     50  {
     51    if(list=="")
     52    {
     53       return(false);
     54    }
     55
     56    items=list.split(",");
     57    for(i=0;i<items.length;i++)
     58    {
     59      opt = document.createElement("option");
     60      opt.value=items[i];
     61      opt.text=items[i];
     62      options.appendChild(opt);
     63    }
     64  }
     65
     66  function makeListFromOptions(options)
     67  {
     68    list="";
     69    for(i=0;i<options.length;i++)
     70    {
     71      (i!=0)?list+=",":"";
     72      list+=options[i].value;
     73    }
     74    return(list);
     75  }
     76
     77  function addIP()
     78  {
     79    ip=isAValidIP($("#iaddblackip").val(), true);
     80
     81    if(ip==false) return(false);
     82
     83    list = $("#iblacklistedip").val()+",";
     84    if(list.indexOf(ip+",")==-1)
     85    {
     86      opt = document.createElement("option");
     87      opt.value=ip;
     88      opt.text=ip;
     89      $("#iblacklistip")[0].appendChild(opt);
     90      $("#iblacklistedip").val(makeListFromOptions($("#iblacklistip")[0].options));
     91    }
     92    $("#iaddblackip").val("");
     93    checkButtons();
     94  }
     95
     96  function delIP()
     97  {
     98    opt = $("#iblacklistip")[0];
     99
     100    i=0;
     101    while(i<opt.options.length)
     102    {
     103      if(opt.options[i].selected)
     104      {
     105        opt.removeChild(opt.options[i]);
     106      }
     107      else
     108      {
     109        i++;
     110      }
     111    }
     112    $("#iblacklistedip").val(makeListFromOptions(opt.options));
     113    checkButtons();
     114  }
     115
     116  function checkButtons()
     117  {
     118    $("#idelipbutton").attr('disabled', !($("#iblacklistip")[0].selectedIndex!=-1));
     119    $("#iaddipbutton").attr('disabled', (isAValidIP($('#iaddblackip').val(),true)==false) );
     120  }
     121
     122  function init()
     123  {
     124    makeOptionsFromList($("#iblacklistedip").val(), $("#iblacklistip")[0]);
     125
     126    $("#iaddblackip").bind("keyup focus", getIPList).bind("blur", hideIPList);
     127    p = $("#iaddblackip").offset()
     128    $("#iplist").css({
     129      left:p.left+1,
     130      top:p.top+$("#iaddblackip").outerHeight()-1
     131    });
     132    $("#iblacklistip").bind("change", checkButtons);
     133    checkButtons();
     134  }
     135
     136  function getIPList()
     137  {
     138    /*if($("#iaddblackip").val()=="")
     139    {
     140      ip="%";
     141    }
     142    else
     143    {
     144      ip=isAValidIP($("#iaddblackip").val(),false);
     145    }
     146    if(ip==false) return(false);*/
     147    ip=$("#iaddblackip").val()+"%";
     148
     149    checkButtons();
     150    $("html,input").css({cursor:"progress"});
     151    $.get("{/literal}{$datas.ajaxurl}{literal}", {
     152        ajaxfct:"astat_listip",
     153        ipfilter:ip,
     154        exclude:$("#iblacklistedip").val()
     155      },
     156      function (data)
     157      {
     158        $("#iplist").html(data).css({visibility:"visible"});
     159        $("#iipsellist")
     160          .bind("mouseover", function (event) {
     161              $("#iaddblackip").unbind("blur");
     162          } )
     163          .bind("mouseout", function (event) {
     164              $("#iaddblackip").bind("blur", hideIPList);
     165          } )
     166          .bind("blur", hideIPList)
     167          .bind("change", function (event) {
     168            $("#iaddblackip").val($("#iipsellist").val());
     169            $("#iipsellist").trigger("blur").attr("selectedIndex", -1);
     170            checkButtons();
     171            hideIPList();
     172          } ) ;
     173        $("html,input").css({cursor:"default"});
     174        $("input:text").css({cursor:"text"});
     175      }
     176    );
     177  }
     178
     179  function hideIPList()
     180  {
     181    $("#iplist").css({visibility:"hidden"});
     182  }
     183
    22184</script>
    23185{/literal}
     
    112274      <tr>
    113275        <td>{'AStat_NbIPPerPages'|@translate}</td>
    114         <td><input type="text" name="f_AStat_NpIPPerPages" value="{$datas.f_AStat_NpIPPerPages}" maxlength=4/></td>
     276        <td colspan="2"><input type="text" name="f_AStat_NpIPPerPages" value="{$datas.f_AStat_NpIPPerPages}" maxlength=4/></td>
    115277      </tr>
    116278
    117279      <tr>
    118280        <td>{'AStat_DefaultSortIP'|@translate}</td>
    119         <td>
     281        <td colspan="2">
    120282          <select name="f_AStat_DefaultSortIP">
    121283            {html_options values=$AStat_defaultsortip_list_values output=$AStat_defaultsortip_list_labels selected=$datas.AStat_defaultsortip_selected}
     
    123285        </td>
    124286      </tr>
     287
     288      <tr>
     289        <td>{'AStat_BlackListedIP'|@translate}</td>
     290        <td>
     291          <input type="text" size="15" id="iaddblackip" style="width:200px;" autocomplete="off"/>
     292          <input type="hidden" id="iblacklistedip" name="f_AStat_BlackListedIP" value="{$datas.f_AStat_BlackListedIP}"/>
     293          <div id="iplist"></div>
     294        </td>
     295        <td>
     296          <input type="button" value="{'AStat_AddIP'|@translate}" id="iaddipbutton" onclick="addIP();"/>
     297        </td>
     298      </tr>
     299      <tr>
     300        <td>&nbsp;</td>
     301        <td>
     302         <select multiple size="4" id="iblacklistip" style="width:200px;height:150px;">
     303         </select>
     304        </td>
     305        <td>
     306         <input type="button" value="{'AStat_DelIP'|@translate}" id="idelipbutton" onclick="delIP();"/>
     307        </td>
     308      </tr>
     309
     310
     311
    125312    </table>
    126313  </fieldset>
     
    190377</form>
    191378
    192 
    193 
     379<script type="text/javascript">
     380  init();
     381</script>
     382
Note: See TracChangeset for help on using the changeset viewer.