Example #1
0
function make_request()
{
    $user = $_GET['login'];
    $password = md5($_GET['password']);
    $packet_id = wddx_packet_start("Authentication Request");
    wddx_add_vars($packet_id, 'user', 'password');
    $packet = wddx_packet_end($packet_id);
    // make a custom POST request to the server with the wddx packet
    return send_request($packet);
}
Example #2
0
 /**
  * create an ini representation of the current config
  *
  * @access	private
  * @param	array	$config		config to serialize
  * @param	array	$options	options for the serialization
  * @return	string	$content	xml representation
  */
 function serializeConfig($config, $options)
 {
     if (!function_exists("wddx_add_vars")) {
         return patErrorManager::raiseError(PATCONFIGURATION_ERROR_DRIVER_NOT_WORKING, "WDDX extension is not installed on your system.");
     }
     if (!isset($options["comment"])) {
         $options["comment"] = "Configuration generated by patConfiguration v" . $this->configObj->systemVars["appVersion"] . ", (c) " . implode(",", $this->configObj->systemVars["author"]);
     }
     $options["comment"] = $this->replaceXMLSpecialchars($options["comment"]);
     $packet_id = wddx_packet_start($options["comment"]);
     foreach ($config as $key => $value) {
         ${$key} = $value;
         wddx_add_vars($packet_id, $key);
     }
     $packet = wddx_packet_end($packet_id);
     $config = "<?xml version=\"1.0\" encoding=\"{$this->configObj->encoding}\"?>" . $packet;
     return $config;
 }
Example #3
0
<?php

//a unix timestamp
$date = "1094095513";
//some data to be included
$books = array('programming' => array('php', 'perl', 'java'), 'markup' => array('UML', 'XML', 'HTML'));
//stick data to an array to iterate over
$data_to_serialize = array($date, $books);
//create the packet
$packet = wddx_packet_start("SOME DATA ARRAY");
//loop through the data
foreach ($data_to_serialize as $key => $data) {
    //create a var whith the name of the content of $key
    ${$key} = $data;
    wddx_add_vars($packet, $key);
}
echo wddx_packet_end($packet);
Example #4
0
<?php

$now = time();
$uptime = `uptime`;
$re = '/^\\s*([0-9]{1,2}:[0-9]{2}(am|pm))\\s+up (.+),\\s+(\\d+) users,\\s+load average: (.+), (.+), (.+)/';
$timestamp = gmdate('Y-m-d H:i:s', $now);
preg_match($re, $uptime, $part);
$uptime = array('time' => $part[1], 'duration' => $part[3], 'users' => (int) $part[4], 'load1' => (double) $part[5], 'load5' => (double) $part[6], 'load15' => (double) $part[7]);
$packet = wddx_packet_start('uptime info');
wddx_add_vars($packet, 'timestamp', 'uptime');
$out = wddx_packet_end($packet);
echo $out;
Example #5
0
<?php

$usuario = array('name' => 'John Q. Public', 'email' => '*****@*****.**', 'account' => array('type' => 'editor', 'scope' => 'global'));
$wddx = wddx_packet_start('Propiedades de usuario');
wddx_add_vars($wddx, 'usuario');
$xml = wddx_packet_end($wddx);
echo $xml;
 function url(&$rq_err, &$out_contenttype, &$out_add_headers)
 {
     global $stats_start, $stats_cnx, $stats_hits, $stats_modlist, $stats_resperr, $stats_vhosts, $stats_xfer, $stats_rej, $remote_ip, $remote_host, $modules, $conf, $logger_pids, $scoreboard, $mypid, $query_string, $htreq_headers, $banned_ips;
     if ($allow = $conf["global"]["statusallowhost"]) {
         for ($a = 0; $a < count($allow); $a++) {
             if (strpos($remote_host, $allow[$a]) !== false || strpos($remote_ip, $allow[$a]) !== false) {
                 $host_allowed = true;
             }
         }
     }
     $t = time();
     if ($host_allowed) {
         $rq_err = 200;
         if ($query_string == "who") {
             $out_contenttype = "text/plain";
             $c = count($scoreboard);
             $s = ($c ? $c : "no") . " active servers";
             $st["status"]["active_servers"] = $c;
             if ($c) {
                 $s .= "\n\n";
                 foreach ($scoreboard as $pid => $st_arr) {
                     $s .= str_pad($pid, 5, " ", STR_PAD_LEFT) . " - " . str_pad($this->ts2str($t - $st_arr[NW_SB_FORKTIME]), 7, " ", STR_PAD_LEFT) . " - " . $st_arr[NW_SB_PEERHOST] . "\n     -> " . $st_arr[NW_SB_STATUS] . "\n";
                     $pst["pid"] = $pid;
                     $pst["peer_host"] = $st_arr[NW_SB_PEERHOST];
                     $pst["status"] = $st_arr[NW_SB_STATUS];
                     $pst["uptime"] = $t - $st_arr[NW_SB_FORKTIME];
                     $st["who"][] = $pst;
                 }
             }
         } else {
             if (is_callable("memory_get_usage")) {
                 $im = memory_get_usage();
                 $um = (int) ($im / 1024) . " KB";
             } else {
                 $um = false;
             }
             $out_contenttype = "text/html";
             $startd = gmdate("D, d M Y H:i:s T", $stats_start);
             $uptime = time() - $stats_start;
             $upstr = $this->ts2str($uptime);
             $nst = nw_server_string();
             $s = "<center>Nanoweb server status module</center><br>";
             $s .= "<br>";
             $s .= "Server  : <b>" . $nst . "</b><br>";
             $s .= "Started : <b>" . $startd . "</b><br>";
             $s .= "Uptime  : <b>" . $upstr . "</b><br>";
             if ($um) {
                 $s .= "Memory  : <b>" . $um . "</b><br>";
             }
             $s .= "<br>";
             $st["status"]["server_string"] = $nst;
             $st["status"]["started_str"] = $startd;
             $st["status"]["uptime_str"] = $upstr;
             $st["status"]["started"] = $stats_start;
             $st["status"]["uptime"] = $uptime;
             if ($im) {
                 $st["status"]["memory_usage"] = $im;
             }
             $acs = count($scoreboard) + 1;
             if (!$conf["global"]["singleprocessmode"][0]) {
                 $s .= "Active servers : <b>" . $acs . "</b>/" . ((int) $conf["global"]["maxservers"][0] ? (int) $conf["global"]["maxservers"][0] : "-") . " (";
                 $st["status"]["active_servers"] = $acs;
                 $st["status"]["max_active_servers"] = (int) $conf["global"]["maxservers"][0];
                 unset($tmp);
                 foreach ($scoreboard as $pid => $dummy) {
                     $tmp[] = $pid;
                 }
                 $tmp[] = $mypid;
                 $s .= implode(" ", $tmp);
                 $st["status"]["servers_pid"] = $tmp;
                 $s .= ")<br>";
             }
             if ($conf["global"]["loggerprocess"][0]) {
                 $acl = count($logger_pids);
                 $s .= "Active loggers : <b>" . $acl . "</b>/" . (int) $conf["global"]["loggerprocess"][0] . " (";
                 $st["status"]["active_loggers"] = $acl;
                 $st["status"]["configured_loggers"] = (int) $conf["global"]["loggerprocess"][0];
                 if ($c = count($logger_pids)) {
                     unset($tmp);
                     while (list($pid, $lgid) = each($logger_pids)) {
                         $tmp[] = "#" . $lgid . "=" . $pid;
                     }
                     $s .= implode(" ", $tmp);
                     $st["status"]["loggers_pid"] = array_keys($logger_pids);
                 }
                 $s .= ")<br>";
             }
             $s .= "<br>";
             $s .= "Total hits/connections : <b>" . ($stats_hits + 1) . "/" . $stats_cnx . "</b> (avg <b>" . sprintf("%.2f", $stats_hits / $uptime * 60) . "</b>/m <b>" . sprintf("%.2f", $stats_hits / $uptime) . "</b>/s)<br>";
             $st["stats"]["total_hits"] = $stats_hits + 1;
             $st["stats"]["total_connections"] = $stats_cnx;
             $s .= "Total sent size        : <b>" . number_format(sprintf("%.1f", $stats_xfer / 1024)) . "</b> KB (avg <b>" . sprintf("%.2f", $stats_xfer / 1024 / $uptime * 60) . "</b> KB/m <b>" . sprintf("%.2f", $stats_xfer / 1024 / $uptime * 8) . "</b> Kbit/s)<br>";
             $st["stats"]["total_sent_bytes"] = $stats_xfer;
             $s .= "<br>";
             if (strpos($query_string, "detailed") !== false) {
                 $s .= "Loaded modules<br><br>";
                 for ($a = 0; $a < count($stats_modlist); $a++) {
                     $s .= str_pad($stats_modlist[$a][0], 18) . " - " . $stats_modlist[$a][1] . "<br>";
                     $mst["module_name"] = $stats_modlist[$a][0];
                     $mst["module_desc"] = $stats_modlist[$a][1];
                     $st["modules"][] = $mst;
                 }
                 $s .= "<br>";
                 $tresp = $stats_resperr;
                 ksort($tresp);
                 $s .= "HTTP responses statistics<br><br>";
                 foreach ($tresp as $key => $val) {
                     $s .= str_pad($GLOBALS["HTTP_HEADERS"][$key], 26) . " : <b>" . $val . "</b><br>";
                     $tst["response_code"] = $key;
                     $tst["hits"] = $val;
                     $st["responses"][] = $tst;
                 }
                 $s .= "<br>";
                 $bln_str = ", " . (int) $stats_rej . " total rejected connections";
                 if (($nbip = count($banned_ips)) == 0) {
                     $s .= "No blocked IP address" . ($nbip > 1 ? "es" : "") . $bln_str . "<br><br>";
                 } else {
                     $s .= $nbip . " blocked IP addresses" . $bln_str . "<br><br>";
                     $s .= "Source               Address          Type (expires)                 Rej<br>-------------------- ---------------- ------------------------------ -------<br>";
                     foreach ($banned_ips as $addr => $bip) {
                         $bip["address"] = $addr;
                         $s .= str_pad($bip["source"], 20) . " " . str_pad($addr, 16) . " " . str_pad($bip["type"] . ($bip["type"] == "TEMP" ? " (" . date("Y-m-d H:i:s", $bip["expires"]) . ")" : ""), 30) . " " . (int) $bip["rejects"] . "<br>";
                         $st["blocked_ips"][] = $bip;
                     }
                     $s .= "<br>";
                 }
             }
             if (strpos($query_string, "vstats") !== false) {
                 $s .= "Virtual hosts statistics<br><br>";
                 $sv = $stats_vhosts;
                 arsort($sv);
                 foreach ($sv as $vh => $hits) {
                     if (!$hmax) {
                         $hmax = $hits or $hmax = 1;
                     }
                     $s .= str_pad(substr($vh, 0, 20), 20, " ", STR_PAD_LEFT) . " " . str_pad("", (int) ($hits / $hmax * 50), "#") . " " . $hits . "<br>";
                     $vst["name"] = $vh;
                     $vst["hits"] = $hits;
                     $st["vhosts"][] = $vst;
                 }
                 $s .= "<br>";
             }
             $s .= "<center>The server is working properly</center>";
             if (strpos($htreq_headers["USER-AGENT"], "Lynx") === 0) {
                 $out_contenttype = "text/plain";
                 $s = strip_tags(str_replace("<br>", "\n", $s));
             }
         }
     } else {
         // Return 403 Forbidden if hit is not coming from allowed host
         $rq_err = 403;
         $s = "no access";
     }
     if (strpos($query_string, "php-serialize") !== false) {
         $out_contenttype = "text/plain";
         $s = serialize($st);
     } else {
         if (strpos($query_string, "wddx") !== false) {
             if (is_callable("wddx_packet_start")) {
                 $wd = wddx_packet_start("nanoweb mod_status");
                 wddx_add_vars($wd, "st");
                 $s = wddx_packet_end($wd);
             } else {
                 $s = "wddx support not built in PHP";
             }
         } else {
             if (strpos($query_string, "xml") !== false) {
                 $out_contenttype = "text/xml";
                 $s = $this->arr_to_xml($st, "nanoweb_mod_status");
             }
         }
     }
     return $s;
 }
<?php

$pkt = wddx_packet_start('TEST comment');
$var1 = NULL;
$var2 = 'some string';
$var3 = 756;
$var4 = true;
// add vars to packet
wddx_add_vars($pkt, 'var1', 'var2', array('var3', 'var4'));
echo wddx_packet_end($pkt);
Example #8
0
<?php

// Our assoc array
$talk = array('id' => 4, 'title' => 'Dynamic Images in PHP - How and When to Use Them', 'date' => '2002-04-29', 'speaker' => 'Alison Gianotto', 'url' => 'http://www.sdphp.net/talks/ag_image');
// we can serialize the value and
// create the packet in one step
$ser1 = wddx_serialize_vars('talk');
echo format_packet($ser1, 'In one step');
// or we could serialize it in several steps
$packet = wddx_packet_start("One of Alison's talks at SDPHP");
wddx_add_vars($packet, 'talk');
$ser2 = wddx_packet_end($packet);
echo format_packet($ser2, 'Making the packet by hand');
// now let's deserialize the packet
$vars = wddx_deserialize($ser2);
echo "<pre>\n<small>\n";
print_r($vars);
echo "</small>\n</pre>\n";
function format_packet($pckt, $title = 'wddx packet')
{
    $re = '/^[^<]/';
    $pckt = str_replace('>', ">\n", $pckt);
    $t = explode("\n", $pckt);
    $s = "[ {$title} ]<br>\n<pre>\n";
    foreach ($t as $line) {
        if (trim($line) == '') {
            continue;
        } elseif (preg_match($re, $line)) {
            $tmp = explode("\n", str_replace('<', "\n<", $line));
            $s .= ' <span style="color: blue;">' . $tmp[0] . "</span>\n" . htmlspecialchars($tmp[1]) . "\n";
        } else {
Example #9
0
<?php

class foo
{
    var $bar;
    function foo()
    {
        $this->bar = 1;
    }
}
$a = 1;
$b = array(1, 2, 3);
$c = new foo();
// create a new wddx packet, with description
$p_id = wddx_packet_start("My PHP Packet");
// append variables to wddx packet
wddx_add_vars($p_id, 'a', 'b', 'c');
// finalize & serialize the packet
$wddx_packet = wddx_packet_end($p_id);
echo $wddx_packet;
Example #10
0
<?php

$allowed_users = array('ilia' => '0b2c539c3e7f85d808df3f2dfe8906b9', 'derick' => 'ad0234829205b9033196ba818f7a872b', 'sterling' => '8ad8757baa8564dc136c1e07507f4a98');
if (isset($HTTP_RAW_POST_DATA)) {
    $data = wddx_deserialize($HTTP_RAW_POST_DATA);
    if (isset($allowed_users[$data['user']])) {
        if ($allowed_users[$data['user']] !== $data['password']) {
            $error = 2;
            $error_str = "Invalid Password for specified account";
            $login = FALSE;
        } else {
            $login = TRUE;
            $error = $error_str = NULL;
        }
    } else {
        $error = 1;
        $error_str = "Invalid Login Name";
        $login = FALSE;
    }
} else {
    $error = 3;
    $error_str = "No Input.";
    $login = FALSE;
}
$packet_id = wddx_packet_start("Authentication Response");
wddx_add_vars($packet_id, 'login', 'error', 'error_str');
echo wddx_packet_end($packet_id);