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 --- sms/Makefile | 47 ++++++++++++++++++++++ sms/sms.class | 122 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 169 insertions(+) create mode 100644 sms/Makefile create mode 100644 sms/sms.class (limited to 'sms') diff --git a/sms/Makefile b/sms/Makefile new file mode 100644 index 0000000..33cd428 --- /dev/null +++ b/sms/Makefile @@ -0,0 +1,47 @@ +## +## $Id$ +## +## Makefile for itools/sms.lib +## +## $Log$ +## Revision 1.1 2000/01/10 23:04:09 weber +## SMS functions added +## + +CPP= cpp +QUIETMAKE= $(MAKE) -s +PHPCOMPILE= /usr/local/bin/phpcompile + +MODULE= sms +SUBDIRS= +CLASSES= sms.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 "$(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 "^" >>$(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/sms/sms.class b/sms/sms.class new file mode 100644 index 0000000..6483035 --- /dev/null +++ b/sms/sms.class @@ -0,0 +1,122 @@ + it_sms; "OUT": it_sms -> Handy */ + var $date; /* Date of message sent / received */ + + var $number; /* FQPhone number of other party z. B. 0041763901391 */ + var $message; /* Message text */ + + var $result; /* Result of transaction or empty */ + + /* Private */ + var $logfile; /* Log file name or empty for no log */ + + + /* Constructor */ + function it_sms($service, $keyword, $logfile="XX") + { + $this->service = $service; + $this->keyword = $keyword; + $this->logfile = $logfile; + + if ($logfile == "XX") + $this->logfile = $_SERVER['DOCUMENT_ROOT']."/../log/sms.log"; + } + + + /* Write a log file entry */ + function log() + { + if ($this->logfile == "") + return; + + $log = date("Y-m-d H:i:s") . " DIR=$this->direction NUMBER=$this->number RESULT=$this->result TEXT=\"$this->message\""; + if ($_COOKIE['UID']) + $log .= " UID=\"" . $_COOKIE['UID'] . "\""; + + if ($file = fopen($this->logfile, "a")) + { + fwrite($file, $log . "\n"); + fclose($file); + } + } + + + /* Send an SMS. Returns 1 on success, 0 otherwise. */ + function send($number, $message) + { + $this->direction = "OUT"; + $this->date = date("Y-m-d H:i:s"); + + /* Remove all non-digits */ + $number = ereg_replace('[^+0-9]', '', $number); + + /* Change 076 to 004176 etc. */ + $this->number = ereg_replace('^0([1-9])', '0041\\1', $number); + + $this->message = $message; + + $url = "http://panther.minick.ch/cgi-bin/$this->service/send?number=$this->number&message=" . urlencode($this->keyword." ".$this->message); + + /* debug("Sending SMS: $url
\n"); */ + + $result = file($url); + $this->result = trim($result[5]); /* "OKAY" or "NOTOK" w/o newline */ + $this->log(); + + if ($this->result == "OKAY") + return 1; /* Success */ + + return 0; /* Failure */ + } + + + /* + ** Receive an SMS from HTTP GET request + ** Format: number=Absendertelefonnummer, message=SMS-Text, id=xxxxx + ** Returns: 1=got a valid message, 0=got invalid garbage, ignore. + */ + function receive($secret="") + { + $this->direction = "IN"; + $this->date = date("Y-m-d H:i:s"); + + $this->number = $_GET['number']; + $this->message = $_GET['message']; + + if ($_GET['id'] == $secret) + { + $this->result = "OKAY"; + $this->log(); + return 1; + } + else + { + $this->result = "NOTOK: Bad authentication \"".$_GET['id']."\""; + $this->log(); + $this->number = $this->message = ""; + return 0; + } + } + +} /* End class it_sms */ +?> -- cgit v1.2.3