Zubrag.com
September 21, 2019, 10:19:59 PM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Cpanel Subdomain Creator Redirect  (Read 16520 times)
onlinemkt
Newbie
*
Posts: 6


« on: January 25, 2007, 12:03:40 PM »

Hi,

I loved the script but I got a problem.... when it creates subdomains it automatically redirects to a folder with name of subdomain created, I mean, when I create the submain called "test" it points to the folder http://domain.com/test/.

The problem is that I want to point to a html file on root or on a specific folder... like http://domain/test.htm... so each subdomain should point to a html file with same name of recent subdomain created.

Lest's suppose I 've created the "test1","test2" and "test3" subdomains from a file.

It will look like:
http://domain.com/test1/
http://domain.com/test2/
http://domain.com/test3/

What I want is to point to same name file like this:
http://domain.com/test1.htm
http://domain.com/test2.htm
http://domain.com/test3.htm

Is it possible ? ... because If not I have to redirect it manually....

Thanks in advance,
Leo Grin

Logged
zubrag
Administrator
Hero Member
*****
Posts: 788


WWW
« Reply #1 on: January 25, 2007, 02:19:52 PM »

You could try creating index files in those folders, like:

http://domain.com/test1/index.html -> this file would be a copy of test1.htm
http://domain.com/test2/index.html -> this file would be a copy of test2.htm
http://domain.com/test3/index.html -> this file would be a copy of test3.htm

When some user types http://test3.domain.com one would see http://domain.com/test3/index.html, which is a copy of test3.htm

Wouldn't that work for you?

If you really want to setup subdomain redirects like you described then after following code:
  $request = "/frontend/$cpanel_skin/subdomain/doadddomain.html?rootdomain=$domain&domain=$subd";
  $result = subd('localhost',2082,$cpaneluser,$cpanelpass,$request);
  $show = strip_tags($result);
  echo $show;

add this code
  // subdomain redirection url
  $url = 'http://'.$domain.'/'.$subd.'.htm';
  $request = "/frontend/$cpanel_skin/subdomain/saveredirect.html?domain=". $subd.'_'.$domain .'&url='.$url;
  $result = subd('localhost',2082,$cpaneluser,$cpanelpass,$request);
  $show = strip_tags($result);
  echo $show;

Does it help?
Logged
onlinemkt
Newbie
*
Posts: 6


« Reply #2 on: January 25, 2007, 05:30:46 PM »

Wow !

You got it ! ... It worked perfectly ... more than thanks man !   Grin

Regards,
Leo
Logged
onlinemkt
Newbie
*
Posts: 6


« Reply #3 on: March 12, 2007, 05:38:58 PM »

Hi,

I changed my domain and host... now I'm having trouble...

the 404 error appears when I type the subdomain address on browser and the address line is like this:


http://domain.info/mp3.htm%0d


Don't know why it's looking like this and also the redirection looks ok on the first subdomain created but the others followed by it is giving the error:


HTTP/1.0 200 OK Server: cpsrvd/10.6.1 Connection: close Date: Mon, 12 Mar 2007 23:30:08 +0000 Content-type: text/html Cache-Control: no-cache Pragma: no-cache cPanel X   Sub Domain Maintenance   SubDomain Redirection acoustica. is currently being redirected to nowhere (Redirection Disabled!)     [ Go Back ] HTTP/1.0 200 OK Server: cpsrvd/10.6.1 Connection: close Date: Mon, 12 Mar 2007 23:30:08 +0000 Content-type: text/html Cache-Control: no-cache Pragma: no-cache cPanel X   Sub Domain Maintenance   SubDomain Creation Bind reloading on fry using rndc zone: [domain.info] Error reloading bind on fry: rndc: no key definition for name rndckey Bind reloading on winslow using rndc zone: [domain.info] The subdomain, album.domain.info has been added.     [ Go Back ]

The subdomains created on my cpanel screen looks like this:


acoustica.domain.info (acoustica)
album.domain.info (album)
albums.domain.info (albums)
all.domain.info (all)
mp3.domain.info (mp3) [redirect]

Only the first subdomain created (mp3) have been recorded the redirection but it's giving that error I wrote.

Is it easy to solve, because I have no idea what's going on ... seems everything is ok ! But it's not working.

The script code on my server is like this:


<?php

###############################################################
# cPanel Subdomains Creator 1.1
###############################################################
# Visit http://www.zubrag.com/scripts/ for updates
###############################################################
#
# Can be used in 3 ways:
# 1. just open script in browser and fill the form
# 2. pass all info via url and form will not appear
# Sample: cpanel_subdomains.php?cpaneluser=USER&cpanelpass=PASSWORD&domain=DOMAIN&subdomain=SUBDOMAIN
# 3. list subdomains in file. In this case you must provide all the defaults below
#
# Note: you can omit any parameter, except "subdomain".
# When omitted, default value specified below will be taken
###############################################################

// cpanel user
define('CPANELUSER','user');

// cpanel password
define('CPANELPASS','pass');

// name of the subdomains list file.
// file format may be 1 column or 2 columns divided with semicilon (Wink
// Example for two columns:
//   rootdomain1;subdomain1
//   rootdomain1;subdomain2
// Example for one columns:
//   subdomain1
//   subdomain2
define('INPUT_FILE','domains.txt');

// cPanel skin (mainly "x")
// Check http://www.zubrag.com/articles/determine-cpanel-skin.php
// to know it for sure
define('CPANEL_SKIN','x');

// Default domain (subdomains will be created for this domain)
// Will be used if not passed via parameter and not set in subdomains file
define('DOMAIN','');


/////////////// END OF INITIAL SETTINGS ////////////////////////
////////////////////////////////////////////////////////////////

function getVar($name, $def = '') {
  if (isset($_REQUEST[$name]) && ($_REQUEST[$name] != ''))
    return $_REQUEST[$name];
  else
    return $def;
}

$cpaneluser=getVar('cpaneluser', CPANELUSER);
$cpanelpass=getVar('cpanelpass', CPANELPASS);
$cpanel_skin = getVar('cpanelskin', CPANEL_SKIN);

if (isset($_REQUEST["subdomain"])) {
  // get parameters passed via URL or form, emulate string from file
  $doms = array( getVar('domain', DOMAIN) . ";" . $_REQUEST["subdomain"]);
  if (getVar('domain', DOMAIN) == '') die("You must specify domain name");
}
else {
  // open file with domains list
  $doms = @file(INPUT_FILE);
  if (!$doms) {
    // file does not exist, show input form
    echo "
Cannot find input file with subdomains information. It is ok if you are not creating subdomains from file.<br>
Tip: leave field empty to use default value you have specified in the script's code.<br>
<form method='post'>
  Subdomain:<input name='subdomain'><br>
  Domain:<input name='domain'><br>
  cPanel User:<input name='cpaneluser'><br>
  cPanel Password:<input name='cpanelpass'><br>
  cPanel Skin:<input name='cpanelskin'><br>
  <input type='submit' value='Create Subdomain' style='border:1px solid black'>
</form>";
    die();
  }
}

// create subdomain
function subd($host,$port,$ownername,$passw,$request) {

  $sock = fsockopen('localhost',2082);
  if(!$sock) {
    print('Socket error');
    exit();
  }

  $authstr = "$ownername:$passw";
  $pass = base64_encode($authstr);
  $in = "GET $request\r\n";
  $in .= "HTTP/1.0\r\n";
  $in .= "Host:$host\r\n";
  $in .= "Authorization: Basic $pass\r\n";
  $in .= "\r\n";
 
  fputs($sock, $in);
  while (!feof($sock)) {
    $result .= fgets ($sock,128);
  }
  fclose( $sock );

  return $result;
}

foreach($doms as $dom) {
  $lines = explode(';',$dom);
  if (count($lines) == 2) {
    // domain and subdomain passed
    $domain = trim($lines[0]);
    $subd = trim($lines[1]);
  }
  else {
    // only subdomain passed
    $domain = getVar('domain', DOMAIN);
    $subd = trim($lines[0]);
  }
  // http://[domainhere]:2082/frontend/x2/subdomain/doadddomain.html?domain=[subdomain here]&rootdomain=[domain here]
  $request = "/frontend/x2/subdomain/doadddomain.html?rootdomain=$domain&domain=$subd";
  echo "<font color=red>$request</font>";
  $result = subd('localhost',2082,$cpaneluser,$cpanelpass,$request);
  $show = $result;
  echo $show;
  // subdomain redirection url
  $url = 'http://'.$domain.'/'.$subd.'.htm';
  $request = "/frontend/x2/subdomain/saveredirect.html?domain=". $subd.'_'.$domain .'&url='.$url;
  echo "<font color=red>$request</font>";
  $result = subd('localhost',2082,$cpaneluser,$cpanelpass,$request);
  $show = $result;
  echo $show;

}
?>

----------------------------------------------------------------------

Logged
zubrag
Administrator
Hero Member
*****
Posts: 788


WWW
« Reply #4 on: March 13, 2007, 12:26:53 PM »

Could you backup your script and try if subdomains and redirects are created ok with standard sub-domain creator? Just to know if the problem is in your custom script.
Logged
onlinemkt
Newbie
*
Posts: 6


« Reply #5 on: March 13, 2007, 01:41:54 PM »

Ok,

Domains have been created with the normal script, maybe it's something with custom script...

The message when I created:


HTTP/1.0 200 OK Server: cpsrvd/10.6.1 Connection: close Date: Tue, 13 Mar 2007 19:35:01 +0000 Content-type: text/html Cache-Control: no-cache Pragma: no-cache cPanel X   Sub Domain Maintenance   SubDomain Creation Bind reloading on fry using rndc zone: [domain.info] Error reloading bind on fry: rndc: no key definition for name rndckey Bind reloading on winslow using rndc zone: [domain.info] The subdomain, mp3.domain.info has been added.     [ Go Back ] HTTP/1.0 200 OK Server: cpsrvd/10.6.1 Connection: close Date: Tue, 13 Mar 2007 19:35:13 +0000 Content-type: text/html Cache-Control: no-cache Pragma: no-cache cPanel X   Sub Domain Maintenance   SubDomain Creation Bind reloading on fry using rndc zone: [domain.info] Error reloading bind on fry: rndc: no key definition for name rndckey Bind reloading on winslow using rndc zone: [domain.info] The subdomain, acoustica.mercadosocio.info has been added.     [ Go Back ]

There's already a error message, don't know If it's normal or not...

Thanks for the fast replies and please help on this.

Thanks,
Leo
Logged
zubrag
Administrator
Hero Member
*****
Posts: 788


WWW
« Reply #6 on: March 13, 2007, 01:58:54 PM »

I modified script you posted above. Added debug messages. Please give it a try and let me know the output.
Logged
onlinemkt
Newbie
*
Posts: 6


« Reply #7 on: March 13, 2007, 04:44:28 PM »

It's strange....

I ran the new script and on the screen this is what appeared:


/frontend/x2/subdomain/doadddomain.html?rootdomain=domain.info&domain=mp3HTTP/1.0 200 OK Server: cpsrvd/10.6.1 Connection: close Date: Tue, 13 Mar 2007 22:37:13 +0000 Content-type: text/html Cache-Control: no-cache Pragma: no-cache

SubDomain Creation

Bind reloading on fry using rndc zone: [domain.info]
Error reloading bind on fry: rndc: no key definition for name rndckey

Bind reloading on winslow using rndc zone: [domain.info]

The subdomain, mp3.domain.info has been added.
   

/frontend/x2/subdomain/saveredirect.html?domain=mp3_domain.info&url=http://domain.info/mp3.htmHTTP/1.0 200 OK Server: cpsrvd/10.6.1 Connection: close Date: Tue, 13 Mar 2007 22:37:25 +0000 Content-type: text/html Cache-Control: no-cache Pragma: no-cache

SubDomain Redirection
mp3.domain.info is currently being redirected to http://domain.info/mp3.htm

More strange than that was my attempt to point to ww instead of only http ... I changed on cpanel redirection config the url destination from http://mp3.domain.info to http://www.mp3.domain.info and worked.... BUT ... when trying to access the site using Firefox it gave me an error I already posted wich is: http://domain.info/mp3.htm%0d

On IE it opened normal using the www change.

Logged
zubrag
Administrator
Hero Member
*****
Posts: 788


WWW
« Reply #8 on: March 14, 2007, 04:07:53 AM »

I tried http://mp3. and http://www.mp3. on your site with Firefox 2 and it correctly redirected me to mp3.htm. Maybe your Firefox is broken?
Logged
onlinemkt
Newbie
*
Posts: 6


« Reply #9 on: March 14, 2007, 01:48:26 PM »

Yeah,

I contacted my webserver admin... it was a problem on their database... wich was corrected today's morning... sorry to take your time on this... and again, thanks for prompt help.

Seeya,
Leo
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC