jj_norris Posted March 9, 2010 Share Posted March 9, 2010 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 Link to comment https://forums.phpfreaks.com/topic/194592-dynamically-delete-specific-lines-from-files/ Share on other sites More sharing options...
trq Posted March 9, 2010 Share Posted March 9, 2010 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. Link to comment https://forums.phpfreaks.com/topic/194592-dynamically-delete-specific-lines-from-files/#findComment-1023441 Share on other sites More sharing options...
jj_norris Posted March 9, 2010 Author Share Posted March 9, 2010 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)? Link to comment https://forums.phpfreaks.com/topic/194592-dynamically-delete-specific-lines-from-files/#findComment-1023464 Share on other sites More sharing options...
jj_norris Posted March 9, 2010 Author Share Posted March 9, 2010 I hate to bump, but this is vital to my project. Any help will be greatly appreciated. Thanks. Link to comment https://forums.phpfreaks.com/topic/194592-dynamically-delete-specific-lines-from-files/#findComment-1023747 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.