<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>Web Hooks (Google Code)</title>
		<link>http://www.allegro.cc/forums/view/599014</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Sat, 31 Jan 2009 10:14:00 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Samuel Henderson and I are using Google Code for a project we&#39;re doing for a university class. Anyway, we&#39;re planning to use Doxygen to document the code and thought it would be great if we could have the up-to-date documentation automatically published on the Web.</p><p>In the administration section for Google Code, there is a text field for a post-commit URL. This sounds like just what we need, but I&#39;m having trouble understanding what the request will look like so I can process it.</p><p>The request is described as an HTTP POST request, and in <a href="http://code.google.com/p/support/wiki/PostCommitWebHooks">How to use Post-Commit Web Hooks for your project</a>, they describe the request &quot;payload&quot; (what <i>is</i> an HTTP POST payload?) as describing the commit using the <a href="http://webhooks.pbwiki.com/">Web Hooks</a> model, consisting of a UTF8-encoded <a href="http://www.json.org/">JSON</a> &quot;dictionary&quot;.</p><p>I was hoping to use PHP for the post-commit hook because I already know enough about it to be comfortable and I expect &quot;the Web host&quot; has PHP installed (they did in the past anyway). I expected to just write a Web-based PHP script that would make some (ugh) <tt>exec</tt> (or similar) calls to update a working copy, generate up-to-date documentation with Doxygen, and copy the up-to-date documentation to a Web path.</p><p>I just don&#39;t understand what the request will look like. Specifically, the payload/JSON parts... <img src="http://www.allegro.cc/forums/smileys/undecided.gif" alt=":-/" /> And I don&#39;t want to test it out with a bunch of meaningless commits when I don&#39;t even know what I&#39;m getting...</p><p>Is anybody familiar with Web hooks and what I should expect? Can I use a PHP script with a typical Web server (Apache) to process it? Is the JSON going to be accessible to PHP if I do...? <img src="http://www.allegro.cc/forums/smileys/undecided.gif" alt=":-/" /></p><p>I can&#39;t seem to find an appropriate channel to ask Google Code themselves and it seems nobody else is having this problem because my searches have come up empty... <img src="http://www.allegro.cc/forums/smileys/sad.gif" alt=":(" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (bamccaig)</author>
		<pubDate>Mon, 26 Jan 2009 09:12:16 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>The payload is basically the same as a form post I would think. And PHP 5.2 at least has JSON support by default (maybe it was 5.1 that had it) but you can find libraries for JSON anyway.</p><p>The Google page you posted does show what the JSON may look like. Sadly, I never heard of Web Hooks, so I&#39;m not sure where you would read the data from, and the wiki doesn&#39;t seem to help at all.</p><p>[edit] If I&#39;m reading the Python code correctly, then the data should be coming in $_POST[&#39;body&#39;] for the JSON string. But seeing as I never bother to learn AppEngine and have no web page related knowledge with Python, that is only a guess on my part. It seems Web Hooks is just an idea really, like the Model View Controller (MVC) model.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (MiquelFire)</author>
		<pubDate>Fri, 30 Jan 2009 05:39:28 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I guess it won&#39;t hurt to try... <img src="http://www.allegro.cc/forums/smileys/undecided.gif" alt=":-/" /> I can log whatever I do get to a file and see what I have, I suppose... Hopefully nothing explodes as a result.</p><p> <i>** EDIT **</i></p><p>I have written a simple PHP script that logs everything in the <tt>$_REQUEST</tt> superglobal (i.e., the contents of <tt>$_GET</tt>, <tt>$_POST</tt>, and <tt>$_COOKIE</tt>) to a file. When I supplied Google Code with the URL there was initially nothing. I figured my PHP was wrong because I thought Google Code was definitely supposed to send the project name and revision as GET data, but then I realized that I had to include <tt>%p</tt> and <tt>%r</tt> placeholders in my URL for Google to send that. Once I made the necessary changes to my URL, those variables were logged and nothing else. So that JSON must be somewhere else... <img src="http://www.allegro.cc/forums/smileys/undecided.gif" alt=":-/" /> Any ideas?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (bamccaig)</author>
		<pubDate>Fri, 30 Jan 2009 07:05:55 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>You will need to set always_populate_raw_post_data to true with ini_set, then read from <a>php://input</a> to get the raw post data. That&#39;s where the JSON will be I believe. $_REQUEST won&#39;t work because it&#39;s not encoded form data.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (BAF)</author>
		<pubDate>Fri, 30 Jan 2009 07:39:25 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">BAF said:</div><div class="quote"><p>
You will need to set always_populate_raw_post_data to true with ini_set, then read from <a>php://input</a> to get the raw post data. That&#39;s where the JSON will be I believe. $_REQUEST won&#39;t work because it&#39;s not encoded form data.
</p></div></div><p>
That sounds like something. Do you have a link that might explain that a little further? <img src="http://www.allegro.cc/forums/smileys/huh.gif" alt="???" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (bamccaig)</author>
		<pubDate>Fri, 30 Jan 2009 07:43:25 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Look up ini_set to learn how to use that. Then open <a>php://input</a> like any other file and read from it.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (BAF)</author>
		<pubDate>Fri, 30 Jan 2009 08:10:57 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Are you sure I need to set <tt>always_populate_raw_post_data</tt> to <tt>true</tt>? <img src="http://www.allegro.cc/forums/smileys/huh.gif" alt="???" />
</p><div class="quote_container"><div class="title">PHP: PHP input/output streams - Manual said:</div><div class="quote"><p>
<i><a>php://input</a></i> allows you to read raw POST data. It is a less memory intensive alternative to <i><a href="http://ca3.php.net/manual/en/reserved.variables.httprawpostdata.php">$HTTP_RAW_POST_DATA</a></i> and does not need any special <i>php.ini</i> directives. <i><a>php://input</a></i> is not available with <i>enctype=&quot;multipart/form-data&quot;</i>.
</p></div></div><p> - <a href="http://ca3.php.net/wrappers.php">Source</a></p><p> <i>** EDIT **</i></p><p>Well I seemingly read from <tt><a>php://input</a></tt>, but what I read was nothing... <img src="http://www.allegro.cc/forums/smileys/undecided.gif" alt=":-/" /> Oddly, even the <tt>GET</tt> data that is supposed to be logged before the <tt><a>php://input</a></tt> is no longer in the file... I&#39;m not sure what is happening. I haven&#39;t yet set <tt>always_populate_raw_post_data</tt> to <tt>true</tt>, which could explain why that isn&#39;t working... But why is the <tt>GET</tt> data gone? <img src="http://www.allegro.cc/forums/smileys/lipsrsealed.gif" alt=":-X" />
</p><div class="source-code"><div class="toolbar"></div><div class="inner"><table width="100%"><tbody><tr><td class="number">1</td><td><span class="k3">&lt;</span>?php</td></tr><tr><td class="number">2</td><td>    $filename <span class="k3">=</span> <span class="s">"/path/to/file/in/home/directory"</span><span class="k2">;</span></td></tr><tr><td class="number">3</td><td>&#160;</td></tr><tr><td class="number">4</td><td>    $logfile <span class="k3">=</span> @<a href="http://www.delorie.com/djgpp/doc/libc/libc_337.html" target="_blank">fopen</a><span class="k2">(</span>$filename, <span class="s">"r+"</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">5</td><td>&#160;</td></tr><tr><td class="number">6</td><td>    <span class="k1">if</span><span class="k2">(</span><span class="k3">!</span>$logfile<span class="k2">)</span></td></tr><tr><td class="number">7</td><td>        $logfile <span class="k3">=</span> <a href="http://www.delorie.com/djgpp/doc/libc/libc_337.html" target="_blank">fopen</a><span class="k2">(</span>$filename, <span class="s">"x+"</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">8</td><td>&#160;</td></tr><tr><td class="number">9</td><td>    <span class="k1">if</span><span class="k2">(</span><span class="k3">!</span>$logfile<span class="k2">)</span></td></tr><tr><td class="number">10</td><td>        <a href="http://www.delorie.com/djgpp/doc/libc/libc_298.html" target="_blank">exit</a><span class="k2">(</span><span class="s">"FAIL. Could not open the file.\n"</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">11</td><td>&#160;</td></tr><tr><td class="number">12</td><td>    foreach<span class="k2">(</span>$_REQUEST as $<a href="http://www.allegro.cc/manual/key" target="_blank"><span class="a">key</span></a> <span class="k3">=</span><span class="k3">&gt;</span> $value<span class="k2">)</span></td></tr><tr><td class="number">13</td><td>        <a href="http://www.delorie.com/djgpp/doc/libc/libc_371.html" target="_blank">fwrite</a><span class="k2">(</span>$logfile, <span class="s">"$key = $value\n"</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">14</td><td>&#160;</td></tr><tr><td class="number">15</td><td>    <span class="k1">if</span><span class="k2">(</span>$input <span class="k3">=</span> <a href="http://www.delorie.com/djgpp/doc/libc/libc_337.html" target="_blank">fopen</a><span class="k2">(</span><span class="s">"php://input"</span>, <span class="s">"r"</span><span class="k2">)</span><span class="k2">)</span></td></tr><tr><td class="number">16</td><td>    <span class="k2">{</span></td></tr><tr><td class="number">17</td><td>        <a href="http://www.delorie.com/djgpp/doc/libc/libc_371.html" target="_blank">fwrite</a><span class="k2">(</span>$logfile, <span class="s">"\nphp://input...\n\n"</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">18</td><td>&#160;</td></tr><tr><td class="number">19</td><td>        <span class="k1">while</span><span class="k2">(</span><span class="k3">!</span><a href="http://www.delorie.com/djgpp/doc/libc/libc_313.html" target="_blank">feof</a><span class="k2">(</span>$input<span class="k2">)</span><span class="k2">)</span></td></tr><tr><td class="number">20</td><td>            <a href="http://www.delorie.com/djgpp/doc/libc/libc_371.html" target="_blank">fwrite</a><span class="k2">(</span>$logfile, <a href="http://www.delorie.com/djgpp/doc/libc/libc_349.html" target="_blank">fread</a><span class="k2">(</span>$input, <span class="n">8192</span><span class="k2">)</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">21</td><td>&#160;</td></tr><tr><td class="number">22</td><td>        <a href="http://www.delorie.com/djgpp/doc/libc/libc_308.html" target="_blank">fclose</a><span class="k2">(</span>$input<span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">23</td><td>    <span class="k2">}</span></td></tr><tr><td class="number">24</td><td>&#160;</td></tr><tr><td class="number">25</td><td>    <a href="http://www.delorie.com/djgpp/doc/libc/libc_308.html" target="_blank">fclose</a><span class="k2">(</span>$logfile<span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">26</td><td>&#160;</td></tr><tr><td class="number">27</td><td>    print<span class="k2">(</span><span class="s">"Success? o_O\n"</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">28</td><td>?<span class="k3">&gt;</span></td></tr></tbody></table></div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (bamccaig)</author>
		<pubDate>Fri, 30 Jan 2009 08:14:43 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I don&#39;t know, I just read something about <a>php://input</a> and HTTP_RAW_POST_DATA not being populated for unrecognized MIME types.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (BAF)</author>
		<pubDate>Fri, 30 Jan 2009 10:09:38 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>The docs seem to say it doesn&#39;t work for multipart/form-data forms, which seems silly. How does php handle forms with file upload items?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Fri, 30 Jan 2009 11:54:46 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>It does so internally, it just doesn&#39;t allow you to access the raw data in that case.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (BAF)</author>
		<pubDate>Fri, 30 Jan 2009 19:55:33 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>As expected, I don&#39;t seem to have permissions to change that setting. <img src="http://www.allegro.cc/forums/smileys/sad.gif" alt=":(" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (bamccaig)</author>
		<pubDate>Fri, 30 Jan 2009 20:44:58 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Maybe it&#39;s in $_FILES?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (MiquelFire)</author>
		<pubDate>Fri, 30 Jan 2009 21:21:52 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I figured I would forget about the JSON data for now and just attempt to get my hook script working as intended (updating doxygen html documentation and moving it into a public location). Unfortunately, it occurred to me that without read/write access, the script is unable to do anything on disk... Which means it can&#39;t even do its job. <img src="http://www.allegro.cc/forums/smileys/undecided.gif" alt=":-/" /> I don&#39;t think there&#39;s any &#39;secure&#39; way to do it ATM. I could give certain files read/write permissions for everyone, but then anybody with access to the server could stumble upon it and do something malicious... <img src="http://www.allegro.cc/forums/smileys/sad.gif" alt=":(" /> So I basically can&#39;t do anything, except for maybe talk to the administrator to see if they can get my script running in a specialized user account. Then I could create a special working copy for my Web scripts and give just that account full permissions on the necessary files... Without that, I don&#39;t think I have any options... <img src="http://www.allegro.cc/forums/smileys/sad.gif" alt=":(" /> And I REALLY doubt they would go to that trouble on account of a graduate... Last I heard, the server was being administered by the IT department and they weren&#39;t happy about it (it used to have a dedicated administrator).
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (bamccaig)</author>
		<pubDate>Fri, 30 Jan 2009 21:36:36 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>CGI scripts should run as your user. Suck it up and use a different language for what seems to be trivial commit processing.</p><p>Anyway, if you do permissions right and the web host is set up right, it should be <i>mostly</i> secure anyhow. The files should be owned by group apache (or a group apache runs under), with RW access given to group (not global though). CGI scripts would be running as the owner, so they shouldn&#39;t be able to access. PHP runs as apache if you&#39;re using the module (at least last I knew), but if that is secured (with open_basedir and such) then it should be fine. Not counting loopholes/exploits, and if your data is so valuable that obscure exploits are a security liability, you wouldn&#39;t be on shared hosting anyway.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (BAF)</author>
		<pubDate>Sat, 31 Jan 2009 02:26:06 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">BAF said:</div><div class="quote"><p>
CGI scripts should run as your user. Suck it up and use a different language for what seems to be trivial commit processing.
</p></div></div><p>
I don&#39;t know how to use CGI scripts... <img src="http://www.allegro.cc/forums/smileys/undecided.gif" alt=":-/" /> I assume the server has to be configured specially for that (which I assume it isn&#39;t...)? I&#39;ll look into it though, thanks.
</p><div class="quote_container"><div class="title">BAF said:</div><div class="quote"><p>
The files should be owned by group apache (or a group apache runs under), with RW access given to group (not global though).
</p></div></div><p>
I already tried to find out what user the PHP script was running as by executing print(getenv(&#39;USER&#39;));, but nothing came out. <img src="http://www.allegro.cc/forums/smileys/lipsrsealed.gif" alt=":-X" /> And even if I did use a Web server specific user or group, that still opens it up for any malicious student to write a PHP script and access it over the Web... <img src="http://www.allegro.cc/forums/smileys/lipsrsealed.gif" alt=":-X" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (bamccaig)</author>
		<pubDate>Sat, 31 Jan 2009 03:54:30 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Are you on a Windows box? To get the user, use get_current_user() if you&#39;re running Windows, otherwise, posix_getpwuid(posix_geteuid())[&#39;name&#39;] (syntax don&#39;t work I believe for PHP, but you get the point)
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (MiquelFire)</author>
		<pubDate>Sat, 31 Jan 2009 04:02:12 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I&#39;m doing this from a Linux box. <tt>get_current_user</tt> didn&#39;t work either (I guess cause it&#39;s Linux). I&#39;ll try the POSIX version when I get a chance. <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (bamccaig)</author>
		<pubDate>Sat, 31 Jan 2009 05:18:16 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>You can look at some of the a5 code that fetches the user and its home dir.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Sat, 31 Jan 2009 06:09:53 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I take it back! <tt>\o/</tt> Apparently our old administrator enabled CGI when he was here and it hasn&#39;t been changed! I just wrote my first CGI program, hello_world, in C! <img src="http://www.allegro.cc/forums/smileys/shocked.gif" alt=":o" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (bamccaig)</author>
		<pubDate>Sat, 31 Jan 2009 10:14:00 +0000</pubDate>
	</item>
</rss>
