-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.php
145 lines (123 loc) · 4.53 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
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
<?php
// Copyright (c) 2017 Sacarlson sacarlson_2000@yahoo.com -->
// stellar federation server
// mysql needed table Users
// fields index, username, account_id, seed same as stellar go federation with added seed text field added
header('Content-type: application/json');
//header('Vary: Origin');
//header('Access-Control-Allow-Origin: *');
//header('Access-Control-Allow-Methods: POST, GET, OPTIONS, DELETE, PUT');
include('config.php');
//echo "start";
// test: http://b.funtracker.site/fed2?q=sacarlson*funtracker.site&type=name
// test2: http://b.funtracker.site/fed2?q=sacarlson@yahoo.com*funtracker.site&type=name
$q = $_GET['q'];
$type = $_GET['type'];
// Create connection
$conn = new mysqli($servername, $mysql_username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
echo "bad mysql connect error: " . $conn->connect_error;
die("Connection failed: " . $conn->connect_error);
}
if ($mysql_enable == "true"){
//echo " mysql enabled";
if ($type == "name"){
fed_lookup_name($anchor_publicid);
}
if ($type == "id"){
fed_lookup_id($anchor_domain);
}
//insert_data();
$conn->close();
}
//logsession();
function fed_lookup_name($anchor_publicid){
global $conn;
$array = explode("*",$_GET['q']);
$username = $array[0];
$domain = $array[1];
// output should be
//{
// "stellar_address": <username*domain.tld>,
// "account_id": <account_id>,// "memo_type": <"text", "id" , or "hash"> *optional*
// "memo": <memo to attach to any payment. if "hash" type then will be base64 encoded> *optional*
//}
//echo "username: $username, domain: $domain";
$username = mysqli_real_escape_string($conn, $username);
$sql = 'DELETE FROM `Users` WHERE `status` = "pre_proc" AND date_added < TIMESTAMPADD(MINUTE, -120, NOW())';
if(!$result = $conn->query($sql)){
echo "error mysql 3";
//wrt_log("check user query fail: " . mysqli_error($conn) . "\n");
return FALSE;
}
$sql = "SELECT * FROM `Users` WHERE `username` = '" . $username . "'";
if(!$result = $conn->query($sql)){
echo "error mysql 2";
//wrt_log("check user query fail: " . mysqli_error($conn) . "\n");
return FALSE;
}
if ($result->num_rows > 0) {
//wrt_log("username exists true \n");
$user = $result->fetch_assoc();
if ($user["account_id"] == "not_set"){
echo '{"stellar_address":"' . $_GET['q'] . '","account_id":"' . $anchor_publicid . '","memo_type":"text","memo":"' . $user["index"] . '"}';
return TRUE;
}
echo '{"stellar_address":"' . $_GET['q'] . '","account_id":"' . $user["account_id"] . '"}';
return TRUE;
// check if username is an email address must have @ in it
} else if (filter_var($username, FILTER_VALIDATE_EMAIL)){
$idx = insert_user($username,"not_set","pre_proc");
echo '{"stellar_address":"' . $_GET['q'] . '","account_id":"' . $anchor_publicid . '","memo_type":"text","memo":"' . $idx . '"}';
return FALSE;
} else{
echo '{"stellar_address":"' . $_GET['q'] . '","account_id":"' . "not_found" . '"}';
}
}
function insert_user($user,$account_id,$status){
global $conn;
$sql = "INSERT INTO Users (username,account_id,status) VALUES ('$user','$account_id','$status');";
//echo "sql: " . $sql;
//wrt_log("sql: " . $sql . "\n");
$result = $conn->query($sql);
if ($result === TRUE) {
return $conn->insert_id;
//return true;
} else {
return false;
}
}
function fed_lookup_id($anchor_domain){
global $conn;
// output should be
//{
// "stellar_address": <username*domain.tld>,
// "account_id": <account_id>,
// "memo_type": <"text", "id" , or "hash"> *optional*
// "memo": <memo to attach to any payment. if "hash" type then will be base64 encoded> *optional*
//}
//echo "account_id: $_GET['q']";
//$sql = "SELECT * FROM `Users` WHERE `username` = '" . $username . "'";
$id = mysqli_real_escape_string($conn, $_GET['q']);
$sql = "SELECT * FROM `Users` WHERE `account_id` = '" . $id . "'";
if(!$result = $conn->query($sql)){
echo "error mysql 2";
return FALSE;
}
if ($result->num_rows > 0) {
$user = $result->fetch_assoc();
echo '{"stellar_address":"' . $user["username"] . "*". $anchor_domain . '","account_id":"' . $_GET['q'] . '"}';
return TRUE;
} else {
echo '{"stellar_address":"' . "not_found" . '","account_id":"' . $_GET['q'] . '"}';
return FALSE;
}
}
function wrt_log( $string) {
$f = fopen("./session_track.log", "a");
fwrite( $f, $string );
fclose($f);
return;
}
?>