Exemplo n.º 1
0
function readJsonsFile($file)
{
    // It's dead, jim? TODO: FIXME: IMPORTANT?
    // Reads file, strips comments and other non-json stuff, json_decodes it -> Returns a json STRING not an object
    $jsons = fr($file);
    if (!$jsons) {
        return false;
    }
    $linebreaks = goFigureLinebreaks($jsons);
    $jsonslines = explode($linebreaks, $jsons);
    $newjsonslines = array();
    foreach ($jsonslines as $linenum => $line) {
        // remove comments > everything after // is removed
        $comment_pos = strpos($line, "//");
        if ($comment_pos !== FALSE) {
            $line = substr($line, 0, $comment_pos);
            $line = str_replace("  ", " ", $line);
            if ($line == "" || $line == " ") {
                continue;
            }
        }
        // remove/skip tabs
        $line = str_replace("\t", "", $line);
        // remove/skip empty lines
        $line = str_replace("  ", " ", $line);
        if (!$line) {
            continue;
        }
        // store line
        $newjsonslines[] = $line;
    }
    $newjsons = implode($linebreaks, $newjsonslines);
    return $newjsons;
}
Exemplo n.º 2
0
function sqldumptable($table, $fp = 0)
{
    $tabledump = "DROP TABLE IF EXISTS {$table};\n";
    $tabledump .= "CREATE TABLE {$table} (\n";
    $firstfield = 1;
    $fields = q("SHOW FIELDS FROM {$table}");
    while ($field = mysql_fetch_array($fields)) {
        if (!$firstfield) {
            $tabledump .= ",\n";
        } else {
            $firstfield = 0;
        }
        $tabledump .= "   {$field['Field']} {$field['Type']}";
        if (!empty($field["Default"])) {
            $tabledump .= " DEFAULT '{$field['Default']}'";
        }
        if ($field['Null'] != "YES") {
            $tabledump .= " NOT NULL";
        }
        if ($field['Extra'] != "") {
            $tabledump .= " {$field['Extra']}";
        }
    }
    fr($fields);
    $keys = q("SHOW KEYS FROM {$table}");
    while ($key = mysql_fetch_array($keys)) {
        $kname = $key['Key_name'];
        if ($kname != "PRIMARY" && $key['Non_unique'] == 0) {
            $kname = "UNIQUE|{$kname}";
        }
        if (!is_array($index[$kname])) {
            $index[$kname] = array();
        }
        $index[$kname][] = $key['Column_name'];
    }
    fr($keys);
    while (list($kname, $columns) = @each($index)) {
        $tabledump .= ",\n";
        $colnames = implode($columns, ",");
        if ($kname == "PRIMARY") {
            $tabledump .= "   PRIMARY KEY ({$colnames})";
        } else {
            if (substr($kname, 0, 6) == "UNIQUE") {
                $kname = substr($kname, 7);
            }
            $tabledump .= "   KEY {$kname} ({$colnames})";
        }
    }
    $tabledump .= "\n);\n\n";
    if ($fp) {
        fwrite($fp, $tabledump);
    } else {
        echo $tabledump;
    }
    $rows = q("SELECT * FROM {$table}");
    $numfields = mysql_num_fields($rows);
    while ($row = mysql_fetch_array($rows)) {
        $tabledump = "INSERT INTO {$table} VALUES(";
        $fieldcounter = -1;
        $firstfield = 1;
        while (++$fieldcounter < $numfields) {
            if (!$firstfield) {
                $tabledump .= ", ";
            } else {
                $firstfield = 0;
            }
            if (!isset($row[$fieldcounter])) {
                $tabledump .= "NULL";
            } else {
                $tabledump .= "'" . mysql_escape_string($row[$fieldcounter]) . "'";
            }
        }
        $tabledump .= ");\n";
        if ($fp) {
            fwrite($fp, $tabledump);
        } else {
            echo $tabledump;
        }
    }
    fr($rows);
    if ($fp) {
        fwrite($fp, "\n");
    } else {
        echo "\n";
    }
}
Exemplo n.º 3
0
<?php

include "../s.functions.php";
header("Content-Type: text/plain");
header("Access-Control-Allow-Origin: *");
$fr = fr("log.txt");
echo $fr;
Exemplo n.º 4
0
 $jsons = json_encode($json);
 $fw = fw($path_jsons, $jsons);
 // auth json..
 $path_auth_jsons = "data/data_authkeys.json";
 // check vars
 if (!$nfcpyr_id) {
     error("_GET[nfcpyr_id] not provided");
 }
 if (!$nfcpyr_user) {
     error("_GET[nfcpyr_user] not provided");
 }
 if (!$nfcpyr_pass) {
     error("_GET[nfcpyr_pass] not provided");
 }
 // get json
 $jsons = fr($path_auth_jsons);
 if (!$jsons) {
     $jsons = "[]";
 }
 $json = json_decode($jsons, true);
 // -> find user + id
 foreach ($json as $entry) {
     if ($entry["id"] == $nfcpyr_id && $entry["user"] == $nfcpyr_user) {
         error("Authkey for user and/or id already exists");
     }
 }
 // do
 $newentry = array();
 $newentry["id"] = $nfcpyr_id;
 $newentry["user"] = $nfcpyr_user;
 $newentry["pass"] = $nfcpyr_pass;
Exemplo n.º 5
0
function sqldumptable($table, $fp = 0)
{
    global $mysqllink;
    $tabledump = "DROP TABLE IF EXISTS `{$table}`;\n";
    $res = q("SHOW CREATE TABLE {$table}");
    $create = mysql_fetch_row($res);
    $tabledump .= $create[1] . ";\n\n";
    if ($fp) {
        fwrite($fp, $tabledump);
    } else {
        echo $tabledump;
    }
    $tabledump = '';
    $rows = q("SELECT * FROM {$table}");
    while ($row = mysql_fetch_assoc($rows)) {
        foreach ($row as $k => $v) {
            $row[$k] = "'" . @mysql_real_escape_string($v) . "'";
        }
        $tabledump = 'INSERT INTO `' . $table . '` VALUES (' . implode(", ", $row) . ');' . "\n";
        if ($fp) {
            fwrite($fp, $tabledump);
        } else {
            echo $tabledump;
        }
    }
    fwrite($fp, "\n\n");
    fr($rows);
}
Exemplo n.º 6
0
<?php

include "s.functions.php";
// Read data
$jsons = fr("../../api/data/analytics.json");
$json = json_decode($jsons, true);
$data = array();
$data["byid"] = array();
$data["byversion"] = array();
$data["bymodel"] = array();
$data["byplatform"] = array();
$data["installgraph"] = array();
foreach ($json as $jsonk => $jsonv) {
    $newid = false;
    // By id
    $id = $jsonv["id"];
    if (!$data["byid"][$id]) {
        $data["byid"][$id] = $jsonv;
        $data["byid"][$id]["entries"] = 1;
        $newid = true;
    } else {
        $data["byid"][$id]["entries"]++;
    }
    // By version
    $version = $jsonv["app_version"];
    if (!$data["byversion"][$version]) {
        $data["byversion"][$version] = array();
        $data["byversion"][$version]["ids"][] = $id;
        $data["byversion"][$version]["datas"][] = $jsonv;
        $data["byversion"][$version]["entries"] = 1;
    } else {
Exemplo n.º 7
0
     break;
 case "station_icon":
     // NOTE: does not return json, it returns http responses! // TODO: yes?
     $filename = $_FILES['file']['name'];
     $filepath = "../static/uploaded/{$filename}";
     $filetmp = $_FILES['file']['tmp_name'];
     /*
                     // redundant check. this is easily faked..
     				$postkey = $_POST["key"];
     				$getkey = $queryobj["key"];
     				if ($postkey!=$getkey) {
     					http_response_code(403);
     					error("Access denied'");
     				}
                     /**/
     $devicess = fr("data/deviceids.json");
     $devices = json_decode($devicess, true);
     if (!in_array($queryobj["device"], $devices)) {
         http_response_code(403);
         error("Access denied'");
     }
     $moved = move_uploaded_file($filetmp, $filepath);
     if (!$moved) {
         http_response_code(500);
         error("Could not move file '{$filetmp}' to '{$filepath}'");
     } else {
         http_response_code(200);
         echo json_encode(array("info" => array(), "data" => array("post" => "ok", "filename" => $filename)));
     }
     break;
     // default
Exemplo n.º 8
0
	if ($lastdevice != $deviceId) { $res .= "<tr><td>&nbsp;</td></tr>\n\n"; $newdevice = true; }
	$lastdevice = $deviceId;
	
	// Find device name
	foreach ($byDeviceId as $file) {
	
		$path = "html/".$file;
		
		$filemtime = @filemtime($path);
		$date = date("Y-m-d H:i:s",$filemtime);
		$date_short = date("m-d H:i",$filemtime);
		
		if ($newdevice) {
		
			$fr = fr($path);
			$lines = explode("\n",$fr);
			
			foreach($lines as $line) {
				if (strpos($line,"Device Info")!==FALSE) {
					break;
				}
			}
			
		}
		
		$res .= "<tr><td>{$date_short}&nbsp;&nbsp;&nbsp;</td><td><a title='$date' href='{$path}'>$file</a></td><td>&nbsp;&nbsp;{$line}</td></tr>\n";
		
		$newdevice = false;
		
	}
Exemplo n.º 9
0
$force = $_GET["force"]; // ignore errors;

// ----------------------------------------------------------------------------
	
// File name + extension
$imgName = substr($imgFile, strrpos($imgFile,"/")+1);
$imgSrcExtension = strtolower(substr($imgFile, strrpos($imgFile,".")+1));

// Check Cache
if ($cfg["cacheEnabled"]) { 
	
	// Check if image is available from cache, if so: show it
		$imgCache = cache_load($imgFile, $thWidth, $thHeight); 
		if ($imgCache) { //header("location: $imgCache");
			$content = fr($imgCache);
			if (strtolower($imgSrcExtension)=="jpg") { $type = "jpeg"; }
			else { $type = strtolower($imgSrcExtension); }
			header("Content-Disposition: filename=\"{$imgName}\"");
			header("Content-type: image/{$type}");
			echo $content;
			setIdle();
			die();
			}
		
	}

// Handle if image is located on remote server
if ($imgIsRemote) {
	
	// It is: attempt to download to local server
Exemplo n.º 10
0
    fr('First Name', '<input type="text" name="first_name" value="" size="50" maxlength="60"  />', 'Enter your first name.  Maximum 20 characters.');
    fr('Last Name', '<input type="text" name="last_name" value="" size="50" maxlength="60"  />', 'Enter your last name.  Maximum 20 characters.');
    fr('Contact Phone Number', '<input type="text" name="phone" value="" size="30" maxlength="30"  />', 'Enter a phone number where we can contact you, including your direct extensions.');
    fr('Mailing Address', '<textarea name="addr" cols=50 rows=4></textarea>', 'Enter your mailing address here.');
    fr('How did you hear about us?', '
			<input type=radio name=hear value="participant" > Participated before<br>
			<input type=radio name=hear value="deloitte" > Deloitte<br>
			<input type=radio name=hear value="scholastic" > Scholastic<br>
			<input type=radio name=hear value="card" > Holiday card<br>
			<input type=radio name=hear value="press" > Press<br>
			<input type=radio name=hear value="teacher" > Teacher<br>
			<input type=radio name=hear value="friend" > Friend<br>
			<input type=radio name=hear value="other"> Other (type into the box below)<br>
			', 'Other: <input type=text name=hear_other size=50 axlength="255">');
    fr('', '&nbsp;');
    fr('', '<p><input type="submit" value="Next" alt="Continue"/>');
    /*fr('', '<font color=#aa0000><b>
    		By clicking this button,
    		I agree that I will distribute the parental
    		consent form after I have registered all participants in the
    		Virtual Team Challenge.
    		</b></font><p><input type="submit" value="I Agree" alt="Continue"/>');*/
    ?>

    </table>

  </form>
<?php 
}
?>
Exemplo n.º 11
0
function cache_log($txt)
{
    if (file_exists("cache/cacheDbg.txt")) {
        if (@filesize("cache/cacheDbg.txt") > 2 * 1024 * 1024) {
            @unlink("cache/cacheDbg.txt");
            cache_log("-- CLEAN LOG");
        }
        $log = fr("cache/cacheDbg.txt");
    }
    $log = date("Y-m-d H:i:s") . " :: {$txt}\r\n" . $log;
    fw("cache/cacheDbg.txt", $log);
}
Exemplo n.º 12
0
				//$json["data"] = json_decode($json["data"],true);
				$json["info"]["last_update_time_ms"] = filemtime($filename)*1000; // TODO: More info?
				$json["info"]["last_update_timeago_sec"] = time() - filemtime($filename);
				$json["info"]["last_update_date"] = date("Y-m-d H:i:s",filemtime($filename));
				$json["info"]["desc"] = $queryobj["get"];
				$jsons = json_encode($json);
				$jsons = gzencode($jsons);
				header('Content-Encoding: gzip');
				echo $jsons;
				break;
				
			// station_nowplaying
			case "station_nowplaying":
				if (!$queryobj["station_id"]) { error("Error: 'station_id' not defined for get:station_info"); }
				$filename = "../json/station_nowplaying.".$queryobj["station_id"].".json";
				$json["data"] = fr($filename);
				if (!$json["data"]) { error("Error: file '$filename' not found"); } // TODO: Generate file :D
				//$json["data"] = json_decode($json["data"],true);
				$json["info"]["last_update_time_ms"] = filemtime($filename)*1000; // TODO: More info?
				$json["info"]["desc"] = $queryobj["get"];
				$jsons = gzencode(json_encode($json));
				header('Content-Encoding: gzip');
				echo $jsons;
				break;
			
			// checkforupdates
			case "checkforupdates":
				if (!$queryobj["lookup"]) { error("Error: 'lookup' not defined for get:checkforupdates"); }
				if (!$queryobj["last_update_time_ms"]) { error("Error: 'last_update_time_ms' not defined for get:checkforupdates"); }
				if (!file_exists("../json/".$queryobj["lookup"].".json")) { error("Error: invalid lookup '".$queryobj["lookup"]."', file not found"); }
				$filemtime_ms = @filemtime("../json/".$queryobj["lookup"].".json")*1000;
Exemplo n.º 13
0
<?php

include "s.functions.php";
$data_stations_urls = array();
$data_stations_urls_count = array();
$data_stations = array();
$data_station = array();
$device_ids = array();
$path_stations = "../../api/stations_users/";
$path_station = "../../api/station_users/";
$files_stations = rd($path_stations);
$files_station = rd($path_station);
// Get stations, remove duplicates
foreach ($files_stations as $file_stations) {
    $jsons_stations = fr($path_stations . $file_stations);
    $json_stations = json_decode($jsons_stations, true);
    if (!$json_stations) {
        continue;
    }
    $file_nameparts = explode("_", $file_stations);
    $device_id = $file_nameparts[1];
    foreach ($json_stations as $station) {
        if (!in_array($station["station_url"], $data_stations_urls)) {
            $data_stations_urls_count[$station["station_url"]]++;
            $data_stations_urls[] = $station["station_url"];
            $data_stations[] = $station;
            $device_ids[] = $device_id;
        } elseif (!in_array($device_id, $device_ids)) {
            $data_stations_urls_count[$station["station_url"]]++;
        }
    }
Exemplo n.º 14
0
    }
    $config .= "--cfgArrayName--[\"cfgArrayName\"] = \"{$cfgArrayName}\";\n";
    $config .= "\n\n?>";
    $config = str_replace("\n", "\r\n", $config);
    $config = str_replace("--cfgArrayName--", "\${$cfgArrayName}", $config);
    $config = stripslashes($config);
    $fw = fw($configfile, $config);
    if ($fw) {
        header("location: rgConfigEdit.php?file={$configfile}");
    } else {
        die("Error accured?<br><a href='javascript:history.back(1)'>Back</a>");
    }
    die;
}
// ---------------------------------------------
$config = fr($configfile);
$strStart = 1;
$strEnd = 0;
$strLen = 0;
$whileInt = 0;
while ($strStart > 0) {
    $key = "";
    $val = "";
    if ($strStart > strlen($config)) {
        $strStart = -1;
        continue;
    }
    $whileInt++;
    if ($whileInt > 256) {
        $strStart = -1;
        continue;