Best way to do server side tasks with new ISP

P

Paul E. Schoen

This is my first post here and I have never used Perl, so please bear with
me. I am mostly a hardware guy but I have done a lot of programming since
the punchcard days of the IBM 7094 in 1967, and MSDOS and Windows apps
using BASIC, Pascal, C, and assembly, and embedded Z80 and PIC projects
using assembly and C. More recently I have done some scripting in
JavaScript and VB, and I have done some simple HTML for my website.

I have been with the same dialup ISP, smart.net, since 1996, and I have
been happy enough with the default performance and tools I have used,
particularly a hit counter and the ability to view a directory that does
not have an index.htm. But now I have switched to Verizon FIOS, and their
10M of web space has a broken web counter tool, and viewing of the files in
a directory is forbidden. Also it seems that they do not allow a CGI-BIN
for their residential service.

So I am looking elsewhere for a website host. I could stay with Smart.net
but their web space seems rather expensive. The domain registrar I use,
MyDomain.com, has 10G webspace for about $6/month, and they say they have a
full line of tools like a hit counter and they allow CGI-BIN, but they have
permanantly disabled directory listing of files.

It seems that JavaScript does not provide access to server-side file
directories, and on one forum it was advised to look at
http://us.php.net/manual/en/function.opendir.php. It looks like PHP is
composed of elements of C, Java, and Perl. So I decided to look at Perl,
and I have scanned much of the FAQ. It is rather overwhelming to analyze
and compare the features of so many similar languages and attempt to become
proficient in one or more, especially when I only need to accomplish a few
rather simple things that have probably been done many times before.

I plan to use Borland Delphi for all my local applications, and perhaps use
JScript or VBScript with the WSH for simple local tasks. I also need to use
JavaScript for programming PDF documents using Nitro Pro or Adobe Pro. And
of course some applications such as Access require VBA. And I have also
written some more complex apps in Delphi that use the automation interface
to utilize methods, properties, and events of objects in other programs.

Thus I am just trying to determine if I should attempt to use Perl, or
perhaps PHP or some other language, to do what I want to do. Mostly, I
would like to make a simple index.htm that can display a list of files in
its directory so that users can simply click on any one for download.
Mostly these will be JPG or TXT, but possibly also XLS, DOC, ZIP, or other
common types.

And I would also like to be able to implement a simple form that would have
its results emailed to me, which of course is a common task, but I assume I
would need a CGI application to do that.

Thanks for any advice you may be able to provide.

Paul E. Schoen
www.pstech-inc.com
 
P

Peter J. Holzer

This is my first post here and I have never used Perl, so please bear with
me. I am mostly a hardware guy but I have done a lot of programming since
the punchcard days of the IBM 7094 in 1967, and MSDOS and Windows apps
using BASIC, Pascal, C, and assembly, and embedded Z80 and PIC projects
using assembly and C. More recently I have done some scripting in
JavaScript and VB, and I have done some simple HTML for my website.

I have been with the same dialup ISP, smart.net, since 1996, and I have
been happy enough with the default performance and tools I have used,
particularly a hit counter and the ability to view a directory that does
not have an index.htm. [...]
but their web space seems rather expensive. The domain registrar I use,
MyDomain.com, has 10G webspace for about $6/month, and they say they have a
full line of tools like a hit counter and they allow CGI-BIN, but they have
permanantly disabled directory listing of files.

It seems that JavaScript does not provide access to server-side file
directories,

This is correct for JavaScript running in the browser (some web servers
offer server side JavaScript - this has of course access to server-side
resources, but not to browser resources).
and on one forum it was advised to look at
http://us.php.net/manual/en/function.opendir.php. It looks like PHP is
composed of elements of C, Java, and Perl.

And Perl is composed of elements of C, awk, and sh (with a little bit of
OOP and functional programming thrown into the mix).
So I decided to look at Perl,
and I have scanned much of the FAQ. It is rather overwhelming to analyze
and compare the features of so many similar languages and attempt to become
proficient in one or more, especially when I only need to accomplish a few
rather simple things that have probably been done many times before. [...]
Thus I am just trying to determine if I should attempt to use Perl, or
perhaps PHP or some other language, to do what I want to do.

You could try to solve your problem in Perl, PHP, and a few other
languages and see which one you like best.

Here is a Perl solution which assumes that you can put Perl CGI programs
directly into "normal" directories and aren't constrained to using
cgi-bin:

#!/usr/bin/perl
use warnings;
use strict;
use CGI;

my $cgi = CGI->new();
print "Content-Type: text/html; charset='UTF-8'\n";
print "\n";
print "<title>Directory listing of ",
$cgi->escapeHTML($cgi->self_url),
"</title>\n";
print "<ul>\n";
opendir(my $dh, ".");
for (readdir($dh)) {
print "<li><a href='", $cgi->escapeHTML($_), "'>",
$cgi->escapeHTML($_),
"</a></li>\n";
}
print "</ul>\n";
__END__

Making the output more beautiful, adding metadata (size, modified date,
etc.) and other embellishments are left as an exercise to the reader
;-).

hp
 
P

Paul E. Schoen

[snip]
Making the output more beautiful, adding metadata (size, modified date,
etc.) and other embellishments are left as an exercise to the reader
;-).

Thanks for the response. That code looks rather intimidating, compared to
JavaScript. But at least it's a start, and perhaps I can get used to the
syntax and make sense of it.

Paul
 
J

Jürgen Exner

Paul E. Schoen said:
That code looks rather intimidating, compared to
JavaScript.

Well, what do you expect? The one is a simple DHTLM scripting language,
the other is a fully-featured general purpose programming langauge.

jue
 
P

Paul E. Schoen

Jürgen Exner said:
Well, what do you expect? The one is a simple DHTLM scripting language,
the other is a fully-featured general purpose programming langauge.

Well, I am used to C and Pascal (Delphi), and a little bit of Visual Basic.
I can do just about anything I need on my local machine with those
languages. Then I tried some JavaScript and VBScript using the WSH for some
simple file manipulation scripts, and found some limitations. I also used
some JavaScript in a PDF, and ran into a few more limitations.

But I am coming to understand the issues of security when one includes code
(script) in an HTML document that is downloaded on someone else's machine.
And another level of security when dealing with server-side CGI where even
reading a directory or doing some simple file I/O can be dangerous.

It's already a big leap from embedded assembly and C routines where all of
the hardware and software are visible and under control of the designer, to
applications that run in the context of an OS on a local machine, and then
finally to an instruction set that works in the context of a web page in
someone's browser, or a CGI program that accesses files and resources on a
server.

But mostly I can't understand why well-known languages such as C and
Pascal, or even VB and .NET, are not used for CGI apps (although maybe they
are), and instead require rather arcane-seeming code such as Perl and PHP.
I will need to look into the language a bit more before I can really make a
judgment as to its suitability for my purposes. For now, though, it just
seems confusing.

Paul
 
U

Uri Guttman

PES> But mostly I can't understand why well-known languages such as C
PES> and Pascal, or even VB and .NET, are not used for CGI apps
PES> (although maybe they are), and instead require rather
PES> arcane-seeming code such as Perl and PHP. I will need to look
PES> into the language a bit more before I can really make a judgment
PES> as to its suitability for my purposes. For now, though, it just
PES> seems confusing.

then you have never tried to do major text munging in c with all of its
problems of memory management, poor string handling, etc. this is true
for most compiled languages. perl was the best dynamic language when cgi
came forth and became the defacto language of the web in those days. its
ease of handling strings and memory made it popular with cgi and many
other application areas. and thinking today that perl is still mostly
used in cgi is way off base as it is used in many more areas and with
major amounts of code (see cpan).

and calling pascal well known today is just being silly. cobol is more
well known and is still being coded.

uri
 
M

Michael Vilain

Paul E. Schoen said:
Well, I am used to C and Pascal (Delphi), and a little bit of Visual Basic.
I can do just about anything I need on my local machine with those
languages. Then I tried some JavaScript and VBScript using the WSH for some
simple file manipulation scripts, and found some limitations. I also used
some JavaScript in a PDF, and ran into a few more limitations.

But I am coming to understand the issues of security when one includes code
(script) in an HTML document that is downloaded on someone else's machine.
And another level of security when dealing with server-side CGI where even
reading a directory or doing some simple file I/O can be dangerous.

It's already a big leap from embedded assembly and C routines where all of
the hardware and software are visible and under control of the designer, to
applications that run in the context of an OS on a local machine, and then
finally to an instruction set that works in the context of a web page in
someone's browser, or a CGI program that accesses files and resources on a
server.

But mostly I can't understand why well-known languages such as C and
Pascal, or even VB and .NET, are not used for CGI apps (although maybe they
are), and instead require rather arcane-seeming code such as Perl and PHP.
I will need to look into the language a bit more before I can really make a
judgment as to its suitability for my purposes. For now, though, it just
seems confusing.

Paul

C and Pascal can be used as CGI applications. But Perl and PHP
applications can be run within the context of the web server, thereby
scaling a whole lot better (e.g. each connection is still running inside
the web server's process space rather than as a separate CGI process).
Add access to MySQL and you have a full-service application platform.

Just as C and Pascal had their day, there are other web-technologies
attempting to replace Perl and PHP. Most web hosting companies offer
Perl, PHP, and MySQL. Good luck finding Cold Fusion. Or open your
wallet _yearly_ for Microsoft-based development environments. In this
area, the standard development cycle of edit, compile/build, test is
shortened by removing the compile/build phase.

I guess it's time you decide if you want to do web development or
continue doing your C and Pascal programs on DOS. I've been programming
for 30+ years. I learned new languages when I needed to. Fortran,
PDP-11, DEC-10, or VAX assembly couldn't do it all as it turns out.

Just remember that the penalty for complaining is that you'll live
longer (and continue using Pascal). At this rate, you'll outlive a lot
of us. And you'll still be complaining about C and Pascal.
 
G

Gunnar Hjalmarsson

Michael said:
C and Pascal can be used as CGI applications. But Perl and PHP
applications can be run within the context of the web server, thereby
scaling a whole lot better (e.g. each connection is still running inside
the web server's process space rather than as a separate CGI process).
Add access to MySQL and you have a full-service application platform.

...

Maybe it's time to slow down a bit. The OP wants to be able to list one
or more directories and a hit counter and a form-to-mail app.

Directory listing is a web server thing in the first place. Assuming
Apache, an .htaccess file with this content:

Options +Indexes

might do. If not, it ought to be possible to ask the web hosting
provider to allow directory listing for a specific account, or for one
or more specified directories.

As regards hit counters and form-to-mail scripts, there are numerous of
them out there that may or may not fit the OP's needs. In any case, I
can't see anything wrong with using C for those apps instead of learning
a new language. (The latter presupposes that the hosting provider allows
compiling C programs.)

Scalability, mod_perl and stuff seems not to be a major concern.
 
C

Charlton Wilbur

MV> C and Pascal can be used as CGI applications. But Perl and PHP
MV> applications can be run within the context of the web server,
MV> thereby scaling a whole lot better (e.g. each connection is
MV> still running inside the web server's process space rather than
MV> as a separate CGI process). Add access to MySQL and you have a
MV> full-service application platform.

Er, C can be used within the context of the web server as well, and the
last time I looked, there were C libraries for MySQL.

Charlton
 
P

Peter J. Holzer

How is that code "intimidating"? It's just a bunch of print statements
and a simple loop.

Assuming you had access to a directory, how would that code be simpler
in JavaScript?

Well, what do you expect? The one is a simple DHTLM scripting language,
the other is a fully-featured general purpose programming langauge.

JavaScript is a fully-featured general purpose programming language. In
fact, if you look at the standard, you won't find HTML mentioned at all,
except maybe in the preface. The DOM tree is just a data structure
provided by the environment, not something built into the language.

hp
 
P

Peter J. Holzer

Jürgen Exner said:
Well, what do you expect? The one is a simple DHTLM scripting language,
the other is a fully-featured general purpose programming langauge.

Well, I am used to C and Pascal (Delphi), and a little bit of Visual Basic.
I can do just about anything I need on my local machine with those
languages. [...]
But mostly I can't understand why well-known languages such as C and
Pascal, or even VB and .NET, are not used for CGI apps (although maybe
they are),

They are. I wrote some web applications in C myself. But that was for an
embedded system where the whole system (kernel, web server, application,
and the data it processed) had to fit into a few MB of flash. It would
have been quite a lot faster to develop the thing in Perl, but there
simply wasn't space for a perl interpreter on the system (and using a
bigger flash would have cost a lot more than my few hundred hours of
work).
and instead require rather arcane-seeming code such as Perl
and PHP.

Mass hosters can only offer a few technologies, and they will offer what
their customers demand. Theses days this is usually PHP, plus a little
bit of Perl, Python and Ruby, at least on Linux hosts. On Windows hosts,
they may also offer VB and .NET, but I'm not a Windows guy so I wouldn't
know that.

If you want to write your web apps in C, it's probably best if you get a
virtual host (I've seen some offers for less than 10¤/month). Of course
then you wouldn't need to write a CGI app just to print a directory
listing because you can just configure your web server.

hp
 
P

Peter J. Holzer

Directory listing is a web server thing in the first place. Assuming
Apache, an .htaccess file with this content:

Options +Indexes

might do. If not, it ought to be possible to ask the web hosting
provider to allow directory listing for a specific account, or for one
or more specified directories.

The OP already wrote that he asked them and that it is *not* possible to
turn on directory listings and that they won't make an exception for
him.

hp
 
P

Paul E. Schoen

Peter J. Holzer said:
How is that code "intimidating"? It's just a bunch of print statements
and a simple loop.

Well, it's probably just about learning the syntax:

my $cgi = CGI->new(); // I don't understand what this does, except
possibly assign string $cgi to something

opendir(my $dh, "."); // I assume $dh is a string containing the
directory in text form

for (readdir($dh)) { // So this apparently reads the string one line
at a time

print "<li><a href='", $cgi->escapeHTML($_), "'>",
$cgi->escapeHTML($_),
"</a></li>\n"; // I know this must create HTML code for
hyperlinks to the directory items

The single and double quotes and various other characters and symbols
probably make perfect sense to a Perl programmer, but they seem difficult
to read and understand.

Assuming you had access to a directory, how would that code be simpler
in JavaScript?

I'm not very fluent in JavaScript, but if I had access to an MSDOS command
shell I would just execute a

dir > dirfile.txt

and then I would just parse the filenames and add appropriate HTML to
prepend the URL of the directory to make them hyperlinks.

JavaScript is a fully-featured general purpose programming language. In
fact, if you look at the standard, you won't find HTML mentioned at all,
except maybe in the preface. The DOM tree is just a data structure
provided by the environment, not something built into the language.

I found JavaScript very limited when used in the context of the Windows
Script Host, as it is designed to run in the context of a browser and an
HTML document. It does have some file manipulation capability if you use an
ActiveX FileSystemObject, where you can create directories and text files
which can be written and read, and files can be copied from one place to
another. But a local machine is a much different environment than a web
server!

Thanks for your patience in helping me understand more about various
languages and their appropriateness to different environments. I don't
think I want to learn Perl for the limited use I will probably have for it.
I can see where it is a very powerful tool for text manipulation and
negotiating the environment of the web server and user interaction with an
HTML document, and gathering information. But it seems to be difficult to
follow because of its shorthand notation for complex tasks.

Paul
 
G

Gunnar Hjalmarsson

Peter said:
The OP already wrote that he asked them and that it is *not* possible to
turn on directory listings and that they won't make an exception for
him.

Even if that may be the case, it's not what he wrote. He said with
respect to his current provider that "viewing of the files in a
directory is forbidden", and that's what Apache tells you if directory
listing is not enabled.
 
P

Peter J. Holzer

Even if that may be the case, it's not what he wrote. He said with
respect to his current provider that "viewing of the files in a
directory is forbidden", and that's what Apache tells you if directory
listing is not enabled.


To quote from the first posting in this thread:

| they say they have a full line of tools like a hit counter and they
| allow CGI-BIN, but they have permanantly disabled directory listing of
| files.

hp
 
P

Paul E. Schoen

Peter J. Holzer said:
To quote from the first posting in this thread:

| they say they have a full line of tools like a hit counter and they
| allow CGI-BIN, but they have permanantly disabled directory listing of
| files.

Actually my current dialup ISP allows CGI and shows a directory when there
is no index. But my new high speed ISP, verizon.net, apparently does not
allow either, and their hit counter is broken. I get 10 M free, but I would
like a little more. So I am really just shopping for webspace, and perhaps
there are providers that will give me what I want for a reasonable amount,
like $5/mo for 100 M or so.

Thanks for the interesting discussion.

Paul
 
U

Uri Guttman

PES> Actually my current dialup ISP allows CGI and shows a directory
PES> when there is no index. But my new high speed ISP, verizon.net,
PES> apparently does not allow either, and their hit counter is
PES> broken. I get 10 M free, but I would like a little more. So I am
PES> really just shopping for webspace, and perhaps there are
PES> providers that will give me what I want for a reasonable amount,
PES> like $5/mo for 100 M or so.

jeez, do you know how many web hosters there are out there? and that you
can get decent deals for $5 or more a month? using your isp for a web
host is usually a poor idea and even worse using them for the email
domain. since you seem to have your own domain why don't you move it to
a hoster that has what you want. most have large checklists of features
for each plan they offer so it would be easy to find one that matches
your needs.

uri
 
M

Mart van de Wege

Ben Morrow said:
Quoth "Paul E. Schoen" <[email protected]>:

(Notice how Perl makes the rather common operation of 'iterate over all
the entries in a list' much easier than JS does. JS 1.6 has

entries.forEach(function { print(...) });

but that isn't exactly pretty.)

Erm.

JavaScript 1.5 *does* have the equivalent construct:

'for (var in list)'.

Mart
 
C

Charlton Wilbur

PES> Well, it's probably just about learning the syntax:

It *is* just about learning the syntax. Well, and the semantics.

Perl is not Javascript, C, VB, or Pascal. You need to get your head
around that concept first. You can use what you know of other languages
to help you get a handle on Perl, but the sooner you accept Perl for
what it is, and stop trying to understand it as if it were some other
language with lots of errors, the sooner you'll start making progress.

PES> The single and double quotes and various other characters and
PES> symbols probably make perfect sense to a Perl programmer, but
PES> they seem difficult to read and understand.

Fortunately, there are plenty of resources to help you learn to read and
understand them.

All languages have learning curves. Why did you accept C and Pascal's,
but balk at Perl's?

Charlton
 
J

Jürgen Exner

Charlton Wilbur said:
PES> The single and double quotes and various other characters and
PES> symbols probably make perfect sense to a Perl programmer, but
PES> they seem difficult to read and understand.

All languages have learning curves. Why did you accept C and Pascal's,
but balk at Perl's?

Well, VB, Pascal, C, they are all the same anyway.

Try Lisp, Prolog, and APL. After you got familiar with those Perl will
feel like a vacation on a tropical island with a light breeze and a pina
colada in your hands.

jue
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top