Jump to content

Dynamically delete specific lines from files?


jj_norris

Recommended Posts

I wrote a form, and php script to delete a specific line from a file called named.conf. This file is used for the BIND DNS server configuration. The form allows you to select the domain you want to delete, then when clicking delete it is suppose to delete the file as well as the entry in named.conf. It seems to only delete the file and not the entry.

 

Here are the contents of my named.conf:

options {
directory "C:\Zpanel\bin\bind\zones";
allow-transfer { none; };
recursion no;
};


zone "internet-hosting-solutions.net" IN {
type master;
file "internet-hosting-solutions.net.txt";
allow-transfer { none; };
};
key "rndc-key" {
algorithm hmac-md5;
secret "EssqJzwTIvRACrxQkCGTPQ==";
};

controls {
inet 127.0.0.1 port 953
	allow { 127.0.0.1; } keys { "rndc-key"; };
};
zone "wixard.co.cc" IN {
        type master;
        file "wixard.co.cc.txt";
        allow-transfer { none; };
};
zone "unknownrangers.co.cc" IN {
	type master;
file "unknownrangers.co.cc.txt";
allow-transfer { none; };
};
zone "protection-information.co.cc" IN {
	type master;
file "protection-information.co.cc.txt";
allow-transfer { none; };
};

Now say I want to delete unknownrangers.co.cc entry right? It deletes the file but not the entry. Here is my php code for the form. The form btw is correct, it's my php code that is at fault. I believe I am doing something wrong.

 

Here is the contents of my php code:

<?php
$file = ("C:/Zpanel/bin/bind/zones/") . $_GET['name'];
unlink($file);
?>
<?php
$namedconf = ("C:/ZPanel/bin/bind/etc/named.conf");
$handle = fopen($namedconf,'a');
fwrite($handle, str_replace("\r\n" . 'zone "' . $_GET['name'] . '" IN {' . "\r\n" . ' 	type master;' . "\r\n" . '	file "' . $_GET['name'] . ".txt" . '";' . "\r\n" . '	allow-transfer { none; };' . "\r\n" . "};",'',$content));
fclose($handle);
?>
<?php
popen ('"C:/Zpanel/bin/bind/bin/rndc reload"','r');
?>

 

What am I doing wrong? Thanks in advance for any help.

 

Sincerely,

 

Junious Norris

I would be more inclined to use sed rather than trying to do this in php alone. Something like....

 

exec("sed -i '/{$_GET['name']}/d'  C:/ZPanel/bin/bind/etc/named.conf");

 

Of course you may want to test this first via a terminal. Remove the -i option while testing to prevent your file being written too.

I would be more inclined to use sed rather than trying to do this in php alone. Something like....

 

exec("sed -i '/{$_GET['name']}/d'  C:/ZPanel/bin/bind/etc/named.conf");

 

Of course you may want to test this first via a terminal. Remove the -i option while testing to prevent your file being written too.

 

I do not have sed. Is there another way to do this?e.g.(preg_replace)?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.