1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
  2 <?php
  3 
  4 
  5 /**
  6  * look at xmlBlanster.inc to know more
  7  *
  8  * 08/07/02 21:51 cyrille@ktaland.com 
  9  */
 10 
 11 // ===============
 12 $DEBUG = 1;
 13 function dbgprint($str) {
 14    global $DEBUG;
 15    if (isset ($DEBUG) && $DEBUG > 0)
 16       error_log("[DBG] $str", 0);
 17 } //dbgprint
 18 function svar_dump($data) {
 19    // like var_dump, but no print !
 20    ob_start();
 21    var_dump($data);
 22    $ret_val = ob_get_contents();
 23    ob_end_clean();
 24    return $ret_val;
 25 }
 26 // ===============
 27 
 28 include ('xmlBlaster.inc');
 29 
 30 $server = getHttpVar('server', 'localhost');
 31 $port = getHttpVar('port', 8080);
 32 $user = getHttpVar('user', 'joe');
 33 $password = getHttpVar('password', 'secret');
 34 $securityPlugin = getHttpVar('securityPlugin', 'htpasswd');
 35 $xpathQuery = getHttpVar('xpathQuery', '//key');
 36 $xbMethod = getHttpVar('xbMethod');
 37 $publishKey = getHttpVar('publishKey');
 38 $publishQos = getHttpVar('publishQos');
 39 $publishContent = getHttpVar('publishContent');
 40 $publishRes = getHttpVar('publishRes');
 41 
 42 if ($xpathQuery != "") {
 43    $xpathQuery = preg_replace("/\\\'/", "'", $xpathQuery);
 44 }
 45 
 46 if ($publishKey != "") {
 47    $publishKey = preg_replace("/\\\'/", "'", $publishKey);
 48 }
 49 if ($publishQos != "") {
 50    $publishQos = preg_replace("/\\\'/", "'", $publishQos);
 51 }
 52 
 53 /*
 54  * Create a xmlBlaster object and connect it to xmlBlaster server
 55  */
 56 
 57 $xb = new xmlBlaster($server, $port, $user, $password);
 58 $xb->securityService_type = $securityPlugin;
 59 
 60 $res = $xb->connect();
 61 if ($res[0] != 'OK') {
 62    $error_message = $res[1];
 63 }
 64 
 65 /*
 66  * get some server's information
 67  */
 68 
 69 $sysInternal = array ();
 70 if ($xb->isConnected()) {
 71 
 72    $sysInternalVariables = array (
 73       'nodeId',
 74       'version',
 75       'uptime',
 76       'totalMem',
 77       'usedMem',
 78       'freeMem',
 79       'clientList'
 80    );
 81    //$sysInternalVariables = array( 'uptime' );
 82    //$sysInternalVariables = array( 'freeMem','syspropList','toto' );
 83 
 84    foreach ($sysInternalVariables as $sysVar) {
 85 
 86       $res = $xb->get("<key oid='__cmd:?$sysVar' />");
 87 
 88       // pre-define content because used later for echo in html ...
 89       $sysInternal[$sysVar] = '?';
 90 
 91       if ($res[0] != 'OK') {
 92          $error_message = $res[1];
 93 
 94          $sysInternal[$sysVar] = $error_message;
 95 
 96       } else {
 97          $messages = $res[1];
 98          $message_count = count($messages);
 99          // should be only one because it's admin value
100 
101          foreach ($messages as $msg) {
102             dbgPrint("MSG:" . $msg->content());
103             $sysInternal[$sysVar] = $msg->content();
104          }
105       }
106    }
107 }
108 ?>
109 
110 <html>
111 <head>
112    <title>PHP XmlBlaster client - running on <?php echo $server ?> </title>
113 
114 <style type="text/css">
115 <!--
116 .text {  font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10pt; color: #666666}
117 .title {  font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12pt; color: #000000}
118 .error {  font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12pt; color: #FF2020}
119 -->
120 </style>
121 
122 <script language="javascript"> <!--
123 
124 // --> </script>
125 
126 </head>
127 <body>
128 
129 <!-- only for debugging purposes uncomment this
130 <center>
131 <table>
132   <tr><th></th><th></th></tr>
133   <tr><td>server</td><td><?php echo $server; ?></td></tr>
134   <tr><td>port</td><td><?php echo $port; ?></td></tr>
135   <tr><td>user</td><td><?php echo $user; ?></td></tr>
136   <tr><td>password</td><td><?php echo $password; ?></td></tr>
137   <tr><td>xpathQuery</td><td><?php echo $xpathQuery; ?></td></tr>
138   <tr><td>xbMethod</td><td><?php echo $xbMethod; ?></td></tr>
139   <tr><td>publishKey (html)</td><td><?php echo htmlentities($publishKey); ?></td></tr>
140   <tr><td>publishQos (html)</td><td><?php echo htmlentities($publishQos); ?></td></tr>
141   <tr><td>publishContent</td><td><?php echo $publishContent; ?></td></tr>
142   <tr><td>publishRes</td><td><?php echo $publishRes; ?></td></tr>
143 </table>
144 </center>
145 -->
146 
147 <table>
148 <tr>
149 <td class="title"><a href="http://xmlBlaster.org/"><img src="logo_xmlBlaster_2.gif" border="0"></a></td>
150 <td class="title"><a href="http://xmlBlaster.org/">xmlBlaster</a> client for <a href="http://php.net/">php</a>,<br>using <a href="http://phpxmlrpc.sourceforge.net/">xml-rpc</a> protocol</td>
151 </tr>
152 </table>
153 
154 <?php if( isset($error_message) ){ ?>
155 <p>&nbsp;</p>
156 <table border="1"><tr><td class="error">
157 ERROR : <?php echo $error_message; ?>
158 </td></tr></table>
159 <?php } ?>
160 
161 <p>&nbsp;</p>
162 <form method="GET">
163 <div class="text">Need some parameters to connect :</div>
164  <table>
165 
166   <tr>
167    <td class="text">server :</td>
168    <td class="text">
169    <input type="text" name="server" value="<?php echo $server; ?>">
170    </td>
171 
172    <td class="text" rowspan="4">
173 
174    <table>
175    <?php foreach ($sysInternal as $k => $v) {?>
176    <tr><td class="text"> &nbsp; <?php echo htmlentities($k); ?></td><td class="text"><?php echo htmlentities($v); ?></td></tr>
177    <?php } ?>
178    </table>
179 
180    </td>
181   </tr>
182   <tr><td class="text">port :</td><td class="text"><input type="text" name="port" value="<?php echo $port; ?>"></td></tr>
183   <tr><td class="text">user :</td><td class="text"><input type="text" name="user" value="<?php echo $user; ?>"></td></tr>
184   <tr><td class="text">password :</td><td class="text"><input type="text" name="password" value="<?php echo $password; ?>"></td></tr>
185   <tr><td class="text">securityPlugin :</td><td class="text"><input type="text" name="securityPlugin" value="<?php echo $securityPlugin; ?>"></td></tr>
186   <tr><td class="text" colspan="3" align="center"><input type="submit" value=" Connect "></td></tr>
187  </table>
188 </form>
189 
190 <p>&nbsp;</p>
191 <form method="GET">
192 <div class="text">After connection, you can query the server for messages :</div>
193    <input type="hidden" name="xbMethod" value="get">
194    <input type="hidden" name="server" value="<?php echo $server; ?>"><input type="hidden" name="port" value="<?php echo $port; ?>">
195    <input type="hidden" name="user" value="<?php echo $user; ?>"><input type="hidden" name="password" value="<?php echo $password; ?>">
196    <input type="hidden" name="securityPlugin" value="<?php echo $securityPlugin; ?>">
197  <table border="1">
198   <tr>
199    <td class="text">
200    XPath Query :<br><input type="text" name="xpathQuery" value="<?php echo $xpathQuery; ?>" size="50">
201    </td>
202   </tr>
203   <tr><td><input type="submit" value=" Query "></td></tr>
204 
205 <?php
206 
207 
208 if ($xb->isConnected() && isset ($xpathQuery) && ($xbMethod == 'get')) {
209 
210    // $key = "<key oid='' queryType='XPATH'>/xmlBlaster/key[starts-with(\@oid,'myHel')]</key>" ;
211    $res = $xb->get("<key oid='' queryType='XPATH'>$xpathQuery</key>");
212 
213    if ($res[0] != 'OK') {
214       $error_message = $res[1];
215 ?>
216       <tr><td>
217          <?php echo $error_message; ?>
218       </td></tr>
219       <?php
220 
221 
222    } else {
223       $messages = $res[1];
224 
225       foreach ($messages as $msg) {
226          //dbgPrint( "MSG.type:" .gettype($msg) );
227          dbgPrint("MSG:" . svar_dump($msg));
228          if ($msg == 0) {
229 ?>
230             <tr><td>
231                No Result.
232             </td></tr>
233             <?php
234 
235 
236          } else {
237 ?>
238             <tr><td>
239                <?php echo htmlentities($msg->keyOid()); ?>
240                <br>
241                <?php echo htmlentities($msg->content()); ?>
242             </td></tr>
243             <?php
244 
245 
246          }
247       }
248    }
249 }
250 ?>
251 
252  </table>
253 </form>
254 
255 
256 <p>&nbsp;</p>
257 <form method="GET">
258 <div class="text">A Publish Test :</div>
259  <input type="hidden" name="xbMethod" value="publish">
260 <?php
261 
262 if ($xbMethod == 'publish') {
263    $arr = $xb->publish($publishKey, $publishContent, $publishQos);
264    if ($arr[0] == "OK") {
265       $publishReturnQos = $arr[1];
266       $publishRes = $publishReturnQos->state();
267       dbgprint("PublishReturnQos::state=" . $publishRes);
268    }
269    else {
270       $publishRes = $arr[1];
271       dbgprint("PublishReturnQos::failed=" . $arr[1]);
272    }
273 }
274 ?> 
275 
276   <input type="hidden" name="server" value="<?php echo $server; ?>"><input type="hidden" name="port" value="<?php echo $port; ?>">
277   <input type="hidden" name="user" value="<?php echo $user; ?>"><input type="hidden" name="password" value="<?php echo $password; ?>">
278   <input type="hidden" name="securityPlugin" value="<?php echo $securityPlugin; ?>">
279 
280 
281   <input type="hidden" name="$publishRes" value="<?php echo $publishRes; ?>">
282 
283  <table border="1">
284   <tr><td class="text">key :</td><td class="text"><input type="text" id='publishKey' name="publishKey" value="<key oid='phpPublish'/>" size="50"></td></tr>
285   <tr><td class="text">content :</td><td class="text"><input type="text" id='publishContent' name="publishContent" value="<?php echo $publishContent; ?>" size="50"></td></tr>
286   <tr><td class="text">qos :</td><td class="text"><input type="text" id='publishQos' name="publishQos" value="&lt;qos/>" size="50"></td></tr>
287   <tr><td class="text">Result :</td><td class="text"><input type="text" id='publishRes' name="publishRes" value="<?php echo $publishRes; ?>" size="50"></td></tr>
288   <tr><td class="text" colspan="2" align="center"><input type="submit" value=" Publish "></td></tr>
289  </table>
290 </form>
291 
292 
293 </body>
294 </html>
295 
296 <?php $xb->logout(); ?>
297 
298 <?php
299 
300 
301 function getHttpVar($name, $defaultVal = null) {
302    // 04/06/02 mad@ktaland.com
303    //global $HTTP_GET_VARS, $HTTP_POST_VARS, $HTTP_SERVER_VARS ;
304    if ($_SERVER['REQUEST_METHOD'] == 'POST') {
305       if (isset ($_POST[$name])) {
306          return $_POST[$name];
307       }
308    } else {
309       if (isset ($_GET[$name])) {
310          return $_GET[$name];
311       }
312    }
313    return $defaultVal;
314 }
315 ?>


syntax highlighted by Code2HTML, v. 0.9.1