-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
executable file
·67 lines (63 loc) · 1.66 KB
/
index.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
<?php
#
# Written by Oscar Kraemer 22.05.2014
#
function start(){
$out = "not set";
if( isset( $_GET['machine'])){
$out = getIP($_GET['machine']);
}elseif( isset( $_GET['m'])){
$out = getIP($_GET['m']);
}elseif( empty( $_POST['machine']) ){
$out = $_SERVER['REMOTE_ADDR'];
}elseif( $_POST['update'] == "true" ){
$out = updateip($_POST['machine']);
}elseif($_POST['machine']){
$out = getIP($_POST['machine']);
}else{
echo "Congratulation you managed to make an request that I did not anticipate :1 \n";
}
echo $out;
}
function updateip($machine){
$old = getIP($machine);
$new = $_SERVER['REMOTE_ADDR'];
if ($old == false){
return "Does not exist";
}elseif($new == $old){
return "Same ip";
}else{
$result = query("UPDATE ipHost SET IP=(INET_ATON('".$new."')) WHERE hostname='".$machine."';");
$out = updateLog($machine, $new);
return $out;
}
}
function updateLog ( $machine, $new ){
$mf = fopen("ipaddr.log", 'a');
fwrite($mf,$new." ".$machine.PHP_EOL);
fclose($mf);
return "log Update";
}
function getIP($machine){
$result = query("SELECT hostname, INET_NTOA(IP) FROM ipHost");
while($row = mysqli_fetch_array($result)){
if ($row['hostname'] == $machine){
return $row["INET_NTOA(IP)"];
}
}
return false;
}
function query($query){
require "db.php";
//conection=mysqli_connect("127.0.0.1","account","passswd","db");
$conection=mysqli_connect($db_ip,$db_user,$db_passwd,$db_db);
if (mysqli_connect_errno($conection))
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($conection, $query);
mysqli_close($conection);
return $result;
}
start();
?>