Subscription page for Instant Messaging gateway
You MUST have a SIP account on IPTEL.ORG
User info
- for any operation you MUST provide your 'iptel.org' username and password
AIM Gateway subscription
- choose 'AIM' as 'IM service'
- 'IM nickname' is your display name for AIM network
- 'IM account' is your AIM account name (ex: 'alpha')
- 'IM password' is the password of your AIM account
- click on 'Subscribe'
ICQ Gateway subscription
- choose 'ICQ' as 'IM service'
- 'IM nickname' is your display name for ICQ network
- 'IM account' is your ICQ number (ex: '158251040')
- 'IM password' is the password of your ICQ account
- click on 'Subscribe'
MSN Gateway subscription
- choose 'MSN' as 'IM service'
- 'IM nickname' is your display name for MSN network
- 'IM account' is your MSN account (ex: 'alpha@hotmail.com' or 'alpha@msn.com')
- 'IM password' is the password of your MSN account
- click on 'Subscribe'
Yahoo Gateway subscription
- choose 'Yahoo' as 'IM service'
- 'IM nickname' is your display name for Yahoo network
- 'IM account' is your Yahoo account (ex: 'alpha')
- 'IM password' is the password of your Yahoo account
- click on 'Subscribe'
IM Gateway unsubscription
- choose the 'IM service' from which you want to unsubscribe
- click on 'Unsubscribe'
Instant Messaging Gateway
";
$dblink = mysql_connect($sip_db_srv, $sip_db_usr, $sip_db_pas) or
html_die("Could not connect to SIP database server");
mysql_select_db($sip_db_db, $dblink)
or html_die("Could not select SIP database");
$query = "SELECT $sip_db_cusr FROM $sip_db_tab WHERE $sip_db_cusr='$sipname' AND $sip_db_cpas='$sippasswd'";
dbg_msg("$query
");
$result = mysql_query($query) or html_die("Invalid SQL query");
if(mysql_num_rows($result) == 0)
html_die("Invalid SIP username or password");
mysql_close($dblink);
***************************************** */
#
#------------------------------------------------------
#
# -----
# check if is already registered to Jabber gateway
# -----
$sipuri = "sip:".$sipname."@iptel.org";
$dblink = mysql_connect($jab_db_srv, $jab_db_usr, $jab_db_pas) or html_die("Could not connect to Jabber database");
mysql_select_db($jab_db_db, $dblink) or html_die("Could not use Jabber database");
# ----
if($action == "Disable")
{
$query = "UPDATE jusers SET tyep=1 WHERE sip_id='$sipuri'";
$result = mysql_query($query, $dblink);
if(mysql_affected_rows() != 1)
{
mysql_close($dblink);
html_die("
Cannot find Jabber ID of '$sipname' in database");
}
mysql_close($dblink);
html_die("
Your IM account was updated");
}
# ----
$query = "SELECT jab_id FROM jusers WHERE sip_id='$sipuri'";
$result = mysql_query($query, $dblink) or html_die("Invalid SQL query");
if(mysql_num_rows($result) == 0)
{ // no Jabber account - create one
$fd = jab_connect($jserver, $jport);
if(!$fd)
html_die("Could not connect to Jabber server");
$buf_recv = fread($fd, 2048);
while(!$buf_recv)
{
usleep(100);
$buf_recv = fread($fd, 2048);
}
$jid1 = stristr($buf_recv, "id='");
$jid1 = substr($jid1, 4);
if($jid1)
{
$jid2 = strstr($jid1, "'");
if($jid2)
{
$jid = substr($jid1, 0, strlen($jid1)-strlen($jid2));
dbg_msg("JID: $jid
");
}
}
$jcid = $jcid + 1;
jab_get_reg($fd, $jcid, $jserver);
$buf_recv = fread($fd, 2048);
while(!$buf_recv)
{
usleep(100);
$buf_recv = fread($fd, 2048);
}
$jcid = $jcid + 1;
$new_passwd = "#".$sipname."%";
jab_set_reg($fd, $jcid, $jserver, $sipname, $new_passwd);
$buf_recv = fread($fd, 2048);
while(!$buf_recv)
{
usleep(100);
$buf_recv = fread($fd, 2048);
}
if(stristr($buf_recv, " id='$jcid'") && stristr($buf_recv, " type='error'"))
{
mysql_close($dblink);
jab_disconnect($fd);
html_die("
Something bizarre with account '$sipname'");
}
# -----
# Add user in database
# -----
$query = "INSERT INTO jusers (jab_id, jab_passwd, sip_id) VALUES ('$sipname', '$new_passwd', '$sipuri')";
$result = mysql_query($query, $dblink);
if(mysql_affected_rows() != 1)
{
mysql_close($dblink);
jab_disconnect($fd);
html_die("
Can not insert '$sipname' in database");
}
jab_disconnect($fd);
}
# -----
if($action == "Enable")
{
$query = "UPDATE jusers SET type=0 WHERE sip_id='$sipuri'";
$result = mysql_query($query, $dblink);
if(mysql_affected_rows() != 1)
{
mysql_close($dblink);
html_die("
Cannot find Jabber ID of '$sipname' in database");
}
mysql_close($dblink);
html_die("
Your IM account was updated");
}
# -----
$query="SELECT juid,jab_id,jab_passwd,type FROM jusers WHERE
sip_id='$sipuri' and type=0";
$result = mysql_query($query, $dblink) or html_die("Invalid SQL query");
if(mysql_num_rows($result) != 1 || (!($row = mysql_fetch_array($result))))
{
mysql_close($dblink);
html_die("
You do not have an associated Jabber account or it is
disabled!
Press 'Enable' in order to create a new one or to activate an
old one.
If error persists, please inform the administrator.");
}
$juid = $row[0];
$jab_id = $row[1];
$jab_passwd = $row[2];
$jab_type = $row[3];
dbg_msg("Jabber User ID: $juid
");
$fd = jab_connect($jserver, $jport);
if(!$fd)
html_die("Could not connect to Jabber server");
$buf_recv = fread($fd, 2048);
while(!$buf_recv)
{
usleep(100);
$buf_recv = fread($fd, 2048);
}
$jid1 = stristr($buf_recv, "id='");
$jid1 = substr($jid1, 4);
if($jid1)
{
$jid2 = strstr($jid1, "'");
if($jid2)
{
$jid = substr($jid1, 0, strlen($jid1)-strlen($jid2));
dbg_msg("JID: $jid
");
}
}
$jcid = $jcid + 1;
jab_get_auth($fd, $jcid, $jab_id);
$buf_recv = fread($fd, 2048);
while(!$buf_recv)
{
usleep(100);
$buf_recv = fread($fd, 2048);
}
$jcid = $jcid + 1;
jab_set_auth($fd, $jcid, $jab_id, $jab_passwd);
$buf_recv = fread($fd, 2048);
while(!$buf_recv)
{
usleep(100);
$buf_recv = fread($fd, 2048);
}
if(stristr($buf_recv, " id='$jcid'") && stristr($buf_recv, " type='error'"))
{
jab_disconnect($fd);
html_die("
Wrong username or password at Jabber authentication");
}
# -----
# browse agents
# -----
$jcid = $jcid + 1;
jab_get_agents($fd, $jcid, $jserver);
$buf_agents = fread($fd, 4096);
while(!$buf_agents)
{
usleep(100);
$buf_agents = fread($fd, 4096);
}
# dbg_msg("\n");
# -----
$imag1 = stristr($buf_agents, "
");
}
}
# -----
if(isset($imag))
{
if($action == "Subscribe" && isset($imname) && $imname != "")
{
echo "IM ($imtype) subscription
";
# -----
# unsubscribe the previous IM account (if exists)
# -----
$jcid = $jcid + 1;
jab_set_unreg($fd, $jcid, $icqag);
$buf_recv = fread($fd, 2048);
while(!$buf_recv)
{
usleep(100);
$buf_recv = fread($fd, 2048);
}
sleep(1);
# -----
# subscription
# -----
$jcid = $jcid + 1;
jab_get_reg($fd, $jcid, $imag);
$buf_recv = fread($fd, 2048);
while(!$buf_recv)
{
usleep(100);
$buf_recv = fread($fd, 2048);
}
$imkey1 = stristr($buf_recv, "");
$imkey1 = substr($imkey1, 5);
if($imkey1)
{
$imkey2 = strstr($imkey1, "");
if($imkey2)
{
$imkey = substr($imkey1, 0, strlen($imkey1)-strlen($imkey2));
dbg_msg("IM key: $imkey
");
}
}
if(!isset($imkey))
{
jab_disconnect($fd);
mysql_close($dblink);
html_die("
Session key for IM ($imtype) Transport not found");
}
$jcid = $jcid + 1;
jab_set_regk($fd, $jcid, $imag, $imname, $impasswd, $imnick, $imkey);
$buf_recv = fread($fd, 2048);
while(!$buf_recv)
{
usleep(100);
$buf_recv = fread($fd, 2048);
}
if(stristr($buf_recv, " id='$jcid'") && stristr($buf_recv, " type='error'"))
{
$err1 = stristr($buf_recv, "");
$err1 = substr($err1, 1);
if($err1)
{
$err2 = strstr($err1, "");
if($err2)
$err = substr($err1, 0, strlen($err1)-strlen($err2));
}
jab_disconnect($fd);
mysql_close($dblink);
html_die("
Error registering your IM ($imtype) account: $err");
}
jab_send_presence($fd, $imag."/registered", "subscribed");
# -----
# Update database
$query = "SELECT ".$imtype."_id FROM ".$imtype." WHERE juid='$juid'";
$result = mysql_query($query, $dblink) or html_die("Invalid SQL query");
if(mysql_num_rows($result) == 0)
{ # INSERT
$query = "INSERT INTO ".$imtype." (juid, ".$imtype."_id, ".$imtype."_passwd, ".$imtype."_nick) VALUES ('$juid', '$imname', '$impasswd', '$imnick')";
dbg_msg("$query
");
$result = mysql_query($query, $dblink);
if(mysql_affected_rows() != 1)
{
echo "
Can not register '$sipname'/'$imname'";
}
else
{
echo "Your IM ($imtype) account was successfully registered
";
}
}
else
{ # UPDATE
$query = "UPDATE ".$imtype." SET ".$imtype."_id='$imname', ".$imtype."_passwd='$impasswd', ".$imtype."_nick='$imnick' WHERE juid='$juid'";
dbg_msg("$query
");
$result = mysql_query($query, $dblink);
if(!$result)
{
echo "
Can not update '$sipname'/'$imname'
";
}
else
{
if(mysql_affected_rows() == 1)
{
echo "Your IM ($imtype) account was successfully updated
";
}
else
{
echo "No modification in your IM ($imtype) account
";
}
}
}
}
else
{
echo "IM ($imtype) unsubscription
";
# -----
# unsubscribe the IM account
# -----
$jcid = $jcid + 1;
jab_set_unreg($fd, $jcid, $icqag);
$buf_recv = fread($fd, 2048);
while(!$buf_recv)
{
usleep(100);
$buf_recv = fread($fd, 2048);
}
sleep(1);
$query = "DELETE FROM ".$imtype." WHERE juid='$juid'";
dbg_msg("$query
");
$result = mysql_query($query, $dblink);
if(!$result)
{
echo "
Can not remove IM ($imtype) information from database
";
}
else
{
echo "
Unsubscription from IM ($imtype) completed
";
}
}
}
sleep(1);
jab_disconnect($fd);
mysql_close($dblink);
}
?>