store client name and last use time for tokens. show them in token management
[grauphel.git] / lib / client.php
diff --git a/lib/client.php b/lib/client.php
new file mode 100644 (file)
index 0000000..358e60b
--- /dev/null
@@ -0,0 +1,55 @@
+<?php
+/**
+ * Part of grauphel
+ *
+ * PHP version 5
+ *
+ * @category  Tools
+ * @package   Grauphel
+ * @author    Christian Weiske <cweiske@cweiske.de>
+ * @copyright 2014 Christian Weiske
+ * @license   http://www.gnu.org/licenses/agpl.html GNU AGPL v3
+ * @link      http://cweiske.de/grauphel.htm
+ */
+namespace OCA\Grauphel\Lib;
+
+/**
+ * Client identification helper
+ *
+ * @category  Tools
+ * @package   Grauphel
+ * @author    Christian Weiske <cweiske@cweiske.de>
+ * @copyright 2014 Christian Weiske
+ * @license   http://www.gnu.org/licenses/agpl.html GNU AGPL v3
+ * @version   Release: @package_version@
+ * @link      http://cweiske.de/grauphel.htm
+ */
+class Client
+{
+    public function getClient()
+    {
+        if (isset($_SERVER['HTTP_X_TOMBOY_CLIENT'])) {
+            $client = $_SERVER['HTTP_X_TOMBOY_CLIENT'];
+            $doublepos = strpos($client, ', org.tomdroid');
+            if ($doublepos !== false) {
+                //https://bugs.launchpad.net/tomdroid/+bug/1375436
+                //X-Tomboy-Client header is sent twice
+                $client = substr($client, 0, $doublepos);
+            }
+            return $client;
+        }
+
+        return false;
+    }
+
+    public function getNiceName($client)
+    {
+        if (substr($client, 0, 12) == 'org.tomdroid') {
+            //org.tomdroid v0.7.5, build 14, Android v4.4.2, innotek GmbH/VirtualBox
+            return 'Tomdroid';
+        }
+        return $client;
+    }
+
+}
+?>
\ No newline at end of file