Make your own SMS sender in LINUX!!! [Warid, Telenor Added]

Discussion of programming on Linux, including shell scripting, perl, python, c/c++, mono, java. Whatever tickles your fancy.
Post Reply
zaeemarshad
Lieutenant Colonel
Posts: 660
Joined: Sat Jul 06, 2002 12:35 pm
Location: Islamabad
Contact:

Post by zaeemarshad »

gr8 job dude....smart work both of u..keep up the good work.

regards
zaeem
wtiwana
Cadet
Posts: 6
Joined: Sun Oct 31, 2004 5:37 am

Great work

Post by wtiwana »

Excellant work guys.
:D :)
wtiwana
Cadet
Posts: 6
Joined: Sun Oct 31, 2004 5:37 am

PHP Code Problem

Post by wtiwana »

Salamz guys;

I was wondering if someone on this forum could have a look at the following code. It is basically a function used to send sms to Ufone mobiles only. It is based on the code contributed by Mr. Masud. All the credit is his and his alone, I just ported it to PHP . :D

This code in question was working fine a few days ago, but is not working now, maybe I am not doing something correctly. Please tolerate the fact that I am a novice php socket programmer( I have been programming in php for the last 2 years. Working on sockets for the last 15 days 8) ...).

Here is the code:

function send_sms_ufone($num,$nick,$message)
{
$address = "202.125.152.246";
$port = "5000";
$socket = socket_create(AF_INET,SOCK_STREAM,SOL_TCP) ;

$res=socket_recv($socket,$buf,20,0);

for($i=0;$i<=strlen($buf);$i++)
{
if($i>10)
$id.=$buf[$i];
}
$d=sprintf("ID_RECIVED 0 0 0 0 %s wht",$id);
socket_write($socket,$d,strlen($d));
$msgfin=sprintf("Message MobileServer %s 0 %s %s: %s",$num,$id,$nick,$message);
socket_write($socket,$msgfin,strlen($msgfin));
socket_close($socket);
}
masud
Havaldaar
Posts: 108
Joined: Thu Aug 05, 2004 12:15 am
Location: Fremont, CA
Contact:

sure

Post by masud »

salamz!
sorry i was in maree and just came now, i will study and impliment it tomorrow and reply u soon :)
ALLAHHAFIZ
--SP--
Kdaemon
Naib Subedar
Posts: 346
Joined: Sat Nov 30, 2002 12:22 pm
Location: Islamabad. GPS: LHR

Post by Kdaemon »

was this working on your side?

Code: Select all

-Warning: socket_recv() unable to read from socket [107]: Transport endpoint is not connected in /tmp/a.php on line 8
$res=socket_recv($socket,$buf,20,0);

-Warning: socket_write() unable to write to socket [32]: Broken pipe in /tmp/a.php on line 18
$res=socket_write($socket,$d,strlen($d));

-Warning: socket_write() unable to write to socket [32]: Broken pipe in /tmp/a.php on line 22
socket_write($socket,$msgfin,strlen($msgfin));

output with these errors.
reg linux user #298274
zeenix
Naik
Posts: 67
Joined: Wed Apr 23, 2003 4:01 am
Location: Finland
Contact:

Post by zeenix »

Hello everyone,
althoug u already given answer in ur question LOL
all we need is address and second thing about that gets()
you can use dat stuff in a local process , i mean the process whic is run by you, but for the process which hosts users and run by any privilage user then u already hav an exelent defination given bye "zaeemarshad"
IMHO, the problems with gets is not at all related to local process or a privileged one. The reason you were not geting a segfault was that your array was located just after the pointer to that array (by which you refer to it). I gues this diagram would allow you to understand:

Code: Select all

   &array -------------->  | array |   --------|
                             | array_byte0 |  <------|
                             | array_byte1 |
now array would point to array_byte0, and &array would point to the array_reference. But you wouldn't always be lucky enough to have the reference and array at the same place, so watch your code.
"I think therefore I am" --- Rene Descartes
masud
Havaldaar
Posts: 108
Joined: Thu Aug 05, 2004 12:15 am
Location: Fremont, CA
Contact:

Post by masud »

salamz!!!
thnx for ur little peice of information!!
IMHO, the problems with gets is not at all related to local process or a privileged one. The reason you were not geting a segfault was that your array was located just after the pointer to that array (by which you refer to it). I gues this diagram would allow you to understand:
IMHO read it again, we were discussing gets() usage against buffer overflows, and why we are welcomed by the message of " warning " while using gets(). Althoug this part is informative for me
now array would point to array_byte0, and &array would point to the array_reference. But you wouldn't always be lucky enough to have the reference and array at the same place, so watch your code.
and now some thing about local processes and privilage processes for those who didnt get what we were discussing,

Any process which is locally running cant be balmed for buffer overflow, because every one has to use it locally and no interaction between network users, procces run by a user and if he buffer overflow it with any any malicious code it will be run under his privilages.

Privilaged proccess, a procces run by a any privilage user like "root" can be buffer overflowed using gets() function, because of its no boundry check. and any person with un priviliged access can use gets() input to have any work done under privilage user using that gets() function.
--SP--
zeenix
Naik
Posts: 67
Joined: Wed Apr 23, 2003 4:01 am
Location: Finland
Contact:

Post by zeenix »

Hello again,
Now that you write your messages in english, we are able to comprehend it. There were more than one queries regarding gets and I didn't know which one you replied to. The query i thought you replied to was regarding the legitimacy of passing &buf instead of buf to gets, which doesn't have anything to do with buffer-overflow.
"I think therefore I am" --- Rene Descartes
wtiwana
Cadet
Posts: 6
Joined: Sun Oct 31, 2004 5:37 am

PHP code problem resolved

Post by wtiwana »

Dear All;

Salamz;

Sorry could not post this early. The Ufone PHP sending script I posted earlier is not faulty and is working correctly. The problem was with the firewall deployed on the server. It was blocking PHP's attempts to connect to target addresses.
The problem is now resolved.

Thanks to all who contributed to the effort. :D

Allah Hafiz.
masud
Havaldaar
Posts: 108
Joined: Thu Aug 05, 2004 12:15 am
Location: Fremont, CA
Contact:

hi

Post by masud »

salamz!
wtiwana wrote:
Sorry could not post this early. The Ufone PHP sending script I posted earlier is not faulty and is working correctly. The problem was with the firewall deployed on the server. It was blocking PHP's attempts to connect to target addresses.
The problem is now resolved.
no your code is not working. "Kdaemon" pointed out some thing in his post as well and the thing which is causing all this problem is that your code dont have socket_connect call.
I am posting my two working code of PHP here, using fsockopen and socket_connect methods, and they are working perfectly,

Code: Select all


 <?php

if(!($sock = fsockopen("202.125.152.246",5000)))
 {
   echo "connection failed";
   exit();
 }

$buf=fread($sock,100);

for($i=0;$i< (strlen($buf)-11);$i++)
{
$id.=$buf[11+$i];
}

$ver=sprintf("ID_RECIVED 0 0 0 0 %s wht",$id);

fputs($sock,$ver);
$msg=sprintf("Message MobileServer %s 0 %s %s: %s",$num,$id,$nick,$message);
fputs($sock,$msg);
fclose($sock);

 echo " your message has been send";
?>
second one

Code: Select all

<?php
$address = "202.125.152.246";
$port = 5000;
$socket = socket_create(AF_INET,SOCK_STREAM,SOL_TCP);

if (!socket_connect($socket,$address,$port)) {
   socket_close($socket);
   die("Sock_Error: Socket was unable to bind.\n");
}


$res=socket_recv($socket,$buf,20,0);

for($i=0;$i<=strlen($buf);$i++)
{
if($i>10)
$id.=$buf[$i];
}

$d=sprintf("ID_RECIVED 0 0 0 0 %s wht",$id);


socket_write($socket,$d,strlen($d));
$msgfin=sprintf("Message MobileServer %s 0 %s %s: %s",$num,$id,$nick,$message);

socket_write($socket,$msgfin,strlen($msgfin));
socket_close($socket); 

echo " your message has been send";
?>
practicle example:
http://aosp.net/sms/ufone.htm
http://aosp.net/sms/ufone1.htm
--SP--
Kdaemon
Naib Subedar
Posts: 346
Joined: Sat Nov 30, 2002 12:22 pm
Location: Islamabad. GPS: LHR

Post by Kdaemon »

ok tested it's working fine. :!:
reg linux user #298274
wtiwana
Cadet
Posts: 6
Joined: Sun Oct 31, 2004 5:37 am

Sorry about the code

Post by wtiwana »

Dear All,

Salamz;

Sorry to all. Yes that is correct, the code I had posted does not have a connect call. I corrected it but forgot to post the right code,, :oops:

The code I am using right now is:


function send_sms_ufone($mob,$nick,$message)
{
$address = "202.125.152.246";
$port = "5000";
$socket = socket_create(AF_INET,SOCK_STREAM,SOL_TCP) ;
$result = socket_connect( $socket, $address, $port);
$res=socket_recv($socket,$buf,20,0);

for($i=0;$i<=strlen($buf);$i++)
{
if($i>10)
$id.=$buf[$i];
}
$sendd=sprintf("ID_RECIVED 0 0 0 0 %s wht",$id);
socket_write($socket,$sendd,strlen($sendd));
$msgfin=sprintf("Message MobileServer %s 0 %s %s: %s",$mob,$id,$nick,$message);
socket_write($socket,$msgfin,strlen($msgfin));
socket_close($socket);
}

The above is the correct one. Hope it is correct :oops:

Anyway, I am thinking of implementing a system in which we can be sure that the message has reached or has been delivered to the mobile device. Something like a message delivered notification. The reason for this that if the message has been lost in the way and has not reached its destination then we can resend it.
Any ideas on this..... :roll:

Keep up the good work.

Allah Hafiz

P.S. Thanks to Masud and Kdeamon for helping me with the code and thanks to all those who thought about posting a reply but felt lazy enough to type. thanks to ALL. Keep it real Guyz
masud
Havaldaar
Posts: 108
Joined: Thu Aug 05, 2004 12:15 am
Location: Fremont, CA
Contact:

Post by masud »

salamz!
its already done in the code, how?

1) we are using TCP and the main concept of TCP is to make a three way handshake with the server before sending any information/data. Its work is not over, because after this, it has to control the transmition in which windowing , retransmition, packets numbering etc..... each packet has an ID/number and reciver after taking the packet return the ID number as an acknowledgement of packet has been recived successfully. IF sender recieves no ACK packet then it will resend the packet again and we dont have to do any thing else beacause TCP is doing hard work for us already.

now as you said about how we know weather the sms is delivered or not is little hard when mobile sever(any mobile server) give you an ACK packet and your code will always complete successfully.

second thing is, dont repeat the same message again beacause it wount be delivered, it will show you delivered but in reality it isnt. thats the only check they do.

now one thing left and that is,,, after sending message to the user ask him to mis call you hehehe:):):):)

if any one else have another idea please post it.

wtiwana:: i try my best to explain you the reason of why we cant make such a system. try it ur self u always have a positive responce from a server but that server is not performing its duty then its not over fault :).
--SP--
eGuru
Cadet
Posts: 1
Joined: Sun May 16, 2004 1:59 am
Contact:

Post by eGuru »

how to bypass the ufones confirmation message.?
Abul Asim M. R. Qarshi
jess
Company Havaldaar Major
Posts: 198
Joined: Sat Jul 31, 2004 7:05 am
Location: Toronto
Contact:

Post by jess »

Can you guys make it into a kopete plugin?
Post Reply