in

Dotnetpanel Forums

Community support forums for DotNetPanel products

Configuring AWStats with DNP

Last post 07-06-2006 4:15 AM by Feodor Fitsner. 0 replies.
Page 1 of 1 (1 items)
Sort Posts: Previous Next
  • 07-06-2006 4:15 AM

    Configuring AWStats with DNP

    AWStats is quite good and cost-effective solution (it's free Wink [;)]), but only when it is correctly cooked.

    We are not going to describe here how to install AWStats, because it is installed like any other Perl application and the documentation

    coming with AWStats has plenty info how to do that.

    However, the goal of this article is to show how to
    a) make AWStats showing up with http://stats.customerdomain.com and
    b) secure access to AWStats domain statistics

    Yes, default AWStats service properties page in DNP puts "http://stats.[DOMAIN_NAME]" URL pattern for viewing statistics, but this

    doesn't mean AWStats will be automatically responding on this URL. There are at least two possible ways available to make AWStats

    responding on each http://stats.customerdomain.com URL. Both methods depend on whether you have a free dedicated IP address for AWStats

    or not.

    AWStats on dedicated IP
    1. Install AWStats to a separate IIS web site.
    2. Bind AWStats web site to some dedicated IP. In IIS manager for AWStats web site you should add required IP and port (80 by default)

    on "Web Site" tab -> "Web Site Identification" region -> "Advanced..." dialog.

    2. In DNP on AWStats service properties page in "DNS Records" section add a new "stats" (or any other custom name) "A" record with

    AWStats dedicated IP in “data” field.

    Now every customer DNS zone will have that "stats" "A" record and requesting http://stats.customerdomain.com in the browser would

    opening AWStats web site.


    AWStats on a shared IP
    1. In this case AWStats can be installed in any location, say in "AWStats" virtual directory of "Default Web Site".

    2. "Stats" “A” DNS record can be also defined to point to any IP address listening by "Default Web Site" (by default it is listening

    all server IP addresses). But if you have "*" “A” record defined in WEB service you may leave without "stats" record, because all

    requests with unknown host headers (server bindings) will be served by "Default Web Site".

    In both dedicated and shared IP scenarios the next step is redirecting incoming http://stats.domain.com requests to

    http://<awstats_location>/cgi-bin/awstats.pl?config=domain.com. In order to do this you can use this simple ASP.NET script:


    <script runat="server" language="C#">
     void Page_Load()
     {
      Hashtable redirects = new Hashtable();

      // the text you want to display when the specified sub-domain was not found
      string missingText = "<h2>There is no subdomain here.</h2>";

      // Define redirects list.
      // HOW TO add redirects:
      //
      // redirects[<sub-domain name>] = new SubDomainRedirect(
      //  <page title>,
      //  <page URL> - you may use [domain] variable in the URL which will be subsituted,
      //  <true - open URL in the frame; false - perform redirect to the URL>);
      //
      //////////////////////////////////////////////////////
      
      redirects["stats"] = new SubDomainRedirect(
       "Statistics Server",
       "http://awstats.myserver.com/cgi-bin/awstats.pl?config=[domain]",
       true);
       
      redirects["mysql"] = new SubDomainRedirect(
       "PHP MyAdmin",
       "http://mysql.myserver.com",
       true);
       

      // process redirects
      string domain = Request.Url.Host;

      int dotIdx = domain.IndexOf(".");
      string subDomain = (dotIdx != -1) ? domain.Substring(0, dotIdx).ToLower() : null;

      if (subDomain == null)
      {
       // show missing text
       RenderMissingText(domain, missingText);
      }
      else if (redirects[subDomain] == null)
      {
       // show missing text
       RenderMissingText(domain, missingText);
      }
      else
      {
       SubDomainRedirect redirect = (SubDomainRedirect)redirects[subDomain];

       // subsitute domain
       redirect.Url = redirect.Url.Replace("[domain]", domain.Substring(dotIdx+1));

       if(!redirect.Framed)
        Response.Redirect(redirect.Url, true);

       string title = (redirect.Title != "") ? redirect.Title : domain;

       // show frames
       RenderFrames(title, redirect.Url);
      }
     }
     
     private void RenderMissingText(string title, string missingText)
     {
      Response.Write(String.Format(@"<html>
        <head><title>{0}</title>
        <body>
         {1}
        </body>
        </html>", title, missingText));
     }

     private void RenderFrames(string title, string url)
     {
      Response.Write(String.Format(@"<html>
        <head><title>{0}</title>
        <frameset rows=""1,*"" border=""0"">
        <frame src=""#"">
        <frame src=""{1}""></frame>
        </frameset>
        </html>", title, url));
     }

     public class SubDomainRedirect
     {
      public string Url;
      public string Title;
      public bool Framed;

      public SubDomainRedirect(string title, string url, bool framed)
      {
       this.Title = title;
       this.Url = url;
       this.Framed = framed;
      }
     }
    </script>

    Just create "Default.aspx" page, copy-paste the code and place it to “c:\inetpub\wwwroot” folder for shared IP case and to the root

    folder of AWStats web site for dedicated IP case.

    NOTE: If you use AWStats Viewer solution (http://forum.dotnetpanel.com/forums/thread/1253.aspx) you don't need this page.

    Securing AWStats
    AWStats is not secure solution by design and everybody on the Internet can view customer statistics by accessing

    http://stats.customerdomain.com. DotNetPanel team has developed a simple ASP.NET application to fill this gap.
    How to install and configure this application (as well as its binaries and sources) you can find in this article:

    http://forum.dotnetpanel.com/forums/thread/1253.aspx

    Sincerely yours,
    Feodor Fitsner, Director
    DotNetPanel - professionally developed software for hosting businesses
Page 1 of 1 (1 items)
Powered by Community Server (Commercial Edition), by Telligent Systems