From a5a19fd672bc0b8113d620669b557f17dccd343a Mon Sep 17 00:00:00 2001
From: Christian Schneider
Date: Thu, 26 Oct 2006 13:35:12 +0000
Subject: Moved itools to live branch
---
license/license.class | 142 ++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 142 insertions(+)
create mode 100644 license/license.class
(limited to 'license/license.class')
diff --git a/license/license.class b/license/license.class
new file mode 100644
index 0000000..83a71a5
--- /dev/null
+++ b/license/license.class
@@ -0,0 +1,142 @@
+host = strtolower(gethostbyaddr(getenv('HTTP_HOST')));
+ $this->product = $product;
+ $this->licensefile = '/tmp/'.$this->product.'-'.$this->host.'.license';
+ $this->licenseurl = 'http://license.relog.ch/license.php?host='.$this->host.'&product='.$this->product;
+
+ if ($this->get_license(1)) /* Cached license file exists */
+ {
+ $age = time() - filemtime($this->licensefile);
+
+ if ($age > 86400) /* Cached file is expired */
+ {
+ if (!$this->get_license()) /* Try to get a new license from server */
+ {
+ if ($age > 604800) /* Couldn't get a new license for a week */
+ {
+ unlink($this->licensefile); /* License finally expired */
+ unset($this->license);
+ }
+ }
+ }
+ }
+ else $this->get_license();
+
+ $this->check();
+
+ if (!$this->internal)
+ {
+ if ($fh = fopen($this->licensefile, "w"))
+ {
+ fwrite($fh, $this->license);
+ fclose($fh);
+ }
+ }
+}
+
+
+function get_license($internal=0)
+{
+ $url = $internal ? $this->licensefile : $this->licenseurl;
+
+ /* echo "Getting license \"$url\"
\n"; */
+
+ if ($file = @file($url))
+ {
+ $this->license = $file[0];
+ $this->internal = $internal;
+ return $url;
+ }
+ return 0;
+}
+
+
+function check()
+{
+ $secret="Jm+sd3O5NfvBudDhaf/N24-%C";
+
+ list($header, $formatversion, $comment, $code, $md5, $end) = explode('|', $this->license);
+ if ($header == 'RELOG/ULTRALICENSE3000')
+ {
+ if ($formatversion == 1)
+ {
+ if (md5($secret.$code.$secret) == base64_decode($md5))
+ {
+ list($formatversion, $host, $product, $this->exp) = explode('|', base64_decode($code));
+ if ($formatversion == 1)
+ {
+ if ($host == $this->host)
+ {
+ if ($product == $this->product)
+ {
+ list($year, $month, $day) = explode('-', $this->exp);
+ $exp = mktime(0, 0, 0, $month, $day, $year);
+ $now = time();
+
+ if ($exp > $now) /* Valid license */
+ return;
+
+ $error = 'license expired on '.$this->exp;
+ }
+ else $error = 'wrong product';
+ }
+ else $error = 'wrong host';
+ }
+ else $error = 'format2';
+ }
+ else $error = 'license not authentic';
+ }
+ else $error = 'format';
+ }
+ else $error = 'no license';
+ echo $this->host.": invalid license for product $product, reason: $error
\n";
+ exit;
+}
+
+
+function valid_until()
+{
+ return $this->exp;
+}
+
+
+
+} /* End class it_license */
+?>
--
cgit v1.2.3