-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmemo-send-message.php
78 lines (62 loc) · 2.32 KB
/
memo-send-message.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
<?php
include("config.php");
include($cfgProgDir."secure.php");
// preparing response
$res['status'] = 500;
$res['_tok'] = '';
if(! isset($_SESSION['login']) || $_SESSION['login'] == '') {
$res['response'] = "<div class='alert alert-danger' style='margin-left: 0px;'>Login First</div>";
exit (json_encode($res));
}
// validation is login
if (!$_SESSION["login"]){
$res['response'] = "<div class='alert alert-danger' style='margin-left: 0px;'>Please login first</div>";
exit (json_encode($res));
}
if (checkCaptcha('scrTok', $_POST['_tok'])){
// create new auth token
$_SESSION['scrTok'] = base64_encode(md5(session_id(). str_shuffle('memo'.time())));
// preparing response
$res['_tok'] = $_SESSION['scrTok'];
// validation
$subject = $_POST["title"];
$body = $_POST["descr"];
$subject = str_replace("http://", "", $subject);
$subject = str_replace("<", "(", $subject);
$subject = str_replace(">", ")", $subject);
$body = str_replace("http://", "", $body);
$body = str_replace("<", "(", $body);
$body = str_replace(">", ")", $body);
if (!$subject){
$res['response'] = "<div class='alert alert-danger' style='margin-left: 0px;'>Please fill subject!</div>";
exit (json_encode($res));
}else if (!$body){
$res['response'] = "<div class='alert alert-danger' style='margin-left: 0px;'>Please fill meessage!</div>";
exit (json_encode($res));
}else{
// submit process
$reqAPIMemoSend = array(
"auth" => $authapi,
"userid" => $login,
"mto" => $agentwlable,
"mfrom" => $login,
"subject" => $subject,
"content" => $body,
"type" => 1,
);
$respMemoSend = sendAPI($url_Api."/memo",$reqAPIMemoSend,'JSON','02e97eddc9524a1e');
// print_r($respMemoSend);exit();
// error response
if( $respMemoSend->status != 200 ){
$res['response'] = "<div class='alert alert-danger' style='margin-left: 0px;'>" . $respMemoSend->msg . "</div>";
exit (json_encode($res));
}
// success response
$res['status'] = 200;
$res['response'] = "<div class='alert alert-success' style='margin-left: 0px;'>" . $respMemoSend->msg . "</div>";
exit (json_encode($res));
}
}
$res['response'] = "<div class='alert alert-danger' style='margin-left: 0px;'>Authentication Failed</div>";
exit (json_encode($res));
?>