• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 173
  • Last Modified:

Include external files w/o layers?

Is it possible to add  external files to a document, in the same manner as an include virtual-tag, but from another server? I do not wish to use frames, nor layers, since it must work on at least Navigator 301, preferrably 201, i.e. no strange Microsoft solutions either... But cgi-scripting is OK.
If this could be worked out i will add more points for a functional solution.
/Fischier
0
fischier
Asked:
fischier
  • 10
  • 8
  • 8
  • +1
1 Solution
 
martinagCommented:
Using the well-known
<!--#include --> I don't know if it is possible.

One could write a simple script though. My only problem is that I have no possibility of testing it...
I'll give it a shot anyway. It's perl and should be saved as .pl, eg "getdoc.pl"

#!/usr/bin/perl

use IO::Socket;
$site = 'some.where.com"; // Change this...
$http_port=80;
$url = "http://some.where.com/some/path.html"; // ...and this

$them = IO::Socket::INET->new(
                              Proto    => "tcp",
                              PeerAddr => $site,
                              PeerPort => $http_port,
                              )
or die "cannot connect to http server $site:$$http_port";
print $them "GET $url HTTP/1.0\n\n";
@entire_page=  <$them>;
close $them or die "cannot close connection: $!";

print STDOUT "Content-Type: text/plain\n\n@entirepage";

---

Then call it from your .stm:
<!--#exec cgi="getdoc.pl" -->

Martin
0
 
MasseyMCommented:
You can also use the OBJECT tag.

<OBJECT DATA="yourfile.htm" WIDTH=500 HEIGHT=100></OBJECT>

This will load the "yourfile.htm" into an object box.
0
 
martinagCommented:
I see now that
print STDOUT "Content-Type: text/plain\n\n@entirepage";
should be
print STDOUT "Content-Type: text/plain\n\n@entire_page";

Martin
0
Get 10% Off Your First Squarespace Website

Ready to showcase your work, publish content or promote your business online? With Squarespace’s award-winning templates and 24/7 customer service, getting started is simple. Head to Squarespace.com and use offer code ‘EXPERTS’ to get 10% off your first purchase.

 
martinagCommented:
MasseyM, is that an IE4 tag? I've never heard of it before.

Martin
0
 
MasseyMCommented:
OBJECT is an HTML 3.0 standard tag developed by the W3 Consortium...  http://www.w3.org

0
 
MasseyMCommented:
OBJECT is an HTML 3.0 standard tag developed by the W3 Consortium...  http://www.w3.org
0
 
martinagCommented:
I see. Thanks.

Martin
0
 
fischierAuthor Commented:
Thanks, but this is a bit over my head. Could you please clean it to a runnable script, preferrably with comments?
/Fischier
0
 
MasseyMCommented:
To include a file, use this:

<OBJECT DATA="filename.htm" WIDTH=150 HEIGHT=200></OBJECT>

This will create a "box" on your page with the file 'filename.htm' loaded in it.  IT is VERY simple.
0
 
fischierAuthor Commented:
I'm sorry, i can't get this to work, neither with Navigator 301, 405 nor Explorer.
Any ideas what i'm doing wrong?
/F
0
 
Michel PlungjanIT ExpertCommented:
MasseyM, HTML 3.0 was never accepted and many of the things are not supported. Your IE only object tag might embed a new IE web browser but I have never seen this in real life.
IE3+ supports the
<IFRAME SRC="filename.htm" WIDTH=300 HEIGHT=500></IFRAME>

but Netscape 2.0, IE3.0 and OPERA 2.?? all support frames so why not just use that?

Michel
0
 
fischierAuthor Commented:
Well Michel, i was trying to avoid using frames since we've been having terrible problems with downloading times, besides, since it has to be a scrollable page, i'd have to live with scrolling bars in the middle of the window, which i sincerely dislike.
I haven't tried Martins CGI-suggestion, would it work, and what would i have to do?
/Fischier
0
 
Michel PlungjanIT ExpertCommented:
Martin has suggested a socket solution. That will always work (if  your cgi can convince the foreign site to give you the data...) even in mosaic 1.0 (unless the html itself is complex)
You will need cgi access and perl installed on the web server (in the above example - other programming languages like c can also be used...)

Michel
0
 
fischierAuthor Commented:
I have CGI-access and perl installed, how would i proceed, and would the whole document have to be created on the fly? Also: how great a security risk would this script be?
/F
0
 
martinagCommented:
Put the code I gave you in a file called getPage.pl.

Make sure that the first line points to perl if you're on UNIX, otherwise you don't have to care about that.

Replace this:
$site = 'some.where.com"; // Change this...
$http_port=80;
$url = "http://some.where.com/some/path.html"; // ...and this
with this:
$site = "some.where.com"; # Change this...
$http_port=80;
$url = "http://some.where.com/some/path.html"; # ...and this

Also, you must change the strings' values in order to download the right document from the right server.

In your HTML, put this where it should be inserted:
<!--#exec cgi="/cgi-bin/getFile.pl"-->

If you're on a UNIX you must chmod the script 666.

About security, it much depends on the server. The script itself is secure but if your server isn't, someone with knowledge enough could change the script in order to change/delete important files, download password files or just be a pain in the ass.

Martin
0
 
Michel PlungjanIT ExpertCommented:
Fishier: Martins solution does not have to be restricted to SSI (Server Side Include) - it can also be just a normal cgi with a

print STDOUT "Content-Type: text/html\n\n"
as the first statement, the outputting of a local html 'header'
output of @entire_page and then output of
local html 'footer'

The foreign file might need to have some tags removed by the way (<BODY> in a frame set or vice versa)

I am sure Martin can add this if needed.

Be sure to understand any copyright issues.

Michel
0
 
fischierAuthor Commented:
Hi Martin, i tried it but i'm only getting "[an error occurred while processing this directive] ". i tried chmodding it up to 777, set parsing to exec, but to no avail.

This is what the script looks like:
                #!/usr/bin/perl

                use IO::Socket;
             
                $site = "www.ettnet.se"; # Change this...
                $http_port=80;
                $url = "http://www.ettnet.se/~boris/1950s.html"; # ...and this

                $them = IO::Socket::INET->new(
                                              Proto    => "tcp",
                                              PeerAddr => $site,
                                              PeerPort => $http_port,
                                              )
                or die "cannot connect to http server $site:$$http_port";
                print $them "GET $url HTTP/1.0\n\n";
                @entire_page=  <$them>;
                close $them or die "cannot close connection: $!";

                print STDOUT "Content-Type: text/plain\n\n@entire_page";


Tag is: <!--#exec cgi="http://www.gp.se/cgi-bin/getPage.pl"-->
(not getFile.pl )    ;-)

I'm running out of ideas, unless our firewall is making the fuss... but both script and file is outside it...
/T
0
 
fischierAuthor Commented:
Michel: Could <BODY> etc be the reason for an error message?
I'm also trying to force the external page into a Table... could this affect the result?
/F
0
 
Michel PlungjanIT ExpertCommented:
I doubt it.
The error message probably comes from the web server so I would try the following:

1. Run the program from the commandline on the server and see if there are error messages. If yes, fix them.

2. Is the web server owner/member of the group that owns the perl file (chown)
I get GP har inte funnit sidan if I try to load http://www.gp.se/cgi-bin/getPage.pl from the location bar

3. Is http://www.ettnet.se/~boris/1950s.html available?

2. Is exec ssi enabled on the server? Could be that #exec is not allowed (quite often it is not) but i suspect a typo or script error but I do not do perl in that much detail...

Michel
0
 
fischierAuthor Commented:
Well, i'm a bit dubious about using exec anyway... I still can't get it to work, but i'd be willing to award Martin his points anyway, and i'll keep working on it.
/Fischier
0
 
Michel PlungjanIT ExpertCommented:
If you call your cgi in a link or in a form, it would not need SSI exec
The cgi would just need to output the complete page including the stuff from the foreign page...

First get the cgi to run from the comand line, then the rest should be a matter of web server settings/chmod/chown

Michel
0
 
martinagCommented:
Michel have answered all of your questions.
If your server doesn't support <!--#exec--> just let me now and I'll add a few lines to the script.

Martin
0
 
fischierAuthor Commented:
Michel: Thanks a lot, as always your knowledge is dazzling.
Martin: Yes please, i'd prefer to run the script w/o exec activated. Could you give me a runnable script?
0
 
Michel PlungjanIT ExpertCommented:
Glad to be of service.

Michel
0
 
martinagCommented:
#!/usr/bin/perl

# Get extern file
use IO::Socket;
$site = "www.ettnet.se";
$http_port=80;
$url = "http://www.ettnet.se/~boris/1950s.html";

$them = IO::Socket::INET->new(
  Proto    => "tcp",
  PeerAddr => $site,
  PeerPort => $http_port,
) or die "cannot connect to http server $site:$$http_port";

print $them "GET $url HTTP/1.0\n\n";

$externfile = "";
while (<$them>) {
  $externfile .= $_;
}

close $them or die "cannot close connection: $!";

# I take it you only want the stuff between <BODY> and </BODY>.
$title = "none";
$externfile =~ s/<TITLE>(.*?)<\/TITLE>/$title=$1;"<TITLE>$1<\/TITLE>";/e;
$externfile =~ s/.*<BODY.*?>//;
$externfile =~ s/<\/BODY.*?>.*//;

# Get local file and paste the extern into it
open (FILE, "<local.htm") or die "open file: $!";
$localfile = "";
$localfile .= $_ while <FILE>;
close FILE;
$localfile =~ s/<!-- insert extern file -->/<!-- begin extern file (Title: $title) -->\n$externfile\n<!-- end extern file -->/;

# Return
print "Content-Type: text/html\nPragma: no-cache\n\n$localfile";

---

Replace local.htm with the name of the file that should be read. Then call the script like any file at all:
<A HREF="theScript.pl">A page</A>

Martin
0
 
fischierAuthor Commented:
Well, to whom am i going to award the points?
Do you wish for me to split it?
/F
0
 
Michel PlungjanIT ExpertCommented:
That would be nice! I think Martin should answer :-)

Michel
0
 
martinagCommented:
All right...

If you want to give Michel, Massey or maybe both some points you can ask linda in the Customer Service area and you won't have to pay any extra points. I don't think so at least.

Martin
0
 
Michel PlungjanIT ExpertCommented:
No extra points needed to split points between experts

Michel
0
 
fischierAuthor Commented:
Just waiting for reply from Linda.'
/F
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

  • 10
  • 8
  • 8
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now