Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function copy_dnsuser($modo,$type,$path,$user,$timer,$db){ // pendiente
- $passmysql=conexbd();
- $mysqli = new mysqli("localhost", "root", $passmysql, "root_cwp");
- $sel='Select * FROM user WHERE username="'.$user.'"';
- $resp=mysqli_query($mysqli,$sel);
- $row=mysqli_fetch_assoc($resp);
- writeslog($path."named/");
- if(file_exists($path."named/")){
- shell_exec('find '.$path.'named/ -name "*.db" -print | xargs sed -i "s/{IPSERVER}/'.$row['ip_address'].'/g"');
- writeslog('find '.$path.'named/ -name "*.db" -print | xargs sed -i "s/{IPSERVER}/'.$row['ip_address'].'/g"');
- $arradns=scandir($path.'named/');
- writeslog(json_encode($arradns));
- $error=0;
- $exito=0;
- $total=(count($arradns)-2);
- for($i=0;$i<count($arradns);$i++){
- if(($arradns[$i]!='.')and($arradns[$i]!='..')){
- $domainsel=trim(str_replace('.db','',$arradns[$i]));
- writeslog($domainsel);
- $command=$domainsel." ".$path."/named/".$arradns[$i];
- $chk=shell_exec("named-checkzone {$command} 2>&1");
- writeslog("named-checkzone {$command} 2>&1");
- $returnarray=preg_replace('/\n/', '', $chk);
- $srst=substr($returnarray, -2);
- $commgrep='grep "serial," '.$path.'/named/'.$arradns[$i];
- $line=shell_exec($commgrep);
- $troz=explode(';',$line);
- $serial=substr(trim($troz[0]),0,-2);
- $fecha=date('Ymd');
- if(trim($serial)==trim($fecha)){ $newserial=trim($troz[0])+1; }else{ $newserial=trim($fecha).'00'; }
- shell_exec("sed -i 's/20[0-1][0-9]\{7\}/'{$newserial}'/' {$path}'/named/{$arradns[$i]}");
- writeslog("sed -i 's/20[0-1][0-9]\{7\}/'{$newserial}'/' {$path}'/named/{$arradns[$i]}");
- if($srst=='OK'){
- $rsync='rsync -av '.$path.'/named/'.$arradns[$i].' /var/named/'. $arradns[$i];
- shell_exec($rsync);
- $rndc = shell_exec('rndc reload '.$domainsel.' 2> /dev/null > /dev/null && echo ok || echo failed');
- writeslog('rndc reload '.$domainsel.' 2> /dev/null > /dev/null && echo ok || echo failed');
- $exito++;
- }else{
- createerror($timer,$user,$returnarray,$db);
- $rsync='rsync -av '.$path.'/named/'.$arradns[$i].' /var/named/'. $arradns[$i].'.restore';
- shell_exec($rsync);
- writeslog('rsync -av '.$path.'/named/'.$arradns[$i].' /var/named/'. $arradns[$i].'.restore');
- $error++;
- }
- }
- }
- writeslog("Added {$exito} DNS of {$total}, with a total of {$error} errors");
- }else{
- writeslog("There are no records");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement