This is interesting because it has very little to do with the core of DNS management. Most paid DNS services do offer these redirection services but they are a service of http/cgi and have little or nothing to do with DNS IMHO. I don't know what the scope of vegadns is but it would seem at first glance that this is out of the scope.

>From what I can gather the "redirect" field in the database would be something that your php script would use to lookup the results for the redirect. This should stay a separate application. There is no "DNS" record that is being served by this new field. The point of vegadns is to create a valid tinydns cdb file and manage that via the web. A regular CNAME or A record seem to do just fine to point to your server and script. What would be helpful in your case is to have multiple default record templates. That way when you are creating a domain that is going to use your redirect script you can have default A records (pointing to redirect.mydom.com) all setup. So the proper patch for your situation is default record templates.

I could be wrong about the direction of this project, in which case bring on the patches!

-Ryan

[EMAIL PROTECTED] wrote:
In the past we had the case where we needed to add web redirection services for some friends..
 
I've been googling to find out some ways to do so.. found only one sf.net .. but wasn't satified with it.. as it would require not using vegadns anymore..
 
So, one night, after long thoughs, i've decided to ask two friends to find a way to, at first, to design a script that would handle
any calls to it, and redirect to the apropriate url, based on a simple file database.. Than, publish the script, and see if someone
would be interested to add some "redirection" field to vegadns interface and database, that would only add the apropriate fields in the database of the
targeted domain..
 
After some tests, we came out with a pretty simple script, that uses (for the moment), a simple text file to figure "who goes where"..
 
In my further examples, i'll be using this general idea:
some.url.domain.com needs to point to www.some.isp.com/some/dir/some.file.html
 
Also note, as pre-setup on my "main" company domain, i've created a generic alias that will be used as cname for any url needed to be redirected..
Therefore: i made one Alias on my main domain like : redirect.mydom.com > alias > 192.168.0.11
 
Than, in the zone of "domain.com", i created : record some.url.domain.com > cname > redirect.mydom.com
 
The idea is that all redirections have to point to redirect.mydom.com.
 
Now, the apache is setup on 192.168.0.11 :
one spare ip for apache is needed, on my apache box, i'll use 192.168.0.11 here, with a very basic vhost definition (provided below)
 
---cut---
<VirtualHost 192.168.0.11:80>
     DocumentRoot /home/system/redirect/docs
    ErrorLog /home/system/redirect/logs/redirect-error_log
    CustomLog /home/system/redirect/logs/redirect-access_log common
</VirtualHost>
---end of cut---
 
 
At this point, all dns answers redirect to redirect.mydom.com, and apache is setup to use /home/system/redirect/docs/ as documentroot.
 
And now, the magic script:
 
---cut---
<?
// redirect.php version 0.3
// 27.11.04
//
// script created by Thomas Foncelle (lobotom<at>lobotom<dot>org)
// based on ideas from Rudolph Sand (r.sand<at>new-net<dot>net)
//
// edit this
// the file should be fully readable/writable for apache..
$config_file = '/some/path/redirection.txt';
 
// don't touch anything else
$separators = Array("\t", " ");
 
if($_GET[debug]) {
    echo('
        <table border="1">');
} // fin if($_GET[debug])
$fp = fopen($config_file, 'r');
while ($data = "" 1024)) {
    $line += 1;
    if (strlen(trim($data)) && substr($data, 0, 1) != '#') {
        unset($separator);
        for ($i = 0; $i < sizeof($separators); $i++) {
            if (strpos($data, $separators[$i])) {
                $separator = $separators[$i];
            } // fin if (strpos($data, $separators[$i]))
        } // fin for ($i = 0; $i < sizeof($separators); $i++)
        if (!$separator) {
            die("<br>Erreur dans le fichier ".$config_file.": separateur non trouve. (ligne ".$line.")");
        } // fin if (!$separator)
        else {
            $tmp = explode($separator, $data);
            unset($domain, $url);
            $domain = trim($tmp[0]);
            $url = "">             if ($domain && $url) {
                $redir[$domain] = $url;
                if($_GET[debug]) {
                    echo('
                        <tr>
                            <td>'.(($_SERVER[HTTP_HOST] == $domain) ? '<b>' : '').$domain.(($_SERVER[HTTP_HOST] == $domain) ? '</b>' : '').'</td>
                            <td>'.(($_SERVER[HTTP_HOST] == $domain) ? '<b>' : '').'pointe vers'.(($_SERVER[HTTP_HOST] == $domain) ? '</b>' : '').'</td>
                            <td>'.(($_SERVER[HTTP_HOST] == $domain) ? '<b>' : '').$url.(($_SERVER[HTTP_HOST] == $domain) ? '</b>' : '').'</td>
                        <tr>');
                } // fin if($_GET[debug])
            } // fin if ($domain && $url)
            else {
                die("<br>Erreur dans le fichier ".$config_file.": parametre manquant. (ligne ".$line." \"".$data."\")");
            } // fin else
        } // fin else
    } // fin if (strlen(trim($data)) && substr($data, 0, 1) != '#')
} // fin while ($data = ""> fclose($fp);
if($_GET[debug]) {
    echo('
        </table>');
} // fin if($_GET[debug])
 
if (!$redir) {
    die("<br>Aucune redirection trouvee dans le fichier ".$config_file.".");
} // fin if (!$redir)
 
if ($redir[$_SERVER[HTTP_HOST]]) {
    if($_GET[debug]) {
        echo('<br><br>Vous allez etre redirige vers <b>'.$redir[$_SERVER[HTTP_HOST]].'</b> en cliduant <a href="">ici</a>');
    } // fin if
    else {
        header("location: ".$redir[$_SERVER[HTTP_HOST]].(($_SERVER[QUERY_STRING]) ? '?'.$_SERVER[QUERY_STRING] : ''));
    } // fin else
} // fin if ($redir[$_SERVER[HTTP_HOST]])
else {
    die("<br>Aucune redirection trouvee pour le domaine <b>".$_SERVER[HTTP_HOST]."</b>.");
} // fin else
?>
---end of cut---
 
Finally, here is the "database file" wich of course should be replaced by proper calls to vegadns's database..
warning: u must keep the first line of file (#Domain    Url) ...
 
---cut---
neptune# more /home/www/radio-psylone/redirection.txt
#Domain    Url
#here are infos for first redir:
some.url.domain.com needs    http://www.some.isp.com/some/dir/some.file.html
#here are infos for second redir:
another.url.domain.com needs    http://www.another.isp.com/some.file.html
# etc...
---end of cut---
 
I have the setup running fine for over a month, with over 200 redirections in a .txt file
 
I'm providing this script with concent of Thomas.
We both agree it should be freely used by anyone needing such services
But we both strongly request to be kept informed of further changes made to the script.
 
Now the question is, would someone feel to add the sql calls to vegadns' database ?
And provide modification to the forms, so another type of field could be field : "REDIR"
 
Of course, such field could follow Len's sanity checking policy.. Although the script already checks for a few commun mistakes..
 
Ah, final note, for those winXX users.. avoid NOTEPAD for editing redirection.txt.. could save you some troubles..
 
Bye ;)
 
 

Reply via email to