forked from zeroc-ice/ice-demos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathChatI.php
146 lines (132 loc) · 3.78 KB
/
ChatI.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
146
<?php
//
// Enable error reporting
//
error_reporting(E_ERROR | E_WARNING | E_PARSE);
//
// Copyright (c) ZeroC, Inc. All rights reserved.
//
//
// Encode the param $data as Json and send it to the client browser.
//
function printJson($data)
{
print(json_encode($data));
}
//
// Check that the Ice extension is loaded.
//
if(!extension_loaded("ice"))
{
printJson("IcePHP extension is not loaded. Revise your IcePHP installation.");
error_log("IcePHP extension is not loaded. Revise your IcePHP installation.");
exit(1);
}
require_once 'Ice.php';
require_once dirname(__FILE__) . '/SessionI.php';
require_once dirname(__FILE__) . '/PollingChat.php';
$data = new \Ice\InitializationData;
$data->properties = \Ice\getProperties();
if($data->properties->getProperty("PollingChatSessionFactory") == '')
{
$data->properties->setProperty("Ice.Plugin.IceSSL", "IceSSL:createIceSSL");
$data->properties->setProperty("IceSSL.UsePlatformCAs", "1");
$data->properties->setProperty("IceSSL.CheckCertName", "1");
$data->properties->setProperty("PollingChatSessionFactory",
"PollingChatSessionFactory:wss -h zeroc.com -p 443 -r /demo-proxy/chat/poll");
$data->properties->setProperty("OverrideSessionEndpoints", "1");
}
$communicator = \Ice\initialize($data);
//
// Disable session cookie.
//
ini_set("session.use_cookies", false);
//
// Disable transid in urls.
//
ini_set("session.session.use_transid", false);
if(isset($_POST['id']))
{
session_id($_POST['id']);
}
//
// Disable caching
//
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past
//
// Start the session, but do not report any PHP error to the client if it fails.
// There are exploits that use errors to get knowledge of web server backend internals
// and to search for other system vulnerabilities.
//
@session_start();
if(isset($_SESSION)) // Check that the session started OK
{
try
{
//
// Get the action from the post params.
//
$_action = isset($_POST['action']) ? $_POST['action'] : 'none';
//
// Create the session PHP object and pass a reference to $communicator.
//
$session = new Session($communicator);
//
// Process the action.
//
switch($_action)
{
case 'login':
{
$userName = stripslashes(isset($_POST['username']) ? $_POST['username'] : 'nobody');
$userPassword = stripslashes(isset($_POST['password']) ? $_POST['password'] : 'nobody');
printJson($session->login($userName, $userPassword));
break;
}
case 'logout':
{
printJson($session->logout());
break;
}
case 'send':
{
$message = stripslashes(isset($_POST['message']) ? $_POST['message'] : '');
printJson($session->send($message));
break;
}
case 'getUpdates':
{
printJson($session->getUpdates());
break;
}
case 'getInitialUsers':
{
printJson($session->getInitialUsers());
break;
}
default:
{
printJson("InvalidActionException");
break;
}
}
}
catch(Exception $ex)
{
if(!isset($ex->jsontype))
{
error_log("Exception: " . $ex);
$ex->jsontype = "Exception";
}
printJson($ex);
}
}
else
{
$ex = new Exception("Error starting the PHP session");
$ex->jsontype = "Exception";
error_log($ex->getMessage());
printJson($ex);
}
?>