Click here to Skip to main content
15,881,561 members
Articles / Web Development / HTML5

cStats - A cPanel Statistics Application

Rate me:
Please Sign up or sign in to vote.
5.00/5 (11 votes)
26 Jan 2013CPOL4 min read 49K   9   6
Access realtime Linux Web server statistics right away from Windows Store App

This article is an entry in our AppInnovation Contest. Articles in this sub-section are not required to be full articles so care should be taken when voting.

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 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 contain 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 needs to add more rich UI.)

Image 1

Login Page to access the app

Image 2

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
<?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
<?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 October, 2012
    • Initial Writeup Analysis and Design Phase
  • 14th October, 2012
    • Features Added (Designing phase)
      • Semantic Zoom and Multitouch
      • Check server latency through global GPS
  • 27th January, 2013
    • Lots more updates in GUI and backend moved to cloud with Windows Azure
      Success - 90%

Next Release Expected Feature

Proxy Support: Even though your Windows 8 tablet/PC is not directly connected to the internet, users can access the statistics through proxy support. (It should be in the network and the server should be in direct connection with the 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.

This application was developed by me as an internal tool for Softaculous Ltd. But after the 90% development of this application, it's 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)


Written By
Software Developer (Senior)
India India
-

Comments and Discussions

 
QuestionSite Style Pin
Olanrewaju Sideeq15-Oct-12 11:11
Olanrewaju Sideeq15-Oct-12 11:11 
AnswerRe: Site Style Pin
pepethepepe15-Oct-12 17:41
pepethepepe15-Oct-12 17:41 
As you can say porting perl/PHP server script into windows store app.

Previously i was displaying result of awstats of cPanel into Windows app.

Its been improving and working on creating a separate XML services to implement it into Windows App. Just to enhance the look and accessibility.

Let me know if you need further info. Smile | :)

GeneralMy vote of 5 Pin
Shintu Dhang14-Oct-12 16:54
professionalShintu Dhang14-Oct-12 16:54 
GeneralMy vote of 5 Pin
Alex J Jones10-Oct-12 19:46
professionalAlex J Jones10-Oct-12 19:46 
GeneralRe: My vote of 5 Pin
pepethepepe11-Oct-12 5:25
pepethepepe11-Oct-12 5:25 
GeneralMy vote of 5 Pin
priyaja12-Oct-12 6:10
priyaja12-Oct-12 6:10 

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

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