1<?php 2 3function get_command_filename ($session_id) 4{ 5 //return session_save_path ()."/command.gda"; 6 return session_save_path ()."/GDA".$session_id."Cpipe"; 7} 8 9function get_reply_filename ($session_id) 10{ 11 //return session_save_path ()."/reply.gda"; 12 return session_save_path ()."/GDA".$session_id."Rpipe"; 13} 14 15function try_include ($file, $debug=false) 16{ 17 $array = explode (":", get_include_path ()); 18 foreach ($array as $index => $path) { 19 if (file_exists ($path.DIRECTORY_SEPARATOR.$file)) { 20 include_once ($path.DIRECTORY_SEPARATOR.$file); 21 if ($debug) 22 echo "<b>Using PEAR MDB2:</b> ".$path.DIRECTORY_SEPARATOR.$file."\n"; 23 return true; 24 } 25 } 26 return false; 27} 28 29function gda_add_hash ($key, $text) 30{ 31 if ($key == "") 32 return "NOHASH\n".$text; 33 else 34 return hmac ($key, $text)."\n".$text; 35} 36 37// Create an md5 HMAC 38function hmac ($key, $data) 39{ 40 // RFC 2104 HMAC implementation for php. 41 // Creates an md5 HMAC. 42 // Eliminates the need to install mhash to compute a HMAC 43 // Hacked by Lance Rushing 44 45 $b = 64; // byte length for md5 46 if (strlen($key) > $b) { 47 $key = pack("H*",md5($key)); 48 } 49 $key = str_pad($key, $b, chr(0x00)); 50 $ipad = str_pad('', $b, chr(0x36)); 51 $opad = str_pad('', $b, chr(0x5c)); 52 $k_ipad = $key ^ $ipad ; 53 $k_opad = $key ^ $opad; 54 55 return md5($k_opad . pack("H*",md5($k_ipad . $data))); 56} 57 58// Generate a random character string 59function rand_str($length = 32, $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890') 60{ 61 // Length of character list 62 $chars_length = (strlen($chars) - 1); 63 64 // Start our string 65 $string = $chars{rand(0, $chars_length)}; 66 67 // Generate random string 68 for ($i = 1; $i < $length; $i = strlen($string)) 69 { 70 // Grab a random character from our list 71 $r = $chars{rand(0, $chars_length)}; 72 73 // Make sure the same two characters don't appear next to each other 74 if ($r != $string{$i - 1}) $string .= $r; 75 } 76 77 // Return the string 78 return $string; 79} 80 81function mdb2_type_to_gtype ($mdb2type) 82{ 83 switch ($mdb2type) { 84 default: 85 case "text": 86 case "clob": 87 return "gchararray"; 88 case "integer": 89 return "gint"; 90 case "boolean": 91 return "boolean"; 92 case "decimal": 93 return "GdaNumerical"; 94 case "float": 95 return "gdouble"; 96 case "date": 97 return "GDate"; 98 case "time": 99 return "GdaTime"; 100 case "timestamp": 101 return "GdaTimestamp"; 102 case "blob": 103 return "GdaBinary"; 104 } 105} 106 107/** 108 * Logging class: 109 * - contains lfile, lopen and lwrite methods 110 * - lfile sets path and name of log file 111 * - lwrite will write message to the log file 112 * - first call of the lwrite will open log file implicitly 113 * - message is written with the following format: hh:mm:ss (script name) message 114 */ 115class Logging{ 116 // define default log file 117 private $log_file = '/tmp/gdalog'; 118 // define file pointer 119 private $fp = null; 120 // set log file (path and name) 121 public function lfile($path) { 122 $this->log_file = $path; 123 } 124 // write message to the log file 125 public function lwrite($message){ 126 // if file pointer doesn't exist, then open log file 127 if (!$this->fp) $this->lopen(); 128 // define script name 129 $script_name = pathinfo($_SERVER['PHP_SELF'], PATHINFO_FILENAME); 130 // define current time 131 $time = date('H:i:s'); 132 // write current time, script name and message to the log file 133 fwrite($this->fp, "$time ($script_name) $message\n"); 134 } 135 // open log file 136 private function lopen(){ 137 // define log file path and name 138 $lfile = $this->log_file; 139 // define the current date (it will be appended to the log file name) 140 $today = date('Y-m-d'); 141 // open log file for writing only; place the file pointer at the end of the file 142 // if the file does not exist, attempt to create it 143 $this->fp = fopen($lfile . '_' . $today, 'a') or exit("Can't open $lfile!"); 144 } 145} 146 147/* 148 * Define this variable to enable logging 149 */ 150//$log = new Logging(); 151 152?>