Users: Add XMLRPC API key code generation (QRCode)
authorMichal Novotny <minovotn@redhat.com>
Mon, 8 Oct 2012 15:17:51 +0000 (17:17 +0200)
committerMichal Novotny <minovotn@redhat.com>
Mon, 8 Oct 2012 15:19:47 +0000 (17:19 +0200)
Also include the installer script (setup-qrencode.sh) for the
QRCode library installation.

Signed-off-by: Michal Novotny <minovotn@redhat.com>

manager.css
pages/users.php
setup-qrencode.sh [new file with mode: 0755]

index a60142c..f6dbe2a 100644 (file)
@@ -169,3 +169,25 @@ table tr td {
 #conn-detail {
        margin-left: 150px;
 }
+
+.qr_line{
+    clear:both;
+    overflow:hidden;
+    height:4px;
+}
+
+.qr_line b{
+    background:#fff;
+    width:4px;
+    height:4px;
+    float:left;
+    overflow:hidden;
+}
+
+.qr_line i{
+    background:#000;
+    width:4px;
+    height:4px;
+    float:left;
+    overflow:hidden;
+}
index ab8bfce..0b277b1 100644 (file)
         <div class="nl" />
 </div>
 
+<script language="javascript">
+<!--
+       function ask() {
+               if (confirm('<?php echo $lang->get('apikey-renew') ?> ?')) {
+                       location.href='<?php echo $_SERVER['REQUEST_URI'] ?>&renew=1';
+               }
+       }
+-->
+</script>
+
 <div class="item">
        <div class="label">API Key: </div>
        <div class="value">
-               <textarea rows="3" cols="50" readonly="readonly"><?php echo $apikey ?></textarea> &nbsp; <input type="button" value=" <?php echo $lang->get('apikey-renew') ?> " onclick="javascript:location.href='<?php echo $_SERVER['REQUEST_URI'] ?>&amp;renew=1'"/>
+               <textarea rows="3" cols="75" readonly="readonly"><?php echo $apikey ?></textarea>
+               &nbsp;
+               <input type="button" value=" <?php echo $lang->get('apikey-renew') ?> " onclick="javascript:ask()"/>
        </div>
        <div class="nl" />
 </div>
 
+<?php
+       if (function_exists('qrencode')) {
+               echo "<div class=\"item\">";
+               echo "<div class=\"label\">QR Code: </div>";
+               echo "<div class=\"value\">";
+
+               $str = "http://localhost/virtDroid/?address=http://".$_SERVER['REMOTE_HOST']."/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\">";
+                       foreach($row as $cell)
+                               echo ($cell=="0") ? "<b></b>" : "<i></i>";
+                       echo "</div>";
+               }
+
+               echo "</div>";
+               echo "<div class=\"nl\" />";
+               echo "</div>";
+       }
+?>
+
 <div class="item">
         <div class="label">&nbsp;</div>
        <div class="value">
diff --git a/setup-qrencode.sh b/setup-qrencode.sh
new file mode 100755 (executable)
index 0000000..55b739b
--- /dev/null
@@ -0,0 +1,40 @@
+#!/bin/bash
+
+if [ `id -u` -ne 0 ]; then
+       echo "Error: You have to run this script as root!"
+       exit 1
+fi
+
+num=$(locate libqrencode | wc -l)
+if [ $num -eq 0 ]; then
+       echo "libqrencode not found. Downloading ..."
+       wget -O test.tgz http://fukuchi.org/works/qrencode/qrencode-3.3.1.tar.gz
+       tar -xzf test.tgz
+       rm -f test.tgz
+       cd qrencode-3.3.1
+       ./configure --prefix=/usr
+       make
+       make install
+       cd ..
+       rm -rf qrencode-3.3.1
+fi
+
+git clone https://github.com/cviebrock/php-qrencode.git
+cd php-qrencode
+phpize
+./configure
+make
+make install
+cd ..
+rm -rf php-qrencode
+echo extension=qrencode.so > /etc/php.d/qrencode.ini
+php -m | grep qr > /dev/null
+if [ "$?" -ne 0 ]; then
+       rm -f /etc/php.d/qrencode.ini
+       echo "ERROR: Cannot find phpqrcode extension in PHP modules. Reverting..."
+       exit 1
+fi
+
+echo "Restarting apache..."
+service httpd restart
+echo "All done"