SlideShare a Scribd company logo
1 of 33
Some Crazy things
  done on PHP
     Taras Kalapun
Connecting PHP to M$ Word
getting string starting with “subject:”

                    $app = com_get_active_object("Word.Application")
                               or die("Can't connect to Word");
                     
                    echo $app->version;
                     
                    $app->Selection->WholeStory();
                    $x = $app->Selection->Text;
                     
                    $text = explode("r", $x);
                    $subject = '';
                    foreach ($text as $s) {
                        if (stristr($s, 'subject:')) {
                            preg_match("/subject:(.+)$/i", $s, $subject);
                            $subject = trim($subject[1]);
                        }
                    }
                    echo 'Subject: ' . $subject;
getting Thumbnail data from
Adobe Lightroom *.noindex

                 $path = '3.noindex'; // Thumbnail File
                 $level = 4; // Thumbnail level
                  
                 header('Content-Type: image/jpeg');
                 header('Last-Modified: '.date('r', filemtime($path)));
                  
                 $file = file_get_contents($path);
                  
                 $AgHg = explode('AgHg', $file);
                  
                 $max_level = count($AgHg)-2;

                 if ($level > $max_level) $level = $max_level;
                  
                 // 0 - array
                 // 1 - small img
                  
                 $level_img = explode('level_'.$level, $AgHg[$level+1]);
                 $image = ltrim($level_img[1], "x00");
                 echo $image;
getting elevation data   private function _dataFile($lat, $lon)
                         {
from SRTM source             $X = $lon;
                             $Y = $lat;
                          
                             $Ix = abs($X + 0.5); // nearest degree
                             $Iy = abs($Y + 0.5);

                             // 1 second tolerance
                             if (abs($X - $Ix) < 0.0002) $X = $Ix;
                             if (abs($Y - $Iy) < 0.0002) $Y = $Iy;
                          
                             if ($X <= -180)$X = $X + 360;
                             if ($X > 180) $X = $X - 360;
                          
                             $EW = ($X > 0) ? "W" : "E";
                          
                             $lon = abs( (int) $X );
                          
                             if ($lon < 100) $lon = "0".$lon;
                          
                             $NS = ($Y >= 0) ? "N" : "S";
                             $lat = abs( (int) $Y );
                          
                             $this->_lat0 = (int) $Y;
                             $this->_lon0 = (int) $X;
                          
                             return $NS.$lat.$EW.$lon;
                         }
private function _getAlt($lat, $lon)
{
    $lat = abs($lat);
    $lon = abs($lon);
 
    $latx = ($lat - floor($lat)) * 100000; //x
    $lonx = ($lon - floor($lon)) * 100000; //y
 
    $dim = 83.26394671; // 99999/1201
    //$dim = 83.19384;
 
    $lat_p = round($latx/$dim);
    $lon_p = round($lonx/$dim);
 
    // seeking in file
    $seek = -1201 * 2*($lat_p+1) + 2*(abs($lon_p-1));
    fseek($this->_fp, $seek, SEEK_END);
    $b = fread($this->_fp, 2);
 
    // swapping
    $ht = $this->signMag($b[0], $b[1]);
    return $ht;
}
/**
  * Converts a 2-byte High-Order sign magnitude
to integer.
  * Bit 15 is sign bit, bits 0-14 are magnitude
of number
  */
private function signMag($b1, $b2)
{
     $b1 = ord($b1);
     $b2 = ord($b2);
     if ($b1 < = 127) {
         $ht = ($b1 * 256) + $b2;
     } else if ($b1 > 127) {
         $ht = -(($b1 - 128) * 256 + $b2);
     }
     return $ht;
}
$radius = new Monitor_RADIUS;
if ($radius->isError()) {
    foreach ($radius->getErrors() as $ip => $error) {
        // Send SNMP Trap (-v 2c -c PUBLIC_COMMON 10.36.1.212 ""
OS ucdDemoPublicString.0 s "OS")
        Notify::send(
            $radius->getErrorType(),
            $radius->getServiceName($ip),
            $radius->getErrorDescription($ip)
        );
    }
}
public function isError() {
    $this->connect();
    $data = $this->getStat();
    $this->findErrors($data);
    if ($this->error != false) return true;
    else return false;
}
 
public function connect() {
    try {
        $this->dbh = new PDO('oci:dbname='.$this->_db_db, $this->_db_user, $this->_db_pass);
    } catch (PDOException $e) {
        print "Error!: " . $e->getMessage() . "<br />";
        die();
    }
    return $this;
}
 
protected function getStat() {
    $time = date("H:i:00", mktime(date("H"), date("i") - $this->minute_diff ));
    $date    = date("Y-m-d " . $time);
 
    $radius_ip_sql = " AND server_ip ". $this->ip2sql($this->radius_ip);
 
    $sql = "SELECT TO_CHAR(reg_date, 'YYYY-MM-DD HH24:MI:SS') AS reg_date, server_ip,
packet_all, packet_err, packet_autor, timeave_fun FROM statistic " ."WHERE
reg_date>to_date('" . $date . "','YYYY-MM-DD HH24:MI:SS') " . $radius_ip_sql . "ORDER BY
reg_date DESC";
 
    $sth = $this->dbh->prepare($sql);
    $sth->execute();
    $data = $sth->fetchAll();
 
    return $data;
}
protected function findErrors(&$data) {
    $error = array();
    $server_up = array();
 
    foreach ($data as $row) {
         $server_up[ $row['SERVER_IP'] ] = true;
         if ($row['PACKET_ALL'] < = 0) {
             $error[ $row['SERVER_IP'] ][] = $row['REG_DATE'] . ':   '
                 . 'packet_all = '.$row['PACKET_ALL'];
         }
         if ($row['PACKET_AUTOR'] <= 0) {
             $error[ $row['SERVER_IP'] ][] = $row['REG_DATE'] . ':   '
                 . 'packet_autor = '.$row['PACKET_AUTOR'];
         }
         if ($row['PACKET_ERR'] > 5) {
             $error[ $row['SERVER_IP'] ][] = $row['REG_DATE'] . ':   '
                 . 'packet_err = '.$row['PACKET_ERR'];
         }
         if ($row['TIMEAVE_FUN'] > 400) {
             $error[ $row['SERVER_IP'] ][] = $row['REG_DATE'] . ':   '
                 . 'timeave_fun = '.$row['TIMEAVE_FUN'];
         }
 
    }
 
    foreach ($this->radius_ip as $server) {
         if (!array_key_exists($server, $server_up))
             $error[$server][] = 'No packet information for this
Server';
    }
 
    $this->error = $error;
    return $this;
}
protected static function prepareTrapPacket($varBinds=null, $community='public', $requestId=null)
{
 

   
   $requestId = ($requestId) ? $requestId : rand(10000, 30000); // from 10000 to 40000 ?

   
   $upTime = rand(100, 900) * 1000000;
 

   
   $trap['version']   
 = self::varPack(1); //pack('H*', '0201'.'01');
 // SNMP v2c

   
   $trap['community'] = self::varPack($community);

   
   $trap['header']
   
    = pack('H*',

   
   
   
   
  
   
   
    
     '0202' . self::dec2hex($requestId) 
 // request-id

   
   
   
   
  
   
   
    
   .'020100'
 // error-status: noError (0)

   
   
   
   
  
   
   
    
   .'020100' 
 // error-index: 0

   
   
   
   
  
   
   
    );
 

   
   $var_sysUpTime 
     = self::packVarBind(array( 'oid' 
 => '1.3.6.1.2.1.1.3.0',

   
   
   
   
  
   
   
    
   
    
  
   
   'value' => $upTime,

   
   
   
   
  
   
   
    
   
    
  
   
   'type' 
 'o' // x43
                                                           =>

   
   
   
   
  
   
   
    
   
    
  
   )); // sysUpTime.0
 

   
   $var_snmpTrapOID = self::packVarBind(array( 'oid' 
 => '1.3.6.1.6.3.1.1.4.1.0',

   
   
   
   
  
   
   
    
   
    
  
   
   'value' => '1.3.6.1.2.1.31.2.1',

   
   
   
   
  
   
   
    
   
    
  
   
   'type' 
 'oid' // x06
                                                           =>

   
   
   
   
  
   
   
    
   
    
  
   )); // snmpTrapOID.0
 

   
   $varBindsPack = $var_sysUpTime . $var_snmpTrapOID . self::packVarBinds($varBinds);
 

   
   $trap['varBindsHeader'] = pack('H*', '30' . self::hexlen($varBindsPack,1)); // varBinds
size
 

   
   $trapBody = $trap['header'] . $trap['varBindsHeader'] . $varBindsPack;
 

   
   $trap['header0'] = pack('H*', 'a7'. self::hexlen($trapBody,1));
 

   
   $trap = $trap['version'] . $trap['community'] . $trap['header0'] . $trapBody;

   
   $trap = pack('H*', '30' . self::hexlen($trap,1)) . $trap;

   
   return $trap;

   }
Avaya OSSIS
public function connect($host, $port=5023, $login=null, $passwd=null,
$pin=null)

 {

 
 if (!$this->_connected) {

 
 
 $this->_host = $host;

 
 
 $this->_port = $port;

 
 
 $this->setCredentials($login, $passwd, $pin);
 

 
 
 $this->telnet = new Telnet($this->_host, $this->_port);

 
 
 $this->telnet->login($this->_login, $this->_password);
 

 
 
 if ($this->_pin) {

 
 
 
 $this->telnet->waitPrompt('Pin:');

 
 
 
 $this->telnet->write($pin);

 
 
 }
 

 
 
 $class = 'Avaya_Protocol_'.$this->_protocolType;

 
 
 $this->protocol = new $class;

 
 
 $this->protocol->setTelnet($this->telnet);

 
 
 //$this->protocol->connect();
 

 
 
 // Term Emulation

 
 
 $this->telnet->waitPrompt('[513]');

 
 
 $this->telnet->write($this->protocol->getTermEmulation());

 
 
 $this->telnet->waitPrompt('[y]');

 
 
 $this->telnet->write('y');
 

 
 
 $this->telnet->waitPrompt($this->protocol->getTermPrompt());
 

 
 
 $this->_connected = true;

 
 }

 
 return $this->_connected;

 }
protected function _fidsToDataArray($data)

 {

 
 $newData = array();

 
 foreach($data as $fid=>$val) {

 
 
 if (substr($fid, 0, 5) == '000d0') {

 
 
 
 $iRecord = substr($fid, 6, 2);

 
 
 
 $iVal 
 = substr($fid, 4, 2); // 4,2 or 5,1 ???

 
 
 
 $iRecord = hexdec($iRecord);

 
 
 
 $iVal         = hexdec($iVal);
 

 
 
 
 $newData['data'][$iRecord][$iVal] = $val;

 
 
 } else {

 
 
 
 $newData['fids'][$fid] = $val;

 
 
 }

 
 }

 
 //$newData['data'] = array_filter($newData['data']);

 
 $newData['data'] = array_remove_empty($newData['data']);
 

 
 return $newData;

 }
 
public function getSkillLog($skill)

 {

 
 $cmd = 'list bcms skill';

 
 $fids = array(

 
 
 '3e82ff00',// => 'time',

 
 
 '3e83ff00',// => 'acd_calls',

 
 
 '3e84ff00',// => 'avg_speed_ans',

 
 
 '3e85ff00',// => 'aband_calls',

 
 
 '3e86ff00',// => 'avg_aband_time'
Win32 service on PHP

// First you need to create a service, you only need to do this once
win32_create_service(array(
    'service' => 'phpavtelnet',
    'display' => 'PHP Avaya Telnet',
    'params' => 'c:xampphtdocsservicephpavtelnet.php',
    'path' => 'c:xamppphpphp.exe'));
$myservicename = 'phpavtelnet';
 
$socket = null;
$port = 999;
$max_clients = 10;
$telnet = null;
 
// Connect to service dispatcher and notify that startup was successful
if (!win32_start_service_ctrl_dispatcher($myservicename)) die('Could not connect to
service :'.$myservicename);
win32_set_service_status(WIN32_SERVICE_RUNNING);
 

 sock_server_init();

 require_once 'Telnet.php';

 require_once 'CM.php';

 $avaya = new Avaya_CM;

 $avaya->connect();
 
// Main Server Loop
while (1) {
    switch (win32_get_last_control_message()) {
        case WIN32_SERVICE_CONTROL_CONTINUE: break;
        case WIN32_SERVICE_CONTROL_INTERROGATE:
win32_set_service_status(WIN32_NO_ERROR); break;
        case WIN32_SERVICE_CONTROL_STOP:
win32_set_service_status(WIN32_SERVICE_STOPPED); service_stop();
        default: win32_set_service_status(WIN32_ERROR_CALL_NOT_IMPLEMENTED);
    }

 sock_server_loop();
}
 
win32_set_service_status(WIN32_SERVICE_STOPPED);
function sock_server_init() {

 global $port, $socket, $clients, $max_clients;
 

 $socket = socket_create(AF_INET,SOCK_STREAM,SOL_TCP);
 

 socket_set_option($socket,SOL_SOCKET,SO_REUSEADDR,1);

 socket_bind($socket,0,$port);

 socket_listen($socket,$max_clients);
 

 write_log('Server started on port '.$port);
 

 $clients = array('0' => array('socket' => $socket));
}

                function sock_server_loop() {
                   for($i=1;$i<$max_clients+1;$i++) {
                
 
 
 if(in_array($clients[$i]['socket'],$read)) {
                 
                
 
 
 
 $data = @socket_read($clients[$i]['socket'],1024000,
                PHP_NORMAL_READ);
                 
                
 
 
 
 if ($data === FALSE) {
                
 
 
 
 
 unset($clients[$i]);
                
 
 
 
 
 continue;
                
 
 
 
 }
                 
                
 
 
 
 $data = trim($data);
                
 
 
 
 if(!empty($data)) {
                
 
 
 
 
 process_data($data, $clients[$i]);
                
 
 
 
 }
                
 
 
 }
                
 
 }
function process_data($data, $client) {

 global $avaya;


   if (strstr($data, 'getAgentSkills') !== false) {

   
 $x = explode(' ', $data);

   
 $ext = $x[1];


   
   $skills = $avaya->getAgentSkills($ext);

   
   $skills = $avaya->skills2str($skills);

   
   socket_write($client['socket'], $skills."rn");

   }
if (!$this->ds) {

   $this->ds = ldap_connect($host);

   if ($this->ds) {

   
   ldap_set_option($this->ds, LDAP_OPT_PROTOCOL_VERSION, 3);

   
   ldap_set_option($this->ds, LDAP_OPT_REFERRALS, 0);

   
   if (!@ldap_bind($this->ds, $login, $passwd)) {

   
   
   return false;

   
   }

   
   return $this;

   } else {

   
   return false;

   }
}
 
public function searchUser($s) {

   $attributes = array('sAMAccountName', 'cn');

   $filter = '(&(objectCategory=user)(displayName=*'.$s.'*))';

   $sr = ldap_search($this->ds, $this->dn, $filter, $attributes);

   $num_enntries = ldap_count_entries($this->ds, $sr);

   $users = array();

   if ($num_enntries > 0) {

   
   $info = ldap_get_entries($this->ds, $sr);

   
   foreach($info as $u) {

   
   
   if (!empty($u['cn'][0]))

   
   
   $users[] = array(

   
   
   
   
  'login' => $u['samaccountname'][0],

   
   
   
   
  'name' => $u['cn'][0],

   
   
   
   );

   
   }

   
   return $users;

   } else {

   
   return false;

   }
}
include("pChart/pData.class");
include("pChart/pChart.class");
 
// Dataset definition
$DataSet = new pData;
$DataSet->AddPoint($data,"Serie1");
$DataSet->AddPoint($legend,"Serie2");
$DataSet->AddAllSeries();
$DataSet->SetAbsciseLabelSerie("Serie2");
 
// Initialise the graph
$graph = new pChart(720,350);
$graph->loadColorPalette('hard_bright.txt');
 
// Draw the pie chart
$graph->setFontProperties("Fonts/tahoma.ttf",12);
$graph->drawTitle(50,20,'Top 20 Принятых за '.$date ,0,0,0);
 
$graph->setFontProperties("Fonts/tahoma.ttf",9);
 
$graph->drawPieGraph($DataSet->GetData(),$DataSet-
>GetDataDescription(),210,160,180,PIE_PERCENTAGE,TRUE,50,20,5);
$graph->drawPieLegend(420,5,$DataSet->GetData(),$DataSet-
>GetDataDescription(),250,250,250);
 
$graph->Stroke();
What next?
Crazy things done on PHP

More Related Content

What's hot

An Elephant of a Different Colour: Hack
An Elephant of a Different Colour: HackAn Elephant of a Different Colour: Hack
An Elephant of a Different Colour: HackVic Metcalfe
 
The Zen of Lithium
The Zen of LithiumThe Zen of Lithium
The Zen of LithiumNate Abele
 
Command Bus To Awesome Town
Command Bus To Awesome TownCommand Bus To Awesome Town
Command Bus To Awesome TownRoss Tuck
 
Teaching Your Machine To Find Fraudsters
Teaching Your Machine To Find FraudstersTeaching Your Machine To Find Fraudsters
Teaching Your Machine To Find FraudstersIan Barber
 
Models and Service Layers, Hemoglobin and Hobgoblins
Models and Service Layers, Hemoglobin and HobgoblinsModels and Service Layers, Hemoglobin and Hobgoblins
Models and Service Layers, Hemoglobin and HobgoblinsRoss Tuck
 
PHP 5.3 and Lithium: the most rad php framework
PHP 5.3 and Lithium: the most rad php frameworkPHP 5.3 and Lithium: the most rad php framework
PHP 5.3 and Lithium: the most rad php frameworkG Woo
 
Doctrine fixtures
Doctrine fixturesDoctrine fixtures
Doctrine fixturesBill Chang
 
Object Calisthenics Applied to PHP
Object Calisthenics Applied to PHPObject Calisthenics Applied to PHP
Object Calisthenics Applied to PHPGuilherme Blanco
 
Debugging: Rules And Tools - PHPTek 11 Version
Debugging: Rules And Tools - PHPTek 11 VersionDebugging: Rules And Tools - PHPTek 11 Version
Debugging: Rules And Tools - PHPTek 11 VersionIan Barber
 
Things I Believe Now That I'm Old
Things I Believe Now That I'm OldThings I Believe Now That I'm Old
Things I Believe Now That I'm OldRoss Tuck
 
Object Calisthenics Adapted for PHP
Object Calisthenics Adapted for PHPObject Calisthenics Adapted for PHP
Object Calisthenics Adapted for PHPChad Gray
 
The Art of Transduction
The Art of TransductionThe Art of Transduction
The Art of TransductionDavid Stockton
 
From mysql to MongoDB(MongoDB2011北京交流会)
From mysql to MongoDB(MongoDB2011北京交流会)From mysql to MongoDB(MongoDB2011北京交流会)
From mysql to MongoDB(MongoDB2011北京交流会)Night Sailer
 
PHP for Adults: Clean Code and Object Calisthenics
PHP for Adults: Clean Code and Object CalisthenicsPHP for Adults: Clean Code and Object Calisthenics
PHP for Adults: Clean Code and Object CalisthenicsGuilherme Blanco
 
PHP 7 – What changed internally? (Forum PHP 2015)
PHP 7 – What changed internally? (Forum PHP 2015)PHP 7 – What changed internally? (Forum PHP 2015)
PHP 7 – What changed internally? (Forum PHP 2015)Nikita Popov
 

What's hot (20)

An Elephant of a Different Colour: Hack
An Elephant of a Different Colour: HackAn Elephant of a Different Colour: Hack
An Elephant of a Different Colour: Hack
 
The Zen of Lithium
The Zen of LithiumThe Zen of Lithium
The Zen of Lithium
 
Command Bus To Awesome Town
Command Bus To Awesome TownCommand Bus To Awesome Town
Command Bus To Awesome Town
 
Teaching Your Machine To Find Fraudsters
Teaching Your Machine To Find FraudstersTeaching Your Machine To Find Fraudsters
Teaching Your Machine To Find Fraudsters
 
Models and Service Layers, Hemoglobin and Hobgoblins
Models and Service Layers, Hemoglobin and HobgoblinsModels and Service Layers, Hemoglobin and Hobgoblins
Models and Service Layers, Hemoglobin and Hobgoblins
 
PHP 5.3 and Lithium: the most rad php framework
PHP 5.3 and Lithium: the most rad php frameworkPHP 5.3 and Lithium: the most rad php framework
PHP 5.3 and Lithium: the most rad php framework
 
Doctrine fixtures
Doctrine fixturesDoctrine fixtures
Doctrine fixtures
 
Object Calisthenics Applied to PHP
Object Calisthenics Applied to PHPObject Calisthenics Applied to PHP
Object Calisthenics Applied to PHP
 
Debugging: Rules And Tools - PHPTek 11 Version
Debugging: Rules And Tools - PHPTek 11 VersionDebugging: Rules And Tools - PHPTek 11 Version
Debugging: Rules And Tools - PHPTek 11 Version
 
Daily notes
Daily notesDaily notes
Daily notes
 
Nubilus Perl
Nubilus PerlNubilus Perl
Nubilus Perl
 
Drupal 8 database api
Drupal 8 database apiDrupal 8 database api
Drupal 8 database api
 
Things I Believe Now That I'm Old
Things I Believe Now That I'm OldThings I Believe Now That I'm Old
Things I Believe Now That I'm Old
 
PHP and MySQL
PHP and MySQLPHP and MySQL
PHP and MySQL
 
Object Calisthenics Adapted for PHP
Object Calisthenics Adapted for PHPObject Calisthenics Adapted for PHP
Object Calisthenics Adapted for PHP
 
The Art of Transduction
The Art of TransductionThe Art of Transduction
The Art of Transduction
 
Perl Web Client
Perl Web ClientPerl Web Client
Perl Web Client
 
From mysql to MongoDB(MongoDB2011北京交流会)
From mysql to MongoDB(MongoDB2011北京交流会)From mysql to MongoDB(MongoDB2011北京交流会)
From mysql to MongoDB(MongoDB2011北京交流会)
 
PHP for Adults: Clean Code and Object Calisthenics
PHP for Adults: Clean Code and Object CalisthenicsPHP for Adults: Clean Code and Object Calisthenics
PHP for Adults: Clean Code and Object Calisthenics
 
PHP 7 – What changed internally? (Forum PHP 2015)
PHP 7 – What changed internally? (Forum PHP 2015)PHP 7 – What changed internally? (Forum PHP 2015)
PHP 7 – What changed internally? (Forum PHP 2015)
 

Similar to Crazy things done on PHP

How to stand on the shoulders of giants
How to stand on the shoulders of giantsHow to stand on the shoulders of giants
How to stand on the shoulders of giantsIan Barber
 
Introdução ao Perl 6
Introdução ao Perl 6Introdução ao Perl 6
Introdução ao Perl 6garux
 
Introduction to CloudForecast / YAPC::Asia 2010 Tokyo
Introduction to CloudForecast / YAPC::Asia 2010 TokyoIntroduction to CloudForecast / YAPC::Asia 2010 Tokyo
Introduction to CloudForecast / YAPC::Asia 2010 TokyoMasahiro Nagano
 
Design Patterns avec PHP 5.3, Symfony et Pimple
Design Patterns avec PHP 5.3, Symfony et PimpleDesign Patterns avec PHP 5.3, Symfony et Pimple
Design Patterns avec PHP 5.3, Symfony et PimpleHugo Hamon
 
Taking Perl to Eleven with Higher-Order Functions
Taking Perl to Eleven with Higher-Order FunctionsTaking Perl to Eleven with Higher-Order Functions
Taking Perl to Eleven with Higher-Order FunctionsDavid Golden
 
Your code sucks, let's fix it - DPC UnCon
Your code sucks, let's fix it - DPC UnConYour code sucks, let's fix it - DPC UnCon
Your code sucks, let's fix it - DPC UnConRafael Dohms
 
Wx::Perl::Smart
Wx::Perl::SmartWx::Perl::Smart
Wx::Perl::Smartlichtkind
 
Neatly Hashing a Tree: FP tree-fold in Perl5 & Perl6
Neatly Hashing a Tree: FP tree-fold in Perl5 & Perl6Neatly Hashing a Tree: FP tree-fold in Perl5 & Perl6
Neatly Hashing a Tree: FP tree-fold in Perl5 & Perl6Workhorse Computing
 
Security Challenges in Node.js
Security Challenges in Node.jsSecurity Challenges in Node.js
Security Challenges in Node.jsWebsecurify
 
究極のコントローラを目指す
究極のコントローラを目指す究極のコントローラを目指す
究極のコントローラを目指すYasuo Harada
 
Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)Kang-min Liu
 
JavaScript for PHP developers
JavaScript for PHP developersJavaScript for PHP developers
JavaScript for PHP developersStoyan Stefanov
 
Coding Horrors
Coding HorrorsCoding Horrors
Coding HorrorsMark Baker
 
Perl Bag of Tricks - Baltimore Perl mongers
Perl Bag of Tricks  -  Baltimore Perl mongersPerl Bag of Tricks  -  Baltimore Perl mongers
Perl Bag of Tricks - Baltimore Perl mongersbrian d foy
 
Silex meets SOAP & REST
Silex meets SOAP & RESTSilex meets SOAP & REST
Silex meets SOAP & RESTHugo Hamon
 

Similar to Crazy things done on PHP (20)

How to stand on the shoulders of giants
How to stand on the shoulders of giantsHow to stand on the shoulders of giants
How to stand on the shoulders of giants
 
Introdução ao Perl 6
Introdução ao Perl 6Introdução ao Perl 6
Introdução ao Perl 6
 
PHP Tips & Tricks
PHP Tips & TricksPHP Tips & Tricks
PHP Tips & Tricks
 
Presentation1
Presentation1Presentation1
Presentation1
 
Introduction to CloudForecast / YAPC::Asia 2010 Tokyo
Introduction to CloudForecast / YAPC::Asia 2010 TokyoIntroduction to CloudForecast / YAPC::Asia 2010 Tokyo
Introduction to CloudForecast / YAPC::Asia 2010 Tokyo
 
wget.pl
wget.plwget.pl
wget.pl
 
Design Patterns avec PHP 5.3, Symfony et Pimple
Design Patterns avec PHP 5.3, Symfony et PimpleDesign Patterns avec PHP 5.3, Symfony et Pimple
Design Patterns avec PHP 5.3, Symfony et Pimple
 
Bag of tricks
Bag of tricksBag of tricks
Bag of tricks
 
Taking Perl to Eleven with Higher-Order Functions
Taking Perl to Eleven with Higher-Order FunctionsTaking Perl to Eleven with Higher-Order Functions
Taking Perl to Eleven with Higher-Order Functions
 
Your code sucks, let's fix it - DPC UnCon
Your code sucks, let's fix it - DPC UnConYour code sucks, let's fix it - DPC UnCon
Your code sucks, let's fix it - DPC UnCon
 
Wx::Perl::Smart
Wx::Perl::SmartWx::Perl::Smart
Wx::Perl::Smart
 
Neatly Hashing a Tree: FP tree-fold in Perl5 & Perl6
Neatly Hashing a Tree: FP tree-fold in Perl5 & Perl6Neatly Hashing a Tree: FP tree-fold in Perl5 & Perl6
Neatly Hashing a Tree: FP tree-fold in Perl5 & Perl6
 
Security Challenges in Node.js
Security Challenges in Node.jsSecurity Challenges in Node.js
Security Challenges in Node.js
 
究極のコントローラを目指す
究極のコントローラを目指す究極のコントローラを目指す
究極のコントローラを目指す
 
Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)
 
JavaScript for PHP developers
JavaScript for PHP developersJavaScript for PHP developers
JavaScript for PHP developers
 
C99
C99C99
C99
 
Coding Horrors
Coding HorrorsCoding Horrors
Coding Horrors
 
Perl Bag of Tricks - Baltimore Perl mongers
Perl Bag of Tricks  -  Baltimore Perl mongersPerl Bag of Tricks  -  Baltimore Perl mongers
Perl Bag of Tricks - Baltimore Perl mongers
 
Silex meets SOAP & REST
Silex meets SOAP & RESTSilex meets SOAP & REST
Silex meets SOAP & REST
 

Recently uploaded

Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?XfilesPro
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraDeakin University
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsHyundai Motor Group
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 

Recently uploaded (20)

Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?
 
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptxVulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 

Crazy things done on PHP

  • 1. Some Crazy things done on PHP Taras Kalapun
  • 2.
  • 3.
  • 4. Connecting PHP to M$ Word getting string starting with “subject:” $app = com_get_active_object("Word.Application") or die("Can't connect to Word");   echo $app->version;   $app->Selection->WholeStory(); $x = $app->Selection->Text;   $text = explode("r", $x); $subject = ''; foreach ($text as $s) { if (stristr($s, 'subject:')) { preg_match("/subject:(.+)$/i", $s, $subject); $subject = trim($subject[1]); } } echo 'Subject: ' . $subject;
  • 5. getting Thumbnail data from Adobe Lightroom *.noindex $path = '3.noindex'; // Thumbnail File $level = 4; // Thumbnail level   header('Content-Type: image/jpeg'); header('Last-Modified: '.date('r', filemtime($path)));   $file = file_get_contents($path);   $AgHg = explode('AgHg', $file);   $max_level = count($AgHg)-2; if ($level > $max_level) $level = $max_level;   // 0 - array // 1 - small img   $level_img = explode('level_'.$level, $AgHg[$level+1]); $image = ltrim($level_img[1], "x00"); echo $image;
  • 6. getting elevation data private function _dataFile($lat, $lon) { from SRTM source $X = $lon; $Y = $lat;   $Ix = abs($X + 0.5); // nearest degree $Iy = abs($Y + 0.5); // 1 second tolerance if (abs($X - $Ix) < 0.0002) $X = $Ix; if (abs($Y - $Iy) < 0.0002) $Y = $Iy;   if ($X <= -180)$X = $X + 360; if ($X > 180) $X = $X - 360;   $EW = ($X > 0) ? "W" : "E";   $lon = abs( (int) $X );   if ($lon < 100) $lon = "0".$lon;   $NS = ($Y >= 0) ? "N" : "S"; $lat = abs( (int) $Y );   $this->_lat0 = (int) $Y; $this->_lon0 = (int) $X;   return $NS.$lat.$EW.$lon; }
  • 7. private function _getAlt($lat, $lon) { $lat = abs($lat); $lon = abs($lon);   $latx = ($lat - floor($lat)) * 100000; //x $lonx = ($lon - floor($lon)) * 100000; //y   $dim = 83.26394671; // 99999/1201 //$dim = 83.19384;   $lat_p = round($latx/$dim); $lon_p = round($lonx/$dim);   // seeking in file $seek = -1201 * 2*($lat_p+1) + 2*(abs($lon_p-1)); fseek($this->_fp, $seek, SEEK_END); $b = fread($this->_fp, 2);   // swapping $ht = $this->signMag($b[0], $b[1]); return $ht; }
  • 8. /** * Converts a 2-byte High-Order sign magnitude to integer. * Bit 15 is sign bit, bits 0-14 are magnitude of number */ private function signMag($b1, $b2) { $b1 = ord($b1); $b2 = ord($b2); if ($b1 < = 127) { $ht = ($b1 * 256) + $b2; } else if ($b1 > 127) { $ht = -(($b1 - 128) * 256 + $b2); } return $ht; }
  • 9.
  • 10.
  • 11. $radius = new Monitor_RADIUS; if ($radius->isError()) { foreach ($radius->getErrors() as $ip => $error) { // Send SNMP Trap (-v 2c -c PUBLIC_COMMON 10.36.1.212 "" OS ucdDemoPublicString.0 s "OS") Notify::send( $radius->getErrorType(), $radius->getServiceName($ip), $radius->getErrorDescription($ip) ); } }
  • 12. public function isError() { $this->connect(); $data = $this->getStat(); $this->findErrors($data); if ($this->error != false) return true; else return false; }   public function connect() { try { $this->dbh = new PDO('oci:dbname='.$this->_db_db, $this->_db_user, $this->_db_pass); } catch (PDOException $e) { print "Error!: " . $e->getMessage() . "<br />"; die(); } return $this; }   protected function getStat() { $time = date("H:i:00", mktime(date("H"), date("i") - $this->minute_diff )); $date = date("Y-m-d " . $time);   $radius_ip_sql = " AND server_ip ". $this->ip2sql($this->radius_ip);   $sql = "SELECT TO_CHAR(reg_date, 'YYYY-MM-DD HH24:MI:SS') AS reg_date, server_ip, packet_all, packet_err, packet_autor, timeave_fun FROM statistic " ."WHERE reg_date>to_date('" . $date . "','YYYY-MM-DD HH24:MI:SS') " . $radius_ip_sql . "ORDER BY reg_date DESC";   $sth = $this->dbh->prepare($sql); $sth->execute(); $data = $sth->fetchAll();   return $data; }
  • 13. protected function findErrors(&$data) { $error = array(); $server_up = array();   foreach ($data as $row) { $server_up[ $row['SERVER_IP'] ] = true; if ($row['PACKET_ALL'] < = 0) { $error[ $row['SERVER_IP'] ][] = $row['REG_DATE'] . ': ' . 'packet_all = '.$row['PACKET_ALL']; } if ($row['PACKET_AUTOR'] <= 0) { $error[ $row['SERVER_IP'] ][] = $row['REG_DATE'] . ': ' . 'packet_autor = '.$row['PACKET_AUTOR']; } if ($row['PACKET_ERR'] > 5) { $error[ $row['SERVER_IP'] ][] = $row['REG_DATE'] . ': ' . 'packet_err = '.$row['PACKET_ERR']; } if ($row['TIMEAVE_FUN'] > 400) { $error[ $row['SERVER_IP'] ][] = $row['REG_DATE'] . ': ' . 'timeave_fun = '.$row['TIMEAVE_FUN']; }   }   foreach ($this->radius_ip as $server) { if (!array_key_exists($server, $server_up)) $error[$server][] = 'No packet information for this Server'; }   $this->error = $error; return $this; }
  • 14.
  • 15. protected static function prepareTrapPacket($varBinds=null, $community='public', $requestId=null) { $requestId = ($requestId) ? $requestId : rand(10000, 30000); // from 10000 to 40000 ? $upTime = rand(100, 900) * 1000000;   $trap['version'] = self::varPack(1); //pack('H*', '0201'.'01'); // SNMP v2c $trap['community'] = self::varPack($community); $trap['header'] = pack('H*', '0202' . self::dec2hex($requestId) // request-id .'020100' // error-status: noError (0) .'020100' // error-index: 0 );   $var_sysUpTime = self::packVarBind(array( 'oid' => '1.3.6.1.2.1.1.3.0', 'value' => $upTime, 'type' 'o' // x43 => )); // sysUpTime.0   $var_snmpTrapOID = self::packVarBind(array( 'oid' => '1.3.6.1.6.3.1.1.4.1.0', 'value' => '1.3.6.1.2.1.31.2.1', 'type' 'oid' // x06 => )); // snmpTrapOID.0   $varBindsPack = $var_sysUpTime . $var_snmpTrapOID . self::packVarBinds($varBinds);   $trap['varBindsHeader'] = pack('H*', '30' . self::hexlen($varBindsPack,1)); // varBinds size   $trapBody = $trap['header'] . $trap['varBindsHeader'] . $varBindsPack;   $trap['header0'] = pack('H*', 'a7'. self::hexlen($trapBody,1));   $trap = $trap['version'] . $trap['community'] . $trap['header0'] . $trapBody; $trap = pack('H*', '30' . self::hexlen($trap,1)) . $trap; return $trap; }
  • 16.
  • 18. public function connect($host, $port=5023, $login=null, $passwd=null, $pin=null) { if (!$this->_connected) { $this->_host = $host; $this->_port = $port; $this->setCredentials($login, $passwd, $pin);   $this->telnet = new Telnet($this->_host, $this->_port); $this->telnet->login($this->_login, $this->_password);   if ($this->_pin) { $this->telnet->waitPrompt('Pin:'); $this->telnet->write($pin); }   $class = 'Avaya_Protocol_'.$this->_protocolType; $this->protocol = new $class; $this->protocol->setTelnet($this->telnet); //$this->protocol->connect();   // Term Emulation $this->telnet->waitPrompt('[513]'); $this->telnet->write($this->protocol->getTermEmulation()); $this->telnet->waitPrompt('[y]'); $this->telnet->write('y');   $this->telnet->waitPrompt($this->protocol->getTermPrompt());   $this->_connected = true; } return $this->_connected; }
  • 19. protected function _fidsToDataArray($data) { $newData = array(); foreach($data as $fid=>$val) { if (substr($fid, 0, 5) == '000d0') { $iRecord = substr($fid, 6, 2); $iVal = substr($fid, 4, 2); // 4,2 or 5,1 ??? $iRecord = hexdec($iRecord); $iVal = hexdec($iVal);   $newData['data'][$iRecord][$iVal] = $val; } else { $newData['fids'][$fid] = $val; } } //$newData['data'] = array_filter($newData['data']); $newData['data'] = array_remove_empty($newData['data']);   return $newData; }   public function getSkillLog($skill) { $cmd = 'list bcms skill'; $fids = array( '3e82ff00',// => 'time', '3e83ff00',// => 'acd_calls', '3e84ff00',// => 'avg_speed_ans', '3e85ff00',// => 'aband_calls', '3e86ff00',// => 'avg_aband_time'
  • 20. Win32 service on PHP // First you need to create a service, you only need to do this once win32_create_service(array( 'service' => 'phpavtelnet', 'display' => 'PHP Avaya Telnet', 'params' => 'c:xampphtdocsservicephpavtelnet.php', 'path' => 'c:xamppphpphp.exe'));
  • 21. $myservicename = 'phpavtelnet';   $socket = null; $port = 999; $max_clients = 10; $telnet = null;   // Connect to service dispatcher and notify that startup was successful if (!win32_start_service_ctrl_dispatcher($myservicename)) die('Could not connect to service :'.$myservicename); win32_set_service_status(WIN32_SERVICE_RUNNING);   sock_server_init(); require_once 'Telnet.php'; require_once 'CM.php'; $avaya = new Avaya_CM; $avaya->connect();   // Main Server Loop while (1) { switch (win32_get_last_control_message()) { case WIN32_SERVICE_CONTROL_CONTINUE: break; case WIN32_SERVICE_CONTROL_INTERROGATE: win32_set_service_status(WIN32_NO_ERROR); break; case WIN32_SERVICE_CONTROL_STOP: win32_set_service_status(WIN32_SERVICE_STOPPED); service_stop(); default: win32_set_service_status(WIN32_ERROR_CALL_NOT_IMPLEMENTED); } sock_server_loop(); }   win32_set_service_status(WIN32_SERVICE_STOPPED);
  • 22. function sock_server_init() { global $port, $socket, $clients, $max_clients;   $socket = socket_create(AF_INET,SOCK_STREAM,SOL_TCP);   socket_set_option($socket,SOL_SOCKET,SO_REUSEADDR,1); socket_bind($socket,0,$port); socket_listen($socket,$max_clients);   write_log('Server started on port '.$port);   $clients = array('0' => array('socket' => $socket)); } function sock_server_loop() { for($i=1;$i<$max_clients+1;$i++) { if(in_array($clients[$i]['socket'],$read)) {   $data = @socket_read($clients[$i]['socket'],1024000, PHP_NORMAL_READ);   if ($data === FALSE) { unset($clients[$i]); continue; }   $data = trim($data); if(!empty($data)) { process_data($data, $clients[$i]); } } }
  • 23. function process_data($data, $client) { global $avaya; if (strstr($data, 'getAgentSkills') !== false) { $x = explode(' ', $data); $ext = $x[1]; $skills = $avaya->getAgentSkills($ext); $skills = $avaya->skills2str($skills); socket_write($client['socket'], $skills."rn"); }
  • 24.
  • 25.
  • 26. if (!$this->ds) { $this->ds = ldap_connect($host); if ($this->ds) { ldap_set_option($this->ds, LDAP_OPT_PROTOCOL_VERSION, 3); ldap_set_option($this->ds, LDAP_OPT_REFERRALS, 0); if (!@ldap_bind($this->ds, $login, $passwd)) { return false; } return $this; } else { return false; } }   public function searchUser($s) { $attributes = array('sAMAccountName', 'cn'); $filter = '(&(objectCategory=user)(displayName=*'.$s.'*))'; $sr = ldap_search($this->ds, $this->dn, $filter, $attributes); $num_enntries = ldap_count_entries($this->ds, $sr); $users = array(); if ($num_enntries > 0) { $info = ldap_get_entries($this->ds, $sr); foreach($info as $u) { if (!empty($u['cn'][0])) $users[] = array( 'login' => $u['samaccountname'][0], 'name' => $u['cn'][0], ); } return $users; } else { return false; } }
  • 27.
  • 28.
  • 29.
  • 30. include("pChart/pData.class"); include("pChart/pChart.class");   // Dataset definition $DataSet = new pData; $DataSet->AddPoint($data,"Serie1"); $DataSet->AddPoint($legend,"Serie2"); $DataSet->AddAllSeries(); $DataSet->SetAbsciseLabelSerie("Serie2");   // Initialise the graph $graph = new pChart(720,350); $graph->loadColorPalette('hard_bright.txt');   // Draw the pie chart $graph->setFontProperties("Fonts/tahoma.ttf",12); $graph->drawTitle(50,20,'Top 20 Принятых за '.$date ,0,0,0);   $graph->setFontProperties("Fonts/tahoma.ttf",9);   $graph->drawPieGraph($DataSet->GetData(),$DataSet- >GetDataDescription(),210,160,180,PIE_PERCENTAGE,TRUE,50,20,5); $graph->drawPieLegend(420,5,$DataSet->GetData(),$DataSet- >GetDataDescription(),250,250,250);   $graph->Stroke();
  • 31.

Editor's Notes

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n
  26. \n
  27. \n
  28. \n
  29. \n
  30. \n
  31. \n
  32. \n
  33. \n