reSIProcate
SIP stack, Dialog Usage Manager and related libraries
Loading...
Searching...
No Matches
WebAdmin.cxx
Go to the documentation of this file.
1#include "rutil/ResipAssert.h"
2#include <time.h>
3
5
8#include <rutil/Data.hxx>
9#include <rutil/DnsUtil.hxx>
10#include <rutil/Logger.hxx>
11#include <rutil/ParseBuffer.hxx>
12#include <rutil/Socket.hxx>
13#include <rutil/Timer.hxx>
15
16#include "AppSubsystem.hxx"
17#include "HttpBase.hxx"
18#include "HttpConnection.hxx"
19#include "WebAdmin.hxx"
20#include "ActiveCallInfo.hxx"
21#include "Server.hxx"
22
23using namespace resip;
24using namespace mohparkserver;
25using namespace std;
26
27#define RESIPROCATE_SUBSYSTEM AppSubsystem::MOHPARKSERVER
28
29
30WebAdmin::RemoveKey::RemoveKey(const Data &key1, const Data &key2) : mKey1(key1), mKey2(key2)
31{
32};
33
34bool
35WebAdmin::RemoveKey::operator<(const RemoveKey& rhs) const
36{
37 if(mKey1 < rhs.mKey1)
38 {
39 return true;
40 }
41 else if(mKey1 == rhs.mKey1 && mKey2 < rhs.mKey2)
42 {
43 return true;
44 }
45 else
46 {
47 return false;
48 }
49}
50
52 bool noChal,
53 const Data& realm, // this realm is used for http challenges
54 const Data& adminPassword,
55 int port,
56 IpVersion version ):
57 HttpBase( port, version, realm ),
58 mNoWebChallenges( noChal ),
59 mServer(server)
60{
61}
62
63
64void
66 int pageNumber,
67 const resip::Data& pUser,
68 const resip::Data& pPassword )
69{
70 ParseBuffer pb(uri);
71
72 DebugLog (<< "Parsing URL" << uri );
73
74 const char* anchor = pb.skipChar('/');
75 pb.skipToChar('?');
76 Data pageName;
77 pb.data(pageName,anchor);
78
79 DebugLog (<< " got page name: " << pageName );
80
81 // if this is not a valid page, redirect it
82 if (pageName != Data("activecalls.html"))
83 {
84 setPage( resip::Data::Empty, pageNumber, 301 );
85 return;
86 }
87
88 // parse any URI tags from form entry
89 mRemoveSet.clear();
90 mHttpParams.clear();
91
92 if (!pb.eof())
93 {
94 pb.skipChar('?');
95
96 while ( !pb.eof() )
97 {
98 const char* anchor1 = pb.position();
99 pb.skipToChar('=');
100 Data key;
101 pb.data(key,anchor1);
102
103 const char* anchor2 = pb.skipChar('=');
104 pb.skipToChar('&');
105 Data value;
106 pb.data(value,anchor2);
107
108 if ( !pb.eof() )
109 {
110 pb.skipChar('&');
111 }
112
113 if ( key.prefix("remove.") ) // special case of parameters to delete one or more records
114 {
115 Data tmp = key.substr(7); // the ID is everything after the dot
116 if (!tmp.empty())
117 {
118 DebugLog (<< " remove key=" << tmp.urlDecoded());
119 mRemoveSet.insert(RemoveKey(tmp.urlDecoded(),value.urlDecoded())); // add to the set of records to remove
120 }
121 }
122 else if ( !key.empty() && !value.empty() ) // make sure both exist
123 {
124 DebugLog (<< " key=" << key << " value=" << value << " & unencoded form: " << value.urlDecoded() );
125 mHttpParams[key] = value.urlDecoded(); // add other parameters to the Map
126 }
127 }
128
129 }
130
131 Data page;
132 DataStream s(page);
133 buildPageOutlinePre(s);
134
135 if ( pageName == Data("activecalls.html"))
136 {
137 buildActiveCallsSubPage(s);
138 }
139 else
140 {
141 resip_assert(false);
142 }
143 buildPageOutlinePost(s);
144 s.flush();
145
146 resip_assert( !page.empty() );
147 setPage( page, pageNumber,200 );
148}
149
150
151void
152WebAdmin::buildActiveCallsSubPage(DataStream& s)
153{
154 if (!mRemoveSet.empty())
155 {
156 int j = 0;
157 for (set<RemoveKey>::iterator i = mRemoveSet.begin(); i != mRemoveSet.end(); ++i)
158 {
159 Uri aor(i->mKey1);
161 Data::size_type bar1 = i->mKey2.find("|");
162 Data::size_type bar2 = i->mKey2.find("|",bar1+1);
163
164 if(bar1==Data::npos || bar2 == Data::npos)
165 {
166 InfoLog(<< "Registration removal key was malformed: " << i->mKey2);
167 continue;
168 }
169
170 try
171 {
172 resip::Data rawNameAddr = i->mKey2.substr(0,bar1).urlDecoded();
173 rec.mContact = NameAddr(rawNameAddr);
174 rec.mInstance = i->mKey2.substr(bar1+1,bar2-bar1-1).urlDecoded();
175 rec.mRegId = i->mKey2.substr(bar2+1,Data::npos).convertInt();
176 //mRegDb.lockRecord(aor); // TODO
177 //mRegDb.removeContact(aor, rec);
178 //mRegDb.unlockRecord(aor);
179 ++j;
180 }
181 catch(resip::ParseBuffer::Exception& e)
182 {
183 InfoLog(<< "Registration removal key was malformed: " << e <<
184 " Key was: " << i->mKey2);
185 }
186
187 }
188 s << "<p><em>Removed:</em> " << j << " records</p>" << endl;
189 }
190
191 s <<
192 "<form id=\"showReg\" method=\"get\" action=\"registrations.html\" name=\"showReg\" enctype=\"application/x-www-form-urlencoded\">" << endl <<
193 //"<button name=\"removeAllReg\" value=\"\" type=\"button\">Remove All</button>" << endl <<
194 //"<hr/>" << endl <<
195
196 "<table border=\"1\" cellspacing=\"2\" cellpadding=\"0\" align=\"left\">" << endl <<
197
198 "<tr>" << endl <<
199 " <td>Held URI</td>" << endl <<
200 " <td>Invoking URI</td>" << endl <<
201 " <td>Hold Type</td>" << endl <<
202 " <td>Participant ID</td>" << endl <<
203 " <td>Conversation ID</td>" << endl <<
204 //" <td><input type=\"submit\" value=\"Remove\"/></td>" << endl << // TODO
205 "</tr>" << endl;
206
207 CallInfoList callInfos;
208 mServer.getActiveCallsInfo(callInfos);
209 for (CallInfoList::iterator it = callInfos.begin(); it != callInfos.end(); ++it )
210 {
211 s << "<tr>" << endl
212 << " <td>" << Data::from(it->mHeldUri).xmlCharDataEncode() << "</td>" << endl
213 << " <td>" << Data::from(it->mInvokingUri).xmlCharDataEncode() << "</td>" << endl
214 << " <td>" << it->mHoldType << "</td>" << endl
215 << " <td>" << it->mParticipantId << "</td>" << endl
216 << " <td>" << it->mConversationId << "</td>" << endl
217 //<< " <td><input type=\"checkbox\" name=\"remove." << it->mHeldUri << "\" value=\"" << it->mParticipantId << "\"/></td>" << endl // TODO
218 << "</tr>" << endl;
219 }
220
221 s << "</table>" << endl <<
222 "</form>" << endl;
223}
224
225void
226WebAdmin::buildPageOutlinePre(DataStream& s)
227{
228s << "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
229s << "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\" \"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">\n";
230s << "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n";
231s << " <head>\n";
232s << " <meta http-equiv=\"content-type\" content=\"text/html;charset=utf-8\" />\n";
233s << " <title>MOHParkServer Active Call List</title>\n";
234s << " </head>\n";
235s << " <style>\n";
236s << "body { bgcolor: white; font-size: 90%; font-family: Arial, Helvetica, sans-serif }\n";
237s << "h1 { font-size: 200%; font-weight: bold }\n";
238s << "h2 { font-size: 100%; font-weight: bold; text-transform: uppercase }\n";
239s << "h3 { font-size: 100%; font-weight: normal }\n";
240s << "h4 { font-size: 100%; font-style: oblique; font-weight: normal } \n";
241s << "hr { line-height: 2px; margin-top: 0; margin-bottom: 0; padding-top: 0; padding-bottom: 0; height: 10px }\n";
242s << "div.title { color: white; background-color: #395af6; padding-top: 10px; padding-bottom: 10px; padding-left: 10px }\n";
243s << "div.title h1 { text-transform: uppercase; margin-top: 0; margin-bottom: 0 } \n";
244s << "div.menu { color: black; background-color: #ff8d09; padding: 0 10px 10px; \n";
245s << " width: 9em; float: left; clear: none; overflow: hidden }\n";
246s << "div.menu p { font-weight: bold; text-transform: uppercase; list-style-type: none; \n";
247s << " margin-top: 0; margin-bottom: 0; margin-left: 10px }\n";
248s << "div.menu h2 { margin-top: 10px; margin-bottom: 0 ; text-transform: uppercase; }\n";
249s << "div.main { color: black; background-color: #dae1ed; margin-left: 11em }\n";
250s << "div.space { font-size: 5px; height: 10px }\n";
251s << " </style>\n";
252s << " <body>\n";
253}
254
255
256void
257WebAdmin::buildPageOutlinePost(DataStream& s)
258{
259s << " </body>\n";
260s << "</html>\n";
261}
262
263
264/* ====================================================================
265 * The Vovida Software License, Version 1.0
266 *
267 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved.
268 *
269 * Redistribution and use in source and binary forms, with or without
270 * modification, are permitted provided that the following conditions
271 * are met:
272 *
273 * 1. Redistributions of source code must retain the above copyright
274 * notice, this list of conditions and the following disclaimer.
275 *
276 * 2. Redistributions in binary form must reproduce the above copyright
277 * notice, this list of conditions and the following disclaimer in
278 * the documentation and/or other materials provided with the
279 * distribution.
280 *
281 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
282 * and "Vovida Open Communication Application Library (VOCAL)" must
283 * not be used to endorse or promote products derived from this
284 * software without prior written permission. For written
285 * permission, please contact vocal@vovida.org.
286 *
287 * 4. Products derived from this software may not be called "VOCAL", nor
288 * may "VOCAL" appear in their name, without prior written
289 * permission of Vovida Networks, Inc.
290 *
291 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
292 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
293 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
294 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
295 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
296 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
297 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
298 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
299 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
300 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
301 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
302 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
303 * DAMAGE.
304 *
305 * ====================================================================
306 */
#define DebugLog(args_)
Definition Logger.hxx:128
#define InfoLog(args_)
Definition Logger.hxx:131
#define resip_assert(x)
This file needs to work for both C and C++ code.
Handles cross-platform sockets compatibility.
void setPage(const resip::Data &page, int pageNumber, int response=200, const resip::Mime &pType=resip::Mime("text","html"))
Definition HttpBase.cxx:200
void getActiveCallsInfo(CallInfoList &callInfos)
Definition Server.cxx:479
virtual void buildPage(const resip::Data &uri, int pageNumber, const resip::Data &user, const resip::Data &password)
Definition WebAdmin.cxx:65
WebAdmin(Server &server, bool noWebChallenges, const resip::Data &realm, const resip::Data &adminPassword, int port=5082, resip::IpVersion version=resip::V4)
Definition WebAdmin.cxx:51
A single contact record, bound to an Aor during registration.
An iostream that operates on an existing Data.
An alternative to std::string, encapsulates an arbitrary buffer of bytes.
Definition Data.hxx:90
static const Data Empty
Constant that represents a zero-length data.
Definition Data.hxx:882
Data xmlCharDataEncode() const
Performs in-place XML Character Data escaping of a Data.
Definition Data.cxx:1454
bool prefix(const Data &pre) const noexcept
Returns true if this Data starts with the bytes indicated by the passed-in Data.
Definition Data.cxx:1888
Data substr(size_type first, size_type count=Data::npos) const
Copies a portion of this Data into a new Data.
Definition Data.cxx:1932
bool empty() const noexcept
Checks whether the Data is empty.
Definition Data.hxx:591
Data urlDecoded() const
Performs in-place HTTP URL un-escaping of a Data.
Definition Data.cxx:1341
size_t size_type
Definition Data.hxx:94
static Data from(const T &x)
Converts from arbitrary other type to Data.
Definition Data.hxx:398
static const size_type npos
Represents an impossible position; returned to indicate failure to find.
Definition Data.hxx:887
Represents the "name-addr" and the "addr-spec" elements in the RFC 3261 grammar.
Definition NameAddr.hxx:19
Provides string-parsing functionality with protection from buffer overflow.
CurrentPosition skipToChar(char c)
CurrentPosition position() const
CurrentPosition skipChar()
void data(Data &data, const char *start) const
make the passed in data share memory with the buffer (uses Data::Share)
Represents the "SIP-URI" and "SIPS-URI" elements in the RFC 3261 grammar.
Definition Uri.hxx:22
std::list< ActiveCallInfo > CallInfoList
dcm! – add UnusedChecking(_enum) below;
IpVersion
An enumeration of IP versions.