Using Log Parser: get website usage statistics.

Wednesday, 28 October 2009 16:13 by myro

Microsoft Log Parser is a great tool when it comes to parse your IIS Log files. But probably you will need something more usable than a command line program: here comes the excellent tool provided by Lizard Labs: Log Parser Lizard GUI (free edition).

With this program you can query you IIS Log using a SQL-Like syntax and export your results into excel. Using Log Parser you can obtain almost any kind of information that is incapsulated into your IIS's logs. For example if you want to know, how many Http Requests (Hits) did a particular site on your web server gets  since a certain date you can run:

SELECT  date as Data, cs-username as Utente, cs-uri-stem as Url, COUNT(cs-uri-stem) as Hits
FROM 'c:\YOUR_IIS_LOG_FOLDER\ex*.log'
WHERE (cs-uri-stem NOT LIKE '%.jpg' AND
 cs-uri-stem NOT LIKE '%.gif'  AND
 cs-uri-stem NOT LIKE '%.css' AND
 cs-uri-stem NOT LIKE '%.js'  AND
 cs-username  <> null AND
 cs-uri-stem LIKE '%/YOURSITE/YOURFOLDER/%'  AND
 date >= '2009-01-01'

)
GROUP BY Data , Utente, cs-uri-stem
ORDER BY Data, Utente, Hits

As you can see, i have excluded different file types extensions, because i'm not interested in this kind of files. If you are intersted in tracking only aspx file extensions, you should modify the query in appropriate way.

Important searcheble IIS log fields are described into this table:

Table 1: IIS Log Fields

Field Name Description Uses
Date (date) The date of the request. Event correlation.
Time (time) The UTC time of the request. Event correlation, determine time zone, identify scanning scripts.
Client IP Address
(c-ip)
The IP address of the client or proxy that sent the request. Identify user or proxy server.
User Name
(cs-username)
The user name used to authenticate to the resource. Identify compromised user passwords.
Service Name
(s-sitename)
The W3SVC instance number of the site accessed. Can verify the site accessed if the log files are later moved from the system.
Server Name
(s-computername)
The Windows host name assigned to the system that generated the log entry. Can verify the server accessed if the log files are later moved from the system.
Server IP Address
(s-ip)
The IP address that received the request. Can verify the IP address accessed if the log files are later moved from the system or if the server is moved to a new location.
Server Port
(s-port)
The TCP port that received the request. To verify the port when correlating with other types of log files.
Method
(cs-method)
The HTTP method used by the client. Can help track down abuse of scripts or executables.
URI Stem
(cs-uri-stem)
The resource accessed on the server. Can identify attack vectors.
URI Query
(cs-uri-query)
The contents of the query string portion of the URI. Can identify injection of malicious data.
Protocol Status
(sc-status)
The result code sent to the client. Can identify CGI scans, SQL injection and other intrusions.
Win32 Status
(sc-win32-status)
The Win32 error code produced by the request. Can help identify script abuse.
Bytes Sent
(sc-bytes)
The number of bytes sent to the client. Can help identify unusual traffic from a single script.
Bytes Received
(cs-bytes)
The number of bytes received from the client. Can help identify unusual traffic to a single script.
Time Taken
(time-taken)
The amount of server time, in milliseconds, taken to process the request. Can identify unusual activity from a single script.
Protocol Version
(cs-version)
The HTTP protocol version supplied by the client. Can help identify older scripts or browsers.
Host (cs-host) The contents of the HTTP Host header sent by the client. Can determine if the user browsed to the site by IP address or host name.
User Agent
(cs(User-Agent))
The contents of the HTTP User-Agent header sent by the client. Can help uniquely identify users or attack scripts.
Cookie
(cs(Cookie))
The contents of the HTTP Cookie header sent by the client. Can help uniquely identify users.
Referer
(cs(Referer))
The contents of the HTTP Referer header sent by the client. Can help identify the source of an attack or see if an attacker is using search engines to find vulnerable sites.
 

If you need more informations about Log Parsers capabilites, consider visiting: http://www.securityfocus.com/infocus/1712 

Currently rated 3.3 by 3 people

  • Currently 3.333333/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Categories:   Web
Actions:   Bookmark and Share | Permalink | Comments (0) | Comment RSSRSS comment feed

Add WaterMark to TextBox in Asp.Net: The simple way!

Sunday, 11 October 2009 17:17 by myro

There are different solutions on the web that describes how to implement a watermark over an asp.net TextBox. The solution I still prefer is just using JavaScript with  of asp.net's parser capabilities:

Into your ASPX markup page, try the solution posted below. solution:

<script type = "text/javascript">


// This Javascript is written by Peter Velichkov (www.creonfx.com)
// and is distributed under the following license : http://creativecommons.org/licenses/by-sa/3.0/
// Use and modify all you want just keep this comment. Thanks
// Defining array that holds the IDs or Names of the inputs and the default text to display
// If you are using Names remeber that I am taking only the first one.
// The format is : 'ID1','VALUE1','ID2','VALUE2'....
// var inputs = new Array('firstname','firstvalue','secondid','secondvalue','thirdid','thirdvalue')
// Defining "indexOf" function for Internet Explorer
// It returns the index of the first occurance of an item in the array


// As you can see i'm just inject the Asp.Net TextBoxes client side's IDs into the Javascript Code


var inputs = new Array('<%= txtSearchTerms.ClientID  %>','Search...','<%= txrLogin.ClientID  %>','Login...');

if (!Array.indexOf) {
    Array.prototype.indexOf = function(obj, start) {
        for (var i = (start || 0); i < this.length; i++) {
            if (this[i] == obj) {
                return i;
            }
        }
    }
}
 
// Defining addEvent function since Internet Explorer
 does not support the official way of adding events
 
function addEvent(obj, type, fn) {
    if (obj.addEventListener)
    obj.addEventListener(type, fn, false);
    else if (obj.attachEvent)
    {
        obj["e" + type + fn] = fn;
        obj[type + fn] = function() {
            obj["e" + type + fn](window.event);
        }
        obj.attachEvent("on" + type, obj[type + fn]);
    }
}
 
function inputWatermark() {
    if (inputs.length < 2 || inputs.length % 2 != 0) {
        alert('Wrong usage - please read the source comments!');
    }
    for (i = 0; i < inputs.length; i++) {
        if (i % 2 == 0 && (document.getElementById(inputs[i]) || document.getElementsByName(inputs[i])[0])) {
            var cur = (document.getElementById(inputs[i])) ? (document.getElementById(inputs[i])) : (document.getElementsByName(inputs[i])[0]);
            cur.value = inputs[i + 1];
            addEvent(cur, "focus", onFocusHandler);
            addEvent(cur, "blur", onBlurHandler);
        }
    }
}
 
function onFocusHandler() {
    var inpname = this.id ? this.id: this.name;
    if (this.value == '' || this.value == inputs[inputs.indexOf(inpname) + 1]) {
        this.value = '';
    }
}
 
function onBlurHandler() {
    var inpname = this.id ? this.id: this.name;
    if (this.value == '') {
        this.value = inputs[inputs.indexOf(inpname) + 1];
    }
}
 
addEvent(window, "load", inputWatermark);
</script>


<asp:TextBox ID="txtSearchTerms" runat="server" />
<asp:TextBox ID="txtLogin" runat="server" />

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Tags:   ,
Categories:   .NET | Web
Actions:   Bookmark and Share | Permalink | Comments (0) | Comment RSSRSS comment feed

Set default button in Asp.Net pages and in asp:login form

Saturday, 3 October 2009 15:32 by myro

Setting the default botton that needs to be pushed when the Enter key is pressed into an ASPX page, can be implemented easly in Asp.Net.
Imagine that your page holds 2 controls:

  • a Asp.net TextBox named tb1
  • a Asp.net Button named btn1

To instruct the page, to point the default button  on btn1, you should use:

Page.Form.DefaultButton = btn1.ClientID;

Setting the focus on tb1 can be accomplished by:

Page.Form.DefaultFocus = tb1.ClientID;

As you can see, you have to use control's ClientID and not  the control's ID.

But what happens if you want to set the Page's DefaultButton property to a login button contained in a Login form control? Consider surrounding the <asp:Login /> control with a simple asp.net Panel:

<asp:Panel ID="Panel1" runat="server" Height="100%" Width="100%" DefaultButton="llogin$LoginButton">
    <asp:Login ID="llogin" runat="server"
         PasswordRecoveryUrl="~/passwordrecover.aspx"
         CreateUserUrl="~/register.aspx"
         TitleTextStyle-CssClass="contentGroupHeader"
         OnLoggedIn="SetCookie"  >
    <LoginButtonStyle CssClass="button" ></LoginButtonStyle>
    </asp:Login>
</asp:Panel>

...and  set the DefaultButton property using the syntax provided in the example.

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Tags:  
Categories:   Web
Actions:   Bookmark and Share | Permalink | Comments (0) | Comment RSSRSS comment feed

Implement a Message Box to confirm an Asp.Net server control event

Tuesday, 9 June 2009 15:45 by myro

You just need to provide a simple Message box that asks for confirmation when a button is clickked? There are several ways to accomplish this, but if you don't need a complicated solution consider in adding a small javascript to the Asp.Net control on the OnClientClick attribute:

<asp:ImageButton ID="imbdelete"
         OnClientClick="return confirm('Are you sure you want to delete this configuration?');"
         runat="server" CausesValidation="false"
         ImageUrl="~/_layouts/Images/DELETE.GIF" OnClick="imbdelete_click" />

A message box will be prompted when users clicks this Imagebutton, which will raise the postback only if the 'yes' button is pressed. Cool..

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Tags:   , ,
Categories:   .NET | Web
Actions:   Bookmark and Share | Permalink | Comments (1) | Comment RSSRSS comment feed

Browser Compatibility Master Table from QuirksMode

Thursday, 30 April 2009 11:10 by myro
Building a cross-browser website is a pain in the ass, but there's someone on the the net who can help you with this job: http://www.quirksmode.org/
I fouded Peter-Paul Koch's site because I had problems developing a cross-browser javascript code and I found it really interesting and easy to understand. After a quite deep reading I can confirm what Peter-Paul says: QuirksMode.org is the prime source for browser compatibility information on the Internet.
His best project can be found in the Compatibility Master Table where you can check before your development, if your ideas will work fine on almost every browser. Probably he is right when he says: "His DOM Compatibility Tables are reliably estimated to have saved the global web developer population about € 5 million on hair transplants in 2007 alone."
I wish i founded this site earlier...

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Categories:   Web
Actions:   Bookmark and Share | Permalink | Comments (0) | Comment RSSRSS comment feed