QREncode: Add option to override host
authorMichal Novotny <minovotn@redhat.com>
Thu, 1 Nov 2012 16:36:26 +0000 (17:36 +0100)
committerMichal Novotny <minovotn@redhat.com>
Thu, 1 Nov 2012 16:36:26 +0000 (17:36 +0100)
Signed-off-by: Michal Novotny <minovotn@redhat.com>

pages/users.php

index 9075561..48172b9 100644 (file)
                echo "<div class=\"label\">QR Code: </div>";
                echo "<div class=\"value\">";
 
-               $str = "http://localhost/virtDroid/?address=http://".(array_key_exists('REMOTE_HOST', $_SERVER) ? $_SERVER['REMOTE_HOST'] : $_SERVER['REMOTE_ADDR'])."/php-virt-control/xmlrpc.php&apikey=".$apikey;
+               if (array_key_exists('host', $_GET))
+                       $addr = $_GET['host'];
+               else {
+                       $addr = (array_key_exists('REMOTE_HOST', $_SERVER) ? $_SERVER['REMOTE_HOST'] : $_SERVER['REMOTE_ADDR']);
+                       if (strpos('.'.$addr, '::')) // IPv6 needs to be encoded in brackets
+                               $addr = '['.$addr.']';
+               }
+
+               $str = "http://localhost/virtDroid/?address=http://".$addr."/php-virt-control/xmlrpc.php&apikey=".$apikey;
                $qrdata = qrencode($str,3,QR_ECLEVEL_M,QR_MODE_8);
                foreach($qrdata as $row) {
                        echo "<div class=\"qr_line\">";