Advertisement
Guest User

Untitled

a guest
Apr 25th, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.86 KB | None | 0 0
  1. function copy_dnsuser($modo,$type,$path,$user,$timer,$db){ // pendiente
  2. $passmysql=conexbd();
  3. $mysqli = new mysqli("localhost", "root", $passmysql, "root_cwp");
  4. $sel='Select * FROM user WHERE username="'.$user.'"';
  5. $resp=mysqli_query($mysqli,$sel);
  6. $row=mysqli_fetch_assoc($resp);
  7. writeslog($path."named/");
  8. if(file_exists($path."named/")){
  9. shell_exec('find '.$path.'named/ -name "*.db" -print | xargs sed -i "s/{IPSERVER}/'.$row['ip_address'].'/g"');
  10. writeslog('find '.$path.'named/ -name "*.db" -print | xargs sed -i "s/{IPSERVER}/'.$row['ip_address'].'/g"');
  11. $arradns=scandir($path.'named/');
  12. writeslog(json_encode($arradns));
  13. $error=0;
  14. $exito=0;
  15. $total=(count($arradns)-2);
  16. for($i=0;$i<count($arradns);$i++){
  17. if(($arradns[$i]!='.')and($arradns[$i]!='..')){
  18. $domainsel=trim(str_replace('.db','',$arradns[$i]));
  19. writeslog($domainsel);
  20. $command=$domainsel." ".$path."/named/".$arradns[$i];
  21. $chk=shell_exec("named-checkzone {$command} 2>&1");
  22. writeslog("named-checkzone {$command} 2>&1");
  23. $returnarray=preg_replace('/\n/', '', $chk);
  24. $srst=substr($returnarray, -2);
  25.  
  26. $commgrep='grep "serial," '.$path.'/named/'.$arradns[$i];
  27. $line=shell_exec($commgrep);
  28. $troz=explode(';',$line);
  29. $serial=substr(trim($troz[0]),0,-2);
  30. $fecha=date('Ymd');
  31. if(trim($serial)==trim($fecha)){ $newserial=trim($troz[0])+1; }else{ $newserial=trim($fecha).'00'; }
  32.  
  33. shell_exec("sed -i 's/20[0-1][0-9]\{7\}/'{$newserial}'/' {$path}'/named/{$arradns[$i]}");
  34. writeslog("sed -i 's/20[0-1][0-9]\{7\}/'{$newserial}'/' {$path}'/named/{$arradns[$i]}");
  35. if($srst=='OK'){
  36. $rsync='rsync -av '.$path.'/named/'.$arradns[$i].' /var/named/'. $arradns[$i];
  37. shell_exec($rsync);
  38. $rndc = shell_exec('rndc reload '.$domainsel.' 2> /dev/null > /dev/null && echo ok || echo failed');
  39. writeslog('rndc reload '.$domainsel.' 2> /dev/null > /dev/null && echo ok || echo failed');
  40. $exito++;
  41. }else{
  42. createerror($timer,$user,$returnarray,$db);
  43. $rsync='rsync -av '.$path.'/named/'.$arradns[$i].' /var/named/'. $arradns[$i].'.restore';
  44. shell_exec($rsync);
  45. writeslog('rsync -av '.$path.'/named/'.$arradns[$i].' /var/named/'. $arradns[$i].'.restore');
  46. $error++;
  47. }
  48. }
  49. }
  50. writeslog("Added {$exito} DNS of {$total}, with a total of {$error} errors");
  51. }else{
  52. writeslog("There are no records");
  53. }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement