Click here to Skip to main content
Click here to Skip to main content

cStats - A cPanel Statistics application

, 26 Jan 2013
Rate this:
Please Sign up or sign in to vote.
Access realtime Linux Web server statistics right away from Windows Store App

Introduction

cStats is a cPanel Statistics Metro Application for Windows 8. This is a Windows Store app and can be downloaded through the Windows Store directly. cPanel is a control panel for Linux servers and my aim is to access the Linux control panel from a Windows 8 installed Ultrabook.

cPanel controls all your Linux Web server environments and generates real time statistics like user visiting count, client IP tracking, top downloads tracking, total views and hits on the server, and all real time statistics which can be useful for a business to generate reports on their website success. 

Why Ultrabook for this app? For this logical question, consider the following scenario : 

  1. Accessing a Linux server through Windows 8 App.
  2. Executing serverside scripting page (PHP) and serverside database (MySQL) from client side language (HTML/JavaScript).
  3. Server administrators need to get server statistics faster, efficiently, and anywhere on the go while on a long vacation too.

All this can be possible done through a lighter,  faster, smarter device which can't be other than Ultrabooks. With some simple touch and swipe, your real time data is on the screen. 

The other primary aim of this app is to provide a very rich graphical UI which will contains data integrated charts, graphs, etc., which can be further normalized via the power of Ultrabook's touch interface or Shake UI.

This application also collects real time geographical access location of a system administrator from where he is accessing the server. 

(Below are the screenshots of the current development. It is still in 50% stage and need to add more rich UI.) 

(Login Page to access the app)

 

(Front page Statistics) 

Background    

Traditionally, if a server administrator wants to access the statistics of a web server, then they have to access the control panel and view the statistics. Visiting the control panel and accessing real time data can be done through the production server in a controlled environment. 

Nowadays server administrators need a friendly environment and an easy to use device. Accessibility and a user friendly environment is a key aspect of any application. Easy user interface, touch, swipe from Ultrabooks are always better than bulky laptops and server statistics devices. 

Using the code

This Windows 8 app, which is basically coded in HTML, javascript, access server side page which will be stored in Linux server, there will be 3 layers in between the user and the data.

Layer 1: User

Layer 2:  Client side page (Windows 8 Metro App)  

Layer 3: Server side page (PHP) 

Layer 4: Statistics database.  

The server-side PHP page will be connected with the Statistics database which continually collects real time stats from the database. I have used "'awstats" which is a pre-built API for the Linux control panel.

Below is the PHP access page of 'awstats' which I have coded. 

<?php
require ('config.php');

// check for valid auth user
if (!isset($_SERVER['PHP_AUTH_USER']) || $_SERVER['PHP_AUTH_USER'] != $username || $_SERVER['PHP_AUTH_PW'] != $password) {
    header('WWW-Authenticate: Basic realm="Site Statistics"');
    header('HTTP/1.0 401 Unauthorized');
    echo 'Authorization Required.';
    exit;
} else {
    // only processed if we have a valid user

    if (isset($_REQUEST['image'])) {
        // if an image is requested, we only need the filename
        $request = $_REQUEST['image'];
    } else {
        // otherwise we build our query to cPanel
        $request = 'awstats.pl?';

        // if we're not requesting a specific frame,
        // we don't have our site set yet, so add that info
        if(empty($_REQUEST['framename'])) {
            $request .= "config=$site&ssl=&lang=en";
        }
        $request .= $_SERVER['QUERY_STRING'];

        // just used to simplify the test later
        $notImage = TRUE;
    } // end if image

    $Curl = curl_init();

    curl_setopt($Curl, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($Curl, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($Curl, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($Curl, CURLOPT_URL, "https://$server:2083/".$request);
    curl_setopt($Curl, CURLOPT_USERPWD, $cpanelusername.':'.$cpanelpassword);

    $Output = curl_exec($Curl);

    if (curl_errno($Curl) > 0) {
        echo 'Curl Error: ' . curl_error($Curl);
        curl_close($Curl);
        exit;
    }

    curl_close($Curl);

    if($notImage) {
        // let's do some parsing to replace paths with ones that work with our proxy script
        if (empty($_REQUEST['framename']) || $_REQUEST['framename'] == 'index') {
            $Output = str_replace('src="', 'src="'.$_SERVER['PHP_SELF'].'?', $Output);
        } else {
            $Output = str_replace('src="http://www.codeproject.com/', 'src="'.$_SERVER['PHP_SELF'].'?image=', $Output);
        }

        $Output = str_replace('<form', '<form method="get"', $Output);
        $Output = str_replace('action="', 'action="'.$_SERVER['PHP_SELF'].'?', $Output);
        $Output = str_replace('href="', 'href="'.$_SERVER['PHP_SELF'].'?', $Output);
        $Output = str_replace('href="'.$_SERVER['PHP_SELF'].'?https://', 'href="https://', $Output);
        $Output = str_replace('awstats.pl?', '', $Output);
    } // end if notImage

    echo $Output;
} // end if valid user
?>

This needs the Configuration data which is included in the above script. All the cPanel credentials are stored in the configuration page as below: config.php

<?php
// username and password used to grant access to view stats pages
$username = "demoadmin";
$password = "demopass";

// domain name (including subdomain) that you want stats for
$site = "xyz.com";

// whm/cpanel hostname
$server = "xyz.com";

// cpanel usename and password
$cpanelusername = "cpaneladmin";
$cpanelpassword = 'cpanelpass';
?>

Place both scripts into a directory of the cPanel enabled Linux server and access the page. It will display the real time server statistics in a single page. 

At this point, all the server configuration access parts are complete. Now I have to access the data generated from the above script into a Windows 8 Metro app with rich UI and controls. 

Client side coding still needs to be done which will be in the Windows 8 Store HTML/JavaScript app. 

History

2nd Oct '12 - Initial Writeup. (Analysis and Design Phase) 

14th  Oct '12 - Features Added (Designing phase)

  • Semantic Zoom and Multitouch. 
  • Check server latency through global GPS.   

01/27/2013 - Lots more update in GUI and backend moved to cloud with Windows Azure. 

Success - 90%   

 

Next Release Expected Feature : 

Proxy Support : Eventhough if your Windows 8 tablet/PC is not directly connected to internet, users can access the statistics through proxy support. (It should be in network and the server should be in direct connection with Internet.)

Points of Interest  

The most important thing which excites me about this app is accessing server side page located in Linux server from Client side page in Windows 8 Metro App.

The 50% working module of this app has cleared the "Microsoft App Excellence Lab" organised in Windows 8 AppFest, Bangalore. http://blogs.windows.com/windows/b/bloggingwindows/archive/2012/09/21/windows-8-appfest-an-18-hour-coding-marathon-windows8appfest.aspx 

This Application was developed by me as an internal tool for Softaculous Ltd. But after the 90% development  of this application, its going to be published through Winspark Network

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Rahul Vijay Manekari
Software Developer (Senior) Softaculous Ltd.
India India
A curious techie who like to legwork on various technology gadgets and software. A software Developer by profession and a blogger by his likeness. IT Graduate, Ex Microsoft Student partner, Microsoft India Rockstar and an official writer at Technorati and currently owning Winspark Network : http://winspark.net
Follow on   Twitter   Google+

Comments and Discussions

 
QuestionSite Style PinmemberOlanrewaju Sideeq15-Oct-12 11:11 
AnswerRe: Site Style PinmemberRahul Vijay Manekari15-Oct-12 17:41 
GeneralMy vote of 5 PinmemberShintu Dhang14-Oct-12 16:54 
GeneralMy vote of 5 PinmemberPurpleDonutGames10-Oct-12 19:46 
GeneralRe: My vote of 5 PinmemberRahul Vijay Manekari11-Oct-12 5:25 
GeneralMy vote of 5 Pinmemberpriyaja12-Oct-12 6:10 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web03 | 2.8.140827.1 | Last Updated 26 Jan 2013
Article Copyright 2012 by Rahul Vijay Manekari
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid