{"id":29,"date":"2012-11-09T21:24:01","date_gmt":"2012-11-09T19:24:01","guid":{"rendered":"http:\/\/www.keinzweifel.ch\/?p=29"},"modified":"2018-03-05T21:03:35","modified_gmt":"2018-03-05T19:03:35","slug":"guacamole-autologin","status":"publish","type":"post","link":"http:\/\/www.keinzweifel.ch\/?p=29","title":{"rendered":"Guacamole autologin"},"content":{"rendered":"<p>After updating my guacamole installation to 0.6.2 and struggling for some time to get the autologin to work again, I decided it&#8217;s time for some little instructions (mainly for my future self \ud83d\ude42 )<br \/>\n&#8212;-Update 6.12.12&#8212; added instructions for guacamole-0.7.0<\/p>\n<p>Here we go:<\/p>\n<p>#euse &#8211;enable cgi vnc<br \/>\n#emerge tomcat guacamole php<br \/>\n#\/etc\/init.d\/tomcat start<br \/>\n#\/etc\/init.d\/guacd start<\/p>\n<p>make guacamole itself work via tomcat and test it&#8230;<\/p>\n<p>Now it gets tricky&#8230; make php work within the guacamole application.<\/p>\n<p>Download the javabridge from here <a href=\"http:\/\/php-java-bridge.sourceforge.net\/pjb\/\">http:\/\/php-java-bridge.sourceforge.net\/pjb\/<br \/>\n<\/a>Place the .war file in the webapps folder and access it once via http. This will unpack its content and one can pick the three jar files from WEB-INF\/lib and copy them over to the guacamole&#8217;s WEB-INF\/lib. Also copy the whole cgi folder over to the guacamole directory. In it, I had to place a link to the php-cgi binary.<br \/>\nln -sf \/usr\/bin\/php-cgi \/var\/lib\/tomcat-7\/webapps\/guacamole\/WEB-INF\/cgi\/i386-linux\/php-cgi<br \/>\nNext place the following lines in the guacamole&#8217;s web.xml under &lt;web-app&gt;<\/p>\n<p>&lt;listener&gt;&lt;listener-class&gt;php.java.servlet.ContextLoaderListener&lt;\/listener-class&gt;&lt;\/listener&gt;<br \/>\n&lt;servlet&gt;&lt;servlet-name&gt;PhpJavaServlet&lt;\/servlet-name&gt;&lt;servlet-class&gt;php.java.servlet.PhpJavaServlet&lt;\/servlet-class&gt;<br \/>\n&lt;\/servlet&gt;<br \/>\n&lt;servlet&gt;&lt;servlet-name&gt;PhpCGIServlet&lt;\/servlet-name&gt;&lt;servlet-class&gt;php.java.servlet.fastcgi.FastCGIServlet&lt;\/servlet-class&gt;<br \/>\n&lt;init-param&gt;&lt;param-name&gt;prefer_system_php_exec&lt;\/param-name&gt;&lt;param-value&gt;On&lt;\/param-value&gt;&lt;\/init-param&gt;<br \/>\n&lt;init-param&gt;&lt;param-name&gt;php_include_java&lt;\/param-name&gt;&lt;param-value&gt;Off&lt;\/param-value&gt;&lt;\/init-param&gt;<br \/>\n&lt;\/servlet&gt;<br \/>\n&lt;servlet-mapping&gt;&lt;servlet-name&gt;PhpJavaServlet&lt;\/servlet-name&gt;&lt;url-pattern&gt;*.phpjavabridge&lt;\/url-pattern&gt; &lt;\/servlet-mapping&gt;<br \/>\n&lt;servlet-mapping&gt;&lt;servlet-name&gt;PhpCGIServlet&lt;\/servlet-name&gt;&lt;url-pattern&gt;*.php&lt;\/url-pattern&gt;&lt;\/servlet-mapping&gt;<\/p>\n<p>After the guacamole-folder gets renamed\/copied or somehow else redestributed to tomcat, php should be available within the container!<\/p>\n<p>Next we need to modify the index to autologin&#8230;<br \/>\ncopy index.xhtml to index.php and remove the xml header and place something like this in it to catch the delivered user credentials.<\/p>\n<p>&lt;?php<br \/>\nif (isset($_REQUEST[username])){<br \/>\nif (isset($_REQUEST[password])){<br \/>\n$username=$_REQUEST[username];<br \/>\n$password=$_REQUEST[password];<br \/>\n}<br \/>\n}<br \/>\n?&gt;<\/p>\n<p><strong>&#8212;&#8211;<br \/>\nGuacamole-0.7.0:\u00a0<\/strong>Add the following function in index.php right before root-ui.js gets loaded:<\/p>\n<p>&lt;script type=&#8221;text\/javascript&#8221;&gt;<br \/>\nwindow.onload = function() {<\/p>\n<p>var data =<br \/>\n&#8220;username=&lt;?php echo $username ?&gt;&#8221;<br \/>\n+ &#8220;&amp;password=&lt;?php echo $password ?&gt;&#8221;<\/p>\n<p>\/\/ Log in<br \/>\nvar xhr = new XMLHttpRequest();<br \/>\nxhr.open(&#8220;POST&#8221;, &#8220;login&#8221;, false);<br \/>\nxhr.setRequestHeader(&#8220;Content-type&#8221;, &#8220;application\/x-www-form-urlencoded&#8221;);<br \/>\nxhr.send(data);<\/p>\n<p>\/\/This php part is for the redirect. if you don&#8217;t like it, leave it away&#8230;<br \/>\n&lt;?php<br \/>\nif (isset($_REQUEST[id])){<br \/>\n$startvnc=$_REQUEST[id];<br \/>\necho &#8220;window.location = &#8216;client.xhtml?id=$startvnc&#8217;;&#8221;;<br \/>\n}<br \/>\n?&gt;<\/p>\n<p>\/\/ Handle failures<br \/>\nif (xhr.status != 200)<br \/>\nthrow new Error(&#8220;Invalid login&#8221;);<br \/>\n};<br \/>\n&lt;\/script&gt;<\/p>\n<p>&nbsp;<\/p>\n<p><strong><strong>&#8212;&#8211;<br \/>\n<\/strong><\/strong><strong>Guacamole-0.6.2:\u00a0<\/strong>Then add the following function just below the complete loginForm.onsubmit funtion (it is a slightly modified version of it which gets executed at loadtime and holds the credendtials captured above.)<\/p>\n<p>window.onload = function() {<\/p>\n<p>\/\/ Get parameters from query string<br \/>\nvar parameters = window.location.search.substring(1);<\/p>\n<p>\/\/ Get username and password from form<br \/>\nvar data =<br \/>\n<strong>&#8220;username=&lt;?php echo $username ?&gt;&#8221;<\/strong><br \/>\n<strong> + &#8220;&amp;password=&lt;?php echo $password ?&gt;&#8221;<\/strong><\/p>\n<p>\/\/ Include query parameters in submission data<br \/>\nif (parameters) data += &#8220;&amp;&#8221; + parameters;<\/p>\n<p>try {<\/p>\n<p>\/\/ Log in<br \/>\nvar xhr = new XMLHttpRequest();<br \/>\nxhr.open(&#8220;POST&#8221;, &#8220;login&#8221;, false);<br \/>\nxhr.setRequestHeader(&#8220;Content-type&#8221;, &#8220;application\/x-www-form-urlencoded&#8221;);<br \/>\nxhr.send(data);<\/p>\n<p>\/\/ Handle failures<br \/>\nif (xhr.status != 200)<br \/>\nthrow new Error(&#8220;Invalid login&#8221;);<\/p>\n<p>\/\/ Ensure username\/password fiels are blurred after submit<\/p>\n<p>username.blur();<br \/>\npassword.blur();<\/p>\n<p>resetUI();<\/p>\n<p>}<br \/>\ncatch (e) {<\/p>\n<p>var loginError = document.getElementById(&#8220;login-error&#8221;);<\/p>\n<p>\/\/ Display error, reset and refocus password field<br \/>\nloginError.textContent = e.message;<br \/>\npassword.value = &#8220;&#8221;;<br \/>\npassword.focus();<\/p>\n<p>return false;<\/p>\n<p>}<\/p>\n<p>\/\/ On success, hide loginUI, get and show connection list.<br \/>\nreturn false;<\/p>\n<p>}<\/p>\n<p>\/\/ On success, hide loginUI, get and show connection list.<br \/>\nreturn false;<\/p>\n<p>}<\/p>\n<p>If you also like to get automatically directed to a specific connection, then you should add the following to the index.php, directly before comment that says &#8220;\/\/ Remove all rows from connections list&#8221;:<\/p>\n<p>&lt;?php<br \/>\nif (isset($_REQUEST[id])){<br \/>\n$startvnc=$_REQUEST[id];<br \/>\necho &#8220;window.location = &#8216;client.xhtml?id=$startvnc&#8217;;&#8221;;<br \/>\n}<br \/>\n?&gt;<\/p>\n<p><strong>&#8212;<\/strong><\/p>\n<p>Now you should be able to use a form somewhere with username and password field (maybe as type=hidden, behind a simple &#8220;vnc&#8221; button) and the guacamole index.php as action=.<\/p>\n<div><\/div>\n<p>Have fun! \ud83d\ude42<\/p>\n","protected":false},"excerpt":{"rendered":"<p>After updating my guacamole installation to 0.6.2 and struggling for some time to get the autologin to work again, I decided it&#8217;s time for some little instructions (mainly for my future self \ud83d\ude42 ) &#8212;-Update 6.12.12&#8212; added instructions for guacamole-0.7.0 &hellip; <a href=\"http:\/\/www.keinzweifel.ch\/?p=29\">Weiterlesen <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[1,3],"tags":[],"_links":{"self":[{"href":"http:\/\/www.keinzweifel.ch\/index.php?rest_route=\/wp\/v2\/posts\/29"}],"collection":[{"href":"http:\/\/www.keinzweifel.ch\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.keinzweifel.ch\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.keinzweifel.ch\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.keinzweifel.ch\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=29"}],"version-history":[{"count":9,"href":"http:\/\/www.keinzweifel.ch\/index.php?rest_route=\/wp\/v2\/posts\/29\/revisions"}],"predecessor-version":[{"id":38,"href":"http:\/\/www.keinzweifel.ch\/index.php?rest_route=\/wp\/v2\/posts\/29\/revisions\/38"}],"wp:attachment":[{"href":"http:\/\/www.keinzweifel.ch\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=29"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.keinzweifel.ch\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=29"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.keinzweifel.ch\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=29"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}