PHP 2 Perl

 
Post new topic   Reply to topic    Aprelium Forum Index -> Perl
View previous topic :: View next topic  
Author Message
TRUSTAbyss
-


Joined: 29 Oct 2003
Posts: 3752
Location: USA, GA

PostPosted: Wed Feb 04, 2004 1:23 pm    Post subject: PHP 2 Perl Reply with quote

I would like to know how I can turn BlueDog's Multiple site
PHP script into .pl format so I can configure my virtual hosts
generator to work with perl platforms. How can I turn this into .pl



Code:

<?php

//get domain entered in browser
if ($_SERVER['HTTP_HOST'] == "") {

//forward to appropriate page
header("Location : /");
exit;

}
//get domain entered in browser
if ($_SERVER['HTTP_HOST'] == "") {

//forward to appropriate page
header("Location : /");
exit;

}
//get domain entered in browser
if ($_SERVER['HTTP_HOST'] == "") {

//forward to appropriate page
header("Location : /");
exit;

}
//end duplicating, insert below.

//else show Main Page
else {

header("Location : /index2.html");
exit;
}

?>


Im sure this can be done , I really need help so I can make my Perl
version of ::Virtual Host Creator:: , Please help me! 8)

-------------------------------------------------------
Virtual Host Creator - http://www.multiple-sites.tk
Back to top View user's profile Send private message Visit poster's website
Anonymoose
-


Joined: 09 Sep 2003
Posts: 2192

PostPosted: Wed Feb 04, 2004 3:05 pm    Post subject: Reply with quote

Didn't someone already post a basic perl version of this somewhere in the tutorials section ? I'm sure I've seen it here before...
Back to top View user's profile Send private message
TRUSTAbyss
-


Joined: 29 Oct 2003
Posts: 3752
Location: USA, GA

PostPosted: Wed Feb 04, 2004 3:21 pm    Post subject: Reply with quote

Not that I no of , its not the same , you have to
type .pl?domain1 at the end of the url to redirect
for the perl version , I want this version to be perl.
Back to top View user's profile Send private message Visit poster's website
jtc970
-


Joined: 24 Mar 2003
Posts: 172

PostPosted: Wed Feb 04, 2004 7:31 pm    Post subject: Reply with quote

this is the one I use
Code:

#!/usr/bin/perl -w
use strict;
################################################################
#                                                              #
#                   DomainDirector v2.2                        #
#               http://www.scriptsolutions.com/                #
#                     All rights reserved                      #
#                                                              #
# Domain Director is copyright 1998-2003, Creative             #
# Fundamentals, Inc.  It is distributed under the same         #
# terms as Perl itself.  See the "Artistic License" at         #
# http://www.opensource.org/licenses/artistic-license.html for #
# licensing terms.                                             #
#                                                              #
################################################################


################################################################
# Enter the main page of your primary website

my $mainpage       = 'index.html';


################################################################
# If your server has wildcards enabled, then enter 1 below.
# Otherwise, enter 0 (that's a zero, not a capital o)

my $wildcards = 0;


################################################################
# To make redirection more transaparent, you can choose to use
# lwp, which will fetch the page and display it without
# causing a change in the browser address bar.  If you have lwp
# installed on your server and want to use transparent
# redirection, enter 1  if you don't, enter 0
# When using lwp, be sure that your target pages use absolute
# urls for your images and links. eg:
# <IMG SRC="http://www.domain.com/images/image.gif"> instead of
# <IMG SRC="image.gif">

my $use_lwp = 0;


################################################################
# Enter domain names below that you do not want to be
# redirected via wildcards.  By default, wildcarded domains
# will use http://wildcarddomain.domain.com/wildcarddomain/, so
# if something needs to be redirected differently, define the
# domain and the page it needs to be redirected to here.
# Note that if you have 4th level domains
#(eg my.fourth.level.domain.com) or higher, each level will be
# its own subdirectory in reverse.  eg:
# http://my.fourth.level.domain.com/level/fourth/my/

# To redirect to an off-server web page, use the fully qualified url,
# such as http://offsite.com/page.html

# To redirect to a page on the server this program is installed, simply
# enter the path to the file starting from the domain name.

my %domains = (

    'coolen.hopto.org' => 'http://one.hopto.org/cgi-bin/exoops/index.php',
    'scriptease.hopto.org' => 'http://two.hopto.org/index.php',
    'sigs.hopto.org' => 'http://three.hopto.org/three/',

);



################################################################
#               DO NOT CHANGE BELOW THIS LINE!                 #
################################################################

my ( $match, $server )  = ( 0, undef );

( $server = lc( $ENV{'HTTP_HOST'} ) ) =~ s/^www\.//;

$server = "www.$server" if ($server =~ tr/\.// == 1);

for my $domain( keys %domains ){

    if ( lc $domain eq $server ){
        $match = 1;

        if ($domains{$server} =~ m|http://|){
            fetch_page( $domains{$server} );
        }
        else {
            fetch_page( "http://$server/$domains{$server}" );
        }
    }
}

unless ( $match == 1 ){

    my $url = "http://$server/$mainpage";

    if ( $wildcards && $server !~ /^www\./ && $server !~ /^(\d{1,3}\.){3}\d{1,3}$/ ){
        my @domain = split( /\./, $server );
        splice ( @domain, -2 ); # throw away first and second levels of domain
        my $dir = join( '/', reverse @domain ) ;
        $url = "http://$server/$dir/";
    }

    fetch_page( $url );

}


sub fetch_page {

    my $url = shift;

    eval { require LWP::UserAgent };

    if ( $@ || !$use_lwp ){
        print "Location: $url\n\n";
        return;
    }
    else {
        my $webagent = new LWP::UserAgent;
        my $response = $webagent->request( new HTTP::Request( GET => $url ) );

        if ( $response->is_success ) {
            print "Content-type:  text/html\n\n", $response->content, "\n";
            return;
        }
    }

    print "Location: $url \n\n";
    return;
}


Back to top View user's profile Send private message
TRUSTAbyss
-


Joined: 29 Oct 2003
Posts: 3752
Location: USA, GA

PostPosted: Wed Feb 04, 2004 8:15 pm    Post subject: Reply with quote

Nice script but I need that PHP script that I posted
to be turned into Perl code so I can create a perl
version of ::Virtual Host Creator::


Virtual Host Creator - http://www.multiple-sites.tk

Any help would be great , All I need to do is learn how to parse those
PHP varibals into the perl varibals so it can be runned by perl platforms
Back to top View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Aprelium Forum Index -> Perl All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB phpBB Group