-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsync.php
More file actions
84 lines (71 loc) · 1.87 KB
/
Copy pathsync.php
File metadata and controls
84 lines (71 loc) · 1.87 KB
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
<?php
require_once("config.php");
require_once("_inc/helper/common.php");
require_once("_inc/helper/file.php");
require_once("_inc/helper/network.php");
if (isLocalhost()) {
echo json_encode(array(
'status' => 'error',
'message' => 'Invalid Action',
'for' => 'invalid',
));
exit();
};
function validateApiAccess($username, $password) {
$valid_clients = array(
'admin@sultan.pos' => array(
'password' => 'admin'
),
);
return isset($valid_clients[$username]) && ($valid_clients[$username]['password'] == $password);
}
$post_data = json_decode(file_get_contents('php://input'), true);
$action = isset($post_data['action']) ? $post_data['action'] : null;
$query_data = isset($post_data['data']) ? json_decode($post_data['data'],true) : null;
if (!isset($post_data['username']) || !isset($post_data['password'])) {
echo json_encode(array(
'status' => 'error',
'message' => 'Invalid Action',
'for' => 'invalid',
));
exit();
}
if (!validateApiAccess($post_data['username'], $post_data['password'])) {
echo json_encode(array(
'status' => 'error',
'message' => 'Invalid Action',
'for' => 'invalid',
));
exit();
}
switch ($action) {
case 'sync':
try {
$db = pdo_start();
}
catch(PDOException $e) {
echo json_encode(array(
'status' => 'error',
'message' => 'Database Connection Error: '.$e->getMessage(),
'for' => 'invalid',
));
exit();
}
foreach ($query_data as $sql) {
$statement = $db->prepare($sql['sql']);
$statement->execute($sql['args']);
}
echo json_encode(array(
'status' => 'success',
'message' => 'sync successfully done',
'for' => 'sync',
));
break;
default:
echo json_encode(array(
'status' => 'error',
'message' => 'Invalid Action',
'for' => 'invalid',
));
break;
}