Pointed/Serviced domain setup


packages->ftp and note ftpserver,
  and/or create a new user in the 'Additional FTP Accounts' form.
  (Wait 10 to 15 minutes if you created new one.)

- Goto https://webftp.powweb.com/
  In the address bar of your browser, copy&paste https://webftp.powweb.com/
  and hit the enter key.

- In the login form, enter servername, username, and the password you noted.

- Click on the 'htdocs' in the file/directory list.
  You should see 'You are here: /htdocs' after doing that.

- Click on the 'Create File" button in the left side.

- Come back to this window/tab, and copy this file. 
  (Make sure to select everything.)
  Ctrl-A for select all, Ctrl-C for copy. You can do it via menu, too. 

- Goto the WebFTP window/tab and paste everything.
  Click in the textarea of the "Createfile" form, and the Ctrl-V to paste.
  Make sure that you see everything in this file, in the textarea.

- Enter the file name "dom.php" and push the 'Save' button.

- Open new Windows/tab in your borwser and enter 'http://yourdomain.com/dom.php'
  in the address bar and hit enter key.

- When the script show the form, enter the name of pointed/serviced domain,
  optionally enter the subdirectory to use, and push the button.

- If it says 'All done', test as it tells you.
  If everything is working, come back to the WebFTP and delete dom.php.

*/

$doc = <<http://hostwick.com/

 The latest version of this script si abailable at:
      http://check-these.info/EasiestMethod.html

Note:

If you want more features, I recommend you to use DomainManager,
or Generic htaccess method. They offer more flexibilities.
(But it also means you need to know/learn more.)

See http://check-these.info/DomainSetup.html for more info.

by extras  

DOCEND;

$user = get_current_user();
$home = "/www/".substr($user,0,1)."/$user";

$sec = $_POST['sec'];

if( $_POST['dir'] != ''){
  $sdir = preg_replace('#[^a-zA-Z0-9/_\.-]#','', $_POST['dir']);
  $sdir = preg_replace("#^$home/htdocs#i",'', $sdir);
  $sdir = preg_replace('#^[\\./]+|(/)([\\./]*/)#','\\1', $sdir);
}else{
  $sdir = str_replace('.','_',$sec);
}

if($pri == ''){
  $pri = preg_replace('#^/www/././([^/]+)/.*#','\\1',$_SERVER['DOCUMENT_ROOT']);
}

function showform(){
 global $pri, $sec, $ver, $doc, $home, $sdir;
 echo <<
Pointed/serviced domain: <== Enter the name (ex. example.com) of new pointed or serviced domain.
$home/htdocs/ <== Optionally, enter the directory. Leave it blank for automatic mode.
Note: Enter only the part after /htdocs/

$doc
ver. $ver   Debug
ENDFORM; ob_flush(); } function debug($dom){ global $home; echo "\n---------- .htaccess --------------\n"; echo file_get_contents("$home/htdocs/.htaccess"); echo "\n------------------------------------\n"; echo `exec 2>&1;host $dom >/dev/null 2>&1 && whois $dom && dig $dom;ls -alt $home $home/*/htdocs $home/htdocs $home/htdocs/*/.htaccess $home/htdocs/*/index.*`; echo "\n------------------------------------\n"; showform(); exit(0); } function domcheck($dom, $n){ global $home, $sdir; $dom = preg_replace('/^www\.(.*)/', '\\1', $dom); if($n == 1){ $ps = 'primary'; }else{ $ps = 'pointed/serviced'; } $ip = gethostbyname($dom); $w = 0; if($ip == $dom){ echo "Warning: $dom isn't resolving.
Have you registered domain? (Maybe it's not propagating, yet.) You can ignore this warning and go ahead to generate/update .htaccess file. The pointed/serviced domain will work when it starts to resolve.
"; $w += 1; ### Not resolving }else{ echo "$dom resolve to $ip
"; } $sa = $_SERVER['SERVER_ADDR']; echo "SERVER_ADDR is $sa
"; if(substr($sa, 0, 9) == "66.152.98"){ $sac = substr($sa,10); if(strlen($sac) ==3 && substr($sac, 0,1) =="2"){ $clust = substr($sac, 1); }else{ $clust = substr($sac,0,strlen($sac)-1); } }else{ echo "Error: This script is written for PowWeb hosted sites.
It will not work on other host, most probably. Please visit Hostwick.com if you want me to adapt this for other hosts or write other version.
"; exit(2); } echo "You are on cluster $clust
"; if(substr($ip, 0, 9) == "66.152.98"){ $ipc = substr($ip,10); if(strlen($ipc) ==3 && substr($ipc, 0,1) =="2"){ $ipclust = substr($ipc, 1); }else{ $ipclust = substr($ipc,0,strlen($ipc)-1); } if( $clust != $ipclust) $w += 2; }else{ $w += 4; ### Not on the resolving cluster } if($w & 6) echo " Warning: $dom isn't resolving to this cluster.
Have you set to use PowWeb's DNS servers (ns3.powweb.com ns3.powweb.com) at your Registrer? If not, you need to do it. If you have done so, maybe this is caused by the propagation delay. Alternatively, you can configure current DNS server to resolve the domkain to PowWeb's IP. You can ignore this warning and go ahead to generate/update .htaccess file. The pointed/serviced domain will work when it starts to resolve.
"; $domst = stat("/www/".substr($dom,0,1)."/".substr($dom,1,1)."/$dom"); $homest = stat($home); if( $domst[1] != $homest[1] ){ $w += 8; ### No virtualhost setup echo "Warning: $dom isn't associated with this account (yet?)
Have you used \"Add pointer domain\" or \"Add serviced domain\" form in OPS->packages to associate $dom to this package? (If it was successful, OPS->package should show the associated domain.) You can ignore this warning and go ahead to generate/update .htaccess file. Once the domain is associated, it'll start to work.
"; } if($w && $_POST['go'] != '1'){ echo <<Debug



If you want to try different setting, please use the form bellow.
CONFIRM;

    showform();
    exit(1);
  }
  echo "
Domain check completd!


"; return $dom; } if($_GET['debug'] != ''){ debug($_GET['dom']); }elseif( $sec != ''){ # check secondary $sec = domcheck($sec,2); # backup, check and write .htaccess $ht = "$home/htdocs/.htaccess"; $skip = 0; if(file_exists($ht)){ echo "You already have the .htaccess. Creating backup '.htaccess.bak' "; copy($ht, "$ht.bak"); $htc = file_get_contents($ht)."\n"; if(! preg_match('/(^|\n)RewriteEngine On/im', $htc)){ echo "Adding 'RewriteEngine On'. "; $htc .= "RewriteEngine On\n"; } if(! preg_match('/\nRewriteBase \//im', $htc)){ $htc = preg_replace( '/((^|\n)RewriteEngine On)/im', '\\1 RewriteBase / ', $htc); echo "Adding 'RewriteBase /'. "; } if(! preg_match('/\n# Missing trailing slash fix/im', $htc)){ $htc = preg_replace('/(\nRewriteBase \/)/im', '\\1 # Missing trailing slash fix RewriteCond s%{HTTPS} ^((s)on|s.*)$ [NC] RewriteRule ^/*(.+/)?([^.]*[^/])$ http%2://%{HTTP_HOST}/$1$2/ [L,R=301] ', $htc); echo "Adding 'Missing trailing slash fix'. "; } if(preg_match('/\n# pointed\/serviced domain code for '.addslashes($sec).'/im', $htc)){ echo "$sec has already pointed/serviced domain RewriteRule in .htaccess. Replacing the rule. "; $htc = preg_replace('/\n# pointed\/serviced domain code for '.addslashes($sec).'\nRewriteCond.*?\nRewriteRule.*?\n/im','',$htc); } }else{ echo "You don't have the .htaccess.\nCreating new one.\n"; $htc .= "RewriteEngine On RewriteBase / # Missing trailing slash fix RewriteCond s%{HTTPS} ^((s)on|s.*)$ [NC] RewriteRule ^/*(.+/)?([^.]*[^/])$ http%2://%{HTTP_HOST}/\$1\$2/ [L,R=301] "; } echo "New pointed/serviced domain '$sec' will be placed in: $home/htdocs/$sdir\n"; if($skip == 0){ $secz = preg_replace('#\\.#','\\.?',$sec); $htc .= "# pointed/serviced domain code for $sec RewriteCond %{HTTP_HOST} ^(www\\.)?([^.]+\\.)?$secz([:.].+)?\$ [NC] RewriteRule !^/*$sdir/ $sdir/%{REQUEST_URI} [L] "; } echo "------ Contents of new .htaccess -----\n$htc\n--------------\n"; $fh = fopen($ht, "wb"); fwrite($fh, $htc); fclose($fh); # ctreate the directory, if it's not there if(! is_dir("$home/htdocs/$sdir")){ echo "Creating $sdir directory for the new pointed/serviced domain, and setting safe permission of 710. Note: If you want Apache's default directory listing, change permission to 750. But please remember that it's less secure if you do that. "; $spart = explode('/', $sdir); $sd = ''; foreach( $spart as $p){ $sd .= "/$p"; echo "

$sd

\n"; if( !( is_dir("$home/htdocs$sd") || mkdir( "$home/htdocs$sd", 0710)) ){ echo "Error: failed to create the directory: $home/htdocs/$sd
\n"; $failed = 1; break; } } } # create default index.html for testing, if it's not there. if(! file_exists("$home/htdocs/$sdir/index.html")){ echo "Creating the default index.html for testing, in $sdir. "; $fh = fopen("$home/htdocs/$sdir/index.html", "wb"); fwrite($fh, "This is a default index.html for $sec in $home/htdocs/$sdir\n"); fclose($fh); } if(! $failed){ echo " All done. Now, check the new pointed/serviced domain via http://www.$sec/. DON'T FORGET to clear the browser cache AND reload the pages on each test. You should see the default index.html for testing, or the index page you created. Upload the files for pointed/serviced domain in /htdocs/$sdir DON'T FORGET to clear the browser cache AND reload the pages on each test. You can also add a question mark followed by junk string to force reloading. http://example.com/ ==> http://example.com/?junkstr http://example.com/subdir/abc.html ==> http://example.com/subdir/abc.html?junkjunk (Do not use this for URL of scripts.) "; } echo " If you have a problem, ask in the powweb forum with the result of this link:Debug
If you want to add more domains, please use the form below. "; $sec=''; $sdir=''; showform(); }else{ showform(); } ?>