Solved

Include external files w/o layers?

Posted on 1998-10-28
30
163 Views
Last Modified: 2013-11-18
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
Comment
Question by:fischier
  • 10
  • 8
  • 8
  • +1
30 Comments
 
LVL 4

Expert Comment

by:martinag
ID: 1839124
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
 
LVL 10

Expert Comment

by:MasseyM
ID: 1839125
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
 
LVL 4

Expert Comment

by:martinag
ID: 1839126
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
 
LVL 4

Expert Comment

by:martinag
ID: 1839127
MasseyM, is that an IE4 tag? I've never heard of it before.

Martin
0
 
LVL 10

Expert Comment

by:MasseyM
ID: 1839128
OBJECT is an HTML 3.0 standard tag developed by the W3 Consortium...  http://www.w3.org

0
 
LVL 10

Expert Comment

by:MasseyM
ID: 1839129
OBJECT is an HTML 3.0 standard tag developed by the W3 Consortium...  http://www.w3.org
0
 
LVL 4

Expert Comment

by:martinag
ID: 1839130
I see. Thanks.

Martin
0
 
LVL 1

Author Comment

by:fischier
ID: 1839131
Thanks, but this is a bit over my head. Could you please clean it to a runnable script, preferrably with comments?
/Fischier
0
 
LVL 10

Expert Comment

by:MasseyM
ID: 1839132
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
 
LVL 1

Author Comment

by:fischier
ID: 1839133
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
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 1839134
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
 
LVL 1

Author Comment

by:fischier
ID: 1839135
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
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 1839136
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
 
LVL 1

Author Comment

by:fischier
ID: 1839137
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
 
LVL 4

Expert Comment

by:martinag
ID: 1839138
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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 1839139
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
 
LVL 1

Author Comment

by:fischier
ID: 1839140
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
 
LVL 1

Author Comment

by:fischier
ID: 1839141
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
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 1839142
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
 
LVL 1

Author Comment

by:fischier
ID: 1839143
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
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 1839144
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
 
LVL 4

Expert Comment

by:martinag
ID: 1839145
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
 
LVL 1

Author Comment

by:fischier
ID: 1839146
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
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 1839147
Glad to be of service.

Michel
0
 
LVL 4

Expert Comment

by:martinag
ID: 1839148
#!/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
 
LVL 1

Author Comment

by:fischier
ID: 1839149
Well, to whom am i going to award the points?
Do you wish for me to split it?
/F
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 1839150
That would be nice! I think Martin should answer :-)

Michel
0
 
LVL 4

Accepted Solution

by:
martinag earned 200 total points
ID: 1839151
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
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 1839152
No extra points needed to split points between experts

Michel
0
 
LVL 1

Author Comment

by:fischier
ID: 1839153
Just waiting for reply from Linda.'
/F
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
This article discusses four methods for overlaying images in a container on a web page
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now