Jump to content

[Solved] cgi-bins don't work


z0n1n0z

Recommended Posts

/usr/bin is a system folder that lives outside of your home folder. You can't see it but should still be able to run the programs in it by name through the scheduler. Does this not work for you?

If not, I wonder if Plesk blocks calls /usr/bin for normal users? If that's the case, then Krydos would need to find another solution or its possible that C++ code is simply not supported (you're the first person to ever try doing this on our Plesk-based service...the method he describes worked perfectly on cPanel).

Link to comment
Share on other sites

I looked at the scheduler settings and realized cron is set to run commands using a shell that's chrooted...you'd never see /usr/bin when / is set to your home folder.

Krydos will need to look at this again.

  • Thanks 1
Link to comment
Share on other sites

Oh, I've never actually used the Plesk task scheduler before. I just assumed it worked the same way as cPanel did. That's actually really nice security on Plesk's part. Thanks for letting us know. Here's an alternate way to compile your C++ executable.

In httpdocs/cgi-bin/ create a file named .htaccess with 644 permissions with these contents

Options +ExecCGI
AddHandler cgi-script .cgi .pl .py .sh

Also in httpdocs/cgi-bin/ create a file named compile.sh with 755 permissions with these contents

#!/bin/bash

exec 2>&1
echo -e "Content-type: text/plain\n"
/usr/bin/gcc /home/z0n1n0z.helioho.st/httpdocs/cgi-bin/test.cpp -o /home/z0n1n0z.helioho.st/httpdocs/cgi-bin/test.cgi

Then execute the compile in your browser by going to z0n1n0z.helioho.st/cgi-bin/compile.sh

After the C++ executable is compiled I recommend changing the compile.sh script to non-executable, for instance 644 permissions, so that people can't run it over and over and cause high load on your account.

I haven't tested the above, but it should work. Let us know if you run into any issues.

  • Thanks 1
Link to comment
Share on other sites

I tried your suggestion literally and got this response in the browser:

/tmp/ccKDTXpt.o: In function `main':
test.cpp:(.text+0xa): undefined reference to `std::cout'
test.cpp:(.text+0xf): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
test.cpp:(.text+0x19): undefined reference to `std::cout'
test.cpp:(.text+0x1e): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
test.cpp:(.text+0x28): undefined reference to `std::cout'
test.cpp:(.text+0x2d): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
test.cpp:(.text+0x37): undefined reference to `std::cout'
test.cpp:(.text+0x3c): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
test.cpp:(.text+0x46): undefined reference to `std::cout'
test.cpp:(.text+0x4b): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
test.cpp:(.text+0x55): undefined reference to `std::cout'
test.cpp:(.text+0x5a): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
test.cpp:(.text+0x64): undefined reference to `std::cout'
test.cpp:(.text+0x69): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
test.cpp:(.text+0x73): undefined reference to `std::cout'
test.cpp:(.text+0x78): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
test.cpp:(.text+0x82): undefined reference to `std::cout'
test.cpp:(.text+0x87): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
/tmp/ccKDTXpt.o: In function `__static_initialization_and_destruction_0(int, int)':
test.cpp:(.text+0xb5): undefined reference to `std::ios_base::Init::Init()'
test.cpp:(.text+0xc4): undefined reference to `std::ios_base::Init::~Init()'
collect2: error: ld returned 1 exit status

then i tried to use `/usr/bin/g++` and it worked great!

thank you for everything (to quote the dolphins=aliens from the "hitchhiker's guide to the galaxy", «thanks for all the fish!») I insisted a little because I had intuition that something was wrong and that it would be useful for you so we have the solution :)

 

Link to comment
Share on other sites

  • z0n1n0z changed the title to [SOLVED] cgi-bins don't work

I'm writing you another note that might be useful. I modified the bash script again like this and it works perfectly:

#!/bin/bash

exec 2>&1
echo -e "Content-type: text/plain\n"
/usr/bin/g++ test.cpp -o test.cgi

so, to compile a c++ program

  • it's better to use `/usr/bin/g++`
  • it is not necessary to use the "absolute" path, the "relative" one is sufficient, which is simpler and safer, because it does not reveal to the users their chroot in the server system

Greetings

Link to comment
Share on other sites

  • Krydos changed the title to [Solved] cgi-bins don't work
  • Krydos locked this topic
Guest
This topic is now closed to further replies.
×
×
  • Create New...