added license.txt, distributed upload/dl support

This commit is contained in:
sandb
2009-12-29 13:54:46 +01:00
parent 6d1ca9cf1e
commit 5e8657def5
5 changed files with 933 additions and 0 deletions

74
lib/upload.php Normal file
View File

@@ -0,0 +1,74 @@
<?php
/*
Copyright 2009 Pieter Iserbyt
This file is part of Pamela.
Pamela is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Pamela is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Pamela. If not, see <http://www.gnu.org/licenses/>.
*/
header("Content-type: text/plain");
require_once("../config.php");
require_once("util.php");
function echoln($str) {
echo("$str\n");
}
class Upload {
private $subnet;
private $macs;
function __construct() {
$this->subnet = intvaldef(getQuery("sn"), NULL);
$this->macs = getQuery("macs");
}
private function parseAndValidate() {
if ($this->subnet == NULL) {
echoln("Missing or bad sn param");
return false;
}
if ($this->macs == NULL) {
echoln("Missing macs param");
return false;
}
if (($this->subnet < 0) || ($this->subnet > 4294967295)) {
echoln("subnet ($this->subnet) is not valid");
return false;
}
$mcs = explode('|', $this->macs);
foreach($mcs as $mac) {
if (preg_match("/^(([\dABCDEF]){2}:){5}([\dABCDEF]){2}$/i", $mac) == 1)
continue;
echoln("mac $mac is not in the right format");
return false;
}
return true;
}
private function writeMacs() {
file_put_contents(OUTPUT_SERVER_DIRECTORY."/$this->subnet.macs", $this->macs);
}
public function run() {
$this->parseAndValidate();
$this->writeMacs();
}
}
$upload = new Upload();
$upload->run();

98
lib/util.php Normal file
View File

@@ -0,0 +1,98 @@
<?php
/*
Copyright 2009 Pieter Iserbyt
This file is part of Pamela.
Pamela is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Pamela is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Pamela. If not, see <http://www.gnu.org/licenses/>.
*/
/* Converts value to int if it is numeric, else returns default */
function intvaldef($value, $default) {
if (is_numeric($value)) return intval($value);
return $default;
}
/* Checks if a $_GET param is set and returns it or NULL if it's not set */
function getQuery($name, $default = NULL) {
if (!querySet($name)) return $default;
return unescape_gpc($_GET[$name]);
}
/* Returns TRUE if a $_GET param is set */
function querySet($name) {
return isset($_GET[$name]);
}
/* Checks if a $_POST param is set and returns it or NULL if it's not set */
function getPost($name, $default = NULL) {
if (!postSet($name)) return $default;
return unescape_gpc($_POST[$name]);
}
function unescape_gpc_array($a) {
$result = array();
foreach ($a as $key => $value) {
$result[$key] = unescape_gpc($value);
}
return $result;
}
/* Returns TRUE if a $_POST param is set */
function postSet($name) {
return isset($_POST[$name]);
}
/* array_map_function used to recursively stripslashes by unescape_gpc */
function stripslashes_deep($value) {
return is_array($value) ? array_map('stripslashes_deep', $value) : stripslashes($value);
}
/* Unescapes get/post/cookie vars/arrays if magic_quotes_gpc is turned on */
function unescape_gpc($gpc) {
if (get_magic_quotes_gpc()) {
//unescape recursively if needed
$gpc = is_array($gpc) ? array_map('stripslashes_deep', $gpc) : stripslashes($gpc);
}
return $gpc;
}
/*
stripos implementation for php4 (by "heavyraptor")
http://be.php.net/manual/en/function.stripos.php#63370
*/
if (!function_exists("stripos")) {
function stripos($str,$needle) {
return strpos(strtolower($str),strtolower($needle));
}
}
/* Redirects to sender */
function redirectToSender() {
$url = $_SERVER["HTTP_REFERER"];
header("Location: $url");
}
/* Returns the name of current page */
function currentPage() {
return basename($_SERVER['PHP_SELF']);
}
/** outputs include for script in head */
function script($source) {
?>
<script type="text/javascript" src="<?=$source?>"></script>
<?php
}
?>