summaryrefslogtreecommitdiff
path: root/license
diff options
context:
space:
mode:
Diffstat (limited to 'license')
-rw-r--r--license/.cvsignore1
-rw-r--r--license/Makefile47
-rw-r--r--license/license.class142
3 files changed, 190 insertions, 0 deletions
diff --git a/license/.cvsignore b/license/.cvsignore
new file mode 100644
index 0000000..a5abf2f
--- /dev/null
+++ b/license/.cvsignore
@@ -0,0 +1 @@
+license.slib
diff --git a/license/Makefile b/license/Makefile
new file mode 100644
index 0000000..0aa63bd
--- /dev/null
+++ b/license/Makefile
@@ -0,0 +1,47 @@
+##
+## $Id$
+##
+## Makefile for itools/license.lib
+##
+## $Log$
+## Revision 1.1 2000/07/13 19:10:19 weber
+## Added licensing suite
+##
+
+CPP= cpp
+QUIETMAKE= $(MAKE) -s
+PHPCOMPILE= /usr/local/bin/phpcompile
+
+MODULE= license
+SUBDIRS=
+CLASSES= license.class
+
+#
+# Library creation rules, do not change stuff below...
+#
+SLIB= $(MODULE).slib
+LIB= ../$(MODULE).lib
+
+all: $(LIB)
+
+$(LIB): $(SLIB)
+ @if [ -x $(PHPCOMPILE) ]; then (echo Compiling $(SLIB) to $(LIB) ...) 1>&2; $(PHPCOMPILE) <$(SLIB) >$(LIB); else (echo $(PHPCOMPILE) not found, copying $(SLIB) to $(LIB) ...) 1>&2; cp $(SLIB) $(LIB); fi
+
+$(SLIB): $(CLASSES) DUMMY
+ @(echo Creating $(SLIB) from $(SUBDIRS) $(CLASSES) ...) 1>&2
+ @echo "<?php" >$(SLIB)
+ @(for dir in DUMMY $(SUBDIRS); do (test -d $$dir && cd $$dir && $(QUIETMAKE) cat); done; for class in DUMMY $(CLASSES); do test -f $$class && cat $$class; done) | $(CPP) -P -undef | perl -ne 's/^\s+//g; print unless /^\s*$$/' | grep -v "^<?php" | grep -v "^?>" >>$(SLIB)
+ @echo "?>" >>$(SLIB)
+
+$(SUBDIRS)::
+ @(cd $@; $(QUIETMAKE))
+
+DUMMY:
+
+cat: $(SLIB)
+ @cat $(SLIB)
+
+clean:
+ @(echo Cleaning $(SLIB) $(LIB) ...) 1>&2
+ @rm -f $(SLIB) $(LIB)
+ @for dir in DUMMY $(SUBDIRS); do (test -d $$dir && cd $$dir && $(QUIETMAKE) $@) || :; done
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 @@
+<?php
+/*
+** $Id$
+**
+** Relog Internet Tools 3 Library ("ITOOLS3")
+**
+** it_license.class - Handle software licensing
+**
+** $Log$
+** Revision 1.2 2000/07/13 19:16:29 daenzer
+** cosmetic changes
+**
+** Revision 1.1 2000/07/13 19:10:19 weber
+** Added licensing suite
+**
+*/
+
+/**
+ * itools (TM) license class
+ */
+class it_license
+{
+ /* private */
+ var $host; /* Host requesting license */
+ var $product; /* Product that we are requesting license for */
+
+ var $license; /* Entire encoded license string */
+ var $licenseurl; /* External URL of license */
+ var $licensefile; /* Local file name of cached license */
+ var $internal; /* 1 if data source is internal cache */
+ var $exp; /* Expiration date */
+
+/**
+ * Create an it_license object for a product installation
+ * @param $product Name of the licensed product / project
+ */
+function it_license($product)
+{
+ $this->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\"<br>\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 <i>$product</i>, reason: <b>$error</b><br>\n";
+ exit;
+}
+
+
+function valid_until()
+{
+ return $this->exp;
+}
+
+
+
+} /* End class it_license */
+?>