Bitcoin Forum
November 19, 2024, 04:39:13 PM *
News: Latest Bitcoin Core release: 28.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Simple CGI Question?  (Read 8007 times)
semyazza (OP)
Sr. Member
****
Offline Offline

Activity: 339
Merit: 250


View Profile
August 18, 2010, 07:25:26 PM
Last edit: August 18, 2010, 07:39:18 PM by semyazza
 #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 <stdio.h>
main()
{
/* Always print a content type and a blank line. */
printf("Content-Type: text/html\n\n");

/* HTML Page Start */
puts("<html>");
puts("<head>");
puts("<title>");
puts("</title>");
puts("<body>");


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("</body>");
puts("</html>");

return 0;
}


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

<html>
<head>
<title>
</title>
<body>
</body>
</html>

The command line output when run in a terminal is(which is correct):
Code:
<html> 
<head>
<title>
</title>
<body>
1: 75029
</body>
</html>


Any ideas? I know I'm missing something simple.
jgarzik
Legendary
*
qt
Offline Offline

Activity: 1596
Merit: 1100


View Profile
August 18, 2010, 07:35:50 PM
 #2

   FILE* output = popen("/var/www/bitcoind.cgi getblockcount", "r");

Seems like an incorrect execution string.


Jeff Garzik, Bloq CEO, former bitcoin core dev team; opinions are my own.
Visit bloq.com / metronome.io
Donations / tip jar: 1BrufViLKnSWtuWGkryPsKsxonV2NQ7Tcj
BioMike
Legendary
*
Offline Offline

Activity: 1658
Merit: 1001


View Profile
August 18, 2010, 09:04:36 PM
 #3

right permissions?
semyazza (OP)
Sr. Member
****
Offline Offline

Activity: 339
Merit: 250


View Profile
August 19, 2010, 02:21:08 PM
 #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.
semyazza (OP)
Sr. Member
****
Offline Offline

Activity: 339
Merit: 250


View Profile
August 19, 2010, 02:22:18 PM
 #5

right permissions?
Permissions are correct.  Owner and group are the webserver and for testing purposes it is 777.
silverman
Newbie
*
Offline Offline

Activity: 59
Merit: 0


View Profile
August 19, 2010, 03:56:59 PM
 #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.)

semyazza (OP)
Sr. Member
****
Offline Offline

Activity: 339
Merit: 250


View Profile
August 19, 2010, 09: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.
BioMike
Legendary
*
Offline Offline

Activity: 1658
Merit: 1001


View Profile
August 20, 2010, 05:12:26 AM
 #8

Do the server logs say anything useful?
lfm
Full Member
***
Offline Offline

Activity: 196
Merit: 104



View Profile
August 20, 2010, 08: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?
semyazza (OP)
Sr. Member
****
Offline Offline

Activity: 339
Merit: 250


View Profile
August 20, 2010, 02:04:58 PM
 #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!
xcikni
Newbie
*
Offline Offline

Activity: 3
Merit: 0


View Profile
August 23, 2010, 03:07:05 AM
 #11

Have you tried closing the <head> tag?
BioMike
Legendary
*
Offline Offline

Activity: 1658
Merit: 1001


View Profile
August 23, 2010, 05:08:43 AM
 #12

Have you tried closing the <head> tag?

FYI. The problem was already solved.
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!