| 1 | <? |
|---|
| 2 | /* |
|---|
| 3 | * licqweb. Copyright 2005, Philip Nelson |
|---|
| 4 | * |
|---|
| 5 | * This file is part of licqweb. |
|---|
| 6 | * |
|---|
| 7 | * licqweb is free software; you can redistribute it and/or modify |
|---|
| 8 | * it under the terms of the GNU General Public License as published by |
|---|
| 9 | * the Free Software Foundation; either version 2 of the License, or |
|---|
| 10 | * (at your option) any later version. |
|---|
| 11 | * |
|---|
| 12 | * licqweb is distributed in the hope that it will be useful, |
|---|
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 15 | * GNU General Public License for more details. |
|---|
| 16 | * |
|---|
| 17 | * You should have received a copy of the GNU General Public License |
|---|
| 18 | * along with licqweb; if not, write to the Free Software |
|---|
| 19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
|---|
| 20 | */ |
|---|
| 21 | require_once('config.php'); |
|---|
| 22 | require_once('serverpush.php'); |
|---|
| 23 | require_once('rms.php'); |
|---|
| 24 | |
|---|
| 25 | define('CODE_NOTIFYxSTATUS', '600'); |
|---|
| 26 | define('CODE_NOTIFYxMESSAGE', '601'); |
|---|
| 27 | define('CODE_LOG', '103'); |
|---|
| 28 | session_set_cookie_params(0, substr($_SERVER['REQUEST_URI'], 0, strrchr($_SERVER['REQUEST_URI'], '/'))); |
|---|
| 29 | session_start(); |
|---|
| 30 | if ($_GET['uin'] || $_GET['password']) { |
|---|
| 31 | $_SESSION['uin'] = $uin; |
|---|
| 32 | $_SESSION['password'] = $password; |
|---|
| 33 | $uin = $_GET['uin']; |
|---|
| 34 | $password = $_GET['password']; |
|---|
| 35 | } else { |
|---|
| 36 | $uin = $_SESSION['uin']; |
|---|
| 37 | $password = $_SESSION['password']; |
|---|
| 38 | } |
|---|
| 39 | session_write_close(); |
|---|
| 40 | if (!$uin || !$password) { |
|---|
| 41 | header('Content-Type: text/xml'); |
|---|
| 42 | echo "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>"; |
|---|
| 43 | echo "<response><method>loginFailed</method><result>Couldn't log in to rms plugin!</result></response>"; |
|---|
| 44 | exit; |
|---|
| 45 | } |
|---|
| 46 | |
|---|
| 47 | $nick = rmsLogin("$uin\r\n", "$password\r\n"); |
|---|
| 48 | if (!$nick) { |
|---|
| 49 | header('Content-Type: text/xml'); |
|---|
| 50 | echo "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>"; |
|---|
| 51 | echo "<response><method>loginFailed</method><result>Couldn't log in to rms plugin!</result></response>"; |
|---|
| 52 | exit; |
|---|
| 53 | } |
|---|
| 54 | |
|---|
| 55 | $nick = substr($nick, 0, -1); |
|---|
| 56 | $cmd = "NOTIFY\r\n"; |
|---|
| 57 | socket_write($sock, $cmd, strlen($cmd)); |
|---|
| 58 | socket_read($sock, 512, PHP_NORMAL_READ); |
|---|
| 59 | |
|---|
| 60 | /* |
|---|
| 61 | $cmd = "LOG 15\r\n"; |
|---|
| 62 | socket_write($sock, $cmd, strlen($cmd)); |
|---|
| 63 | socket_read($sock, 512, PHP_NORMAL_READ); |
|---|
| 64 | */ |
|---|
| 65 | |
|---|
| 66 | http_push_start(); |
|---|
| 67 | |
|---|
| 68 | $ownerInfo = rmsGetStatus(); |
|---|
| 69 | $ownerxml = ""; |
|---|
| 70 | foreach ($ownerInfo as $pp => $info) { |
|---|
| 71 | $ownerxml .= "<owner><id>" . $info['id'] . "</id><pp>$pp</pp><status>" . $info['status'] . "</status></owner>"; |
|---|
| 72 | } |
|---|
| 73 | $message = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n<response><method>setOwnerInfo</method><result>$ownerxml</result></response>"; |
|---|
| 74 | push($message); |
|---|
| 75 | |
|---|
| 76 | $message = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n<response><method>setOwnerNick</method><result>" . xmlentities($nick) . "</result></response>"; |
|---|
| 77 | push($message); |
|---|
| 78 | |
|---|
| 79 | $users = rmsGetlist($_GET['listtype']); |
|---|
| 80 | if (count($users) > 0) { |
|---|
| 81 | $userstxt = "<users>"; |
|---|
| 82 | foreach ($users as $user) { |
|---|
| 83 | $userstxt .= "<user><id>" . xmlentities($user['id']) . "</id><nick>" . str_replace("\n", '', xmlentities($user['nick'])) . "</nick><newmsgs>" . trim(xmlentities($user['newmsgs'])) . "</newmsgs><status>" . str_replace(' ', '', xmlentities($user['status'])) . "</status><pp>" . xmlentities($user['pp']) . "</pp></user>"; |
|---|
| 84 | } |
|---|
| 85 | $userstxt .= "</users>"; |
|---|
| 86 | $res = " |
|---|
| 87 | <response> |
|---|
| 88 | <method>userList</method> |
|---|
| 89 | <result>$userstxt</result> |
|---|
| 90 | </response>"; |
|---|
| 91 | $message = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n" . $res; |
|---|
| 92 | push($message); |
|---|
| 93 | } |
|---|
| 94 | |
|---|
| 95 | while (true) { |
|---|
| 96 | $packet = socket_read($sock, 512, PHP_NORMAL_READ); |
|---|
| 97 | if (!$packet) break; |
|---|
| 98 | $code = substr($packet, 0, 3); |
|---|
| 99 | switch ($code) { |
|---|
| 100 | case CODE_NOTIFYxSTATUS: |
|---|
| 101 | $user = getUserStuff($packet); |
|---|
| 102 | $method = "updateStatus"; |
|---|
| 103 | $txt = "<newstatus><id>" . xmlentities($user['id']) . "</id><pp>" . xmlentities($user['pp']) . "</pp><nick>" . str_replace("\n", '', xmlentities(kses($user['nick']))) . "</nick><nummsgs>" . trim(xmlentities($user['newmsgs'])) . "</nummsgs><status>" . str_replace(' ', '', xmlentities($user['status'])) . "</status></newstatus>"; |
|---|
| 104 | break; |
|---|
| 105 | case CODE_NOTIFYxMESSAGE: |
|---|
| 106 | list($id, $pp, $numMessages) = split(' ', substr($packet, 4), 3); |
|---|
| 107 | $method = "newMessage"; |
|---|
| 108 | $txt = "<newmessage><id>$id</id><pp>$pp</pp><nummsgs>$numMessages</nummsgs></newmessage>"; |
|---|
| 109 | break; |
|---|
| 110 | case CODE_LOG: |
|---|
| 111 | $method = "log"; |
|---|
| 112 | $txt = substr($packet, 4); |
|---|
| 113 | break; |
|---|
| 114 | default: |
|---|
| 115 | continue; |
|---|
| 116 | } |
|---|
| 117 | $message = " |
|---|
| 118 | <response> |
|---|
| 119 | <method>$method</method> |
|---|
| 120 | <result>$txt</result> |
|---|
| 121 | </response> |
|---|
| 122 | "; |
|---|
| 123 | $message = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n" . $message; |
|---|
| 124 | push($message); |
|---|
| 125 | } |
|---|
| 126 | ?> |
|---|