Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Text File On Webserver HD using CGI and C/PERL

Options
  • 11-08-2004 9:44am
    #1
    Closed Accounts Posts: 1,541 ✭✭✭


    Hello Everyone,

    Im looking for a bit of help. I am new to the game of setting up webservers. However I have managed to install an Apache webserver on Windows XP.

    I have a number of question which I hope someone out there may know:

    (1) What is the best way to go about setting up a CGI-bin on an Apache webserver on XP.

    (2) What I want to do is to ask a user to click Button1 or Button2 on my HTML website homepage. If the user presses button1 I want to call a program in my CGI-bin to write the letter A to a text file on my server PC desktop. If the user presses the other button (button2) I want to call a program in my CGI-bin to write "B" to the same text file(overwrite it if possible). Whatever the user presses must be sent/saved to a text file on the hard drive of the server PC. What is the best way of doing this?

    (3) I really want to use a C program(as opposed to PERL) in Cgi-bin to send "A "to a text file whenever button1 is pressed and "B" to the same text file whenever button2 is pressed.

    (a) Is it possible to run a C program from the Cgi-bin and execute it from the internet(I am using my own server).

    (b) Does the server or Cgi-bin have to be configured in a special way to execute C programs?

    (c) If it is possible then how should I best compile the C/C++ to suit this application? How do I transfer my C files from my folder on desktop to the Cgi-bin when I am ready to do so?

    (d) Do I need to install special privilages to create a text file on the server HD from the internet? How is this done?

    Any hepl or advice appreciated. Not many people seem to know much about CGI applications using C. Like I said before all I want to do is ask the user to click one of two buttons on my website and then write A to a text file on my server PC desktop if he/she presses tthe 1st button or write B to a text file on my server PC desktop if she/he presses the 2nd button. There is only one single text file but I could use 2 different CGI programs for each button. Thanks for taking time to read this and I hope someone can help!!

    (I have also posted this on another board)


Comments

  • Registered Users Posts: 326 ✭✭Paulj


    As far as i know this can be done from C however im not sure how to set it up. But why use C, you're making you're life much harder by using it. Perl or PHP can deal the CGI interface natively and you would be able to write you're program much quicker in only a couple of lines of code.


  • Closed Accounts Posts: 1,541 ✭✭✭finnpark


    Thanks Paulj. PHP and PERL soun good. Sorry if I sound stupid but what do you mean by "natively" :confused::) ? I think I will probably use PERL as I have a book on CGI-PERL. What kind of program do I need to write PERL in? How would this be transferred to my CGI-bin? Thanks Again!!


  • Registered Users Posts: 326 ✭✭Paulj


    what i mean is that perl has functions which make it easy to extract parameters passed to it from the html form which the user clicks on. So all you're script has to do is check what parameter is read then write letter A or B to the file accordingly.

    Im not sure how it works with apache in xp but i'd assume you just copy the perl script to you're cgi directory and ensure cgi/perl is enabled in apache. You should be able to write perl scripts with any text editor (such as notepad).

    I have to admit though that php is much nicer to program in and its syntax is similar to C. I started off by learning C and the transition to php went a lot smoother than the transition to perl.


  • Closed Accounts Posts: 1,541 ✭✭✭finnpark


    Thanks again. Any other views also welcome. I may try all 3 methods. PERL, PHP and C in Cgi-bin. If any1 has done anything like this before please reply. Much appreciated as i am a beginner to web stuff.

    :)


  • Registered Users Posts: 1,268 ✭✭✭hostyle


    #!/usr/bin/perl -w
    
    print 'Content-type: text/html \n\n';
    print '<a href="http://www.google.com/search?q=perl+cgi+tutorial">google search</a>';
    

    Enter the above into notepad, save into the cgi-bin sub-directory of your webservers document root as test.cgi. Then visit here


  • Advertisement
  • Closed Accounts Posts: 1,541 ✭✭✭finnpark


    Many thanks. I will defo try this. Very simple indeed when your clever. ;)

    One other thing. Is it possible to "call" or execute a C-program on the desktop of my server PC using PERL.? I want another button on my webpage to execute a program on my server PC's HD. Is this possible or can I just throw the C program into the CGI-bin? Any help/advice welcome and cheers once again for that last post!! :D


  • Registered Users Posts: 1,268 ✭✭✭hostyle


    Its possible and simple enough, but it depends on the program you are trying to run.
    #!/usr/bin/perl -w
    
    exec('notepad.exe');
    
    print 'Content-type: text/html \n\n';
    print '<p>Done!</p>';
    

    should work (on a windows server), but ehm, well, I don't really advise this sort of thing :)


  • Closed Accounts Posts: 1,541 ✭✭✭finnpark


    Yes I know I know there is a huge security risk :( . Is it really that simple? :D .

    Do you know of anyway I could call/execute a C-program on my HD safely? Maybe 1st things 1st. I have quite a bit to keep me busy now, I will worry about security another day.

    Thanks again!! :)


Advertisement