[ Index ] |
|
Code source de Dolibarr 2.0.1 |
1 <?PHP 2 /* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org> 3 * 4 * This program is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation; either version 2 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program; if not, write to the Free Software 16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 * 18 * $Id: getcdr.php,v 1.4 2005/11/02 19:21:55 rodolphe Exp $ 19 * $Source: /cvsroot/dolibarr/dolibarr/htdocs/telephonie/script/getcdr.php,v $ 20 * 21 * 22 * Recupération des fichiers CDR 23 * 24 */ 25 require ("../../master.inc.php"); 26 27 $nbdays = 1; 28 29 for ($i = 1 ; $i < sizeof($argv) ; $i++) 30 { 31 if ($argv[$i] == "-n") 32 { 33 $nbdays = $argv[$i+1]; 34 } 35 if ($argv[$i] == "-v") 36 { 37 $verbose = 1; 38 } 39 } 40 41 if (! is_numeric($nbdays)) 42 { 43 die("Bad argument $nbdays\n"); 44 } 45 46 $ftp_server = GETCDR_FTP_SERVER; 47 $ftp_user_name = GETCDR_FTP_USER; 48 $ftp_user_pass = GETCDR_FTP_PASS; 49 50 // Mise en place d'une connexion basique 51 $conn_id = ftp_connect($ftp_server); 52 53 // Identification avec un nom d'utilisateur et un mot de passe 54 $login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass); 55 56 // Vérification de la connexion 57 if (!$conn_id) 58 { 59 echo "La connexion FTP a échouée !"; 60 echo "Tentative de connexion au serveur $ftp_server"; 61 exit; 62 } 63 64 // Vérification de la connexion 65 if (!$login_result) 66 { 67 echo "L'authentification FTP a échouée !"; 68 echo "Tentative de connexion au serveur $ftp_server pour l'utilisateur $ftp_user_name"; 69 exit; 70 } 71 72 if (!file_exists(DOL_DATA_ROOT.'/telephonie/CDR/temp/')) 73 { 74 create_dir(DOL_DATA_ROOT.'/telephonie/CDR/temp/'); 75 } 76 77 $date = time() - (24 * 3600 * $nbdays); 78 79 $file = "daily_report_".strftime("%Y%m%d", $date).".zip"; 80 81 $remote_file = 'cdr/'.$file; 82 83 $remote_size = ftp_size($conn_id, $remote_file); 84 if ($verbose) 85 echo "Récupération de ".$remote_size." Ko\n"; 86 87 $local_file = DOL_DATA_ROOT.'/telephonie/CDR/temp/'.$file; 88 $handle = fopen($local_file, 'w'); 89 90 if (ftp_fget($conn_id, $handle, $remote_file, FTP_BINARY, 0)) 91 { 92 if ($verbose) 93 echo "Le chargement a réussi dans ".$local_file."\n"; 94 } 95 else 96 { 97 echo "Echec de recuperation du fichier ".$remote_file."\n"; 98 } 99 100 // Fermeture du flux FTP 101 ftp_close($conn_id); 102 103 $local_size = filesize($local_file); 104 105 if (file_exists($local_file) && $local_size === $remote_size && $local_size > 0) 106 { 107 // Dezippage du fichier 108 $zip = zip_open($local_file); 109 110 if ($zip) { 111 112 while ($zip_entry = zip_read($zip)) 113 { 114 if ($verbose) 115 { 116 echo "Nom du fichier : " . zip_entry_name($zip_entry) . "\n"; 117 echo "Taille réelle : " . zip_entry_filesize($zip_entry) . "\n"; 118 echo "Taille compressée : " . zip_entry_compressedsize($zip_entry) . "\n"; 119 echo "Méthode : " . zip_entry_compressionmethod($zip_entry) . "\n"; 120 } 121 122 if (zip_entry_open($zip, $zip_entry, "r")) 123 { 124 if ($verbose) 125 echo "Decompression dans ".DOL_DATA_ROOT.'/telephonie/CDR/atraiter/'.zip_entry_name($zip_entry)."\n"; 126 127 $fp = fopen(DOL_DATA_ROOT.'/telephonie/CDR/atraiter/'.zip_entry_name($zip_entry),"w"); 128 129 if ($fp) 130 { 131 $buf = zip_entry_read($zip_entry, zip_entry_filesize($zip_entry)); 132 133 if (fwrite($fp, $buf) === FALSE) 134 { 135 echo "Erreur d'ecriture\n"; 136 } 137 fclose($fp); 138 } 139 zip_entry_close($zip_entry); 140 } 141 } 142 zip_close($zip); 143 } 144 145 // Archivage du fichier 146 147 } 148 else 149 { 150 print "Erreur de récupération du fichier ".$local_file."\n"; 151 print "Remote size ".$remote_size."\n"; 152 print "Local size ".$local_size."\n"; 153 } 154 155 if (!file_exists(DOL_DATA_ROOT.'/telephonie/CDR/archive/')) 156 { 157 create_dir(DOL_DATA_ROOT.'/telephonie/CDR/archive/'); 158 } 159 160 $dir = DOL_DATA_ROOT.'/telephonie/CDR/archive/'.strftime("%Y", $date); 161 if (!file_exists($dir)) 162 create_dir($dir); 163 164 $dir = DOL_DATA_ROOT.'/telephonie/CDR/archive/'.strftime("%Y", $date).'/'.strftime("%m", $date); 165 if (!file_exists($dir)) 166 create_dir($dir); 167 168 function create_dir($dir) 169 { 170 if (! file_exists($dir)) 171 { 172 umask(0); 173 if (! @mkdir($dir, 0755)) 174 { 175 die ("Erreur: Le répertoire ".$dir." n'existe pas et Dolibarr n'a pu le créer."); 176 } 177 } 178 } 179 180 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Mon Nov 26 12:29:37 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |