PDA

View Full Version : Forced ads on ISPConfig server


grandpagenocide
10th March 2008, 00:06
Forced ads for ISPConfig with .htaccess .
I wrote this “how to” for those who want to place forced ads on their ISPConfig server.
Probably you can setup forced ads in different ways but I found the way descibed here.

I am using Debian Etch and ISPConfig 2.2.19 in this example.
What needs to be done:
- edit apache config
- create .htaccess files
- create header and footer with ads
- disable the ads on accounts that upgrade

I had to enable php server wide for this to work, and since i give all my clients php, it is not a big deal, but if anyone can update this with a meathod to only allow php in the /var/www and /var/www/ads that would be appreciated

Let’s show where our ISPConfig server is capable of, here we go:

STEP 1
Enable php system wide

vi /etc/mime.types

uncomment out the following:

[...]
#application/x-httpd-php phtml pht php
#application/x-httpd-php-source phps
#application/x-httpd-php3 php3
#application/x-httpd-php3-preprocessed php3p
#application/x-httpd-php4 php4
[...]


vi /etc/apache2/mods-enabled/php5.conf

<IfModule mod_php5.c>
# AddType application/x-httpd-php .php .phtml .php3
# AddType application/x-httpd-php-source .phps
</IfModule>


STEP 2
First lets edit apache.conf

vi /etc/apache2/apache2.conf

Towards the bottom of the apache2.conf you will find
<Directory /var/www/sharedip>
Options +Includes -Indexes
AllowOverride None
AllowOverride Indexes AuthConfig Limit FileInfo
Order allow,deny
Allow from all
<Files ~ "^\.ht">
Deny from all
</Files>
</Directory>

immeidately after add
<Directory /var/www>
Options +Includes -Indexes
AllowOverride None
AllowOverride Indexes AuthConfig Limit FileInfo Options
Order allow,deny
Allow from all
<Files ~ "^\.ht">
Deny from all
</Files>
</Directory>

Below that you will find
<Directory /var/www/*/web>
Options +Includes -Indexes
AllowOverride None
AllowOverride Indexes AuthConfig Limit FileInfo
Order allow,deny
Allow from all
<Files ~ "^\.ht">
Deny from all
</Files>
</Directory>


change this to


<Directory /var/www/*/web>
Options +Includes -Indexes
AllowOverride None
AllowOverride Indexes AuthConfig Limit FileInfo Options
Order allow,deny
Allow from all
<Files ~ "^\.ht">
Allow from root
Deny from all
</Files>
</Directory>


save and

/etc/init.d/apache2 restart

STEP 3

Now lets create a directory

mkdir /var/www/ads

STEP 4

we are going to create two php files now
lets make footer.php with your footer ad
and lets make blank.php that is actually blank

STEP 5
Creating .htaccess file
use any text editor you like most of them will give you another extention, but rename the file to .htaccess and have it contain the following:

php_value output_buffering 4098
AddType application/x-httpd-php htm
AddType application/x-httpd-php html
php_value auto_append_file '/var/www/ads/footer.php'

And thats it, now every site on the server will have your forced footer, the same goes if you want a header.

TO DISABLE ADS ON AN INDIVIDUAL SITE
Create another .htaccess file with the following


php_value output_buffering 4098
AddType application/x-httpd-php htm
AddType application/x-httpd-php html
php_value auto_append_file '/var/www/ads/blank.php'

and place it in the /web directory of that site

And thats it guys, you now have forced ads. I am going to try to write a module that will allow this to be controled from ispconfig cp.

grandpagenocide
10th March 2008, 19:40
ok i am trying to replicate it on another server, and for some reason I am getting this error, it is working fine on one server, how do I remove the basedir restriction?
Warning: Unknown: open_basedir restriction in effect. File(/var/www/ads/inc_footer.php) is not within the allowed path(s): (/var/www/web3/) in Unknown on line 0

Warning: Unknown: failed to open stream: Operation not permitted in Unknown on line 0

Fatal error: Unknown: Failed opening required '/ads/inc_footer.php' (include_path='.:/usr/share/php:/usr/share/pear') in Unknown on line 0

grandpagenocide
11th March 2008, 03:12
It works fine the clients site i was viewing had an htaccess in it for chinese encoding and muffed it up

gjcomputer
11th March 2008, 17:20
many thanks, this looks like something i would really like to do...

grandpagenocide
11th March 2008, 19:22
No problem if you need any help PM me

3StrikesDesign
28th July 2008, 20:10
Great post, thanks for providing it to us

webcave
14th August 2008, 01:48
I worked on this code some so here i have some good stuff for you :)

Ok first code i will give you is to not auto add it to every account but FORCE it on every account no matter what before they could just edit out the ad's part of the .htaccess file so.

Go to: /root/ispconfig/isp/conf/
Edit File: vhost.conf.master

Go to the bottom
you will see this

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_METHOD} ^(TRACE|TRACK)
RewriteRule .* - [F]
</IfModule>

Right Below that add

php_value output_buffering 4098
php_value auto_prepend_file '/var/www/ads/header.php'
AddType application/x-httpd-php htm
AddType application/x-httpd-php html
That is the code for your ad replace header.php with your ad file name
Also if you want your ad on the top or the bottom of the page

Top of page: php_value auto_prepend_file '/var/www/ads/header.php'
Bottom of page: php_value auto_append_file '/var/www/ads/header.php'

This code can not be removed from any site so i made a mod for the ad file you will not need blank.php anymore so you can delete it.

So in your ad file right now you have your ad code thats it, Change your file so its like this.

<?
$adfrees = '/var/www/web1/web'; //Change this to the web you want without ad's
$dir = getcwd();
if ($dir == $adfrees) {
echo '';
} else {
echo '
AD CODE HERE
'; }
?>


It works great! :)

Ballistic509
28th August 2008, 00:35
Hmmm...What if I only want this on certain accounts? Say like, not server wide, but on free hosting that I offer. If those accounts ONLY get ads, and not the paid hosts? If there is a way, other than adding each paid account to the ad file.

grandpagenocide
28th August 2008, 03:08
Ballistic, if you use the htaccess meathod i layed out, you can control it through the htaccess files, who has ads and who doesnt.

Ballistic509
28th August 2008, 03:56
but if i do that then i risk the chance that the user deletes the htaccess file or ad line correct?

ISPConfig should include a module for this to select which plans have forced ads.

OR can I add code to something to select which plans do have ads?

falko
28th August 2008, 18:08
but if i do that then i risk the chance that the user deletes the htaccess file or ad line correct?

ISPConfig should include a module for this to select which plans have forced ads.

OR can I add code to something to select which plans do have ads?

You could make root the owner of the .htaccess file. Then your users couldn't delete it.

grandpagenocide
29th August 2008, 03:17
yes they could if you didnt put them in as root. Dont give it write perms.

Ballistic509
4th September 2008, 11:36
If I have this .htaccess file setup on the server, can I have the signup script (the custom framework example) copy this file to the new account directory and then chmod it to root? If so, where would I add it in the script?

grandpagenocide
4th September 2008, 20:31
yes you can i just havent had time to go back and work that into it yet :) so just ask around you may find a thread or two about custom templates on signup.