[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
1 <?php 2 3 4 /** 5 6 * Permet configurer la sauvegarde (Backuppc) 7 * @Version $Id: new_host_valid.php 4995 2009-12-06 11:52:20Z gnumdk $ 8 9 * @Projet LCS / SambaEdu 10 11 * @auteurs Philippe Chadefaux 12 13 * @Licence Distribue selon les termes de la licence GPL 14 15 * @note 16 * @sudo /usr/share/se3/scripts/tarCreate -v -f - -C \$shareName+ --totals 17 */ 18 19 /** 20 21 * @Repertoire: sauvegarde 22 * file: new_host_valid.php 23 24 */ 25 26 27 28 include ("fonction_backup.inc.php"); 29 require ("config.inc.php"); 30 include ("fonctions_rsyncdconf.inc.php"); 31 32 // HTMLPurifier 33 require_once ("traitement_data.inc.php"); 34 35 36 $HostServer = $_GET['HostServer']; 37 $TypeServer = $_GET['TypeServer']; 38 $XferMethod = $_GET['XferMethod']; 39 $dhcp = $_GET['dhcp']; 40 $Share = $_GET['Share']; 41 $defo = $_GET['defo']; 42 $Compte = $_GET['Compte']; 43 $PassWord = $_GET['PassWord']; 44 $AclName = $_GET['AclName']; 45 $LdapName = $_GET['LdapName']; 46 $MysqlName = $_GET['MysqlName']; 47 $Secrets = $_GET['Secrets']; 48 $BackupFilesExclude = $_GET['BackupFilesExclude']; 49 $TypeServerOld = $_GET['TypeServerOld']; 50 $err = $_GET['err']; 51 $ArchiveDest = $_GET['ArchiveDest']; 52 $ArchiveSplit = $_GET['ArchiveSplit']; 53 54 if ($Share != "") { 55 $Share = stripslashes2($Share); 56 } 57 if ($BackupFilesExclude != "") { 58 $BackupFilesExclude = stripslashes2($BackupFilesExclude); 59 } 60 /*************** Affiche la fin du traitement *************************/ 61 62 // On ouvre le fichier 63 $fichier = "/etc/backuppc/".$HostServer.".pl"; 64 $fp=fopen("$fichier","w+"); 65 66 $HOSTFILE = " 67 #============================================================= -*-perl-*- 68 ########################################################################### 69 # General per-PC configuration settings 70 # (can be overridden in the per-PC config.pl) 71 ########################################################################### 72 \$Conf{XferMethod} = '$XferMethod'; 73 \$Conf{XferLogLevel} = 1;"; 74 75 if ($XferMethod=="archive") { 76 $HOSTFILE .= " 77 \$Conf{ArchiveDest} = '$ArchiveDest'; 78 \$Conf{ArchiveComp} = 'gzip'; 79 \$Conf{ArchivePar} = 0; 80 \$Conf{ArchiveSplit} = $ArchiveSplit; 81 \$Conf{ArchiveClientCmd} = '\$Installdir/bin/BackupPC_archiveHost' 82 . ' \$tarCreatePath \$splitpath \$parpath \$host \$backupnumber' 83 . ' \$compression \$compext \$splitsize \$archiveloc \$parfile *'; 84 \$Conf{ArchivePreUserCmd} = undef; 85 \$Conf{ArchivePostUserCmd} = undef; 86 "; 87 } 88 elseif ($XferMethod=="smb") { 89 $Share_corrige = preg_replace("/;/","','",$Share); 90 $Share_corrige = str_replace("/","",$Share_corrige); 91 $Share_corrige = "'".$Share_corrige."'"; 92 $HOSTFILE .= " 93 # Ne pas supprimer la ligne qui suit, utilisee par se3 94 # \$Conf{Repertoire} = $Share; 95 \$Conf{SmbShareName} = [$Share_corrige]; 96 \$Conf{SmbShareUserName} = '$Compte'; 97 \$Conf{SmbSharePasswd} = '$PassWord'; 98 \$Conf{SmbClientPath} = '/usr/bin/smbclient'; 99 \$Conf{SmbClientFullCmd} = '\$smbClientPath \\\\\\\\\$host\\\\\$shareName' 100 . ' \$I_option -U \$userName -E -d 1' 101 . ' -c tarmode\\ full -Tc\$X_option - \$fileList'; 102 \$Conf{SmbClientIncrCmd} = '\$smbClientPath \\\\\\\\\$host\\\\\$shareName' 103 . ' \$I_option -U \$userName -E -d 1' 104 . ' -c tarmode\\ full -TcN\$X_option \$timeStampFile - \$fileList'; 105 \$Conf{SmbClientRestoreCmd} = '\$smbClientPath \\\\\\\$host\\\\\$shareName' 106 . ' \$I_option -U \$userName -E -d 1' 107 . ' -c tarmode\\ full -Tx -'; 108 \$Conf{BackupFilesExclude} = [$BackupFilesExclude]; 109 "; 110 } elseif(($XferMethod=="rsync") or ($XferMethod=="rsyncd")) { 111 $Share_corrige = preg_replace("/;/","','",$Share); 112 $Share_corrige = str_replace("/","",$Share_corrige); 113 $Share_corrige = "'".$Share_corrige."'"; 114 $HOSTFILE .= " 115 \$Conf{RsyncClientPath} = '/usr/bin/rsync'; 116 \$Conf{RsyncClientCmd} = '\$sshPath -q -x -l root \$host \$rsyncPath \$argList+'; 117 \$Conf{RsyncClientRestoreCmd} = '\$sshPath -q -x -l root \$host \$rsyncPath \$argList+'; 118 # Ne pas supprimer la ligne qui suit, utilisee par se3 119 # \$Conf{Repertoire} = $Share; 120 \$Conf{RsyncShareName} = [$Share_corrige]; 121 \$Conf{RsyncdClientPort} = 873; 122 \$Conf{RsyncdUserName} = '$Compte'; 123 \$Conf{RsyncdPasswd} = '$PassWord'; 124 \$Conf{RsyncdAuthRequired} = 1; 125 \$Conf{RsyncCsumCacheVerifyProb} = 0.01; 126 \$Conf{RsyncArgs} = [ 127 '--numeric-ids', 128 '--perms', 129 '--owner', 130 '--group', 131 '--devices', 132 '--links', 133 '--times', 134 '--block-size=2048', 135 '--recursive', 136 ]; 137 \$Conf{RsyncRestoreArgs} = [ 138 '--numeric-ids', 139 '--perms', 140 '--owner', 141 '--group', 142 '--devices', 143 '--links', 144 '--times', 145 '--block-size=2048', 146 '--relative', 147 '--ignore-times', 148 '--recursive', 149 ]; 150 \$Conf{BackupFilesExclude} = [$BackupFilesExclude]; 151 "; 152 } 153 $FullPeriod=$_GET['FullPeriod']; 154 if (($FullPeriod != "")&& ($FullPeriod != variables(FullPeriod,config))) { 155 $HOSTFILE .= " 156 \$Conf{FullPeriod} = $FullPeriod; 157 "; 158 } 159 $IncrPeriod=$_GET['IncrPeriod']; 160 if (($IncrPeriod != "")&&($IncrPeriod != variables(IncrPeriod,config))) { 161 $HOSTFILE .= " 162 \$Conf{IncrPeriod} = $IncrPeriod; 163 "; 164 } 165 $FullKeepCnt=$_GET['FullKeepCnt']; 166 if (($FullKeepCnt != "")&&($FullKeepCnt != variables(FullKeepCnt,config))) { 167 $HOSTFILE .= " 168 \$Conf{FullKeepCnt} = $FullKeepCnt; 169 "; 170 } 171 $FullKeepCntMin=$_GET['FullKeepCntMin']; 172 if (($FullKeepCntMin != "")&&($FullKeepCntMin != variables(FullKeepCntMin,config))) { 173 $HOSTFILE .= " 174 \$Conf{FullKeepCntMin} = $FullKeepCntMin; 175 "; 176 } 177 $IncrKeepCnt=$_GET['IncrKeepCnt']; 178 if (($IncrKeepCnt != "")&&($IncrKeepCnt != variables(IncrKeepCnt,config))) { 179 $HOSTFILE .= " 180 \$Conf{IncrKeepCnt} = $IncrKeepCnt; 181 "; 182 } 183 $IncrKeepCntMin=$_GET['IncrKeepCntMin']; 184 if (($IncrKeepCntMin != "")&&($IncrKeepCntMin != variables(IncrKeepCntMin,config))) { 185 $HOSTFILE .= " 186 \$Conf{IncrKeepCntMin} = $IncrKeepCntMin; 187 "; 188 } 189 $FullAgeMax=$_GET['FullAgeMax']; 190 if (($FullAgeMax != "")&&($FullAgeMax != variables(FullAgeMax,config))) { 191 $HOSTFILE .= " 192 \$Conf{FullAgeMax} = $FullAgeMax; 193 "; 194 } 195 $IncrAgeMax=$_GET['IncrAgeMax']; 196 if (($IncrAgeMax != "")&&($IncrAgeMax != variables(IncrAgeMax,config))) { 197 $HOSTFILE .= " 198 \$Conf{IncrAgeMax} = $IncrAgeMax; 199 "; 200 } 201 $EMailAdminUserName=$_GET['EMailAdminUserName']; 202 if (($EMailAdminUserName != "")&&($EMailAdminUserName != variables(EMailAdminUserName,config))) { 203 $HOSTFILE .= " 204 \$Conf{EMailAdminUserName} = '$EMailAdminUserName'; 205 "; 206 } 207 208 fwrite($fp,$HOSTFILE); 209 fclose($fp); 210 211 // On cree le fichier /etc/rsyncd.conf 212 if (($XferMethod=="rsyncd") && ($TypeServer=="Local")) { 213 // On stoppe rsync 214 exec("sudo /usr/share/se3/scripts/mk_rsyncconf.sh stop"); 215 $hostsAllow=variable("hosts allow"); 216 if ($hostsAllow=="") { 217 $hostsAllow="127.0.0.1"; 218 } 219 $readOnly=variable("read only"); 220 if ($readOnly=="") { 221 $readOnly="no"; 222 } 223 $fichier = "/tmp/rsyncd.conf"; 224 $fp=fopen("$fichier","w+"); 225 $DEFAUT = " 226 uid=root 227 gid=root 228 use chroot=no 229 syslog facility=local5 230 pid file=/var/run/rsyncd.pid 231 auth users=".$Compte." 232 secrets file=/etc/rsyncd.secret 233 hosts allow=$hostsAllow 234 read only=$readOnly"; 235 236 237 // Creation des modules a partir des repertoires a sauvegarder 238 $modules = preg_split("/;/",$Share,-1); 239 for ($i=0; $i < count($modules); $i++) { 240 $rep_module = "$modules[$i]"; 241 $nom_module = str_replace("/","",$modules[$i]); 242 $DEFAUT .= " 243 244 ## $nom_module ; $rep_module 245 [$nom_module] 246 comment = repertoire $rep_module 247 path = $rep_module"; 248 249 } 250 251 fwrite($fp,$DEFAUT); 252 fclose($fp); 253 254 255 // On lance le script de conf 256 exec("sudo /usr/share/se3/scripts/mk_rsyncconf.sh start $Compte $PassWord"); 257 258 } 259 260 /**********************************Creation des fichiers de sauvegarde ***********************/ 261 262 if ($HostServer == "localhost") { 263 $sql="Delete from params where name='mysql_all_save';"; 264 mysql_query($sql); 265 $sql="Insert into params values ('', 'mysql_all_save', '".$MysqlName."', '5', '0', 'Sauvegarde de l ensemble des base SQL pour localhost');"; 266 mysql_query($sql); 267 mysql_close(); 268 } // fin de si localhost 269 /***********************************************************************************/ 270 // Si archive on crée le répertoire. 271 if ($XferMethod == "archive") { 272 $rep_host = "/var/lib/backuppc/pc/".$HostServer; 273 if ( ! is_dir($rep_host)) { 274 mkdir($rep_host,0750); 275 } 276 } 277 278 279 // Ajout dans le fichier hosts 280 if (HostExist($HostServer)) { // si la machine existe déja dans le fichier hosts on la vire d'abord 281 DeleteHost($HostServer); 282 } 283 284 AjoutHosts($HostServer,$dhcp,$TypeServer); 285 reloadBackuPpc(); 286 287 // revient sur la page des machines 288 289 if ($XferMethod == "archive") { 290 echo "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"0; URL=sauv.php\">"; 291 } else { 292 echo "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"0; URL=sauvhost.php\">"; 293 } 294 295 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Tue Mar 17 22:47:18 2015 | Cross-referenced by PHPXref 0.7.1 |