Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

How Would I access a C++ compiler remotely through a Perl CGI Script?

by Spidy (Chaplain)
on Oct 21, 2005 at 16:06 UTC ( [id://502056]=perlquestion: print w/replies, xml ) Need Help??

Spidy has asked for the wisdom of the Perl Monks concerning the following question:

Recently, I've been working on learning how to use C++. Or at least, to develop a working understanding of it. At school, I have a full two blocks during which I can get on computers, but neither of them have C++ compilers. I have a linux box at home, so the idea popped into my head to run a webserver off of it, with a single CGI page on it. I would put my C++ code into this CGI page(form), and it would then print the contents of the form into a file, and use a system call to compile it, and return any errors that actually came back.

Does anyone know if it's actually possible? It would be cool to do...having to wait a full day to check for bugs in my code is not efficient at all.

The way I'm thinking of handling it is to have the CGI script write the form contents into a single file, and delete whatever was in there previously, before calling a system call on that file. However, I'm not 100% certain if I'm actually able to do that...does anyone know for sure?

Thanks,
Spidy


UPDATE: After many people's hackles raising, I've decided to go with SSH, which, after testing, turns out to suit my needs perfectly.
  • Comment on How Would I access a C++ compiler remotely through a Perl CGI Script?

Replies are listed 'Best First'.
Re: Is this actually possible?
by chester (Hermit) on Oct 21, 2005 at 16:19 UTC
    Perhaps look into running an SSH server on your Linux box. That would give you (relatively) safe, remote access to do anything you want (compile programs, write them, whatever).

    Generally, data from web forms should not be considered safe. The idea of taking arbitrary code from a web form and compiling it just doesn't sit right with me, for some strange reason.

      Yeah, it raises the hackles here as well. So long as you didn't run the compiled code you wouldn't necessarily be exposing the compiling machine to anything in the submitted code, but that doesn't mean that the compiler itself couldn't be exploited (e.g. a buffer overrun in gcc). SSH is still the better solution.

        Well, I'm not planning on running the code, just compiling it and storing the errors generated by the compiler. That way I can still get my code bug-free here at school, and then go home and actually run it there.
        I've heard of assuming user input is tainted as a good programming practice, but assuming executables on the web server are tainted is a little ridiculous.

        If you're afraid of a bug in gcc, then you'd have to assume that Apache and Perl itself are equally unsafe.
      That might work, but I need a way to be able to transfer code quickly from here(school) to there(home/linux box). Besides FTP/a form, I'm not completely sure how I'd do that.
        You can use scp. Or run an FTP server on your Linux box. (Better, SFTP.) Or use wget on your Linux box, if you can put the file somewhere your Linux box can see. Or use vim remotely, it displays just fine in a console window. : ) Or even just

        $ cat > filename *paste* ^D
Re: How Would I access a C++ compiler remotely through a Perl CGI Script?
by BigRare (Pilgrim) on Oct 21, 2005 at 16:30 UTC
    SSH would be your best option for C++ and compiling at home...


    But, if SSH is not an option, you might want to check out This online C++ compiler before you go building your own form and such. It might save you some time.
      I tried that one, but it was consistently giving me fatal errors on my includes, while the code would compile on my home system.
Re: Is this actually possible?
by marto (Cardinal) on Oct 21, 2005 at 16:29 UTC
    Hi Spidy,

    It can be done but one thing to consider is your ISPs AUP (Acceptable use policy).
    A few ISPs here that I know of do not allow their users to run webservers etc.
    Have you considered getting an account on something like freeshell.org.
    I know they charge a one off fee to upgrade your account to use gcc, Perl etc.. but you may find it useful to connect from school (or anywhere else) via ssh or telnet to edit your source code, rather than upload it.

    Hope this helps

    Martin
Re: How Would I access a C++ compiler remotely through a Perl CGI Script?
by TomDLux (Vicar) on Oct 21, 2005 at 19:54 UTC

    The simple solution is to carry a Knoppix disk in your school bag, reboot a computer at school into Linux, and develop away, editing, compiling, debugging. You can save files onto a USB key ... or a floppy disk, if you can still buy those. It'll be a while before you fill 1.4 MB of typing.

    Tom

    --
    TTTATCGGTCGTTATATAGATGTTTGCA

      That is a good idea, but the computer they let me use is a mac, and touching the school computers(i.e. rebooting them) would bring the wrath of the Microsoft Certified sysadmin down on my head. Which would be bad.

      Also, the computer that they might let me boot into linux is an eMac, and can only do stuff with USB drives of CD-R's. And I have no USB drives.
Re: How Would I access a C++ compiler remotely through a Perl CGI Script?
by schweini (Friar) on Oct 21, 2005 at 20:52 UTC
    Well, since you don't seem to want to do this over SSH/scp/FTP, let me just point out that it is very easy to do this. Just store the received form data in some file, compile, redirect STDERR and STDIN to some other file or program, and return that to the browser.
    Whether your apache is authorized to access any files gcc might need depends on your system, but usually apache is configured to have as few privileges as possible, so you might want your CGI script to call some other, non-CGI script via 'sudo'. That way, you can easily and securely define just exactly what permissions you want to give the script that's going to compile your script, without altering apache's config or access-privileges. Just make sure to include "NOPASSWD" in your sudoers file, and put your CGI script in some password-protected zone (using .htaccess, for example), because letting strangers compile stuff on your machine doesn't sound as a goog idea.
Re: How Would I access a C++ compiler remotely through a Perl CGI Script?
by december (Pilgrim) on Oct 22, 2005 at 04:46 UTC

    Well, obviously this works much better over a real shell, but you seem to have figured that out pretty quickly. ;)

    But to give you an answer to your question, it could be done. If I would have to implement something like it (at gunpoint), I would use rather a file upload button. That's probably the best way to have it arriving more or less intact to the server.

    From then on, you either use cron to check for incoming files every so many minutes and do automatic builds, or you decide it can't be dirty enough for you and you spawn your building scripts or compiler directly from perl. This surely would require setting higher timeouts for your apache daemon and removing all resource limitations you might have. Also, the web browser would have keep the connection open for as long as is needed. And your cgi program would have to be pretty smart about redirecting the right file handles (STDIN, STDOUT, STDERR, perhaps more) so you'd actually see some of what happens on the other side (unless you are a flawless and *very* bored programmer, which might explain your question, too).

    Ofcourse, I should not forget to mention the possible security implications of letting people compile and run code on your computer remotely, over the web. It just might not be the sanest thing to do from public computer halls over unencrypted (unauthenticated) connections.

    And after you worked around all this, I don't think you would be happy with the end result, either. HTTP and CGI are just not meant to do certain things (efficiently, reliably) which need a whole different approach and environment. To be more precise, a http connection is typically short and stateless, making it very difficult to control and steer long running processes directly.

    But you could write a build system or daemon and let http be one of the interfaces to it. If you have a long running process that can be executed independently of HTTP connections to control whatever it is you want to do, possibilities open up.

    By the way, perhaps you could try out one of the Linux boot cds. If you have trouble finding one that has a full building environment, make one yourself. With vfat support, you could use free space on the windows drives; and you can easily scp (ssh), rsync or email your programs home. In fact, IIRC, there was a way to mount a server as a local filesystem through ssh. Implement that on your boot cd, and you automatically have easy access to your files at home, too. It takes a bit of work, but once you have something that works, you can just pop the cd in pretty much any computer and have your whole environment customised to your needs.

    Not as easy as the ssh option, but you wouldn't have to use windows at all. =)

      Is there any reason to not use HTTPS? It seems like that'd be more or less as safe as SSH and would allow for the ease of use he seems to be looking for.
        Afraid you missed the true point behind SSH for this task. SSH requires a login/password for the machine you're logging into, whereas https is only going to encrypt the data that is sent between the two computers. SSH prevents a random person from using it, https will only prevent a random person in the middle from understanding what another random person is sending to and from the webserver.


        My code doesn't have bugs, it just develops random features.

        Flame

        https is also very expensive to implement especially for a personal project for a student
Re: Is this actually possible?
by castaway (Parson) on Oct 21, 2005 at 16:14 UTC
    Yes, it's possible.

    C.

      Alright, let me rephrase that: "How would I do this?"

      I wasn't completely sure whether Apache would actually allow me to execute system calls or not...
Re: How Would I access a C++ compiler remotely through a Perl CGI Script?
by Moron (Curate) on Oct 24, 2005 at 13:30 UTC
    I was unable to do this kind of thing via my ISP, so I registered a new .com for EUR 40 and got a linux hosting deal to attach a server to it at EUR 9.75 per month (a bit more than $10) which also means I get 24 hour support although much less than whole machine to play with. Later, I started some import/wholesale business on the side of my computing work to retro-justify these costs.

    -M

    Free your mind

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://502056]
Approved by virtualsue
Front-paged by monkfan
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (6)
As of 2024-04-25 11:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found