Changeset 105

Show
Ignore:
Timestamp:
01/13/06 12:03:51 (3 years ago)
Author:
ludo
Message:

sync with 0.8.4 release

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/webmin/backuppc/backupfun.php

    r26 r105  
    2424function readBackupHosts() { 
    2525   
    26   $lines = file('/etc/backuppc/hosts'); 
    27   $hosts = array(); 
    28   foreach ($lines as $line_num => $line) { 
    29      if (ereg("(^[^#][0-9a-zA-Z._-]+)", $line, $regs)) { 
    30        $hosts[$line_num]=$regs[0]; 
    31      
    32  
    33   return $hosts; 
     26       $lines = file('/etc/backuppc/hosts'); 
     27       $hosts = array(); 
     28       foreach ($lines as $line_num => $line) { 
     29               if (ereg("(^[^#][0-9a-zA-Z._-]+)", $line, $regs)) { 
     30                       $hosts[$line_num]=$regs[0]; 
     31               
     32       
     33       return $hosts; 
    3434 
    3535} 
     
    3838 * $host - host name 
    3939 * return true if host is in the /etc/backuppc/hosts file 
    40 */ 
     40 */ 
    4141function hostBackuped($host) { 
    42   $hosts = readBackupHosts(); 
    43   if ( in_array($host, $hosts) &&  
    44        is_readable("/etc/backuppc/".strtolower($host).".pl") ) { 
    45     return true; 
    46  
    47   return false; 
     42       $hosts = readBackupHosts(); 
     43       if ( in_array($host, $hosts) &&  
     44            is_readable("/etc/backuppc/".strtolower($host).".pl") ) { 
     45               return true; 
     46       
     47       return false; 
    4848} 
    4949 
     
    5252 * the created file is /etc/backuppc/$host.pl 
    5353 * $host - host name 
    54 */ 
     54 */ 
    5555function generateDefaultFile($host) { 
    56   $host = strtolower($host); 
    57   $filename = "/etc/backuppc/".$host.".pl"; 
    58   if (!($fh = fopen($filename, "w"))) 
    59     halt("cannot create file $filename"); 
    60   fwrite($fh, "# Configuration of $host\n\$Conf{XferMethod} = 'smb';\n\n\$Conf{SmbShareName} = [];\n\n"); 
    61   #fwrite($fh, "\$Conf{TarClientCmd} = '/usr/bin/env LANG=en \$tarPath -c -v -f - -C \$shareName --totals';\n\n"); 
    62   fwrite($fh, "\n# *** Unchanged Configuration ***\n"); 
    63   fwrite($fh, "\n\n# ***\n"); 
    64   fclose($fh); 
     56       $host = strtolower($host); 
     57       $filename = "/etc/backuppc/".$host.".pl"; 
     58       if (!($fh = fopen($filename, "w"))) 
     59               halt("cannot create file $filename"); 
     60       fwrite($fh, "# Configuration of $host\n\$Conf{XferMethod} = 'smb';\n\n\$Conf{SmbShareName} = [];\n\n"); 
     61#fwrite($fh, "\$Conf{TarClientCmd} = '/usr/bin/env LANG=en \$tarPath -c -v -f - -C \$shareName --totals';\n\n"); 
     62       fwrite($fh, "\n# *** Unchanged Configuration ***\n"); 
     63       fwrite($fh, "\n\n# ***\n"); 
     64       fclose($fh); 
    6565} 
    6666 
     
    7070 * adding a host means adding its name to /etc/backuppc/hosts file and creating a default file 
    7171 * then the host can be configured through webmin interface 
    72 */ 
     72 */ 
    7373function addBackuppcHost($host, $dhcp=0) { 
    74   $filename = '/etc/backuppc/hosts'; 
    75   $fh = fopen($filename, "r+"); 
    76   $f_str = fread($fh, filesize($filename)); 
    77   $str = "$host \t $dhcp \t backuppc\n"; 
    78   if (!strstr($f_str, "\n".$str)) { 
    79     # only add if it does not exist 
    80     if (fwrite($fh, $str) == FALSE) 
    81       halt("cannot write to $filename"); 
    82  
    83   fclose($fh); 
    84   generateDefaultFile($host); 
    85   reloadBPC(); 
     74       $filename = '/etc/backuppc/hosts'; 
     75       $fh = fopen($filename, "r+"); 
     76       $f_str = fread($fh, filesize($filename)); 
     77       $str = "$host \t $dhcp \t backuppc\n"; 
     78       if (!strstr($f_str, "\n".$str)) { 
     79# only add if it does not exist 
     80               if (fwrite($fh, $str) == FALSE) 
     81                       halt("cannot write to $filename"); 
     82       
     83       fclose($fh); 
     84       generateDefaultFile($host); 
     85       reloadBPC(); 
    8686} 
    8787 
    8888/* Tell BPC to reload its main config files */ 
    8989function reloadBPC () { 
    90   exec('/etc/init.d/backuppc reload'); 
     90       exec('/etc/init.d/backuppc reload'); 
    9191} 
    9292 
     
    9494 * $host - host name 
    9595 * $dhcp - dhcp flag, by default 0, might be set through webmin 
    96 */ 
     96 */ 
    9797function changeDHCP($host, $dhcp) { 
    98   $filename = '/etc/backuppc/hosts'; 
    99  
    100   $fh = fopen($filename, "rb"); 
    101   $f_str = fread($fh, filesize($filename)); 
    102   fclose($fh); 
    103    
    104   $reg = "/[^#\s]*".$host."\s+[01]/"; 
    105   $replacement = "$host \t $dhcp"; 
    106   $f_str = preg_replace($reg, $replacement, $f_str); 
    107  
    108   $fh = fopen($filename, "w"); 
    109   if (fwrite($fh, $f_str) == FALSE) 
    110     halt("cannot write to $filename"); 
    111   fclose($fh); 
     98       $filename = '/etc/backuppc/hosts'; 
     99 
     100       $fh = fopen($filename, "rb"); 
     101       $f_str = fread($fh, filesize($filename)); 
     102       fclose($fh); 
     103   
     104       $reg = "/[^#\s]*".$host."\s+[01]/"; 
     105       $replacement = "$host \t $dhcp"; 
     106       $f_str = preg_replace($reg, $replacement, $f_str); 
     107 
     108       $fh = fopen($filename, "w"); 
     109       if (fwrite($fh, $f_str) == FALSE) 
     110               halt("cannot write to $filename"); 
     111       fclose($fh); 
    112112} 
    113113 
     
    115115 * return host's DHCP flag 
    116116 * $host - host name 
    117 */ 
     117 */ 
    118118function getDHCP($host) { 
    119   $filename = '/etc/backuppc/hosts'; 
    120  
    121   $fh = fopen($filename, "rb"); 
    122   $f_str = fread($fh, filesize($filename)); 
    123   fclose($fh); 
    124    
    125   $reg = "/[^#]\s*".$host."\s+([01])/"; 
    126   if (preg_match($reg, $f_str, $regs))  
    127     return $regs[1]; 
    128  
    129   return -1; 
     119       $filename = '/etc/backuppc/hosts'; 
     120 
     121       $fh = fopen($filename, "rb"); 
     122       $f_str = fread($fh, filesize($filename)); 
     123       fclose($fh); 
     124   
     125       $reg = "/[^#]\s*".$host."\s+([01])/"; 
     126       if (preg_match($reg, $f_str, $regs))  
     127               return $regs[1]; 
     128 
     129       return -1; 
    130130} 
    131131 
     
    134134*/ 
    135135function deleteComments($filelines) { 
    136   $no_comment=array(); 
    137   $j=0; 
    138   $reg = "/^#.*$/"; 
    139   for ($i=0; $i<count($filelines);$i++) { 
    140     if (!preg_match($reg, $filelines[$i], $m)) {  
    141       $no_comment[$j] = $filelines[$i]; 
    142       $j++; 
    143     }  
    144   }   
    145   $filestr = implode("", $no_comment); 
    146   return $filestr; 
     136       $no_comment=array(); 
     137       $j=0; 
     138       $reg = "/^#.*$/"; 
     139       for ($i=0; $i<count($filelines);$i++) { 
     140               if (!preg_match($reg, $filelines[$i], $m)) {  
     141                       $no_comment[$j] = $filelines[$i]; 
     142                       $j++; 
     143               }  
     144       }   
     145       $filestr = implode("", $no_comment); 
     146       return $filestr; 
    147147}  
    148148 
     
    164164function findCommonSettings($filestr, &$full, &$incr, &$blackout_begin, &$blackout_end, &$blackout_days) { 
    165165 
    166   if (!isset($full)) { 
    167     $reg = "/[\$]Conf\{FullPeriod\}\s*=\s*(.+);/"; 
    168     if (preg_match($reg, $filestr, $m)) { 
    169        $full = $m[1]; 
    170    
    171  
    172   if (!isset($incr)) { 
    173     $reg = "/[\$]Conf\{IncrPeriod\}\s*=\s*(.+);/"; 
    174     if (preg_match($reg, $filestr, $m)) { 
    175       $incr = $m[1]; 
    176    
    177  
    178  
    179   if (!isset($blackout_begin)) { 
    180     $reg = "/[\$]Conf\{BlackoutHourBegin\}\s*=\s*(.+);/"; 
    181     if (preg_match($reg, $filestr, $m)) 
    182       $blackout_begin = $m[1]; 
    183  
    184    
    185   if (!isset($blackout_end)) { 
    186     $reg = "/[\$]Conf\{BlackoutHourEnd\}\s*=\s*(.+);/"; 
    187     if (preg_match($reg, $filestr, $m))  
    188       $blackout_end = $m[1]; 
    189  
    190  
    191   if (!isset($blackout_days)) { 
    192     $reg = "/[\$]Conf\{BlackoutWeekDays\}\s*=\s*\[(.+)\];/"; 
    193     if (preg_match($reg, $filestr, $m)) { 
    194       $blackoutdays_tmp = array_map("trim", explode(",", $m[1])); 
    195       $blackout_days=array(); 
    196       for ($i=0; $i<7; $i++)  
    197         $blackout_days[$i]=(in_array($i, $blackoutdays_tmp)); 
    198    
    199  
     166       if (!isset($full)) { 
     167               $reg = "/[\$]Conf\{FullPeriod\}\s*=\s*(.+);/"; 
     168               if (preg_match($reg, $filestr, $m)) { 
     169                       $full = $m[1]; 
     170               
     171       
     172       if (!isset($incr)) { 
     173               $reg = "/[\$]Conf\{IncrPeriod\}\s*=\s*(.+);/"; 
     174               if (preg_match($reg, $filestr, $m)) { 
     175                       $incr = $m[1]; 
     176               
     177       
     178 
     179       if (!isset($blackout_begin)) { 
     180               $reg = "/[\$]Conf\{BlackoutHourBegin\}\s*=\s*(.+);/"; 
     181               if (preg_match($reg, $filestr, $m)) 
     182                       $blackout_begin = $m[1]; 
     183       
     184   
     185       if (!isset($blackout_end)) { 
     186               $reg = "/[\$]Conf\{BlackoutHourEnd\}\s*=\s*(.+);/"; 
     187               if (preg_match($reg, $filestr, $m))  
     188                       $blackout_end = $m[1]; 
     189       
     190 
     191       if (!isset($blackout_days)) { 
     192               $reg = "/[\$]Conf\{BlackoutWeekDays\}\s*=\s*\[(.+)\];/"; 
     193               if (preg_match($reg, $filestr, $m)) { 
     194                       $blackoutdays_tmp = array_map("trim", explode(",", $m[1])); 
     195                       $blackout_days=array(); 
     196                       for ($i=0; $i<7; $i++)  
     197                               $blackout_days[$i]=(in_array($i, $blackoutdays_tmp)); 
     198               
     199       
    200200}  
    201201/* read configuration values of host, read them in an intelligent way: if a variable is set don't change it,  
     
    210210 * $blackout_days - blackout week days 
    211211 * on the return the proper variables are set 
    212 */ 
     212 */ 
    213213function readConfFile($host, &$xfermethod, &$shares, &$username, &$passwd, &$full, &$incr, 
    214214                      &$blackout_begin, &$blackout_end, &$blackout_days) { 
    215215  
    216 // values from host file 
    217   $host_file = strtolower($host); 
    218   
    219   $filename = '/etc/backuppc/'.$host_file.'.pl'; 
    220   $filelines = @file($filename); 
    221   if (empty($filelines)) { 
    222     halt("Error while reading $host configuration file; $filename does not exist or is empty."); 
    223     return false; 
    224  
    225   
    226   $filestr = deleteComments($filelines); 
    227   
    228   $reg = "/[\$]Conf\{XferMethod\}\s*=\s*\'(.+)\';/"; 
    229   preg_match($reg, $filestr, $m); 
    230   $xfermethod_orig = $m[1]; 
    231   if ($xfermethod_orig == "tar") { 
    232     $reg = "/[\$]Conf\{TarClientCmd\}\s*=\s*\'(.+)\';/"; 
    233     if (!preg_match($reg, $filestr, $m))  
    234       $xfermethod_orig = "tarssh"; 
    235  
    236  
    237   $xfer_changed = false; 
    238   if (isset($xfermethod)) { 
    239     if ($xfermethod_orig != $xfermethod) 
    240       $xfer_changed = true; 
    241   } else 
    242     $xfermethod = $xfermethod_orig; 
    243    
    244   $str = ucfirst($xfermethod); 
    245    
    246   if (!isset($shares) && !($xfer_changed)) { 
    247     $shares=array(); 
    248     if ($xfermethod == "rsyncd") 
    249       $reg = "/[\$]Conf\{RsyncShareName\}\s*=\s*\[(.*)\];/"; 
    250     else  
    251     if ($xfermethod == "tarssh") 
    252       $reg = "/[\$]Conf\{TarShareName\}\s*=\s*\[(.*)\];/"; 
    253     else 
    254       $reg = "/[\$]Conf\{".$str."ShareName\}\s*=\s*\[(.*)\];/"; 
    255     preg_match($reg, $filestr, $m); 
    256     $shares_full = explode(",", $m[1]); 
    257     $reg = "/\'(.*)\'/"; 
    258     $j = 0; 
    259     for ($i=0; $i<count($shares_full); $i++) { 
    260       preg_match($reg, $shares_full[$i], $m); 
    261       if ($m[1]) { // this is to eliminate empty inputs in table 
    262         $shares[$j] = $m[1]; 
    263         $j++; 
    264      
    265    
    266  
    267   
    268   if (!($xfer_changed) && ($xfermethod == 'smb' || $xfermethod == 'rsyncd') && !isset($username) && !isset($passwd)) { 
    269     $reg = "/[\$]Conf\{".$str."ShareUserName\}\s*=\s*\'(.*)\';/"; 
    270     preg_match($reg, $filestr, $m); 
    271     $username = $m[1]; 
    272  
    273     $reg = "/[\$]Conf\{".$str."SharePasswd\}\s*=\s*\'(.*)\';/"; 
    274     preg_match($reg, $filestr, $m); 
    275     $passwd = $m[1]; 
    276  
    277  
    278   findCommonSettings($filestr, $full, $incr, $blackout_begin, $blackout_end, $blackout_days); 
    279  
    280 // values from config.pl 
    281   $filename = '/etc/backuppc/config.pl'; 
    282  
    283   $filelines = @file($filename); 
    284   if (empty($filelines)) { 
    285     halt("Error while reading configuration file; $filename does not exist or is empty."); 
    286     return false; 
    287  
    288   
    289   $filestr = deleteComments($filelines); 
    290    
    291   findCommonSettings($filestr, $full, $incr, $blackout_begin, $blackout_end, $blackout_days); 
     216       // values from host file 
     217       $host_file = strtolower($host); 
     218  
     219       $filename = '/etc/backuppc/'.$host_file.'.pl'; 
     220       $filelines = @file($filename); 
     221       if (empty($filelines)) { 
     222               halt("Error while reading $host configuration file; $filename does not exist or is empty."); 
     223               return false; 
     224       
     225  
     226       $filestr = deleteComments($filelines); 
     227  
     228       $reg = "/[\$]Conf\{XferMethod\}\s*=\s*\'(.+)\';/"; 
     229       preg_match($reg, $filestr, $m); 
     230       $xfermethod_orig = $m[1]; 
     231       if ($xfermethod_orig == "tar") { 
     232               $reg = "/[\$]Conf\{TarClientCmd\}\s*=\s*\'(.+)\';/"; 
     233               if (!preg_match($reg, $filestr, $m))  
     234                       $xfermethod_orig = "tarssh"; 
     235       
     236 
     237       $xfer_changed = false; 
     238       if (isset($xfermethod)) { 
     239               if ($xfermethod_orig != $xfermethod) 
     240                       $xfer_changed = true; 
     241       } else 
     242               $xfermethod = $xfermethod_orig; 
     243   
     244       $str = ucfirst($xfermethod); 
     245   
     246       if (!isset($shares) && !($xfer_changed)) { 
     247               $shares=array(); 
     248               if ($xfermethod == "rsyncd") 
     249                       $reg = "/[\$]Conf\{RsyncShareName\}\s*=\s*\[(.*)\];/"; 
     250               else  
     251                       if ($xfermethod == "tarssh") 
     252                               $reg = "/[\$]Conf\{TarShareName\}\s*=\s*\[(.*)\];/"; 
     253                       else 
     254                               $reg = "/[\$]Conf\{".$str."ShareName\}\s*=\s*\[(.*)\];/"; 
     255               preg_match($reg, $filestr, $m); 
     256               $shares_full = explode(",", $m[1]); 
     257               $reg = "/\'(.*)\'/"; 
     258               $j = 0; 
     259               for ($i=0; $i<count($shares_full); $i++) { 
     260                       preg_match($reg, $shares_full[$i], $m); 
     261                       if ($m[1]) { // this is to eliminate empty inputs in table 
     262                               $shares[$j] = $m[1]; 
     263                               $j++; 
     264                       
     265               
     266       
     267  
     268       if (!($xfer_changed) && ($xfermethod == 'smb' || $xfermethod == 'rsyncd') && !isset($username) && !isset($passwd)) { 
     269               $reg = "/[\$]Conf\{".$str."ShareUserName\}\s*=\s*\'(.*)\';/"; 
     270               preg_match($reg, $filestr, $m); 
     271               $username = $m[1]; 
     272 
     273               $reg = "/[\$]Conf\{".$str."SharePasswd\}\s*=\s*\'(.*)\';/"; 
     274               preg_match($reg, $filestr, $m); 
     275               $passwd = $m[1]; 
     276       
     277 
     278       findCommonSettings($filestr, $full, $incr, $blackout_begin, $blackout_end, $blackout_days); 
     279 
     280       // values from config.pl 
     281       $filename = '/etc/backuppc/config.pl'; 
     282 
     283       $filelines = @file($filename); 
     284       if (empty($filelines)) { 
     285               halt("Error while reading configuration file; $filename does not exist or is empty."); 
     286               return false; 
     287       
     288  
     289       $filestr = deleteComments($filelines); 
     290   
     291       findCommonSettings($filestr, $full, $incr, $blackout_begin, $blackout_end, $blackout_days); 
    292292 
    293293} 
    294294 
    295295/* show error message and quit 
    296 */ 
     296 */ 
    297297function halt($msg) { 
    298  die("<b>Halted:</b> $msg"); 
    299  return false; 
     298       die("<b>Halted:</b> $msg"); 
     299       return false; 
    300300} 
    301301 
    302302function sshKeyExists() { 
    303   return file_exists('/var/lib/backuppc/.ssh/BackupPC_id_rsa.pub'); 
     303       return file_exists('/var/lib/backuppc/.ssh/BackupPC_id_rsa.pub'); 
    304304} 
    305305 
    306306/* Generate the public/private keys on the server. The public key is later used by a rsyncd, tar ssh clients for authorisation  
    307 */ 
     307 */ 
    308308function generateSshKey() { 
    309   if(!file_exists('/var/lib/backuppc/.ssh')) 
    310     mkdir("/var/lib/backuppc/.ssh", 0644); 
    311   if (!file_exists('/var/lib/backuppc/.ssh/id_rsa.pub')) { 
    312     if (!file_exists('~/.ssh/id_rsa.pub'))  
    313       exec("ssh-keygen -t rsa -N '' -f ~/.ssh/id_rsa"); 
    314      
    315     copy("/root/.ssh/id_rsa", "/var/lib/backuppc/.ssh/id_rsa"); 
    316     copy("/root/.ssh/id_rsa.pub", "/var/lib/backuppc/.ssh/id_rsa.pub"); 
    317   } 
    318   if (!file_exists('/var/lib/backuppc/.ssh/BackupPC_id_rsa.pub')) { 
    319     copy("/root/.ssh/id_rsa.pub", "/var/lib/backuppc/.ssh/BackupPC_id_rsa.pub"); 
    320  
     309        $bpchome = "/var/lib/backuppc"; 
     310 
     311       if (!file_exists('$bpchome/.ssh/id_rsa.pub')) { 
     312                if (!file_exists('$bpchome/.ssh')) 
     313                       mkdir("$bpchome/.ssh", 0700); 
     314               if (!file_exists('$bpchome/.ssh/id_rsa.pub'))  
     315                       exec("ssh-keygen -t rsa -N '' -f $bpchome/.ssh/id_rsa"); 
     316 
     317                copy("$bpchome/.ssh/id_rsa.pub", "$bpchome/.ssh/BackupPC_id_rsa.pub");   
     318                exec("chown -R backuppc:backuppc $bpchome/.ssh/"); 
     319               exec("chmod -R og-rwx $bpchome/.ssh/"); 
     320       
    321321} 
    322322 
    323323/* return the part of the hosts' ocnifuration file between the comments : *** Unchanged Configuration *** and *** */ 
    324324function getUnchangedConf($host) { 
    325   $host_file = strtolower($host); 
    326   $filename = '/etc/backuppc/'.$host_file.'.pl'; 
    327   $filestr = implode("", @file($filename)); 
    328  
    329   if (empty($filestr)) { 
    330     halt("Error while reading $host configuration file; $filename does not exist or is empty."); 
    331     return false; 
    332  
    333   $reg = "/(# \*\*\* Unchanged Configuration \*\*\*[^\*]*# \*\*\*)/"; 
    334   preg_match($reg, $filestr, $m); 
    335    
    336   return $m[1]; 
     325       $host_file = strtolower($host); 
     326       $filename = '/etc/backuppc/'.$host_file.'.pl'; 
     327       $filestr = implode("", @file($filename)); 
     328 
     329       if (empty($filestr)) { 
     330               halt("Error while reading $host configuration file; $filename does not exist or is empty."); 
     331               return false; 
     332       
     333       $reg = "/(# \*\*\* Unchanged Configuration \*\*\*[^\*]*# \*\*\*)/"; 
     334       preg_match($reg, $filestr, $m); 
     335   
     336       return $m[1]; 
    337337} 
    338338 
     
    346346 * $blackout_days - blackout week days 
    347347 * on the return the proper file is written 
    348 */ 
     348 */ 
    349349function saveBackupFile($host, $xfermethod, $shares_str, $username, $passwd, $full, $incr, 
    350350                        $blackout_begin, $blackout_end, $blackout_days) { 
    351   $host_file = strtolower($host); 
    352   $filename = "/etc/backuppc/".$host_file.".pl"; 
    353    
    354   $unchangedConf = getUnchangedConf($host); 
    355    
    356   if (!($fh = fopen($filename, "w"))) 
    357     halt("cannot create file $filename"); 
    358   fwrite($fh, "# Configuration of $host\n"); 
    359   if ($xfermethod == "tarssh") 
    360     fwrite($fh, "\$Conf{XferMethod} = 'tar';\n\n"); 
    361   else 
    362     fwrite($fh, "\$Conf{XferMethod} = '$xfermethod';\n\n"); 
    363   
    364   if ($xfermethod == "tar" || $xfermethod == "tarssh") { 
    365     fwrite($fh, "\$Conf{TarShareName} = $shares_str;\n\n"); 
    366     if ($xfermethod == "tar") 
    367       fwrite($fh, "\$Conf{TarClientCmd} = '/usr/bin/env LANG=en \$tarPath -c -v -f - -C \$shareName --totals';\n\n"); 
    368   } else  
    369   if ($xfermethod == "smb" ) { 
    370     fwrite($fh, "\$Conf{SmbShareName} = $shares_str;\n\n"); 
    371     fwrite($fh, "\$Conf{SmbShareUserName} = '$username';\n"); 
    372     fwrite($fh, "\$Conf{SmbSharePasswd} = '$passwd';\n\n"); 
    373   } else 
    374   if ($xfermethod == "rsync" || $xfermethod == "rsyncd") { 
    375     fwrite($fh, "\$Conf{RsyncShareName} = $shares_str;\n\n"); 
    376     if ($xfermethod == "rsyncd") { 
    377       fwrite($fh, "\$Conf{RsyncdShareUserName} = '$username';\n"); 
    378       fwrite($fh, "\$Conf{RsyncdSharePasswd} = '$passwd';\n\n"); 
    379    
    380   }  
     351       $host_file = strtolower($host); 
     352       $filename = "/etc/backuppc/".$host_file.".pl"; 
     353   
     354       $unchangedConf = getUnchangedConf($host); 
     355   
     356       if (!($fh = fopen($filename, "w"))) 
     357               halt("cannot create file $filename"); 
     358       fwrite($fh, "# Configuration of $host\n"); 
     359       if ($xfermethod == "tarssh") 
     360               fwrite($fh, "\$Conf{XferMethod} = 'tar';\n\n"); 
     361       else 
     362               fwrite($fh, "\$Conf{XferMethod} = '$xfermethod';\n\n"); 
     363  
     364       if ($xfermethod == "tar" || $xfermethod == "tarssh") { 
     365               fwrite($fh, "\$Conf{TarShareName} = $shares_str;\n\n"); 
     366               if ($xfermethod == "tar") 
     367                       fwrite($fh, "\$Conf{TarClientCmd} = '/usr/bin/env LANG=en \$tarPath -c -v -f - -C \$shareName --totals';\n\n"); 
     368       } else  
     369               if ($xfermethod == "smb" ) { 
     370                       fwrite($fh, "\$Conf{SmbShareName} = $shares_str;\n\n"); 
     371                       fwrite($fh, "\$Conf{SmbShareUserName} = '$username';\n"); 
     372                       fwrite($fh, "\$Conf{SmbSharePasswd} = '$passwd';\n\n"); 
     373               } else 
     374                       if ($xfermethod == "rsync" || $xfermethod == "rsyncd") { 
     375                               fwrite($fh, "\$Conf{RsyncShareName} = $shares_str;\n\n"); 
     376                               if ($xfermethod == "rsyncd") { 
     377                                       fwrite($fh, "\$Conf{RsyncdShareUserName} = '$username';\n"); 
     378                                       fwrite($fh, "\$Conf{RsyncdSharePasswd} = '$passwd';\n\n"); 
     379                               
     380                       }  
    381381   
    382382        if ($full != "") 
     
    392392                fwrite($fh, "\$Conf{BlackoutWeekDays} = [$blackout_days];\n"); 
    393393 
    394   fwrite($fh, "\n$unchangedConf\n"); 
    395   
    396   fclose($fh); 
     394       fwrite($fh, "\n$unchangedConf\n"); 
     395  
     396       fclose($fh); 
    397397} 
    398398 
     
    401401 * $username, $passwd 
    402402 * return - the shared folders list, empty in the case of error 
    403 */ 
     403 */ 
    404404function getSmbShares($host, $username, $passwd) { 
    405   $command = "smbclient -U ".$username."%".$passwd." -L $host"; 
    406   $handle = popen($command, "r"); 
    407   $str = fread($handle, 4096); 
    408   pclose($handle); 
    409    
    410   $reg = "/\s([^\s]+)\s+Disk/"; 
    411   preg_match_all($reg, $str, $m); 
    412   $res = array(); 
    413   for ($i = 0; $i < count($m[0]); $i++)  
    414    $res[$i] = $m[1][$i]; 
    415   return $res;  
     405       $command = "smbclient -U ".$username."%".$passwd." -L $host"; 
     406       $handle = popen($command, "r"); 
     407       $str = fread($handle, 4096); 
     408       pclose($handle); 
     409   
     410       $reg = "/\s([^\s]+)\s+Disk/"; 
     411       preg_match_all($reg, $str, $m); 
     412       $res = array(); 
     413       for ($i = 0; $i < count($m[0]); $i++)  
     414               $res[$i] = $m[1][$i]; 
     415       return $res;  
    416416} 
    417417 
     
    419419 * $host - host name 
    420420 * return - the shared folders list, empty in the case of error 
    421 */ 
     421 */ 
    422422function getTarShares($host) { 
    423   $command = "showmount -e $host"; 
    424   $handle = popen($command, "r"); 
    425   $res = array(); 
    426   $i = 0; 
    427   while (!feof($handle)) { 
    428     $str = fgets($handle, 4096); 
    429     $reg = "/(\/[^\s]*)\s/"; 
    430     if (preg_match($reg, $str, $m)) { 
    431       $res[$i] = $m[1]; 
    432       $i++; 
    433    
    434  
    435   pclose($handle);  
    436   return $res;  
     423       $command = "showmount -e $host"; 
     424       $handle = popen($command, "r"); 
     425       $res = array(); 
     426       $i = 0; 
     427       while (!feof($handle)) { 
     428               $str = fgets($handle, 4096); 
     429               $reg = "/(\/[^\s]*)\s/"; 
     430               if (preg_match($reg, $str, $m)) { 
     431                       $res[$i] = $m[1]; 
     432                       $i++; 
     433               
     434       
     435       pclose($handle);  
     436       return $res;  
    437437} 
    438438 
    439439/* verify if LBS is installed on the machine 
    440440 * return boolean 
    441 */ 
     441 */ 
    442442function isLBS() { 
    443   $file = '/etc/lbs.conf'; 
    444   return file_exists($file); 
     443       $file = '/etc/lbs.conf'; 
     444       return file_exists($file); 
    445445} 
    446446 
  • trunk/webmin/backuppc/debian/changelog

    r65 r105  
    1 webmin-backuppc (0.8.2) stable; urgency=low 
     1webmin-backuppc (0.8.4) stable; urgency=low 
    22 
    33  * New release. 
  • trunk/webmin/backuppc/debian/copyversion

    r24 r105  
    1 #!/bin/sh 
     1#!/bin/bash 
    22# 
    33# Check that debian/changelog and module.info versions are in sync 
  • trunk/webmin/backuppc/module.info

    r65 r105  
    1 -e desc=LRS : Files Backup 
     1desc=LRS : Files Backup 
    22desc_fr=LRS : Sauvegarde Fichiers 
    33name=BackupPC 
    44category=Webmin 
    55depends=0.94 lbs_common 
    6 version=0.8.2 
     6version=0.8.4