From 6118b52b0ed582bab04022c5a492e5ed8d520239 Mon Sep 17 00:00:00 2001 From: Gregory Colpart Date: Tue, 3 Jul 2007 10:30:21 +0000 Subject: [PATCH] init --- Makefile | 15 ++++++ README | 5 ++ sendsms2mobyt.c | 130 ++++++++++++++++++++++++++++++++++++++++++++++++ sendsms2mobyt.h | 2 + 4 files changed, 152 insertions(+) create mode 100644 Makefile create mode 100644 README create mode 100644 sendsms2mobyt.c create mode 100644 sendsms2mobyt.h diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..bc715f9 --- /dev/null +++ b/Makefile @@ -0,0 +1,15 @@ +CC=gcc +CFLAGS=-W -Wall -O2 +LDFLAGS= +EXEC=sendsms2mobyt + +all: $(EXEC) + +sendsms2mobyt: sendsms2mobyt.c + $(CC) -o $@ $< $(CFLAGS) + +clean: + rm -rf *.o + +mrproper: clean + rm -rf $(EXEC) diff --git a/README b/README new file mode 100644 index 0000000..67a5e3a --- /dev/null +++ b/README @@ -0,0 +1,5 @@ +Usage: +====== + +echo "alert on router" | sendsms2mobyt + diff --git a/sendsms2mobyt.c b/sendsms2mobyt.c new file mode 100644 index 0000000..d1ccc16 --- /dev/null +++ b/sendsms2mobyt.c @@ -0,0 +1,130 @@ +/* v 0.1 23.06.2007 */ + +/* Copyright (c) 2007 Evolix + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// URL enconding (RFC 1738) +int urlencode (char *msg, char *encmsg) { + + char *h = "0123456789abcdef"; + unsigned int i; + char c; + int ind=0; + + for (i=0;i> 4]; + encmsg[ind+2] = h[c & 0x0f]; + ind +=3; + } + } + + return ind; +} + +int main(void) { + + int sock; + int errsv; + + char buf[BUFSIZ]; + char encbuf[BUFSIZ]; + char httpmsg[BUFSIZ], httpmsg2[BUFSIZ]; + char result[BUFSIZ], result2[BUFSIZ]; + size_t bytes_read; + int bytes_enc; + // designed to be piped + int fd = STDIN_FILENO; + + struct sockaddr_in sa_in; + + // Hum, 194.185.22.170 is actual IP of Mobyt + // TODO : use hostname + memset(&sa_in,0,sizeof(struct sockaddr_in)); + sa_in.sin_family = AF_INET; + sa_in.sin_port = htons(80); + sa_in.sin_addr.s_addr = inet_addr("194.185.22.170"); + + // socket init + sock = socket(PF_INET, SOCK_STREAM, 0); + errsv = errno; + + if (sock == -1) { + printf("error in socket init : %s\n",strerror(errsv)); + } + + // TCP connection init + if (connect(sock,(struct sockaddr *)&sa_in,sizeof(struct sockaddr)) == -1) { + errsv = errno; + printf("error in tcp connection init : %s\n",strerror(errsv)); + } + + // get data + //memset(&buf,0,BUFSIZ); + bytes_read = read(fd,buf,BUFSIZ); + + // url encoding + //memset(&encbuf,0,BUFSIZ); + bytes_enc = urlencode(buf,encbuf); + + // HTTP GET request (read Mobyt doc) + // 167 is length of request without encbuf (*hack*, *hack*) + // hey, you see my mobile number: +33688291152 + // TODO : put user/pass and mobile numbers in conffile + snprintf(httpmsg,167+strlen(encbuf),"GET /sms/send.php?user=F02568&pass=snhom482&rcpt=%%2B33688291152&data=%s&sender=%%2B33491854329&qty=l HTTP/1.1\nHost: multilevel.mobyt.fr\nUser-Agent: Evolix SMS Agent\n\n",encbuf); + + // write/read datas + write(sock,httpmsg,strlen(httpmsg)); + + // TODO : capture OK to verify success + // TODO : ajust offset + read(sock,result,198); + + // same with Alexandre mobile number + snprintf(httpmsg2,167+strlen(encbuf),"GET /sms/send.php?user=F02568&pass=snhom482&rcpt=%%2B33632168886&data=%s&sender=%%2B33491854329&qty=l HTTP/1.1\nHost: multilevel.mobyt.fr\nUser-Agent: Evolix SMS Agent\n\n",encbuf); + write(sock,httpmsg2,strlen(httpmsg2)); + read(sock,result2,198); + + close(sock); + + printf("request = \n\n%s \n\nresult = \n\n%s",httpmsg,result); + printf("request = \n\n%s \n\nresult = \n\n%s",httpmsg2,result2); + + return 0; + +} + diff --git a/sendsms2mobyt.h b/sendsms2mobyt.h new file mode 100644 index 0000000..3ab3b80 --- /dev/null +++ b/sendsms2mobyt.h @@ -0,0 +1,2 @@ +void urlencode (char *, char *); +