Ejemplo n.º 1
0
function redirect($url)
{
    if (headers_sent()) {
        echo '<script type="text/javascript">window.location.href="' . lnk($url) . '";</script>';
        return;
    }
    header('Location: ' . lnk($url));
}
Ejemplo n.º 2
0
function page($text, $link)
{
    global $page;
    //far away from perfect but better than nothing!
    //  if(!ereg("^A-Za-z0-9_-]+$",$link)){ echo "Nice try !"; exit();}
    if ($link == $page) {
        ?>
<li><span class="selected-menu"><?php 
        echo $text;
        ?>
</span></li>
<?php 
    } else {
        lnk($text, $link . ".html");
    }
}
Ejemplo n.º 3
0
$result['bloom']['insert']['time'] = $stat['bloom']['insert']['e']['timestamp'] - $stat['bloom']['insert']['s']['timestamp'];
$result['foe']['insert']['time'] = $stat['foe']['insert']['e']['timestamp'] - $stat['foe']['insert']['s']['timestamp'];
$result['bloom']['insert']['mem'] = $stat['bloom']['insert']['e']['memory'] - $stat['bloom']['insert']['s']['memory'];
$result['foe']['insert']['mem'] = $stat['foe']['insert']['e']['memory'] - $stat['foe']['insert']['s']['memory'];
$result['bloom']['has']['time'] = $stat['bloom']['has']['e']['timestamp'] - $stat['bloom']['has']['s']['timestamp'];
$result['foe']['has']['time'] = $stat['foe']['has']['e']['timestamp'] - $stat['foe']['has']['s']['timestamp'];
$result['bloom']['has']['mem'] = $stat['bloom']['has']['e']['memory'] - $stat['bloom']['has']['s']['memory'];
$result['foe']['has']['mem'] = $stat['foe']['has']['e']['memory'] - $stat['foe']['has']['s']['memory'];
$result['bloom']['total']['time'] = $result['bloom']['insert']['time'] + $result['bloom']['has']['time'];
$result['foe']['total']['time'] = $result['foe']['insert']['time'] + $result['foe']['has']['time'];
$result['bloom']['total']['mem'] = $result['bloom']['insert']['mem'] + $result['bloom']['has']['mem'];
$result['foe']['total']['mem'] = $result['foe']['insert']['mem'] + $result['foe']['has']['mem'];
echo '# <a href="https://github.com/mrspartak/php.bloom.filter" target="_blank">My Bloom</a> VS <a href="https://github.com/taskaz/labloom">Foe Bloom</a>', NL;
echo NL, '<strong>###########</strong>', NL;
echo 'Current number of objects: ' . $number . ', number of check objects: ' . count($check), NL;
echo 'Choose number of objects: ', lnk(100), lnk(1000), lnk(10000), NL;
echo '<strong>## Setting ##</strong>', NL;
echo 'Bloom time: ' . $result['bloom']['insert']['time'] . ' sec.', NL;
echo 'Foe time: ' . $result['foe']['insert']['time'] . ' sec.', NL;
echo advantage($result['bloom']['insert']['time'] / $result['foe']['insert']['time']), NL;
echo 'Bloom memory: ' . $result['bloom']['insert']['mem'] . ' bytes.', NL;
echo 'Foe memory: ' . $result['foe']['insert']['mem'] . ' bytes.', NL;
echo advantage($result['bloom']['insert']['mem'] / $result['foe']['insert']['mem']), NL, NL;
echo '<strong>## Checking ##</strong>', NL;
echo 'Bloom time: ' . $result['bloom']['has']['time'] . ' sec.', NL;
echo 'Foe time: ' . $result['foe']['has']['time'] . ' sec.', NL;
echo advantage($result['bloom']['has']['time'] / $result['foe']['has']['time']), NL;
echo 'Bloom memory: ' . $result['bloom']['has']['mem'] . ' bytes.', NL;
echo 'Foe memory: ' . $result['foe']['has']['mem'] . ' bytes.', NL;
echo advantage($result['bloom']['has']['mem'] / $result['foe']['has']['mem']), NL, NL;
echo '<strong>## Total ##</strong>', NL;
Ejemplo n.º 4
0
        if (!$id) {
            $id = 1;
        }
        $content = file_get_contents("php://input");
        global $db;
        $q = $db->prepare("INSERT INTO reports (RID, DID, Content) VALUES (:report_id, :device_id, :content)");
        if (!$q->execute(array(":report_id" => $id, ":device_id" => $device_id, ":content" => $content))) {
            return error("failure", "Failed to post the report.");
        }
        // REPLY / RENDER //
        REST::response_code("created");
        header('Location: ' . lnk("/reports/{$id}"));
        if (!REST::preferred("text/html")) {
            return success("Successfully posted the report.");
        } else {
            echo '<script type="text/javascript">window.location.href="' . lnk("/reports/{$id}") . '"</script>"';
        }
    } else {
        return error("bad-method", "Unsupported HTTP Method");
    }
}
handle_item_commands:
if (count(REST::$ARGS) == 3 && REST::$ARGS[2] == "commands") {
    if (REST::$REQUEST_METHOD == "GET") {
        $device_id = REST::$ARGS[1];
        if (isset($_REQUEST["since"])) {
            $since = $_REQUEST["since"];
        } else {
            $since = false;
        }
        $args = array(":device_id" => $device_id);
Ejemplo n.º 5
0
<?php

global $command;
if (REST::$REQUEST_METHOD == "POST") {
    $data = json_encode(array($_REQUEST["address"], $_REQUEST["count"], $_REQUEST["interval"], $_REQUEST["ttl"]));
    return $data;
}
?>

<div class="main">
	<form action="<?php 
echo lnk("/commands/" . $command["slug"]);
?>
" method="POST" class="container">
		<div class="title">
			Command: <?php 
echo $command["name"];
?>
		</div>

		<input type="hidden" name="command" value="<?php 
echo $command["slug"];
?>
" />
		<?php 
if (isset($_REQUEST["device"])) {
    //#!!! XSS
    ?>
			<input type="hidden" name="device_id" value="<?php 
    echo $_REQUEST["device"];
    //#!!! XSS
Ejemplo n.º 6
0
        ?>
/" + id + "/exists", function(content) {
				report.style.display = (content == "true")? "block" : "none";
			});

			call("<?php 
        echo lnk("/reports");
        ?>
/" + id + "/date",
				function(content){
					var date = Date.from_mysql(content);
					report_date.innerHTML = date.toLocaleString() + " &nbsp; (" + new Date(new Date() - date).inWords() + " ago)";
				}
			);
			call("<?php 
        echo lnk("/reports");
        ?>
/" + id + "/content", function(content){
				report_content.innerHTML = content;
			});
		}

		window.update_report = function() {
			show_report(document.getElementById("report_selection").value);
		};
		window.update_report();
	}())
	</script>

	<?php 
    }
Ejemplo n.º 7
0
            $device["lastheard"] = "Never";
            $device["reportcount"] = 0;
        } else {
            $device["lastheard"] = $report_info[0]["lastheard"];
            $device["reportcount"] = $report_info[0]["count"];
        }
        ?>

			<li id="device-<?php 
        echo $device["id"];
        ?>
" class="device">
				<div class="device-info">
					<div class="device-name title">
						<a href="<?php 
        echo lnk("/devices/" . $device["id"]);
        ?>
"><?php 
        echo $device["name"];
        ?>
</a></div>
					<div class="device-address">
						<span class="data-label">IP</span>
						<span class="data-value"><?php 
        echo $device["address"];
        ?>
</span>
					</div>
					<div class="device-lastheard">
						<span class="data-label">Last heard</span>
						<span class="data-value"><?php 
Ejemplo n.º 8
0
				</div>

				<ul class="unstyled info-list">
					<li class="report-id">
						<span class="data-label">Report id:</span>
						<span class="data-value"><b><?php 
            echo $report["id"];
            ?>
</b></span>
					</li>

					<li class="report-device">
						<span class="data-label">Device name:</span>
						<span class="data-value">
							<a href="<?php 
            echo lnk("/devices/" . $report["device_id"]);
            ?>
">
								<?php 
            echo $report["device_name"];
            ?>
							</a>
						</span>
					</li>

					<li class="report-absolute-date">
						<span class="data-label">Timestamp:</span>
						<span class="data-value"><?php 
            echo $report["timestamp"];
            ?>
</span>
Ejemplo n.º 9
0
        }
        if (!$authorized) {
            return error(401, "Unauthorized!");
        }
        // POST //
        $query = REST::$ARGS[1];
        global $command;
        $command = false;
        foreach ($commands as $cmd) {
            if ($cmd["slug"] == $query) {
                $command = $cmd;
                break;
            }
        }
        if (!$command) {
            return error("not-found", "Command not found.");
        }
        $cmd = $command["slug"];
        $data = (include $command["view"]);
        global $db;
        $q = $db->prepare("INSERT INTO commands (DID, Command, Data) VALUES (:device_id, :cmd, :data)");
        if (!$q->execute(array(":device_id" => $device_id, ":cmd" => $cmd, ":data" => $data))) {
            return error("failure", "Failed to issue command.");
        }
        success("Successfully issued command.");
        echo '<div class="container"><div class="alert alert-info"><a href="' . lnk("/devices/" . $device_id) . '">Back to device info</a></div></div>';
        exit;
    } else {
        return error("bad-method", "Unsupported HTTP Method");
    }
}