forked from anthillsocial/leaflet-multi-map
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.php
executable file
·126 lines (114 loc) · 3.4 KB
/
utils.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<?php
$IParray = array(
"127.0.0.1", "217.44.122.166","218.44.122.166","86.153.161.219", "217.44.120.135", "81.2.68.178", "217.42.187.243", "158.223.71.200", "86.153.148.146", "94.170.105.61", "46.65.216.68", "213.104.159.16"
);
//$jsonfile = realpath(dirname(".")).'/../config/allphones.json';
$jsonfile = '/home/data/localhost/htdocs/drupal7/sites/transport.yoha.co.uk/leaflet-multi-map/config/allphones.json';
$phoneconfig = json_decode(file_get_contents($jsonfile));
$humanuuid = $phoneconfig->phonename;
//print_r($humanuuid);
// Now lets sort permissions
$IP = $_SERVER['REMOTE_ADDR'];
if(in_array($IP, $IParray)){
define("ISADMIN", true);
}else{
define("ISADMIN", false);
}
// Give human names to the phones
/*
$humanuuid = array(
'287BE0FC-A3BC-4FE1-94C0-5A8FB42167FE' =>"Toms Iphone",
'683c1fef2ba40248'=>"TK Android",
'c8f95d649cd7addd'=>"GF Android",
'aaf09baa1477949'=>"Grahams Android"
);
*/
/*
* Helper function to log output
*
*/
function lmm_checkisset($var, $default){
if(isset($var)) return $var;
else return $default;
}
/*
* Helper function to log output
*
*/
/*
function lmm_logoutput($status){
$msg = strftime('%c')."\n$status\n";
// Prep the vars
$msg = "$status [GETVARS] ";
foreach($_GET as $key=>$value){
$msg .= "$key=$value | ";
}
//$msg .= " [POSTVARS]";
//foreach($_POST as $key=>$value){
// $msg .= "$key=$value | ";
//}
//$msg .= " [SERVERVARS]";
//foreach($_SERVER as $key=>$value){
// $msg .= "$key=$value\n";
//}
/*$postvars = lmm_checkPOSTGETvar('vars', NULL, 'POST');
$vars = json_decode($postvars);
$msg .= 'Title:'.$vars->track->title."\n";
$msg .= 'author:'.$vars->track->author."\n";
$msg .= 'starttime:'.$vars->track->starttime."\n";
$msg .= 'endtime:'.$vars->track->endtime."\n";
$msg .= 'name:'.$vars->track->device->name."\n";
$msg .= 'cordova:'.$vars->track->device->cordova."\n";
$msg .= 'platform:'.$vars->track->device->platform."\n";
$msg .= 'version:'.$vars->track->device->version."\n";
$msg .= 'uuid:'.$vars->track->device->uuid."\n";
// /*
// Write to file
$logpath = "/var/www/localhost/htdocs/drupal7/sites/transport.yoha.co.uk/leaflet-multi-map/map-live/log.txt";
$f = fopen($logpath, 'a') or die(" can't open file");
fwrite($f, "\n$msg\n\n");
fclose($f);
}
*/
/*
* Check if POST/GET variable is set and asign default value
*/
function lmm_checkPOSTGETvar($key, $defaultvalue, $GETPOST="GET+POST"){
if($GETPOST=='GET' || $GETPOST=='GET+POST'){
if(isset($_GET[$key])) return lmm_checkInput($_GET[$key]);
}
if($GETPOST=='POST' || $GETPOST=='GET+POST'){
if(isset($_POST[$key])) return lmm_checkInput($_POST[$key]);
}
return $defaultvalue;
}
/*
* Write data to the begining of a file
*/
function lmm_write_to_file($str, $filename){
if(!file_exists ($filename )){
$fp = fopen($filename,"w");
fwrite($fp, '');
fclose($fp);
}
// Read & save old contents
$old = file_get_contents($filename);
// Open the file & write to it
$fp = fopen($filename,"w");
if(!$fp) return "Can't save string to file";
else fwrite($fp, $str.$old);
fclose($fp);
// Alls fine so don't return an error
return NULL;
}
/*
* Sanitise strings to prevent SQL inject attacks etc
*/
function lmm_checkInput($str) {
$str = @strip_tags($str);
$str = @stripslashes($str);
$invalid_characters = array("$", "%", "#", "<", ">", "|");
$str = str_replace($invalid_characters, "", $str);
return $str;
}
?>