. */ /** * @defgroup mcc Maarch Capture Connector */ /** * mcc_server = server for Maarch Capture Connector * * @file * @author Laurent Giovanonni * @date $date$ * @version $Revision$ * @ingroup mcc * @brief mcc_server, server for Maarch Capture Connector */ //Error mode and function error_reporting(E_ERROR); set_error_handler(errorHandler); //Global var of the program /** * maarch capture connector path */ $_ENV['mccPath'] = ""; /** * maarch tmp path */ $_ENV['maarchTmpPath'] = ""; /** * target path for preprocess */ $_ENV['targetPath'] = ""; /** * keep the orign filename or not */ $_ENV['KEEP_THE_ORIGIN_FILENAME'] = false; /** * location of the database server */ $_ENV['databaseserver'] = ""; /** * port of the database server */ $_ENV['databaseport'] = 0; /** * name of the database */ $_ENV['database'] = ""; /** * type of the database */ $_ENV['databasetype'] = ""; /** * user name of the database */ $_ENV['databaseuser'] = ""; /** * password of the database */ $_ENV['databasepwd'] = ""; /** * path to the log file */ $_ENV['log'] = ""; /** * Creation of the log file */ function loginCreation() { if(!is_dir($_ENV['mccPath'].DIRECTORY_SEPARATOR."logs".DIRECTORY_SEPARATOR)) { mkdir($_ENV['mccPath'].DIRECTORY_SEPARATOR."logs".DIRECTORY_SEPARATOR,0777); } $_ENV['log'] = $_ENV['mccPath'].DIRECTORY_SEPARATOR."logs".DIRECTORY_SEPARATOR."mcc_server.log"; writeLog("Application start with : ".$_SERVER['SCRIPT_FILENAME']); } /** * Write on the log file * @param $eventInfo string text which is written in the log file */ function writeLog($eventInfo) { $logFileOpened = fopen($_ENV['log'], "a"); fwrite($logFileOpened, "[".date("d")."/".date("m")."/".date("Y")." ".date("H").":".date("i").":".date("s")."] ".$eventInfo."\r\n"); fclose($logFileOpened); } /** * Write on the log file errors * @param $eventInfo string text which is written in the log file * @param $errorLevel integer text return code of an error */ function manageError($eventInfo, $errorLevel) { $logFileOpened = fopen($_ENV['log'], "a"); fwrite($logFileOpened, "[".date("d")."/".date("m")."/".date("Y")." ".date("H").":".date("i").":".date("s")."][ERRNO]".$errorLevel."[ERRNO][ERROR]".$eventInfo."[ERROR]\r\n"); fclose($logFileOpened); echo $errorLevel." ".$eventInfo; exit($errorLevel); } /** * Managing of errors * @param $errno integer number of the error * @param $errstr string text of the error * @param $errfile string file concerned with the error * @param $errline integer line of the error * @param $errcontext string context of the error */ function errorHandler($errno, $errstr, $errfile, $errline, $errcontext) { $string = $errstr; $search1="'xml_file_loaded'"; $search2="'Undefined index'"; preg_match($search1,$string,$out); $count=count($out[0]); if($count == 1) { $find1 = true; } preg_match($search2,$string,$out); $count=count($out[0]); if($count == 1) { $find2 = true; } if(!$find1 && !$find2) { manageError("from line ".$errline." : ". $errstr, 1); $_ENV['errorLevel'] = 1; } } /** * Return the file's extention of a file * @param $sFullPath string path of the file */ function extractFileExt($sFullPath) { $sName = $sFullPath; if($sFullPath == "") { $extractFileExt = ""; } else { $extractFileExt = explode(".", $sName); } return $extractFileExt[count($extractFileExt) - 1]; } /** * Return only name of the file path * @param $sFullPath string path of the file */ function extractFileName($sFullPath) { //echo "chemin :".$sFullPath."\n slh : ".DIRECTORY_SEPARATOR."\n position : ".strrpos($sFullPath, DIRECTORY_SEPARATOR)."\n file : ".substr($sFullPath, strrpos($sFullPath, DIRECTORY_SEPARATOR) +1)."\n"; if($_ENV['osName'] == "UNIX") { if(!ereg(DIRECTORY_SEPARATOR, $sFullPath)) { return $sFullPath; } else { return substr($sFullPath, strrpos($sFullPath, DIRECTORY_SEPARATOR) +1); } } else { if(!ereg("\\".DIRECTORY_SEPARATOR, $sFullPath)) { return $sFullPath; } else { return substr($sFullPath, strrpos($sFullPath, DIRECTORY_SEPARATOR) +1); } } } /** * Loading of the xml config file * @param $conf string path to the config file */ function loadConfig($conf) { //loading of the xml config file. $xmlConfig = simplexml_load_file($conf); $CONFIG =$xmlConfig -> CONFIG; $_ENV['mccPath'] = $CONFIG -> MCC_PATH; loginCreation(); writeLog("Loading xml config file : ".$conf); writeLog("mccPath : ".$_ENV['mccPath']); $_ENV['maarchTmpPath'] = $CONFIG -> MAARCH_TMP_PATH; writeLog("maarchTmpPath : ".$_ENV['maarchTmpPath']); $_ENV['targetPath'] = $CONFIG -> TARGET_PATH; $_ENV['KEEP_THE_ORIGIN_FILENAME'] = ( $CONFIG -> KEEP_THE_ORIGIN_FILENAME == "true"); writeLog("targetPath : ".$_ENV['targetPath']); $DATABASE =$xmlConfig -> DATABASE; $_ENV['databaseserver'] = $DATABASE->LOCATION; //writeLog("databaseserver : ".$_ENV['databaseserver']); $_ENV['databaseport'] = $DATABASE->DATABASE_PORT; //writeLog("databaseport : ".$_ENV['databaseport']); $_ENV['database'] = $DATABASE ->DATABASE; //writeLog("database : ".$_ENV['database']); $_ENV['databasetype'] = $DATABASE->DATABASETYPE; //writeLog("databasetype : ".$_ENV['databasetype']); $_ENV['databaseuser'] = $DATABASE -> USER_NAME; //writeLog("databaseuser : ".$_ENV['databaseuser']); $_ENV['databasepwd'] = $DATABASE->PASSWORD; //writeLog("databasepwd : ".$_ENV['databasepwd']); $_ENV['databaseworkspace'] = $DATABASE->DATABASEWORKSPACE; //writeLog("databaseworkspace : ".$_ENV['databaseworkspace']); } //begin date_default_timezone_set('Europe/Paris'); $conf = "config".DIRECTORY_SEPARATOR."config_".$_REQUEST['configName'][0].".xml"; if(!file_exists($conf)) { die ("The read of the configuration file has been stopped by Maarch Capture Connector Server (Xml Error)"); } loadConfig($conf); //print_r($_FILES); //print_r($_REQUEST); writeLog("name : ".$_FILES['images']['name'][0]); writeLog("type : ".$_FILES['images']['type'][0]); writeLog("tmp name : ".$_FILES['images']['tmp_name'][0]); writeLog("error : ".$_FILES['images']['error'][0]); writeLog("size : ".$_FILES['images']['size'][0]); writeLog("md5 : ".$_REQUEST['md5'][0]); writeLog("mlb : ".$_REQUEST['mlb'][0]); if(!empty($_FILES['images']['name'][0])) { $extension = explode(".",$_FILES['images']['name'][0]); $count_level = count($extension) - 1; $the_ext = $extension[$count_level]; if(!is_uploaded_file($_FILES['images']['tmp_name'][0])) { manageError("No upload", 1); } if($_REQUEST['arg1'][0] <> "" ) { $rand = rand(1, 999999); if( $_ENV['KEEP_THE_ORIGIN_FILENAME'] ) { $final_filename = "MAARCH ".$_REQUEST['arg1'][0]." Y ".$_REQUEST['arg2'][0]."_".$_FILES['images']['name'][0].".".$the_ext; } else { $final_filename = "MAARCH ".$_REQUEST['arg1'][0]." Y ".$_REQUEST['arg2'][0]."_".date("Y")."_".date("m")."_".date("d")." ".date("H")."_".date("i")."_".date("s")."_".$rand.".".$the_ext; } if(!move_uploaded_file($_FILES['images']['tmp_name'][0], $_ENV['targetPath'].$final_filename)) { manageError("No copy to tmp dir : ".$_ENV['targetPath']."MAARCH ".$_REQUEST['arg1'][0]." Y ".$_REQUEST['arg2'][0]."_".date("Y")."_".date("m")."_".date("d")." ".date("H")."_".date("i")."_".date("s")."_".$rand.".".$the_ext, 1); } else { writeLog("Copy to tmp dir : ".$_ENV['targetPath']."MAARCH ".$_REQUEST['arg1'][0]." Y ".$_REQUEST['arg2'][0]."_".date("Y")."_".date("m")."_".date("d")." ".date("H")."_".date("i")."_".date("s").".".$the_ext); exit(0); } } else { if($_REQUEST['mlb'][0] == "true") { if(!move_uploaded_file($_FILES['images']['tmp_name'][0], $_ENV['maarchTmpPath']."tmp_file".$_REQUEST['md5'][0].".".$the_ext)) { manageError("No copy to tmp dir : ".$_ENV['maarchTmpPath']."tmp_file".$_REQUEST['md5'][0].'.'.$the_ext, 1); } else { writeLog("Copy to tmp dir : ".$_ENV['maarchTmpPath']."tmp_file".$_REQUEST['md5'][0].'.'.$the_ext); exit(0); } } else { if(!move_uploaded_file($_FILES['images']['tmp_name'][0], $_ENV['maarchTmpPath']."tmp_file_".$_REQUEST['md5'][0].".".$the_ext)) { manageError("No copy to tmp dir : ".$_ENV['maarchTmpPath']."tmp_file_".$_REQUEST['md5'][0].'.'.$the_ext, 1); } else { writeLog("Copy to tmp dir : ".$_ENV['maarchTmpPath']."tmp_file_".$_REQUEST['md5'][0].'.'.$the_ext); exit(0); } } } } exit(0); ?>