SRL Archive - Research & Development Lounge

SMS Controling SCAR


mc_teo

2009-07-23 18:54:40

Hello, and welcome to mc_teo's PlayGround…

Have you ever been away from the keyboard but want to check on SCAR…

There are over 3.1 Billion mobile/Cell Phone subscribers worldwide…

SCAR_SMS

How does it work i hear you say?

The Possibilities are numerous!

Well there are alot of free webtext services on the net, but sadly very few target little old Ireland.
So I found a workaround, SMS_GATEWAY, offer server software that you connect your mobile phone to.

Integrating this server to SCAR is the tricky part…

I wanted to make a Plugin, so SCAR would gain control over the server, for speed and simplicity's sake, but this fell through since i don't use Delphi for anything, and I've never made a Plugin in any language…

Enter the mythical language know only as PHP…

SCAR to Your Mobile

I've made a PHP script that recieves the message from SCAR, and submits it to the server to be sent, and it works beautifully…

This is great for such things as recieving Progress reports, Random Reports, etc.

Your Mobile to SCAR

Now for real functionality, wouldn't it be awesome to get Progress Reports, on request, from afar, Start/Stop scripts remotely and make desisions for SCAR from afar…

But aside from Runescape, this could be used for could for shutting down a computer, checking downloads, and even taking screenshots of your computer…


So this is what I've been doing lately…


Comments and Suggestions will be taken by force, if not surrendered freely… MWAH HAH HAH!!!

Narcle

2009-07-23 18:57:56

I believe someone did this before already. I believe they stopped because SRL is world wide and most SMS services are only for a single country. For SRL it would require multiple SMS services for such a task or a global SMS service - but I don't believe they exist, not for free at least.

mc_teo

2009-07-24 13:50:51

Well, I have got this working…

It runs in three parts;

The Server, PHP scripts, and SCAR functions.


This is basically what it does,


1. The server running on my pc, recieves the messages from the phone/modem.

2. The Server sends it on to a php script.

3. SCAR checks in with the PHP script, to check for new messages.

4. If a new message, is recieved it takes the message out, and checks it against the list of command.

5. If one of these commands are found, it does whatever its programmed to do.

6. It sends replied by submitting data to another PHP script.



Since alot of things are needed to setup this configuration, I would understand if nobody wanted to try it, but anyone that does, I would help them…

I'm available most days on the Rizon IRC channel #SRL, if anyone wants to know more, wants help, or just tell me how awesome this is!

ShowerThoughts

2009-07-24 13:55:18

Where is the code?
I am willing to help but where is the code?

nielsie95

2009-07-24 13:56:54

Sounds good, but where's the code?

mc_teo

2009-07-24 14:16:42

OK, this is the SCAR script i use for listening, will attach the PHP in a minute…



program New;

const
URL = 'http://localhost';

var
num, mess, LastMessage, SMS_Progress: string;

function SendSMS(URL, Number, Msg : string): Boolean;
var
Dbase : string;
Client : Integer;
begin
Client := InitializeHTTPClient(False, False);
ClearPostData(Client);
Wait(10);
AddPostVariable(Client, 'recipient', Number);
AddPostVariable(Client, 'message', Msg);
Dbase := PostHTTPPageEx(Client, URL+'/sendsms.php');
FreeHTTPClient(Client);
Result := true;
end;

function CheckForSMS(URL: string; var LastMessage:string): boolean;
var
buffer: string;
arr: TStringArray;
begin
buffer := GetPage(URL+'/MsgLog.txt');
Wait(10);
arr := Explode(#10, buffer);
if not (LastMessage = arr[high(arr)]) then
begin
Result := True;
LastMessage := arr[high(arr)];
end
else
Result := False;
buffer := '';
arr := ['','',''];
end;

procedure DealWithCommand(Msg:string);
var
TMess:TStringArray;
begin
TMess := Explode(' | ', Msg);
case lowercase(TMess[2]) of
'!progress':
begin
SendSMS(URL, TMess[1], SMS_Progress);
end;
end;
end;

begin
num := '********';
mess := 'This is the test message';
LastMessage := '';
ClearDebug;
SMS_Progress := '* Load Dropped = 32 *';
repeat
if CheckForSMS(URL, LastMessage) then
DealWithCommand(LastMessage);
until(false);

end.

Probably not the most efficient way to do it, but it works…


EDIT: Cant upload PHP… lol

[PHP]<?php

########################################################
# Login information for the SMS Gateway
########################################################

$ozeki_user = "";
$ozeki_password = "";
$ozeki_url = "http://127.0.0.1:9501/api?";

########################################################
# Functions used to send the SMS message
########################################################
function httpRequest($url){
$pattern = "/http…([0-9a-zA-Z-.]*).([0-9]*).(.*)/";
preg_match($pattern,$url,$args);
$in = "";
$fp = fsockopen("$args[1]", $args[2], $errno, $errstr, 30);
if (!$fp) {
return("$errstr ($errno)");
} else {
$out = "GET /$args[3] HTTP/1.1\r\n";
$out .= "Host: $args[1]:$args[2]\r\n";
$out .= "User-agent: Ozeki PHP client\r\n";
$out .= "Accept: */*\r\n";
$out .= "Connection: Close\r\n\r\n";

fwrite($fp, $out);
while (!feof($fp)) {
$in.=fgets($fp, 128);
}
}
fclose($fp);
return($in);
}



function ozekiSend($phone, $msg, $debug=false){
global $ozeki_user,$ozeki_password,$ozeki_url;

$url = 'username='.$ozeki_user;
$url.= '&password='.$ozeki_password;
$url.= '&action=sendmessage';
$url.= '&messagetype=SMS:TEXT';
$url.= '&recipient='.urlencode($phone);
$url.= '&messagedata='.urlencode($msg);

$urltouse = $ozeki_url.$url;
if ($debug) { echo "Request: <br>$urltouse<br><br>"; }

//Open the URL to send the message
$response = httpRequest($urltouse);
if ($debug) {
echo "Response: <br><pre>".
str_replace(array("<",">"),array("&lt;","&gt;"),$response).
"</pre><br>"; }

return($response);
}

########################################################
# GET data from sendsms.html
########################################################

$phonenum = $_POST['recipient'];
$message = $_POST['message'];
$debug = false;

ozekiSend($phonenum,$message,$debug);

?>
[/PHP]

And for recieving

[PHP]<?php

$sender = $_GET['sender'];
$message = $_GET['msgdata'];
$id = $_GET['msgid'];

if ($sender!='') {
$fp = fopen("MsgLog.txt","a");
fputs($fp,"$id | $sender | $message\n");
fclose($fp);

} else {
echo "The PHP script is ready for accepting messages";
}

?>
[/PHP]

ShowerThoughts

2009-07-24 14:22:34

If I run this scar script I can send a message to my phone in the Netherlands?
Edit:
I can do the php script on my site…

nielsie95

2009-07-24 14:24:32

The code's looking good too :)

Smarter Child

2009-07-25 01:22:50

I don't know PHP, but the Scar code is looking real nice:)..Would this perhaps work in Canada?

Awkwardsaw

2009-07-25 02:13:51

it look sgood :) you can do the same to e-mail too, iv used it in my recent scripts

mc_teo

2009-07-25 02:27:48

I stress that this is purely a home setup, it would be extremely difficult for me to make this enabled world-wide, from such a bad internet place as ireland…
(it took me half an hour to d/l 45mb, that 25kb/s, lol)

but it would be possible for you to set it up youself at home.

Getting the things setup is relatively easy, i did it in like two day, on and off…



I tested this today, when at the cinema, it ran flawlessly, and i was able to get up to date progress reports for my powerminer at any time, but thats just me…


To make this world-wide we would need a server, with either a hard mobile connected, (but still has to paid for), or a kick-ass free online provider, that provides recieving, and sending messages…

People on the IRC, (particularly Tootoot222) has suggested SMS over SMTP, which is basically, the computer sending an email to a special address and they recieve it as a MMS message, but this would be very hard to implement, especially when you might want to send messages back to the computer…

Anymore thoughts or suggestions welcome…



P.S. this can also be used to text to pretend you have a friend… it is sure to get you friend envious when they see you recieving these saucy messages from some mysterious girl… lol… you could trick them into texting it too… lol… the possibilities are endless…

ian.

2009-07-25 02:54:46

From: mc_teo
People on the IRC, (particularly Tootoot222) has suggested SMS over SMTP, which is basically, the computer sending an email to a special address and they recieve it as a MMS message, but this would be very hard to implement, especially when you might want to send messages back to the computer…


They get an SMS, don't they?

Awkwardsaw

2009-07-25 03:06:52

an idea so you can respond to the script is, you get the text over e-mail thing, and when you reply back have a php code check it(i dont know if you can, im not too familier with it yet) and have php store it as a variable. then use SCAR to read it

mc_teo

2009-07-25 19:52:08

From: 99_ aka ian.
They get an SMS, don't they?


Well I tested it and i got an MMS message on my Sony Ericsson…

@Awkwardsaw, hmmm…. that could be done, i suppose… the way i do it now is that the server submits it to the PHP script automatically when a message is recieved. the PHP saved in in a file, which SCAR checks for new lines…

So i could try to modify the PHP script to check for new emails recieved, but then it would have to be ran every loop of the SCAR script, which i'd imagine would seriously slow down the script.

So we could setup a SMTP server to do the recieving, and make it submit new emails to the PHP script, like this server does now…


Im not sure this is possible, as I never setup a mailserver before, but it seems feasible…

Then its only a matter of making a database or something for the various SMS gateways (i.e. the domain, after the email to be sent), which are unique to each network, and each country…

anyway, ill do more research and show here…

as usual, any suggestions welcome!

Wizzup?

2009-07-25 20:05:13

One thing I wondered, why not use Mail though?
Everyone can easily set up an SMTP server.

I remember the previous time someone was playing around with SMS'ing it died because most of the sites cost money.

ShowerThoughts

2009-07-25 21:47:55

From: Wizzup?
One thing I wondered, why not use Mail though?
Everyone can easily set up an SMTP server.

I remember the previous time someone was playing around with SMS'ing it died because most of the sites cost money.


We could do this find a site which supports without too much crap a few free sms and make a account creator + proxy support which isn't very hard and then implant a system in php that switches account when out of sms or something…

vinnievinboy

2009-07-26 04:05:18

You talked about a 'hard mobile'
If you could find a cheap contract/pay as you go that has unlim texts for like 10-15quid a month.
For a bit more maybe one that does unlim free international texts?

and sort it out on a website with some advertising and maybe some donate buttons you may get it working like that? Depends on what deals you can get.

ian.

2009-07-26 17:32:52

MMS = Pictures/audio.
SMS = Text.

Right?

vinnievinboy

2009-07-26 17:51:16

Correct Ian

MMS = Multi Media Message
SMS = Short Media Message?

ian.

2009-07-26 17:59:52

SMS = Short Message Service
MMS = Multimedia Message Service

mc_teo

2009-07-26 18:12:04

Ian, I know the difference… Im just saying that when I actually tested it, I recieved a MMS… other networks may send them as SMS… OK?

@Wizzup? Well I thought if you recieve emails, or that then you could vnc to the pc, or something, when with a phone you dont need internet access to check the pc, or to manipulate it…

ian.

2009-07-26 18:28:05

What was in the message. 'o.O I know you know your stuff, but it doesn't make sense to me how it'd be an MMS, so I assumed you got them mixed up when posting.

mc_teo

2009-07-26 19:38:40

I just send an email my networks sms gateway saying "Test Message", and recieved it as an MMS messages saying "Test Message", which would make sense, since MMS can have subjects and CCs and BCCs… but then again this could be down to my network provider


EDIT: MMS can have 1000 chars of text too

ian.

2009-07-26 19:46:14

So it was an MMS but no.. Multimedia? :p That actually makes a bit of sense to me.

Neehosoft

2009-07-26 22:28:26

Is this script working? i would like to put it into my script. Mabye you could make it your own include/plugin. and i might be able to put a server on my comp for WA.

mc_teo

2009-07-27 00:21:59

what is needed is some people who are fairly good at PHP, and a testing server to um… test on!

the server only needs PHP and SendMail, so far… Any Donators?

Lance

2009-07-27 00:33:47

guys you can send and receave texts using MSN, ICQ, yahoo, AIM and so on. why use a website when you could use these programs that everyone has?

Edit: and its free (atleast for the person using there computer) the person getting the text will have to pay the 15cents or w/e it is for texting on there plan, unless they have unlimited texting like me ;D

ShowerThoughts

2009-07-27 00:36:45

I pmed you with username and a password for my server :).

mc_teo

2009-08-13 17:42:40

*UPDATE* A guy I know is setting up a Kannel WEP/SMS Server, with an old GSM modem hardware wise, and he's said I could use this, so will probably update this thread when i get that all setup

cycrosism

2009-08-15 15:40:53

I can run a PHP script/server on one of my dads main servers

minsten

2009-08-19 15:37:16

It woud been nice, but i woud rather use my mobile only as a mobile:)
-Minsten

rya

2009-08-21 14:05:46

From: minsten
It woud been nice, but i woud rather use my mobile only as a mobile:)
-Minsten


I'm the same, but half the time i leave my moblie at home :p

Main

2009-08-24 04:24:55

Is it possible for scar to send emails?

ian.

2009-08-24 04:31:53

Yes.

http://www.villavu.com/forum/showthread.php?t=47589

Main

2009-08-24 05:12:05

Can't VIEW:mad:

ian.

2009-08-24 05:25:10

Oh yeah haha. :p I still don't know why he's keeping that in the members section. PM him if you want, I don't think I should tell you without his permission.

MylesMadness

2009-08-24 05:25:54

From: Main_Ftw
Is it possible for scar to send emails?

[PHP]<?
mail($_GET['to'], $_GET['subject'], $_GET['body']);
?>[/PHP]
Getpage('http://www.url.com/fileabove.php?to=email@gmail.com&subject=test&body=hello world!');

Main

2009-08-24 05:31:02

whats a good free site hoster? and do you know if any one have that thing uploaded? ^_^?

Awkwardsaw

2009-08-24 05:33:36

00webhost is pretty sxc, but not so user friendly

Main

2009-08-24 05:48:49

Is there any one who have a site that doesn't mind hosting this php :D?
From: MylesMadness
[PHP]<?
mail($_GET['to'], $_GET['subject'], $_GET['body']);
?>[/PHP]

ian.

2009-08-24 18:41:51

From: Main_Ftw
Is there any one who have a site that doesn't mind hosting this php :D?


From: Awkwardsaw
00webhost is pretty sxc, but not so user friendly


:) And there's a tut by Camo Kyle (I think he made it) about setting up 00webhost sites. :)