but you don't have a BEGIN block, you have a subroutine called BEGIN, which isn't the same thing at all.

AFAIK, there's no functional difference between a BEGIN block with and without "sub".  The docs say

"These code blocks can be prefixed with "sub" to give the appearance of a subroutine (although this is not considered good style)."

Where would you think a functional difference lies?

As for the OP's problem, the issue presumably is that the www-data user doesn't have a cookie that would allow authentication with the X server.  The fact that it works via a separate ssh connection (with X forwarding) doesn't say much — it is because the ssh server sets up an appropriate DISPLAY/socket and cookie for the connection.  But that cookie can be transferred to a different account, if desired.  For this, list it from within the ssh connection's terminal with xauth. You'd get something like

$ xauth list $DISPLAY somehost.domain.com:10 MIT-MAGIC-COOKIE-1 b412a470ac5605e443cd330f48 +bbc62e

Then switch to the www-data account and run (or run the same command from within the BEGIN block in the CGI)

xauth add somehost.domain.com:10 MIT-MAGIC-COOKIE-1 b412a470ac5605e443 +cd330f48bbc62e

and set DISPLAY to somehost.domain.com:10.  This adds the cookie to the user's xauth database file (by default ~/.Xauthority), and hence allows www-data to connect to the X server via the same tunnel that is used by the ssh connection.  Of course, this only works as long as the ssh connection is established (so you should keep it open while debugging).


In reply to Re^2: Remote ptkdb behind firewall by Eliya
in thread Remote ptkdb behind firewall by glendeni

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.