Author

Topic: Simple CGI Question? (Read 7977 times)

legendary
Activity: 1658
Merit: 1001
August 23, 2010, 01:08:43 AM
#12
Have you tried closing the tag?

FYI. The problem was already solved.
newbie
Activity: 3
Merit: 0
August 22, 2010, 11:07:05 PM
#11
Have you tried closing the tag?
sr. member
Activity: 339
Merit: 250
August 20, 2010, 10:04:58 AM
#10
Do the server logs say anything useful?
I failed debugging 101 somewhere. The error log did indeed give me useful information.

What happened:
The bitcoind client when run acts as an RPC client and connects to the already running instance of bitcoind to get its data(I did not know that). Also, the default apache configuration uses / as its home directory not the same directory the bitcoind client uses to store the bitcoin.conf file. When bitcoind was run with a command switch from the CGI it was looking in the home directory of the user it was run from(the webserver) for bitcoin.conf and not from the home directory of the user bitcoind was running as.

Fixes:
1) Have bitcoind and the webserver run as the same user so they share the same configuration directory
2) Create a link between the bitcoin.conf from the home directories of the users(webserver and bitcoind user)
3) Create a duplicate configuration file for both users.

Thanks for the help everyone!
lfm
full member
Activity: 196
Merit: 104
August 20, 2010, 04:44:44 AM
#9
right permissions?
Permissions are correct.  Owner and group are the webserver and for testing purposes it is 777.

check the return values from the open. is it NULL?
legendary
Activity: 1658
Merit: 1001
August 20, 2010, 01:12:26 AM
#8
Do the server logs say anything useful?
sr. member
Activity: 339
Merit: 250
August 19, 2010, 05:49:19 PM
#7
Content-type: text/html\r\n ?

(or maybe it's Content-type: text/html\r\n\r\n, it's really fussy, and I forget.)


The recommendation is a double line break of \n\n.
http://www.w3.org/International/O-HTTP-charset

I still can't figure this out :-(... anyone?  It should be really simple. I even tried piping the output to a text file and it will not output correctly when run through CGI. I'm using Apache 2.2 if that helps anyone.
newbie
Activity: 59
Merit: 0
August 19, 2010, 11:56:59 AM
#6
Content-type: text/html\r\n ?

(or maybe it's Content-type: text/html\r\n\r\n, it's really fussy, and I forget.)

sr. member
Activity: 339
Merit: 250
August 19, 2010, 10:22:18 AM
#5
right permissions?
Permissions are correct.  Owner and group are the webserver and for testing purposes it is 777.
sr. member
Activity: 339
Merit: 250
August 19, 2010, 10:21:08 AM
#4
   FILE* output = popen("/var/www/bitcoind.cgi getblockcount", "r");

Seems like an incorrect execution string.


Execution string seems to be right as it is runs in the terminal fine.
legendary
Activity: 1658
Merit: 1001
August 18, 2010, 05:04:36 PM
#3
right permissions?
legendary
Activity: 1596
Merit: 1091
August 18, 2010, 03:35:50 PM
#2
   FILE* output = popen("/var/www/bitcoind.cgi getblockcount", "r");

Seems like an incorrect execution string.

sr. member
Activity: 339
Merit: 250
August 18, 2010, 03:25:26 PM
#1
Hello,
I'm having a little trouble parsing and displaying the output from the bitcoind client in the browser from a CGI program written in C.
Code:

#include
main()
{
/* Always print a content type and a blank line. */
printf("Content-Type: text/html\n\n");

/* HTML Page Start */
puts("");
puts("");
puts("");<br /><span style="white-space: pre;"> </span>puts("");
puts("");


int entry = 1;
char line[200];
FILE* output = popen("/var/www/bitcoind.cgi getblockcount", "r");
while ( fgets(line, 199, output) )
{
printf("%5d: %s", entry++, line);
}

puts("");
puts("");

return 0;
}


Is producing only the following HTML code through the cgi interface:
Code:



<br />




The command line output when run in a terminal is(which is correct):
Code:


<br />

1: 75029




Any ideas? I know I'm missing something simple.
Jump to: