-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatabase_server.php
101 lines (84 loc) · 2.6 KB
/
database_server.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
#!/usr/bin/php
<?php
require_once('path.inc');
require_once('get_host_info.inc');
require_once('rabbitMQLib.inc');
//create connection
$conn = new mysqli(172.23.51.116, testUser, password);
// Check connection
if ($conn->connect_error)
{
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
function doLogin($username,$password)
{
//to prevent from mysqli injection
$username = stripcslashes($username);
$password = stripcslashes($password);
$username = mysqli_real_escape_string($conn, $username);
$password = mysqli_real_escape_string($conn, $password);
// lookup username in database
$sql = "SELECT *from 'users' where username = '$username' and password = '$password'";
$result = mysqli_query($conn, $sql);
$row = mysqli_fetch_array($result, MYSQLI_ASSOC);
$count = mysqli_num_rows($result);
if($count == 1)
{
echo "Login succesful!";
return true;
}
else
{
echo" login unsuccesful bicho";
return false;
}
}
function createUser($username, $password)
{
//to prevent from mysqli injection
$username = stripcslashes($username);
$password = stripcslashes($password);
$username = mysqli_real_escape_string($conn, $username);
$password = mysqli_real_escape_string($conn, $password);
// lookup username in database
$sql = "SELECT *from 'users' where username = '$username' and password = '$password'";
$result = mysqli_query($conn, $sql);
$row = mysqli_fetch_array($result, MYSQLI_ASSOC);
$count = mysqli_num_rows($result);
if($count == 1)
{
echo "User already exists!";
return false;
}
else
{
$sql = "INSERT into `users` (username, password)
VALUES ('$username',($password')";
$result = mysqli_query($con, $query);
echo "User created succesfully";
return true;
}
function requestProcessor($request)
{
echo "received request".PHP_EOL;
var_dump($request);
if(!isset($request['type']))
{
return "ERROR: unsupported message type";
}
switch ($request['type'])
{
case "login":
return doLogin($request['username'],$request['password']);
case "validate_session":
return doValidate($request['sessionId']);
}
return array("returnCode" => '0', 'message'=>"Server received request and processed");
}
$server = new rabbitMQServer("testRabbitMQ.ini","dbServer");
echo "testRabbitMQServer BEGIN".PHP_EOL;
$server->process_requests('requestProcessor');
echo "testRabbitMQServer END".PHP_EOL;
exit();
?>