Find this useful? Enter your email to receive occasional updates for securing PHP code.

Signing you up...

Thank you for signing up!

PHP Decode

<?php namespace Backend\Router\Controllers\Session; use Backend\Configuration; use ..

Decoded Output download

<?php 
 
namespace Backend\Router\Controllers\Session; 
 
use Backend\Configuration; 
use Backend\Constants; 
use Backend\Logger; 
use Backend\Sources\ChatReader; 
use DateTime; 
 
/** 
 * global search and list of sessions 
 */ 
class GlobalSearchController extends ASessionController 
{ 
    protected string $ROW_NUMBERS = "50"; 
 
    protected string $sqlFinalEnvelope = <<<EOF 
select MEDIUM, CONNID, SESSIONID, TIMESTAMP 
from (%s) a 
order by timestamp 
fetch first 100 rows only 
EOF; 
 
    /** 
     * expect: date start, env, date end limit and ROW number 
     * @var string sql for voice 
     */ 
    protected string $sqlVoiceEnvelope = <<<EOF 
voice as (select 'voice'                                            as medium, 
          CONNID, 
          LISTAGG(SESSIONID, ',') WITHIN GROUP (ORDER BY SESSIONID) as SESSIONID, 
          to_char(min(BEGIN_TSTAMP), 'YYYY-MM-DD HH24:MI:SS.ff')    as TIMESTAMP 
   from THINIVRSESSION 
   where BEGIN_TSTAMP >= TO_TIMESTAMP('%s', 'YYYY-MM-DD HH24:MI:SS') 
     and BEGIN_TSTAMP < TO_TIMESTAMP('%s', 'YYYY-MM-DD HH24:MI:SS') 
     and ENV = '%s' 
     %s 
   group by CONNID 
   order by timestamp 
       fetch first %s rows only) 
EOF; 
 
    /** 
     * expect: date start, date end additional limit and ROW number 
     * @var string sql for chat 
     */ 
    protected string $sqlChatEnvelope = <<<EOF 
chat as (select 'chat'                                                               as medium, 
         KEYCONNID                                                                  as connid, 
         SESSIONID, 
         to_char(min(TIMESTAMP + INTERVAL '60' MINUTE), 'YYYY-MM-DD HH24:MI:SS.ff') as timestamp 
  from GCCAILOGS 
  where TIMESTAMP >= TO_TIMESTAMP('%s', 'YYYY-MM-DD HH24:MI:SS') - INTERVAL '60' MINUTE 
    and TIMESTAMP < TO_TIMESTAMP('%s', 'YYYY-MM-DD HH24:MI:SS') - INTERVAL '60' MINUTE 
    and KEYCONNID like '1%%' 
    %s 
  group by SESSIONID, KEYCONNID --- sessionid connect to google 
  order by TIMESTAMP 
      fetch first %s rows only) 
EOF; 
 
    /** 
     * expect: date start, date end limit, env, additional limits and ROW number 
     * @var string sql for mcse 
     */ 
    protected string $sqlMcseEnvelope = <<<EOF 
mcse as (select 'mcse'                                          as medium, 
         SESSIONID                                              as connid, 
         SESSIONID, 
         to_char(min(BEGIN_TSTAMP), 'YYYY-MM-DD HH24:MI:SS.ff') as timestamp 
  from MCSESESSION 
  where SESSIONID like '%%-%%' 
    and BEGIN_TSTAMP >= TO_TIMESTAMP('%s', 'YYYY-MM-DD HH24:MI:SS') 
    and BEGIN_TSTAMP < TO_TIMESTAMP('%s', 'YYYY-MM-DD HH24:MI:SS') 
    and ENV = '%s' 
    %s 
  group by SESSIONID 
  ORDER BY timestamp 
      fetch first %s rows only) 
EOF; 
 
    function __construct() 
    { 
        parent::__construct("", false, true, false, false); 
        $this->sql = $this->sqlFinalEnvelope; 
    } 
 
    /** 
     * @inheritDoc 
     */ 
    function formatSql(): string 
    { 
        // if date missing use now - 1 hour 
        $startDate = $this->getDate("startDate", (new DateTime())->sub(new \DateInterval("PT1H"))); 
        $endDate = $this->getDate("endDate", new DateTime()); 
        // limitations 
        $limitStart = $startDate->format("Y-m-d H:i:s"); 
        $limitEnd = $endDate->format("Y-m-d H:i:s"); 
        $media = strtolower($this->readMedia() ?? ""); 
        $freeText = trim($this->readFreeText() ?? ""); 
        $environment = $this->readEnv(); 
        $sessionId = $this->readSessionId(); 
        $kvpName = $this->readKvpName(); 
        $kvpValue = $this->readKvpValue(); 
        $freeIds = []; 
        if (strlen($freeText) > 0) { 
            $envServer = Constants::CHAT_SERVER_PROD; 
            if ($environment == "U") { 
                $envServer = Constants::CHAT_SERVER_UAT; 
            } 
            $curl = new ChatReader($envServer); 
            $read = $curl->searchText($startDate, $endDate, $freeText); 
            if ($curl->getLastMessage() == "") { 
                $freeIds = $curl->listRelevantData($read); 
            } 
        } 
        $sql = $this->formatSqlDetail($limitStart, $limitEnd, $media, $sessionId, $kvpName, $kvpValue, $environment, $freeText, $freeIds); 
        Logger::Debug(sprintf("Parameters: start=%s, end=%s, medium=%s, sessionId=%s, kvpName=%s, kvpValue=%s, env=%s, free=%s, ids=%s", 
            $limitStart, $limitEnd, $media, $sessionId, $kvpName, $kvpValue, $environment, $freeText, ", " . join($freeIds))); 
        return $sql; 
    } 
 
    public function formatSqlDetail( 
        string $limitStart, string $limitEnd, string $media, string $sessionId, string $kvpName, string $kvpValue, 
        string $environment, string $freeText, array $freeIds 
    ): string 
    { 
        $startSql = "with "; 
        $innerSelect = ""; 
        $chat = ""; 
        $voice = ""; 
        $mcse = ""; 
        if ($media == "" || $media == "voice") { 
            $otherWhere = $this->voiceWhere($sessionId, $kvpName, $kvpValue, $freeText, $freeIds); 
            $voice = sprintf($this->sqlVoiceEnvelope, $limitStart, $limitEnd, $environment, $otherWhere, $this->ROW_NUMBERS); 
            if ($media == "voice") { 
                return $voice; 
            } 
            $voice = $startSql . $voice; 
            $startSql = ", " . PHP_EOL; 
            $innerSelect .= "select * from voice" . PHP_EOL; 
        } 
        if ($media == "" || $media == "chat") { 
            $otherWhere = $this->chatWhere($sessionId, $kvpName, $kvpValue, $freeText, $freeIds); 
            $chat = sprintf($this->sqlChatEnvelope, $limitStart, $limitEnd, $otherWhere, $this->ROW_NUMBERS); 
            if ($media == "chat") { 
                return $chat; 
            } 
            $chat = $startSql . $chat; 
            $startSql = ", " . PHP_EOL; 
            if (strlen($innerSelect) > 0) { 
                $innerSelect .= "union all" . PHP_EOL; 
            } 
            $innerSelect .= "select * from chat" . PHP_EOL; 
        } 
        if ($media == "" || $media == "mcse only") { 
            $otherWhere = $this->mcseWhere($sessionId, $kvpName, $kvpValue, $freeText, $freeIds); 
            $mcse = sprintf($this->sqlMcseEnvelope, $limitStart, $limitEnd, $environment, $otherWhere, $this->ROW_NUMBERS); 
            if ($media == "mcse") { 
                return $mcse; 
            } 
            $mcse = $startSql . $mcse; 
            if (strlen($innerSelect) > 0) { 
                $innerSelect .= "union all" . PHP_EOL; 
            } 
            $innerSelect .= "select * from mcse" . PHP_EOL; 
        } 
        return $voice .$chat .  $mcse . sprintf($this->sqlFinalEnvelope, $innerSelect); 
    } 
 
    function chatWhere(string $sessionId, string $kvpName, string $kvpValue, string $freeText, array $freeIds): string 
    { 
        $ret = ""; 
        if ($sessionId !== "") { 
            $ret = " AND (keyconnid = '" . $sessionId . "' OR  sessionid = '" . $sessionId . "')"; 
        } 
        if (strlen($freeText) > 0) { 
            if (count($freeIds) > 0) { 
                $list = implode(",", array_map(function ($x) { 
                    return "'$x'"; 
                }, $freeIds)); 
                $ret .= " AND (keyconnid in ($list) or sessionid in ($list))"; 
            } else { 
                $ret .= " AND sessionid ='NA'"; 
            } 
        } 
        if (strlen($kvpName) > 0 && strlen($kvpValue) > 0) { 
            $ret .= " AND (keyconnid in (select SESSIONID from searchkvp where key = '" . $kvpName . "' and value = '" . $kvpValue . "' and sessionid like '1%%') " . PHP_EOL 
                . "or sessionid in (select SESSIONID from searchkvp where key = '" . $kvpName . "' and value = '" . $kvpValue . "'))"; 
        } 
        return $ret; 
    } 
 
    function voiceWhere(string $sessionId, string $kvpName, string $kvpValue, string $freeText, array $freeIds): string 
    { 
        $ret = ""; 
        if ($sessionId !== "") { 
            $ret = " AND (sessionid = '$sessionId' or connid = '$sessionId')"; 
        } 
        if (strlen($freeText) > 0) { 
            if (count($freeIds) > 0) { 
                $list = implode(",", array_map(function ($x) { 
                    return "'$x'"; 
                }, $freeIds)); 
                $ret .= " AND (connid in ($list) or sessionid in ($list))"; 
            } else { 
                $ret .= " AND sessionid ='NA'"; 
            } 
        } 
 
        if (strlen($kvpName) > 0 && strlen($kvpValue) > 0) { 
            $ret .= " and (CONNID in (select SESSIONID from SEARCHKVP where KEY = '" . $kvpName . "' and VALUE = '" . $kvpValue . "') " . PHP_EOL 
                . "or SESSIONID in (select SESSIONID from SEARCHKVP where KEY = '" . $kvpName . "' and VALUE = '" . $kvpValue . "'))"; 
        } 
        return $ret; 
    } 
 
    function mcseWhere(string $sessionId, string $kvpName, string $kvpValue, string $freeText, array $freeIds): string 
    { 
        $ret = ""; 
        if ($sessionId !== "") { 
            $ret = " AND (sessionid = '" . $sessionId . "')"; 
        } 
        if (strlen($kvpName) > 0 && strlen($kvpValue) > 0) { 
            $ret .= " AND (sessionid in (select SESSIONID from searchkvp where key = '" . $kvpName . "' and value = '" . $kvpValue . "' and sessionid like '1%%') " . PHP_EOL 
                . "or sessionid in (select SESSIONID from searchkvp where key = '" . $kvpName . "' and value = '" . $kvpValue . "'))"; 
        } 
        return $ret; 
    } 
 
 
    function requestName(): string 
    { 
        return "Global search"; 
    } 
 
    /** 
     * @inheritDoc 
     */ 
    function reformatArrayNames(mixed $data): mixed 
    { 
        if ($data == null || !is_array($data)) { 
            return []; 
        } 
        $return = []; 
        foreach ($data as $row) { 
            $newRow = []; 
            $newRow["medium"] = $this->getDatFromRowOrEmpty($row, "MEDIUM"); 
            $newRow["connId"] = $this->getDatFromRowOrEmpty($row, "CONNID"); 
            $newRow["sessionId"] = $this->getDatFromRowOrEmpty($row, "SESSIONID"); 
            $newRow["timestamp"] = $this->getDatFromRowOrEmpty($row, "TIMESTAMP"); 
            $newRow["chatError"] = $this->getDatFromRowOrEmpty($row, "CHAT_ERROR"); 
            $return[] = $newRow; 
        } 
        return $return; 
    } 
} ?>

Did this file decode correctly?

Original Code

<?php

namespace Backend\Router\Controllers\Session;

use Backend\Configuration;
use Backend\Constants;
use Backend\Logger;
use Backend\Sources\ChatReader;
use DateTime;

/**
 * global search and list of sessions
 */
class GlobalSearchController extends ASessionController
{
    protected string $ROW_NUMBERS = "50";

    protected string $sqlFinalEnvelope = <<<EOF
select MEDIUM, CONNID, SESSIONID, TIMESTAMP
from (%s) a
order by timestamp
fetch first 100 rows only
EOF;

    /**
     * expect: date start, env, date end limit and ROW number
     * @var string sql for voice
     */
    protected string $sqlVoiceEnvelope = <<<EOF
voice as (select 'voice'                                            as medium,
          CONNID,
          LISTAGG(SESSIONID, ',') WITHIN GROUP (ORDER BY SESSIONID) as SESSIONID,
          to_char(min(BEGIN_TSTAMP), 'YYYY-MM-DD HH24:MI:SS.ff')    as TIMESTAMP
   from THINIVRSESSION
   where BEGIN_TSTAMP >= TO_TIMESTAMP('%s', 'YYYY-MM-DD HH24:MI:SS')
     and BEGIN_TSTAMP < TO_TIMESTAMP('%s', 'YYYY-MM-DD HH24:MI:SS')
     and ENV = '%s'
     %s
   group by CONNID
   order by timestamp
       fetch first %s rows only)
EOF;

    /**
     * expect: date start, date end additional limit and ROW number
     * @var string sql for chat
     */
    protected string $sqlChatEnvelope = <<<EOF
chat as (select 'chat'                                                               as medium,
         KEYCONNID                                                                  as connid,
         SESSIONID,
         to_char(min(TIMESTAMP + INTERVAL '60' MINUTE), 'YYYY-MM-DD HH24:MI:SS.ff') as timestamp
  from GCCAILOGS
  where TIMESTAMP >= TO_TIMESTAMP('%s', 'YYYY-MM-DD HH24:MI:SS') - INTERVAL '60' MINUTE
    and TIMESTAMP < TO_TIMESTAMP('%s', 'YYYY-MM-DD HH24:MI:SS') - INTERVAL '60' MINUTE
    and KEYCONNID like '1%%'
    %s
  group by SESSIONID, KEYCONNID --- sessionid connect to google
  order by TIMESTAMP
      fetch first %s rows only)
EOF;

    /**
     * expect: date start, date end limit, env, additional limits and ROW number
     * @var string sql for mcse
     */
    protected string $sqlMcseEnvelope = <<<EOF
mcse as (select 'mcse'                                          as medium,
         SESSIONID                                              as connid,
         SESSIONID,
         to_char(min(BEGIN_TSTAMP), 'YYYY-MM-DD HH24:MI:SS.ff') as timestamp
  from MCSESESSION
  where SESSIONID like '%%-%%'
    and BEGIN_TSTAMP >= TO_TIMESTAMP('%s', 'YYYY-MM-DD HH24:MI:SS')
    and BEGIN_TSTAMP < TO_TIMESTAMP('%s', 'YYYY-MM-DD HH24:MI:SS')
    and ENV = '%s'
    %s
  group by SESSIONID
  ORDER BY timestamp
      fetch first %s rows only)
EOF;

    function __construct()
    {
        parent::__construct("", false, true, false, false);
        $this->sql = $this->sqlFinalEnvelope;
    }

    /**
     * @inheritDoc
     */
    function formatSql(): string
    {
        // if date missing use now - 1 hour
        $startDate = $this->getDate("startDate", (new DateTime())->sub(new \DateInterval("PT1H")));
        $endDate = $this->getDate("endDate", new DateTime());
        // limitations
        $limitStart = $startDate->format("Y-m-d H:i:s");
        $limitEnd = $endDate->format("Y-m-d H:i:s");
        $media = strtolower($this->readMedia() ?? "");
        $freeText = trim($this->readFreeText() ?? "");
        $environment = $this->readEnv();
        $sessionId = $this->readSessionId();
        $kvpName = $this->readKvpName();
        $kvpValue = $this->readKvpValue();
        $freeIds = [];
        if (strlen($freeText) > 0) {
            $envServer = Constants::CHAT_SERVER_PROD;
            if ($environment == "U") {
                $envServer = Constants::CHAT_SERVER_UAT;
            }
            $curl = new ChatReader($envServer);
            $read = $curl->searchText($startDate, $endDate, $freeText);
            if ($curl->getLastMessage() == "") {
                $freeIds = $curl->listRelevantData($read);
            }
        }
        $sql = $this->formatSqlDetail($limitStart, $limitEnd, $media, $sessionId, $kvpName, $kvpValue, $environment, $freeText, $freeIds);
        Logger::Debug(sprintf("Parameters: start=%s, end=%s, medium=%s, sessionId=%s, kvpName=%s, kvpValue=%s, env=%s, free=%s, ids=%s",
            $limitStart, $limitEnd, $media, $sessionId, $kvpName, $kvpValue, $environment, $freeText, ", " . join($freeIds)));
        return $sql;
    }

    public function formatSqlDetail(
        string $limitStart, string $limitEnd, string $media, string $sessionId, string $kvpName, string $kvpValue,
        string $environment, string $freeText, array $freeIds
    ): string
    {
        $startSql = "with ";
        $innerSelect = "";
        $chat = "";
        $voice = "";
        $mcse = "";
        if ($media == "" || $media == "voice") {
            $otherWhere = $this->voiceWhere($sessionId, $kvpName, $kvpValue, $freeText, $freeIds);
            $voice = sprintf($this->sqlVoiceEnvelope, $limitStart, $limitEnd, $environment, $otherWhere, $this->ROW_NUMBERS);
            if ($media == "voice") {
                return $voice;
            }
            $voice = $startSql . $voice;
            $startSql = ", " . PHP_EOL;
            $innerSelect .= "select * from voice" . PHP_EOL;
        }
        if ($media == "" || $media == "chat") {
            $otherWhere = $this->chatWhere($sessionId, $kvpName, $kvpValue, $freeText, $freeIds);
            $chat = sprintf($this->sqlChatEnvelope, $limitStart, $limitEnd, $otherWhere, $this->ROW_NUMBERS);
            if ($media == "chat") {
                return $chat;
            }
            $chat = $startSql . $chat;
            $startSql = ", " . PHP_EOL;
            if (strlen($innerSelect) > 0) {
                $innerSelect .= "union all" . PHP_EOL;
            }
            $innerSelect .= "select * from chat" . PHP_EOL;
        }
        if ($media == "" || $media == "mcse only") {
            $otherWhere = $this->mcseWhere($sessionId, $kvpName, $kvpValue, $freeText, $freeIds);
            $mcse = sprintf($this->sqlMcseEnvelope, $limitStart, $limitEnd, $environment, $otherWhere, $this->ROW_NUMBERS);
            if ($media == "mcse") {
                return $mcse;
            }
            $mcse = $startSql . $mcse;
            if (strlen($innerSelect) > 0) {
                $innerSelect .= "union all" . PHP_EOL;
            }
            $innerSelect .= "select * from mcse" . PHP_EOL;
        }
        return $voice .$chat .  $mcse . sprintf($this->sqlFinalEnvelope, $innerSelect);
    }

    function chatWhere(string $sessionId, string $kvpName, string $kvpValue, string $freeText, array $freeIds): string
    {
        $ret = "";
        if ($sessionId !== "") {
            $ret = " AND (keyconnid = '" . $sessionId . "' OR  sessionid = '" . $sessionId . "')";
        }
        if (strlen($freeText) > 0) {
            if (count($freeIds) > 0) {
                $list = implode(",", array_map(function ($x) {
                    return "'$x'";
                }, $freeIds));
                $ret .= " AND (keyconnid in ($list) or sessionid in ($list))";
            } else {
                $ret .= " AND sessionid ='NA'";
            }
        }
        if (strlen($kvpName) > 0 && strlen($kvpValue) > 0) {
            $ret .= " AND (keyconnid in (select SESSIONID from searchkvp where key = '" . $kvpName . "' and value = '" . $kvpValue . "' and sessionid like '1%%') " . PHP_EOL
                . "or sessionid in (select SESSIONID from searchkvp where key = '" . $kvpName . "' and value = '" . $kvpValue . "'))";
        }
        return $ret;
    }

    function voiceWhere(string $sessionId, string $kvpName, string $kvpValue, string $freeText, array $freeIds): string
    {
        $ret = "";
        if ($sessionId !== "") {
            $ret = " AND (sessionid = '$sessionId' or connid = '$sessionId')";
        }
        if (strlen($freeText) > 0) {
            if (count($freeIds) > 0) {
                $list = implode(",", array_map(function ($x) {
                    return "'$x'";
                }, $freeIds));
                $ret .= " AND (connid in ($list) or sessionid in ($list))";
            } else {
                $ret .= " AND sessionid ='NA'";
            }
        }

        if (strlen($kvpName) > 0 && strlen($kvpValue) > 0) {
            $ret .= " and (CONNID in (select SESSIONID from SEARCHKVP where KEY = '" . $kvpName . "' and VALUE = '" . $kvpValue . "') " . PHP_EOL
                . "or SESSIONID in (select SESSIONID from SEARCHKVP where KEY = '" . $kvpName . "' and VALUE = '" . $kvpValue . "'))";
        }
        return $ret;
    }

    function mcseWhere(string $sessionId, string $kvpName, string $kvpValue, string $freeText, array $freeIds): string
    {
        $ret = "";
        if ($sessionId !== "") {
            $ret = " AND (sessionid = '" . $sessionId . "')";
        }
        if (strlen($kvpName) > 0 && strlen($kvpValue) > 0) {
            $ret .= " AND (sessionid in (select SESSIONID from searchkvp where key = '" . $kvpName . "' and value = '" . $kvpValue . "' and sessionid like '1%%') " . PHP_EOL
                . "or sessionid in (select SESSIONID from searchkvp where key = '" . $kvpName . "' and value = '" . $kvpValue . "'))";
        }
        return $ret;
    }


    function requestName(): string
    {
        return "Global search";
    }

    /**
     * @inheritDoc
     */
    function reformatArrayNames(mixed $data): mixed
    {
        if ($data == null || !is_array($data)) {
            return [];
        }
        $return = [];
        foreach ($data as $row) {
            $newRow = [];
            $newRow["medium"] = $this->getDatFromRowOrEmpty($row, "MEDIUM");
            $newRow["connId"] = $this->getDatFromRowOrEmpty($row, "CONNID");
            $newRow["sessionId"] = $this->getDatFromRowOrEmpty($row, "SESSIONID");
            $newRow["timestamp"] = $this->getDatFromRowOrEmpty($row, "TIMESTAMP");
            $newRow["chatError"] = $this->getDatFromRowOrEmpty($row, "CHAT_ERROR");
            $return[] = $newRow;
        }
        return $return;
    }
}

Function Calls

None

Variables

None

Stats

MD5 5c43f7e2f62c47f4ee12102928295f04
Eval Count 0
Decode Time 69 ms