MCPcopy Create free account
hub / github.com/cuberite/cuberite / HandleWebadminRequest

Method HandleWebadminRequest

src/WebAdmin.cpp:183–317  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

181
182
183void cWebAdmin::HandleWebadminRequest(cHTTPConnection & a_Connection, cHTTPRequest & a_Request)
184{
185 if (!a_Request.HasAuth())
186 {
187 a_Connection.SendNeedAuth("MCServer WebAdmin");
188 return;
189 }
190
191 // Check auth:
192 AString UserPassword = m_IniFile.GetValue("User:" + a_Request.GetAuthUsername(), "Password", "");
193 if ((UserPassword == "") || (a_Request.GetAuthPassword() != UserPassword))
194 {
195 a_Connection.SendNeedAuth("MCServer WebAdmin - bad username or password");
196 return;
197 }
198
199 // Check if the contents should be wrapped in the template:
200 AString URL = a_Request.GetBareURL();
201 ASSERT(URL.length() > 0);
202 bool ShouldWrapInTemplate = ((URL.length() > 1) && (URL[1] != '~'));
203
204 // Retrieve the request data:
205 cWebadminRequestData * Data = (cWebadminRequestData *)(a_Request.GetUserData());
206 if (Data == NULL)
207 {
208 a_Connection.SendStatusAndReason(500, "Bad UserData");
209 return;
210 }
211
212 // Wrap it all up for the Lua call:
213 AString Template;
214 HTTPTemplateRequest TemplateRequest;
215 TemplateRequest.Request.Username = a_Request.GetAuthUsername();
216 TemplateRequest.Request.Method = a_Request.GetMethod();
217 TemplateRequest.Request.Path = URL.substr(1);
218
219 if (Data->m_Form.Finish())
220 {
221 for (cHTTPFormParser::const_iterator itr = Data->m_Form.begin(), end = Data->m_Form.end(); itr != end; ++itr)
222 {
223 HTTPFormData HTTPfd;
224 HTTPfd.Value = itr->second;
225 HTTPfd.Type = "";
226 HTTPfd.Name = itr->first;
227 TemplateRequest.Request.FormData[itr->first] = HTTPfd;
228 TemplateRequest.Request.PostParams[itr->first] = itr->second;
229 } // for itr - Data->m_Form[]
230
231 // Parse the URL into individual params:
232 size_t idxQM = a_Request.GetURL().find('?');
233 if (idxQM != AString::npos)
234 {
235 cHTTPFormParser URLParams(cHTTPFormParser::fpkURL, a_Request.GetURL().c_str() + idxQM + 1, a_Request.GetURL().length() - idxQM - 1, *Data);
236 URLParams.Finish();
237 for (cHTTPFormParser::const_iterator itr = URLParams.begin(), end = URLParams.end(); itr != end; ++itr)
238 {
239 TemplateRequest.Request.Params[itr->first] = itr->second;
240 } // for itr - URLParams[]

Callers

nothing calls this directly

Calls 15

ReplaceStringFunction · 0.85
PrintfFunction · 0.85
HasAuthMethod · 0.80
SendNeedAuthMethod · 0.80
GetValueMethod · 0.80
GetBareURLMethod · 0.80
GetUserDataMethod · 0.80
SendStatusAndReasonMethod · 0.80
beginMethod · 0.80
endMethod · 0.80
c_strMethod · 0.80
SetContentTypeMethod · 0.80

Tested by

no test coverage detected