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 :
- Accessing
a Linux server through Windows 8 App.
- Executing serverside scripting page (PHP) and
serverside database (MySQL) from client side language (HTML/JavaScript).
- 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');
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 {
if (isset($_REQUEST['image'])) {
$request = $_REQUEST['image'];
} else {
$request = 'awstats.pl?';
if(empty($_REQUEST['framename'])) {
$request .= "config=$site&ssl=&lang=en";
}
$request .= $_SERVER['QUERY_STRING'];
$notImage = TRUE;
}
$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) {
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);
}
echo $Output;
} ?>
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 = "demoadmin";
$password = "demopass";
$site = "xyz.com";
$server = "xyz.com";
$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.