Adding scripts

 

Having created all the required tables, we will now add the scripts.

  1. Download example_php_files.zip, open it and then extract events.php and light_viewer.php into the C:\xampp\htdocs\example folder.
    To view the source of events.php, see bellow on this page.
    To view the source of light_viewer.php, see bellow on this page.
  2. Extract and copy the following file -> light_show.tpl into the C:\xampp\htdocs\smarty\templates folder: light_show.tpl.zip
  3. Open events.php file in the C:\xampp\htdocs\example folder and set $host to the approriate address for your case.
  4. Open light_viewer.php file in the C:\xampp\htdocs\example folder and set $host to the approriate address for your case.

 

You have now prepared everything on the web server. Write down the IP address of this web server, you will need.


Source code

events.php

<?php
// prepare parameters to make a connection to our database...
// replace with the appropriate host address
$host = "172.16.118.56";

// replace mysql with the appropriate database type:
// mysql, postgres7, ibase, mssql, borland_ibase, firebird, mssqlpo, maxsql,
// oci8, oci805, oci8po, postgres, oracle, postgres64, sybase
$dbserver = 'mysql';

// replace with the appropriate username
$user = "isltest";

// replace with the appropriate password
$password = "isltest";

// replace with the appropriate database
$database = "isltest";

include_once 'adodb/adodb-errorpear.inc.php';
include_once 'adodb/adodb.inc.php';
include_once 'adodb/tohtml.inc.php';

$db = ADONewConnection($dbserver);
@$db--->Connect($host, $user, $password, $database);

// *** ISL Light event handler ***
if ("ISL_LIGHT" == $_POST["MODULE"]) {
    // define some temp variables that are obtained from POST
    $light_event = $_POST['EVENT'];
    $light_sessionid = $_POST['SESSIONID'];
    $light_timestamp = $_POST['TIMESTAMP'];
    $light_serverid = $_POST['SERVERID'];
    $light_deskversion = $_POST['deskVersion'];
    $light_clientversion = $_POST['clientVersion'];
    $light_cpuserdomain = $_POST['CPUSER_DOMAIN'];
    $light_cpusername = $_POST['CPUSER_NAME'];
    $light_createdtime = $_POST['createdTime'];
    $light_deskcode = $_POST['deskCode'];
    $light_deskaddress = $_POST['deskAddress'];
    $light_clientaddress = $_POST['clientAddress'];
    $light_starttime = $_POST['startTime'];
    $light_totalconnectiontime = $_POST['totalConnectionTime'];
    $light_totaltransferredbytes = $_POST['totalTransferredBytes'];
    $light_lasttransferredpackettime = $_POST['lastTransferredPacketTime'];
    $light_maxlasttransferredpackettime = $_POST['lastTransferredPacketTime'];
    $light_maxtotaltransferredbytes = $_POST['totalTransferredBytes'];

    // put all key-value pairs into a string {{key1,value1},...,{keyn,valuen}}
    $array = $_POST;
    $fields = "{";
    foreach ($array as $key => $value) {
        $fields .= "{" . $key . "," . $value . "}";
    }
    $fields .= "}";
    $inserted_date = date("Y-m-d");
    $result = $db->Execute("INSERT INTO sessions_events (cpg_session_ident, event_type_code, fields, inserted_date, event_date) VALUES ('$light_sessionid', '$light_event', '$fields', '$inserted_date', '$light_timestamp')");
    if (!is_object($result)) {
        $e = ADODB_Pear_Error();
    }

    $array = $_POST;
    foreach ($array as $key => $value) {
        $result = $db->Execute("INSERT INTO sessions_rawdata (cpg_session_ident, event_name, key_name, key_value) VALUES ('$light_sessionid', '$light_event', '$key', '$value')");
        if (!is_object($result)) {
            $e = ADODB_Pear_Error();
        }
    }

    // In the next section we check if there exists an entry with the current SESSIONID.
    // If yes, we get its current status code; otherwise, we create a new entry.
    $result = $db->Execute("SELECT status_code FROM light_sessions WHERE cpg_session_ident='$light_sessionid'");
    if (!is_object($result)) {
        $e = ADODB_Pear_Error();
    }
    $status = $result->fields[0];
    if (!$status) {
        // *** SQL command to execute ***
        $result = $db->Execute("INSERT INTO light_sessions (cpg_server_id, cpg_session_ident, status_code) VALUES ('$light_serverid', '$light_sessionid', 'EMPTY')");
        if (!is_object($result)) {
            $e = ADODB_Pear_Error();
        }
        $status = "EMPTY";
    }

    // We now have the current status for this session and we know which event confproxy reported.
    // It is all we need to get the new status code from our transition table:
    $result = $db->Execute("SELECT new_status_code FROM session_event_to_status WHERE status_code='$status' AND event_type_code='$light_event'");

    if (!is_object($result)) {
        $e = ADODB_Pear_Error();
    }
    $new_status = $result->fields[0];

    if (!$new_status) {
        // Error that should never occur, because we have every possible status transition covered in the table!
    } else {
        switch ($light_event) {
            case "NEWSESSION":
                $result = $db->Execute("UPDATE light_sessions SET desk_version='$light_deskversion', cpg_server_id='$light_serverid', cpg_user_domain_name='$light_cpuserdomain', cpg_user_name='$light_cpusername', created_date='$light_createdtime', session_code='$light_deskcode', status_code='$new_status' WHERE cpg_session_ident='$light_sessionid'");
                break;
            case "START":
                $result = $db->Execute("UPDATE light_sessions SET desk_ip='$light_deskaddress', client_ip='$light_clientaddress', start_time='$light_starttime', status_code='$new_status' WHERE cpg_session_ident='$light_sessionid'");
                break;
            case "STOP":
                $result = $db->Execute("UPDATE light_sessions SET total_connection_time='$light_totalconnectiontime', total_transferred_bytes='$light_totaltransferredbytes', last_transferred_packet_time='$light_lasttransferredpackettime', client_version='$light_clientversion', stop_time='$light_timestamp', status_code='$new_status', max_last_transferred_packet_time='$light_maxlasttransferredpackettime', max_total_transferred_bytes='$light_maxtotaltransferredbytes' WHERE cpg_session_ident='$light_sessionid'");
                break;
            default:
                $result = $db->Execute("UPDATE light_sessions SET status_code='$new_status' WHERE cpg_session_ident='$light_sessionid'");
                break;
        }
        if (!is_object($result)) {
            $e = ADODB_Pear_Error();
        }
    }
}

// close the database connection
@$db->Close();

// Reply needed for ISL Conference Proxy
echo "";
?>


light_viewer.php

<?php
// load Smarty library
require('Smarty.class.php');

// set Smarty parameters
$smarty = new Smarty;
$smarty->template_dir = 'C:/xampp/htdocs/smarty/templates';
$smarty->config_dir = 'C:/xampp/htdocs/smarty/config';
$smarty->cache_dir = 'C:/xampp/smarty/cache';
$smarty->compile_dir = 'C:/xampp/smarty/templates_c';
// IMPORTANT: set force_compile to false for non-development use!
$smarty->force_compile = true;
$smarty->assign('process_tables', 0);

if (isset($_GET['submit'])) {
    //var_dump($_GET);
    //echo '<br><br>';
    // prepare parameters to make a connection to our database...
    // replace with the appropriate host address
    $host = "172.16.118.56";
    // replace mysql with the appropriate database type:
    // mysql, postgres7, ibase, mssql, borland_ibase, firebird, mssqlpo, maxsql,
    // oci8, oci805, oci8po, postgres, oracle, postgres64, sybase
    $dbserver = 'mysql';
    // replace with the appropriate username
    $user = "isltest";
    // replace with the appropriate password
    $password = "isltest";
    // replace with the appropriate database
    $database = "isltest";

    include_once 'adodb/adodb-errorpear.inc.php';
    include_once 'adodb/adodb.inc.php';
    include_once 'adodb/tohtml.inc.php';
    $db = ADONewConnection($dbserver);
    $db->SetFetchMode(ADODB_FETCH_ASSOC);
    @$db->Connect($host, $user, $password, $database);

    // prepare conditions that are going to be used in the SELECT query
    $query_conditions = array();
    if (!empty($_GET['from_year']) && !empty($_GET['from_month']) && !empty($_GET['from_day'])) {
        $from_timestamp = mktime($_GET['from_hour'], $_GET['from_minute'], 00, $_GET['from_month'], $_GET['from_day'], $_GET['from_year']);
        $query_conditions[] = "created_date>=" . $from_timestamp;
    }
    if (!empty($_GET['to_year']) && !empty($_GET['to_month']) && !empty($_GET['to_day'])) {
        $to_timestamp = mktime($_GET['to_hour'], $_GET['to_minute'], 00, $_GET['to_month'], $_GET['to_day'], $_GET['to_year']);
        $query_conditions[] = "created_date<=" . $to_timestamp;
    }
    if (!empty($_GET['domain'])) {
        $query_conditions[] = "cpg_user_domain_name='" . $_GET['domain'] . "'";
    }
    if (!empty($_GET['user'])) {
        $query_conditions[] = "cpg_user_name='" . $_GET['user'] . "'";
    }

    $query_conditions_string = "";
    $query_conditions_string_old = "";
    foreach ($query_conditions as $key => $value) {
        $query_conditions_string_old = $query_conditions_string;
        $query_conditions_string .= $value . " AND ";
        $query_conditions_string_old .= $value;
    }

    $query_conditions_string = $query_conditions_string_old;
    echo '<b>query_conditions_string:</b><br>';
    echo $query_conditions_string;
    echo '<br><br>';

    if (empty($query_conditions_string)) {
        $result = $db->Execute("SELECT cpg_session_ident AS 'id', created_date AS 'created', session_code AS 'code', cpg_user_domain_name AS 'domain', cpg_user_name AS 'user', status_code AS 'status', start_time AS 'start time', total_connection_time AS 'length', total_transferred_bytes AS 'bytes', cpg_server_id AS 'server', desk_version AS 'desk ver', desk_ip AS 'desk ip', client_version AS 'client ver', client_ip AS 'client ip' FROM light_sessions");
    } else {
        $result = $db->Execute("SELECT cpg_session_ident AS 'id', created_date AS 'created', session_code AS 'code', cpg_user_domain_name AS 'domain', cpg_user_name AS 'user', status_code AS 'status', start_time AS 'start time', total_connection_time AS 'length', total_transferred_bytes AS 'bytes', cpg_server_id AS 'server', desk_version AS 'desk ver', desk_ip AS 'desk ip', client_version AS 'client ver', client_ip AS 'client ip' FROM light_sessions WHERE $query_conditions_string");
    }
    if (!is_object($result)) {
        $e = ADODB_Pear_Error();
    }
    $result_array = $result->GetArray();

    // handling the case when there are no results
    if ($result_array) {
        $smarty->assign('show_results', 1);
    } else {
        $smarty->assign('show_results', 0);
    }
    // store all column names in an array
    $field_names = array();
    for ($i = 0, $max = $result->FieldCount(); $i < $max; $i++) {
        $cur_field = $result->FetchField($i);
        $field_names[$i] = $cur_field->name;
    }

    // store all column types in an array
    $field_types = array();
    for ($i = 0, $max = $result->FieldCount(); $i < $max; $i++) {
        $cur_field = $result->FetchField($i);
        $field_types[$i] = $result->MetaType($cur_field->type);
    }

    $smarty->assign('field_names', $field_names);
    $smarty->assign('field_types', $field_types);
    $smarty->assign('search_result', $result_array);
    $smarty->assign('process_tables', 1);
}
$smarty->assign('year', Date("Y"));
$smarty->assign('month', Date("m"));
$smarty->assign('day', Date("d"));
$smarty->assign('hour', date("G"));
$smarty->assign('minute', date("i"));
$smarty->display('light_show.tpl');
?>

Was this article helpful?