Jump to content

A few PHP and Apache q's


Fblade1987
 Share

Recommended Posts

Right so I have three Q's in totally and i thought instead of creating three seperate threads i'd post it in one

Q1

I was wondering if there's a way to always place content into any webpage a user uploads, you know like free web hosting do?

It's just i offered to host some work mates portfolios, in return for them to link back to me, however I feel that it would be much better instead of leaving it up to them to put link back to me is create a little bar at the top of the page that links back to me.

is there an application i can run on my server to do this or would i have to do this manually for each page?

Q2

What it is I want to be able to run say a console application, through my webserver on apache.

I know it a secruity hole so I ask how do I first of all set up apache to allow .EXE to run, and then how to do it so say a .EXE will disgause(sorry for spelling) itself as say a .SOB. So I call something like blah.com/send.SOB.

this is currently the code i have For a test console app(written in delphi)

program Project2;

{$APPTYPE CONSOLE}

uses
  SysUtils,
  ShellAPI,
  windows;

var
  S: array[0..255] of char;
begin

  windows.GetEnvironmentVariable('QUERY_STRING',@S[0], 255);

  writeln('<html><body>');
  writeln('Query=');
  writeln(s);
  Writeln('</ br>Executed</body></html>');
  shellexecute(0,'open','notepad', nil, nil, SW_SHOWNORMAL);
end.

I've Tried this on a mate custom built server application, and all he dose is a simple config edit such as this

[.exe]
CodeBase=

[.snd]
CodeBase=c:\www\localhost\Project2.exe

So all that basically does is will run the .exe on the server but if a .snd is called it will run the code above.

I know this is not as easy on apache thats is where i ask you for help how do i achive this?

AND LAST BUT NOT LEAST Q3

I've noticed that alot of modules for apache need compiling with linux so how do us people who have a windows apache box go about getting these modules to work on our system can it be done or what?

thanks for your help Matt

Link to comment
Share on other sites

Regarding you first question, then try to take a look at this guide: http://www.howtoforge.com/placing-forced-a...ccess-ispconfig

I can't really help on the other two, as I don't run Apache on Windows.

Though, a quick search on google gave this link, which may answer your third question: http://httpd.apache.org/docs/2.2/platform/win_compiling.html

Link to comment
Share on other sites

first one is realy simple, just use a script to put it at the top.....

for 2 & 3, read the apache dev info and manuals first. Your ideas arnt originaly so someone has probably tried to do it before you, so its out there (try google!)

further regards to question 2:

why the h@!! arent you just opening an ssh tunnel and doing what you want that way?

Link to comment
Share on other sites

Regarding you first question, then try to take a look at this guide: http://www.howtoforge.com/placing-forced-a...ccess-ispconfig

I can't really help on the other two, as I don't run Apache on Windows.

Though, a quick search on google gave this link, which may answer your third question: http://httpd.apache.org/docs/2.2/platform/win_compiling.html

thanks for the links but not fully read the 2nd one yet, but from first glance is that not for compiling apache not the modules?

Thanks for the 1st one that will help out tons

first one is realy simple, just use a script to put it at the top.....

for 2 & 3, read the apache dev info and manuals first. Your ideas arnt originaly so someone has probably tried to do it before you, so its out there (try google!)

further regards to question 2:

why the h@!! arent you just opening an ssh tunnel and doing what you want that way?

well thats why i asked the question as i don't even know where to start producing script that forces content in.

and over the ssh I was doing it this way as would like access to my server where ever i go and the only ports that always really open are port 80, port 21 and port 8080 which i am using atm so unless theres another port thats always open that would be useless to me.

thanks matt

Link to comment
Share on other sites

If you are using PHP, then you can run any(so long as your permissions grant you rights) program from the host operations system itself. Apache doesn't need to be configured to do anything, just PHP needs to have access to the "system" command. You can then write any server script (bat or vbs script if the host OS is windows) and use system to execute the script or exe file. Just point to the path of the file.

This would start the calculator on a windows system running apache and php. This is just an example, but you can point to any file on the system that is executable, as if you were at the command prompt. Same goes for *nix systems, as long as you have access to execute the command you want to run. The output shows up in a text box on the web page itself.

<textarea cols="105" rows="20">
<?
//Edited: Looks like any GUI app will cause the script to hang, so using CLI and Bat files would be the way to work around it as they do not hang the script.

system("tasklist"); 

?>
</textarea>

List all files in the current directory on a *nix system

<textarea cols="105" rows="20">
<?
system("ls -al");
?>
</textarea>

Link to comment
Share on other sites

kool thanks btu i dont think it work i tried the windows code you provided and it doesnt stop loading till it times out.

edit

Regarding you first question, then try to take a look at this guide: http://www.howtoforge.com/placing-forced-a...ccess-ispconfig

just tried this i can't seem to get it working i looked in the error log and this is what it said, can anyone make any clue of it?

Link to comment
Share on other sites

Well, the first two lines complain a file not being found. I would suggest trying to swap the slashes for backslashes, but I'm not sure if that solves it as it's running on Windows.

The other errors could point to a broken PHP installation of some sort, but if you have installed Apache/PHP as a WAMP package, that shouldn't be the case. Are the mentioned files to be found on your system?

Link to comment
Share on other sites

kool thanks btu i dont think it work i tried the windows code you provided and it doesnt stop loading till it times out.

Timeout options are set in php.ini By default, I think they give you 60 seconds, but you can increase this. Just remember that if a script is in a loop or borked, it will run for as long as you set the time for, so be carefull.

edit: See my previous post, I updated it. Looks like it only works with CLI programs, as any gui app will cause the script to hang. Sorry about that.

Also, I would remove your one post, as you don't want to give out your IP address to everyone. The error looks like you aren't calling the right path or it can't find the file you are trying to execute. Post your original code.

Link to comment
Share on other sites

For quick access to a server behind a firewall via SSH, consider a VPN. Hamachi is currently free and has clients for all platforms. It's real easy to set up too.

Hmmm i may try that but dont I have to install hamachi on the machine im using aswell as the server?, that wouldnt be really a possiblity?

aswell i have the forced content thing working by using a .htaccess file my question now is how can i get to add at the very top instead of the bottom this is he code i have so far

this is the header.php

<?php
echo "<div style='width:100%; height:20px; background-color:#f6f6f6; padding: 0 0 5px 25px;'> Hosted By Wheresmy.tv</div>";
?>

and this is my .htaccess file

php_value output_buffering 4098
AddType application/x-httpd-php php
AddType application/x-httpd-php html
php_value auto_append_file '<address>/header.php'

thanks matt

edit

Also noticed when it gets placed in the footer it's out side the </html> tag so this wouldn't validate is there a way i can shove it inside the html tag?

Link to comment
Share on other sites

Also noticed when it gets placed in the footer it's out side the </html> tag so this wouldn't validate is there a way i can shove it inside the html tag?

Not without editing each page manually. That's the consequence of "forcing" some code into a page.

Link to comment
Share on other sites

thanks for the reply, with what you said i went a tried this tutorial ( http://www.namepros.com/webmaster-tutorial...resellers.html) but it dosent work get a 404 saying cannot find <address>/header.php/index.php any ideas?

also

As I can't move the forced content using the old method is there anyway i can sort it out so it's valid html?

thanks alot

matt

Link to comment
Share on other sites

I think you need something like this to add it for headers or footers if you are on shared hosting

&lt;Directory "/var/www/html/virtual_host1"&gt;
  php_value auto_prepend_file /var/www/html/virtual_host1/header.php
  php_value auto_append_file /var/www/html/virtual_host1/footer.php
&lt;/Directory&gt;

where virtual_host1 is the name of the server or websites directory path. Change accordingly "/var/www/html/virtual_host1" to match your setup.

Link to comment
Share on other sites

As I can't move the forced content using the old method is there anyway i can sort it out so it's valid html?

I just came to think... Maybe you could prepend a PHP script which makes sure that the page shown is inside a frame, and then make another frame with the ad shown in it. I can't really come up with any other ideas.

Link to comment
Share on other sites

and over the ssh I was doing it this way as would like access to my server where ever i go and the only ports that always really open are port 80, port 21 and port 8080 which i am using atm so unless theres another port thats always open that would be useless to me.

thanks matt

a. just ssl in through 21 and send files over that anyway instead of standerd ftp....

b. if you dont have complet control over the server, chances are they dont want you to be running random (at least to them) exe's on theire server. If you do have complete control over the server, just open up another port....

Link to comment
Share on other sites

I just came to think... Maybe you could prepend a PHP script which makes sure that the page shown is inside a frame, and then make another frame with the ad shown in it. I can't really come up with any other ideas.

would you mind elberating more im not quite sure you mean? do you mean make a base file that takes in the source(clients page) and the ad page (header.php)and places them both in iframes? or am i missing the idea here? and wouldnt that mess up the design say on something like wordpress?

as im after doing on every single after some thought make it look like everysites part of the same network so to speak.

thanks matt

and eman7613 thanks after some more thinking i may just run ssh over say port 8080 or something

Link to comment
Share on other sites

just to let you know guys managed to figure it out the forcing ads if anyone's intrested.

what i did was make the htaccess do both prepend and an append,

php_value output_buffering 4098
AddType application/x-httpd-php php
AddType application/x-httpd-php html
AddType application/x-httpd-php htm
php_value auto_prepend_file '/prepend.php'
php_value auto_append_file '/append.php'

then had two php file the first(prepend) opened a buffer

&lt;?php ob_start(); ?&gt;

then in last php (append) i did what i needed to do and echoed it out

&lt;?php
                       $str = ob_get_clean();

                       
                        // code to find &lt;/head&gt; or &lt;body&gt;
                        // code to insert banner insertion javascript into head. Or insert banner into &lt;body&gt;.
                        // code to put $str back together around both

            $ad = ("&lt;body&gt;&lt;div style='background:#f6f6f6;'&gt;Hello world&lt;/div&gt;");

            if (! strstr($str,$ad))
            {
                if (strstr($str,"&lt;body&gt;")){
                $result= str_replace("&lt;body&gt;",$ad,$str);
                }
                else{
                $result = "hello worldlldldldldlldldl&lt;br /&gt; &lt;br /&gt;" . $str;        
                }
            }
            Echo($result);
            Ob_end_flush();



?&gt;

hope that helps other people other then me

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...