Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++

CGI?

Altera_Forum
Honored Contributor II
24,649 Views

Hello everyone: 

 

Does the boa webserver ("pre-buit version" provided by Microtronix) support CGI ? 

 

In the directory:"/c/altera/kits/nios2/examples/software/linux/apps/boa/util", 

 

there are some files such as *.pl or cgi-test.cgi .....etc, 

 

Is that means those files are examples for writing perl CGI? 

 

http://forum.niosforum.com/work2/style_emoticons/<#EMO_DIR#>/blink.gif
0 Kudos
24 Replies
Altera_Forum
Honored Contributor II
23,619 Views

Yes it does support cgi. I got it to work. 

 

You have to create /home/httpd/cgi-bin directory in your fs project and place your programs there. 

 

-Thomas
0 Kudos
Altera_Forum
Honored Contributor II
23,619 Views

hello Thomas: 

 

thanks for your reply, 

 

so,what CGI language does the Microtronix linux distribution support? perl? 

 

and ,is that means we don&#39;t have to install any additional application to support CGI? 

 

then finally,could you show us a simple CGI program as an exmple? 

 

your information helps a lot, 

 

thanks.
0 Kudos
Altera_Forum
Honored Contributor II
23,619 Views

Ok, 

 

I was going to post this in the web server thread, but i will post it here instead. 

 

CGI program can be written in any language because CGI is a method of passing data not a specific implementation. The easiest way is to create a C program using the Microtronix linux application wizard. For example this is a program that controls the LEDs on the cyclone dev board: 

# include <stdio.h># include <string.h># include <stdlib.h> 

// replace the path with proper path to nios2_system.h# include <C:\altera\kits\nios2\bin\eclipse\workspace\linux1\build\include\nios2_system.h

 

void main(void) 

np_pio *pio = na_led_pio;  

pio->np_piodirection = 3; 

pio->np_piodata = 0; 

 

int content_length=0; 

char *cgiinput ; 

 

unsigned char mydata=0; 

pio->np_piodata = 0x00; 

 

printf("Content-type: text/html\n"); 

printf("\n"); 

 

if ( !(content_length = atoi(getenv("CONTENT_LENGTH"))) ) { 

printf("No Content-Length was sent with the POST request.\n") ; 

exit(1) ; 

 

if ( !(cgiinput=(char *)malloc(content_length+1)) ) { 

printf("Could not allocate memory for cgiinput.\n") ; 

exit(1) ; 

 

if (!fread(cgiinput, content_length, 1, stdin)) { 

printf("Could not read CGI input from STDIN.\n") ; 

exit(1) ; 

 

cgiinput[content_length]=&#39;\0&#39; ; 

 

if (strstr(cgiinput, "LED1")) mydata |= 1; 

if (strstr(cgiinput, "LED2")) mydata |= 2; 

if (strstr(cgiinput, "LED3")) mydata |= 4; 

if (strstr(cgiinput, "LED4")) mydata |= 8; 

if (strstr(cgiinput, "LED5")) mydata |= 16; 

if (strstr(cgiinput, "LED6")) mydata |= 32; 

if (strstr(cgiinput, "LED7")) mydata |= 64; 

if (strstr(cgiinput, "LED8")) mydata |= 128; 

 

pio->np_piodata = mydata; 

 

// printf("cgi input was: \n%s\n", cgiinput); 

 

printf("<html><head><title>CGI\n"); 

printf("Test</title><body>\n"); 

printf("<h1>LEDs set</h1>"); 

printf("\n"); 

printf("</body></html>\n"); 

 

exit(0); 

 

----------- 

Please note that this program does not do proper parsing of CGI input parameters, it only checks if certain parameters were included. That works fine in this simple case. 

 

To place this program in the cgi-bin directory, compile it first, then copy/paste to /home/httpd/cgi-bin and rename to "<filename>.cgi.exe" so that when the filesystem is built, it ends up with the proper ".cgi" extension. 

 

Then you need a html file in order to make this CGI program useful. For example (Note: replace the IP with the dev boards IP, and cgitest2.cgi with the filename of your CGI program): 

 

<FORM METHOD="POST" 

 

 

 

ACTION="http://192.168.1.122/cgi-bin/cgitest2.cgi"> 

 

 

 

1<INPUT TYPE="checkbox" NAME="LED1" VALUE="led1" CHECKED> 

 

2<INPUT TYPE="checkbox" NAME="LED2" VALUE="led2"> 

 

3<INPUT TYPE="checkbox" NAME="LED3" VALUE="led3"> 

 

4<INPUT TYPE="checkbox" NAME="LED4" VALUE="led4"> 

 

5<INPUT TYPE="checkbox" NAME="LED5" VALUE="led5"> 

 

6<INPUT TYPE="checkbox" NAME="LED6" VALUE="led6"> 

 

7<INPUT TYPE="checkbox" NAME="LED7" VALUE="led7"> 

 

8<INPUT TYPE="checkbox" NAME="LED8" VALUE="led8"> 

 

 

 

 

 

 

 

<INPUT TYPE="submit" value="OK"> 

 

</FORM> 

 

------------------- 

You can execute this html file from your PC&#39;s desktop or host it on the dev board under /home/httpd. 

 

I hope this helps, let me know if more explanation is needed. 

 

-Thomas
0 Kudos
Altera_Forum
Honored Contributor II
23,619 Views

http://forum.niosforum.com/work2/style_emoticons/<#EMO_DIR#>/laugh.gif it works! 

Thank you very much,Thomas.
0 Kudos
Altera_Forum
Honored Contributor II
23,619 Views

i do it according to guide 

 

but HTTP 400 appear 

 

why?
0 Kudos
Altera_Forum
Honored Contributor II
23,619 Views

 

--- Quote Start ---  

originally posted by zhangyan_swpu@Oct 17 2006, 04:09 AM 

i do it according to guide 

 

but http 400 appear 

 

why? 

<div align='right'><{post_snapback}> (index.php?act=findpost&pid=18726) 

--- quote end ---  

 

--- Quote End ---  

 

 

hi 

 

don&#39;t give up, try this simple example : ************* html code : index.html****************** <FORM method="get" ACTION="mult.cgi" > Please specify the multiplicands: <INPUT NAME="m" SIZE="5"> <INPUT NAME="n" SIZE="5"> <INPUT TYPE="SUBMIT" VALUE="Multiply!"> </FORM> **************************************** ************** cgi code : mult.c****************** # include <stdio.h># include <stdlib.h> int main(void) { char *data; long m,n; printf("%s%c%c\n", "Content-Type:text/html;charset=iso-8859-1",13,10); printf("<TITLE>Multiplication results</TITLE>\n"); printf("<H3>Multiplication results</H3>\n"); data = getenv("QUERY_STRING"); if(data == NULL) printf(" Error! Error in passing data from form to script."); else if(sscanf(data,"m=%ld&n=%ld",&m,&n)!=2) printf(" Error! Invalid data. Data must be numeric."); else printf(" The product of %ld and %ld is %ld.",m,n,m*n); return 0; } ****************************************************** ******************** Makefile : Makefile***********************# # configurable options# - set DEBUG = 1 to turn on debugging support# DEBUG = 1 PROJ_NAME = mult INSTALL_DIR = PROGS := $(PROJ_NAME).exe CFLAGS += # # You should not need to modify anything beyond this point# TOPDIR = . include ./Rules.mak ifeq &#39;$(DEBUG)&#39; &#39;1&#39; PROGS += $(PROGS:.exe=.gdb) endif all: $(PROGS) .PHONY: clean clean: -rm -f *. *.elf *.gdb *.bin *.exe .PHONY: install install: all ifeq "$(INSTALL_DIR)" "" $(error No installation directory specified) endif mkdir -p $(INSTALL_DIR)/bin install -v $(filter %.exe, $(PROGS)) $(INSTALL_DIR)/bin *************************************************************** steps to follow : --> create a new uclinux application --> add "mult.c" and "Makefile" to project --> right click on project : -- creat make target --> yes -- build make target --> if compilation success it will create a multi.exe --> add "index.html" and "mult.exe" to httpd derictory on file system --> rename "mult.exe" by "mult.cgi" and go ! :D
0 Kudos
Altera_Forum
Honored Contributor II
23,619 Views

thank you very much! 

sdhnain! 

 

i will try again!
0 Kudos
Altera_Forum
Honored Contributor II
23,619 Views

 

--- Quote Start ---  

originally posted by zhangyan_swpu@Oct 17 2006, 11:09 AM 

i do it according to guide 

 

but http 400 appear 

 

why? 

<div align='right'><{post_snapback}> (index.php?act=findpost&pid=18726) 

--- quote end ---  

 

--- Quote End ---  

 

Or, you can move to Linux PC, try out uClinux-dist as in Nios wiki. 

There is a generic cgi example in uClinux-dist. 

 

It is totally wrong to develop Linux on a Windows machine. 

I believe you will need to move to Linux PC, sooner or later.
0 Kudos
Altera_Forum
Honored Contributor II
23,619 Views

Hello, 

 

I&#39;m a newbie. http://forum.niosforum.com/work2/style_emoticons/<#EMO_DIR#>/rolleyes.gif  

I just joined. 

I&#39;ll try this example and post another reply later. 

Basically: 

I&#39;m trying to build a cgi app in C that will pipe SCPI ascii strings to and from a web page(s) and rack of (<=96) modules (CycloneIII&#39;s) via one App on one master controller with Altera Cyclone I/NIOS II/Microtronix Linux/etc. 

All in a few weeks. LOL 

 

Obviously I dont even know what the right questions to ask are yet. LOL. 

http://forum.niosforum.com/work2/style_emoticons/<#EMO_DIR#>/biggrin.gif  

 

I hope this is the right forum?
0 Kudos
Altera_Forum
Honored Contributor II
23,619 Views

I&#39;m trying to build/run the simpler sdhnain version. 

I get these error messages when I try to "-- build make target"? 

 

 

make -k all  

no emulation specific options. 

Makefile:25: *** missing separator. Stop. 

 

 

What are emulation options? from SOPC builder ? 

I&#39;ll try some more. 

 

These are lines 23, 24, 25 in the makefile? 

 

.PHONY: clean 

clean: 

-rm -f *.[oad] *.elf *.gdb *.bin *.exe 

 

What seperator is needed and where?
0 Kudos
Altera_Forum
Honored Contributor II
23,619 Views

 

--- Quote Start ---  

originally posted by rfitz25@Nov 11 2006, 07:01 AM 

hello, 

 

i&#39;m a newbie. http://forum.niosforum.com/work2/style_emoticons/<#emo_dir#>/rolleyes.gif  

i just joined. 

i&#39;ll try this example and post another reply later. 

basically: 

i&#39;m trying to build a cgi app in c that will pipe scpi ascii strings to and from a web page(s) and rack of (<=96) modules (cycloneiii&#39;s) via one app on one master controller with altera cyclone i/nios ii/microtronix linux/etc. 

all in a few weeks. lol 

 

obviously i dont even know what the right questions to ask are yet. lol. 

http://forum.niosforum.com/work2/style_emoticons/<#emo_dir#>/biggrin.gif  

 

i hope this is the right forum? 

<div align='right'><{post_snapback}> (index.php?act=findpost&pid=19373) 

--- quote end ---  

 

--- Quote End ---  

 

Welcome. 

 

The best advice is, ( shall I repeat again and again?) 

You should move to Linux PC, try out uClinux-dist as in Nios wiki. 

There is a working generic cgi example in uClinux-dist. 

 

It is totally wrong to develop Linux on a Windows machine. 

I believe you will need to move to Linux PC, sooner or later.
0 Kudos
Altera_Forum
Honored Contributor II
23,619 Views

Thanks for the feedback. 

 

I understand moving to a Linux PC sounds like a good idea. 

However out here in the real world thats not always an option. 

So theres no need for you to continue repeating yourself. 

http://forum.niosforum.com/work2/style_emoticons/<#EMO_DIR#>/tongue.gif  

 

Anyway I&#39;m back trying to get this project to compile. 

I may try the LED version for the dev boards. 

 

Thanks, 

Richard 

 

 

The best advice is, ( shall I repeat again and again?) 

You should move to Linux PC, try out uClinux-dist as in Nios wiki. 

There is a working generic cgi example in uClinux-dist. 

 

It is totally wrong to develop Linux on a Windows machine. 

I believe you will need to move to Linux PC, sooner or later. 

<div align='right'><{post_snapback}> (index.php?act=findpost&pid=19381)</div> 

 

--- Quote End ---  

0 Kudos
Altera_Forum
Honored Contributor II
23,619 Views

You can run Linux parallel on Windows with vmwares vmplayer or install co-linux or the other way "xenify" linux to run windows parallel on linux or .... 

 

you do not need a second workstation... but if you have another workstation, vnc is a nice option.
0 Kudos
Altera_Forum
Honored Contributor II
23,619 Views

Hello, 

 

I need some help on boa. On the uClinux-dist, I included boa in make menuconfg, then I did 

 

make romfs 

make 

make linux 

make image 

 

I can see /home/httpd and files inside it. 

 

When I start boa, and use a browser to point to it, it doesn&#39;t seem to display anything. 

 

Please help. 

 

My uClinux is 

/home/httpd> cat /proc/version 

Linux version 2.6.17-uc1 (uclinux@colinux) (gcc version 3.4.6)# 46 PREEMPT Wed Nov 15 06:59:46 EST 2006
0 Kudos
Altera_Forum
Honored Contributor II
23,619 Views

Hi, 

 

What did you type in the browser ? 

 

Regards. 

 

 

--- Quote Start ---  

originally posted by albertyong88@Nov 15 2006, 01:15 PM 

hello, 

 

i need some help on boa. on the uclinux-dist, i included boa in make menuconfg, then i  did 

 

make romfs 

make 

make linux 

make image 

 

i can see /home/httpd and files inside it. 

 

when i start boa, and use a browser to point to it, it doesn&#39;t seem to display anything. 

 

please help. 

 

my uclinux is 

/home/httpd> cat /proc/version 

linux version 2.6.17-uc1 (uclinux@colinux) (gcc version 3.4.6)# 46 preempt wed nov 15 06:59:46 est 2006 

<div align='right'><{post_snapback}> (index.php?act=findpost&pid=19442) 

--- quote end ---  

 

--- Quote End ---  

0 Kudos
Altera_Forum
Honored Contributor II
23,619 Views

 

--- Quote Start ---  

originally posted by albertyong88@Nov 15 2006, 08:15 PM 

hello, 

 

i need some help on boa. on the uclinux-dist, i included boa in make menuconfg, then i  did 

 

make romfs 

make 

make linux 

make image 

 

i can see /home/httpd and files inside it. 

 

when i start boa, and use a browser to point to it, it doesn&#39;t seem to display anything. 

 

please help. 

 

my uclinux is 

/home/httpd> cat /proc/version 

linux version 2.6.17-uc1 (uclinux@colinux) (gcc version 3.4.6)# 46 preempt wed nov 15 06:59:46 est 2006 

<div align='right'><{post_snapback}> (index.php?act=findpost&pid=19442) 

--- quote end ---  

 

--- Quote End ---  

 

It should work with default uClinux-dist nios2 config. You need only to enable your ether driver. 

I have tested with both firefox browser and IE. 

 

check, 

1. ifconfig, can you see your eth0 dev ? can you ping to/from your pc? 

2. netstat -a , can you see http service ? 

3. wget http://localhost/index.html (http://localhost/index.html) , try connect from local
0 Kudos
Altera_Forum
Honored Contributor II
23,619 Views

Hi hippo, 

 

Checked that my http service is NOT on. I shall turn it on. Thanks for pointing out.
0 Kudos
Altera_Forum
Honored Contributor II
23,619 Views

Hi, 

 

I started http service by 

 

boa -c /home/httpd 

 

but, the browser doesn&#39;t display the page 

 

However, when I use 

 

telnet 192.168.1.239 80 

GET /index_old.html HTTP/1.1(enter) 

Host: 192.168.1.239(enter) 

(enter) 

 

I get the following: 

 

<div class='quotetop'>QUOTE </div> 

--- Quote Start ---  

HTTP/1.0 200 OK 

Date: Tue, 30 Nov 1999 04:12:48 GMT 

Server: Boa/0.93.15 

Connection: close 

Content-Type: text/html 

Content-Length: 333 

Last-Modified: Tue, 30 Nov 1999 00:00:02 GMT 

 

<HTML> 

<HEAD> 

<TITLE>A test web page</TITLE> 

</HEAD> 

<BODY> 

<H1>Test Page</H1> 

 

 

 

If you are seeing this page,  then your web server is working,  and now 

you need to create some nice pages to replace this one :-). 

 

 

 

If everything has built correctly then the 

<A HREF=/cgi-bin/cgi_demo>CGI Demo</A> should be here. 

</BODY> 

</HTML> 

Connection closed by foreign host. 

uclinux@colinux:~$[/b] 

--- Quote End ---  

 

 

I am more confused now. Pls help.
0 Kudos
Altera_Forum
Honored Contributor II
23,619 Views

 

--- Quote Start ---  

originally posted by albertyong88@Nov 16 2006, 12:18 AM 

hi, 

 

i started http service by 

 

boa -c /home/httpd 

 

but, the browser doesn&#39;t display the page 

 

however, when i use 

 

telnet 192.168.1.239 80 

get /index_old.html http/1.1(enter) 

host: 192.168.1.239(enter) 

(enter) 

 

i get the following: 

 

<div class='quotetop'>quote  

--- quote end ---  

 

--- quote start ---  

http/1.0 200 ok 

date: tue, 30 nov 1999 04:12:48 gmt 

server: boa/0.93.15 

connection: close 

content-type: text/html 

content-length: 333 

last-modified: tue, 30 nov 1999 00:00:02 gmt 

 

<html> 

<head> 

<title>a test web page</title> 

</head> 

<body> 

<h1>test page</h1> 

 

 

 

if you are seeing this page,  then your web server is working,  and now 

you need to create some nice pages to replace this one :-). 

 

 

 

if everything has built correctly then the 

<a href=/cgi-bin/cgi_demo>cgi demo</a> should be here. 

</body> 

</html> 

connection closed by foreign host. 

uclinux@colinux:~$ 

--- Quote End ---  

 

 

I am more confused now. Pls help. 

<div align='right'><{post_snapback}> (index.php?act=findpost&pid=19454)</div> 

[/b] 

--- Quote End ---  

 

Please start it over, 

make clean 

make menuconfig 

Kernel/Library/Defaults Selection--> 

[*] Default all settings (lose changes) 

Then build through the image, without touching anyother config. 

 

Then boot nios2, start boa with "boa &", and run the wget test (on nios2 , not your pc).
0 Kudos
Altera_Forum
Honored Contributor II
23,551 Views

 

--- Quote Start ---  

originally posted by hippo+nov 15 2006, 09:52 pm--><div class='quotetop'>quote (hippo @ nov 15 2006, 09:52 pm)</div> 

--- quote start ---  

<!--quotebegin-albertyong88@Nov 16 2006, 12:18 AM 

hi, 

 

i started http service by 

 

boa -c /home/httpd 

 

but, the browser doesn&#39;t display the page 

 

however, when i use 

 

telnet 192.168.1.239 80 

get /index_old.html http/1.1(enter) 

host: 192.168.1.239(enter) 

(enter) 

 

i get the following: 

 

<div class='quotetop'>quote  

--- quote end ---  

 

--- quote start ---  

http/1.0 200 ok 

date: tue, 30 nov 1999 04:12:48 gmt 

server: boa/0.93.15 

connection: close 

content-type: text/html 

content-length: 333 

last-modified: tue, 30 nov 1999 00:00:02 gmt 

 

<html> 

<head> 

<title>a test web page</title> 

</head> 

<body> 

<h1>test page</h1> 

 

 

 

if you are seeing this page,  then your web server is working,  and now 

you need to create some nice pages to replace this one :-). 

 

 

 

if everything has built correctly then the 

<a href=/cgi-bin/cgi_demo>cgi demo</a> should be here. 

</body> 

</html> 

connection closed by foreign host. 

uclinux@colinux:~$ 

--- Quote End ---  

 

 

I am more confused now. Pls help. 

<div align='right'><{post_snapback}> (index.php?act=findpost&pid=19454)</div> 

[/b] 

--- Quote End ---  

 

Please start it over, 

make clean 

make menuconfig 

Kernel/Library/Defaults Selection--> 

[*] Default all settings (lose changes) 

Then build through the image, without touching anyother config. 

 

Then boot nios2, start boa with "boa &", and run the wget test (on nios2 , not your pc). 

<div align='right'><{post_snapback}> (index.php?act=findpost&pid=19458)</div> 

[/b] 

--- Quote End ---  

 

 

Hippo, I don&#39;t get the wget test on nios2, what do you mean ?
0 Kudos
Reply