00001 #include "otsdaq-core/WizardSupervisor/WizardSupervisor.h"
00002
00003 #include "otsdaq-core/GatewaySupervisor/GatewaySupervisor.h"
00004
00005 #include "otsdaq-core/MessageFacility/MessageFacility.h"
00006 #include "otsdaq-core/Macros/CoutMacros.h"
00007
00008 #include <xdaq/NamespaceURI.h>
00009 #include "otsdaq-core/CgiDataUtilities/CgiDataUtilities.h"
00010 #include "otsdaq-core/XmlUtilities/HttpXmlDocument.h"
00011 #include "otsdaq-core/WebUsersUtilities/WebUsers.h"
00012 #include "otsdaq-core/SOAPUtilities/SOAPUtilities.h"
00013 #include "otsdaq-core/SOAPUtilities/SOAPCommand.h"
00014
00015 #include <iostream>
00016 #include <fstream>
00017 #include <string>
00018 #include <thread>
00019 #include <chrono>
00020 #include <sys/stat.h>
00021 #include <dirent.h>
00022
00023
00024
00025 using namespace ots;
00026
00027
00028 #define SECURITY_FILE_NAME std::string(getenv("SERVICE_DATA_PATH")) + "/OtsWizardData/security.dat"
00029 #define SEQUENCE_FILE_NAME std::string(getenv("SERVICE_DATA_PATH")) + "/OtsWizardData/sequence.dat"
00030 #define SEQUENCE_OUT_FILE_NAME std::string(getenv("SERVICE_DATA_PATH")) + "/OtsWizardData/sequence.out"
00031 #define USER_DATA_PATH std::string(getenv("SERVICE_DATA_PATH")) + std::string("/")
00032
00033
00034 #define XML_STATUS "editUserData_status"
00035
00036 #define XML_ADMIN_STATUS "logbook_admin_status"
00037 #define XML_MOST_RECENT_DAY "most_recent_day"
00038 #define XML_EXPERIMENTS_ROOT "experiments"
00039 #define XML_EXPERIMENT "experiment"
00040 #define XML_ACTIVE_EXPERIMENT "active_experiment"
00041 #define XML_EXPERIMENT_CREATE "create_time"
00042 #define XML_EXPERIMENT_CREATOR "creator"
00043
00044 #define XML_LOGBOOK_ENTRY "logbook_entry"
00045 #define XML_LOGBOOK_ENTRY_SUBJECT "logbook_entry_subject"
00046 #define XML_LOGBOOK_ENTRY_TEXT "logbook_entry_text"
00047 #define XML_LOGBOOK_ENTRY_FILE "logbook_entry_file"
00048 #define XML_LOGBOOK_ENTRY_TIME "logbook_entry_time"
00049 #define XML_LOGBOOK_ENTRY_CREATOR "logbook_entry_creator"
00050 #define XML_LOGBOOK_ENTRY_HIDDEN "logbook_entry_hidden"
00051 #define XML_LOGBOOK_ENTRY_HIDER "logbook_entry_hider"
00052 #define XML_LOGBOOK_ENTRY_HIDDEN_TIME "logbook_entry_hidden_time"
00053
00054 #define XML_PREVIEW_INDEX "preview_index"
00055 #define LOGBOOK_PREVIEW_FILE "preview.xml"
00056
00057
00058
00059 XDAQ_INSTANTIATOR_IMPL(WizardSupervisor)
00060
00061
00062
00063 #undef __MF_SUBJECT__
00064 #define __MF_SUBJECT__ "Wizard"
00065
00066
00067
00068 WizardSupervisor::WizardSupervisor(xdaq::ApplicationStub * s) throw (xdaq::exception::Exception)
00069 : xdaq::Application (s )
00070 , SOAPMessenger (this)
00071 , supervisorClass_ (getApplicationDescriptor()->getClassName())
00072 , supervisorClassNoNamespace_ (supervisorClass_.substr(supervisorClass_.find_last_of(":")+1, supervisorClass_.length()-supervisorClass_.find_last_of(":")))
00073 {
00074 __SUP_COUT__ << "Constructor started." << __E__;
00075
00076 INIT_MF("OtsConfigurationWizard");
00077
00078
00079
00080 mkdir((std::string(getenv("SERVICE_DATA_PATH"))).c_str(), 0755);
00081 mkdir((std::string(getenv("SERVICE_DATA_PATH")) + "/OtsWizardData").c_str(), 0755);
00082
00083 generateURL();
00084 xgi::bind (this, &WizardSupervisor::Default, "Default" );
00085 xgi::bind (this, &WizardSupervisor::verification, "Verify" );
00086 xgi::bind (this, &WizardSupervisor::requestIcons, "requestIcons" );
00087 xgi::bind (this, &WizardSupervisor::editSecurity, "editSecurity" );
00088 xgi::bind (this, &WizardSupervisor::UserSettings, "UserSettings" );
00089 xgi::bind (this, &WizardSupervisor::tooltipRequest, "TooltipRequest" );
00090 xgi::bind (this, &WizardSupervisor::toggleSecurityCodeGeneration, "ToggleSecurityCodeGeneration" );
00091 xoap::bind(this, &WizardSupervisor::supervisorSequenceCheck, "SupervisorSequenceCheck", XDAQ_NS_URI);
00092 xoap::bind(this, &WizardSupervisor::supervisorLastConfigGroupRequest, "SupervisorLastConfigGroupRequest", XDAQ_NS_URI);
00093 init();
00094
00095 __SUP_COUT__ << "Constructor complete." << __E__;
00096 }
00097
00098
00099 WizardSupervisor::~WizardSupervisor(void)
00100 {
00101 destroy();
00102 }
00103
00104
00105 void WizardSupervisor::init(void)
00106 {
00107
00108
00109
00110 allowedFileUploadTypes_.push_back("image/png"); matchingFileUploadTypes_.push_back("png");
00111 allowedFileUploadTypes_.push_back("image/jpeg"); matchingFileUploadTypes_.push_back("jpeg");
00112 allowedFileUploadTypes_.push_back("image/gif"); matchingFileUploadTypes_.push_back("gif");
00113 allowedFileUploadTypes_.push_back("image/bmp"); matchingFileUploadTypes_.push_back("bmp");
00114 allowedFileUploadTypes_.push_back("application/pdf"); matchingFileUploadTypes_.push_back("pdf");
00115 allowedFileUploadTypes_.push_back("application/zip"); matchingFileUploadTypes_.push_back("zip");
00116 allowedFileUploadTypes_.push_back("text/plain"); matchingFileUploadTypes_.push_back("txt");
00117
00118
00119 }
00120
00121
00122 void WizardSupervisor::generateURL()
00123 {
00124
00125 defaultSequence_ = true;
00126
00127 int length = 4;
00128 FILE *fp = fopen((SEQUENCE_FILE_NAME).c_str(),"r");
00129 if(fp)
00130 {
00131 __COUT_INFO__ << "Sequence length file found: " << SEQUENCE_FILE_NAME << std::endl;
00132 char line[100];
00133 fgets(line,100,fp);
00134 sscanf(line,"%d",&length);
00135 fclose(fp);
00136 if(length < 4)
00137 length = 4;
00138 else
00139 defaultSequence_ = false;
00140 srand(time(0));
00141 }
00142 else
00143 {
00144 __COUT_INFO__ << "(Reverting to default wiz security) Sequence length file NOT found: " << SEQUENCE_FILE_NAME << std::endl;
00145 srand(0);
00146 }
00147
00148 __COUT__ << "Sequence length = " << length << std::endl;
00149
00150 securityCode_ = "";
00151
00152 static const char alphanum[] =
00153 "0123456789"
00154 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
00155 "abcdefghijklmnopqrstuvwxyz";
00156
00157
00158 for (int i = 0; i < length; ++i) {
00159 securityCode_ += alphanum[rand() % (sizeof(alphanum) - 1)];
00160 }
00161
00162 std::cout << __COUT_HDR_FL__ <<
00163 getenv("OTS_CONFIGURATION_WIZARD_SUPERVISOR_SERVER") << ":" << getenv("PORT") <<
00164 "/urn:xdaq-application:lid="
00165 << this->getApplicationDescriptor()->getLocalId() << "/Verify?code=" << securityCode_ << std::endl;
00166
00167
00168
00169
00170
00171 fp = fopen((SEQUENCE_OUT_FILE_NAME).c_str(),"w");
00172 if(fp)
00173 {
00174 fprintf(fp,"%s",securityCode_.c_str());
00175 fclose(fp);
00176 }
00177 else
00178 __COUT_ERR__ << "Sequence output file NOT found: " << SEQUENCE_OUT_FILE_NAME << std::endl;
00179
00180
00181 return;
00182 }
00183
00184 void WizardSupervisor::printURL(WizardSupervisor *ptr,
00185 std::string securityCode)
00186 {
00187 INIT_MF("ConfigurationWizard");
00188
00189 int i = 0;
00190 for (; i < 5; ++i)
00191 {
00192 std::this_thread::sleep_for (std::chrono::seconds(2));
00193 std::cout << __COUT_HDR_FL__ <<
00194 getenv("OTS_CONFIGURATION_WIZARD_SUPERVISOR_SERVER") << ":" << getenv("PORT") <<
00195 "/urn:xdaq-application:lid="
00196 << ptr->getApplicationDescriptor()->getLocalId() << "/Verify?code=" << securityCode << std::endl;
00197 }
00198 }
00199
00200
00201 void WizardSupervisor::destroy(void)
00202 {
00203
00204
00205 }
00206
00207
00208
00209 void WizardSupervisor::tooltipRequest(xgi::Input * in, xgi::Output * out)
00210 throw (xgi::exception::Exception)
00211 {
00212 cgicc::Cgicc cgi(in);
00213
00214 std::string Command = CgiDataUtilities::getData(cgi, "RequestType");
00215 __COUT__ << "Command = " << Command << std::endl;
00216
00217 std::string submittedSequence = CgiDataUtilities::postData(cgi, "sequence");
00218
00219
00220 if(securityCode_.compare(submittedSequence) != 0)
00221 {
00222 __COUT__ << "Unauthorized Request made, security sequence doesn't match!" << std::endl;
00223 return;
00224 }
00225 else
00226 {
00227 __COUT__ << "***Successfully authenticated security sequence." << std::endl;
00228 }
00229
00230
00231 HttpXmlDocument xmldoc;
00232
00233 if(Command == "check")
00234 {
00235 WebUsers::tooltipCheckForUsername(
00236 WebUsers::DEFAULT_ADMIN_USERNAME,
00237 &xmldoc,
00238 CgiDataUtilities::getData(cgi, "srcFile"),
00239 CgiDataUtilities::getData(cgi, "srcFunc"),
00240 CgiDataUtilities::getData(cgi, "srcId"));
00241 }
00242 else if(Command == "setNeverShow")
00243 {
00244 WebUsers::tooltipSetNeverShowForUsername(
00245 WebUsers::DEFAULT_ADMIN_USERNAME,
00246 &xmldoc,
00247 CgiDataUtilities::getData(cgi, "srcFile"),
00248 CgiDataUtilities::getData(cgi, "srcFunc"),
00249 CgiDataUtilities::getData(cgi, "srcId"),
00250 CgiDataUtilities::getData(cgi, "doNeverShow") == "1"?true:false,
00251 CgiDataUtilities::getData(cgi, "temporarySilence") == "1"?true:false);
00252
00253 }
00254 else
00255 __COUT__ << "Command Request, " << Command << ", not recognized." << std::endl;
00256
00257 xmldoc.outputXmlDocument((std::ostringstream*) out, false, true);
00258 }
00259
00260
00261 void WizardSupervisor::toggleSecurityCodeGeneration(xgi::Input * in, xgi::Output * out)
00262 throw (xgi::exception::Exception)
00263 {
00264 cgicc::Cgicc cgi(in);
00265
00266 std::string Command = CgiDataUtilities::getData(cgi, "RequestType");
00267 __COUT__ << "Got to Command = " << Command << std::endl;
00268
00269 std::string submittedSequence = CgiDataUtilities::postData(cgi, "sequence");
00270
00271
00272 if(securityCode_.compare(submittedSequence) != 0)
00273 {
00274 __COUT__ << "Unauthorized Request made, security sequence doesn't match!" << std::endl;
00275 return;
00276 }
00277 else
00278 {
00279 __COUT__ << "***Successfully authenticated security sequence." << std::endl;
00280 }
00281
00282
00283 HttpXmlDocument xmldoc;
00284
00285 if(Command == "TurnGenerationOn")
00286 {
00287 __COUT__ << "Turning automatic URL Generation on with a sequence depth of 16!" << std::endl;
00288 std::ofstream outfile ((SEQUENCE_FILE_NAME).c_str());
00289 outfile << "16" << std::endl;
00290 outfile.close();
00291 generateURL();
00292
00293
00294
00295
00296
00297
00298 std::thread([&](WizardSupervisor *ptr, std::string securityCode)
00299 {printURL(ptr,securityCode);},this,securityCode_).detach();
00300
00301 xmldoc.addTextElementToData("Status", "Generation_Success");
00302 }
00303 else
00304 __COUT__ << "Command Request, " << Command << ", not recognized." << std::endl;
00305
00306 xmldoc.outputXmlDocument((std::ostringstream*) out, false, true);
00307 }
00308
00309
00310
00311
00312 xoap::MessageReference WizardSupervisor::supervisorSequenceCheck(xoap::MessageReference message)
00313 throw (xoap::exception::Exception)
00314 {
00315
00316 SOAPParameters parameters;
00317 parameters.addParameter("sequence");
00318 receive(message, parameters);
00319
00320 std::string submittedSequence = parameters.getValue("sequence");
00321
00322
00323
00324 std::map<std::string ,WebUsers::permissionLevel_t> permissionMap;
00325
00326 if(securityCode_ == submittedSequence)
00327 permissionMap.emplace(
00328 std::pair<std::string /*groupName*/,WebUsers::permissionLevel_t>(
00329 WebUsers::DEFAULT_USER_GROUP,
00330 WebUsers::PERMISSION_LEVEL_ADMIN));
00331 else
00332 {
00333 __COUT__ << "Unauthorized Request made, security sequence doesn't match!" << std::endl;
00334
00335 permissionMap.emplace(
00336 std::pair<std::string /*groupName*/,WebUsers::permissionLevel_t>(
00337 WebUsers::DEFAULT_USER_GROUP,
00338 WebUsers::PERMISSION_LEVEL_INACTIVE));
00339 }
00340
00341
00342 SOAPParameters retParameters;
00343 retParameters.addParameter("Permissions", StringMacros::mapToString(permissionMap));
00344
00345
00346 return SOAPUtilities::makeSOAPMessageReference("SequenceResponse",
00347 retParameters);
00348 }
00349
00350
00351
00352
00353
00354
00355 xoap::MessageReference WizardSupervisor::supervisorLastConfigGroupRequest(
00356 xoap::MessageReference message)
00357 throw (xoap::exception::Exception)
00358 {
00359 SOAPParameters parameters;
00360 parameters.addParameter("ActionOfLastGroup");
00361 receive(message, parameters);
00362
00363 return GatewaySupervisor::lastConfigGroupRequestHandler(parameters);
00364 }
00365
00366
00367 void WizardSupervisor::Default(xgi::Input * in, xgi::Output * out )
00368 throw (xgi::exception::Exception)
00369 {
00370 __COUT__ << "Unauthorized Request made, security sequence doesn't match!" << std::endl;
00371 *out << "Unauthorized Request.";
00372 }
00373
00374
00375 void WizardSupervisor::verification(xgi::Input * in, xgi::Output * out )
00376 throw (xgi::exception::Exception)
00377 {
00378 cgicc::Cgicc cgi(in);
00379 std::string submittedSequence = CgiDataUtilities::getData(cgi, "code");
00380 __COUT__ << "submittedSequence=" << submittedSequence <<
00381 " " << time(0) << std::endl;
00382
00383 std::string securityWarning = "";
00384
00385 if(securityCode_.compare(submittedSequence) != 0)
00386 {
00387 __COUT__ << "Unauthorized Request made, security sequence doesn't match!" << std::endl;
00388 *out << "Invalid code.";
00389 return;
00390 }
00391 else
00392 {
00393
00394 __COUT__ << "*** Successfully authenticated security sequence " <<
00395 "@ " << time(0) << std::endl;
00396
00397 if (defaultSequence_)
00398 {
00399
00400 securityWarning = "&secure=False";
00401 }
00402 }
00403
00404 *out << "<!DOCTYPE HTML><html lang='en'><head><title>ots wiz</title>" <<
00405
00406
00407 "<link rel='apple-touch-icon' sizes='57x57' href='/WebPath/images/otsdaqIcons/apple-icon-57x57.png'>\
00408 <link rel='apple-touch-icon' sizes='60x60' href='/WebPath/images/otsdaqIcons/apple-icon-60x60.png'>\
00409 <link rel='apple-touch-icon' sizes='72x72' href='/WebPath/images/otsdaqIcons/apple-icon-72x72.png'>\
00410 <link rel='apple-touch-icon' sizes='76x76' href='/WebPath/images/otsdaqIcons/apple-icon-76x76.png'>\
00411 <link rel='apple-touch-icon' sizes='114x114' href='/WebPath/images/otsdaqIcons/apple-icon-114x114.png'>\
00412 <link rel='apple-touch-icon' sizes='120x120' href='/WebPath/images/otsdaqIcons/apple-icon-120x120.png'>\
00413 <link rel='apple-touch-icon' sizes='144x144' href='/WebPath/images/otsdaqIcons/apple-icon-144x144.png'>\
00414 <link rel='apple-touch-icon' sizes='152x152' href='/WebPath/images/otsdaqIcons/apple-icon-152x152.png'>\
00415 <link rel='apple-touch-icon' sizes='180x180' href='/WebPath/images/otsdaqIcons/apple-icon-180x180.png'>\
00416 <link rel='icon' type='image/png' sizes='192x192' href='/WebPath/images/otsdaqIcons/android-icon-192x192.png'>\
00417 <link rel='icon' type='image/png' sizes='32x32' href='/WebPath/images/otsdaqIcons/favicon-32x32.png'>\
00418 <link rel='icon' type='image/png' sizes='96x96' href='/WebPath/images/otsdaqIcons/favicon-96x96.png'>\
00419 <link rel='icon' type='image/png' sizes='16x16' href='/WebPath/images/otsdaqIcons/favicon-16x16.png'>\
00420 <link rel='manifest' href='/WebPath/images/otsdaqIcons/manifest.json'>\
00421 <meta name='msapplication-TileColor' content='#ffffff'>\
00422 <meta name='msapplication-TileImage' content='/ms-icon-144x144.png'>\
00423 <meta name='theme-color' content='#ffffff'>" <<
00424
00425 "</head>" <<
00426 "<frameset col='100%' row='100%'><frame src='/WebPath/html/Wizard.html?urn=" <<
00427 this->getApplicationDescriptor()->getLocalId() << securityWarning <<"'></frameset></html>";
00428
00429 }
00430
00431
00432 void WizardSupervisor::requestIcons(xgi::Input * in, xgi::Output * out )
00433 throw (xgi::exception::Exception)
00434 {
00435 cgicc::Cgicc cgi(in);
00436
00437 std::string submittedSequence = CgiDataUtilities::postData(cgi, "sequence");
00438
00439
00440 if(securityCode_.compare(submittedSequence) != 0)
00441 {
00442 __COUT__ << "Unauthorized Request made, security sequence doesn't match! " <<
00443 time(0) << std::endl;
00444 return;
00445 }
00446 else
00447 {
00448 __COUT__ << "***Successfully authenticated security sequence. " <<
00449 time(0) << std::endl;
00450 }
00451
00452
00453
00454
00455
00456
00457
00458
00459
00460
00461
00462
00463 *out << "Security Settings,SEC,1,1,icon-SecuritySettings.png,/WebPath/html/SecuritySettings.html,/" <<
00464 ",Edit User Data,USER,1,1,icon-EditUserData.png,/WebPath/html/EditUserData.html,/" <<
00465 ",Configure,CFG,0,1,icon-Configure.png,/urn:xdaq-application:lid=280/,/" <<
00466 ",Table Editor,TBL,0,1,icon-IconEditor.png,/urn:xdaq-application:lid=280/?configWindowName=tableEditor,/" <<
00467
00468
00469
00470
00471 ",Front-end Wizard,CFG,0,1,icon-Configure.png,/WebPath/html/RecordWiz_ConfigurationGUI.html?urn=280&subsetBasePath=FEInterfaceConfiguration&recordAlias=Front%2Dend,Config Wizards" <<
00472 ",Producer Wizard,CFG,0,1,icon-Configure.png,/WebPath/html/RecordWiz_ConfigurationGUI.html?urn=280&subsetBasePath=FEInterfaceConfiguration&recordAlias=Producer,Config Wizards" <<
00473 ",Consumer Wizard,CFG,0,1,icon-Configure.png,/WebPath/html/RecordWiz_ConfigurationGUI.html?urn=280&subsetBasePath=FEInterfaceConfiguration&recordAlias=Consumer,Config Wizards" <<
00474 ",Console,C,1,1,icon-Console.png,/urn:xdaq-application:lid=260/,/" <<
00475
00476 "";
00477 return;
00478 }
00479
00480
00481 void WizardSupervisor::editSecurity(xgi::Input * in, xgi::Output * out )
00482 throw (xgi::exception::Exception)
00483 {
00484
00485
00486 cgicc::Cgicc cgi(in);
00487 std::string submittedSequence = CgiDataUtilities::postData(cgi, "sequence");
00488 std::string submittedSecurity = CgiDataUtilities::postData(cgi, "selection");
00489 std::string securityFileName = SECURITY_FILE_NAME;
00490
00491
00492
00493 if(securityCode_.compare(submittedSequence) != 0)
00494 {
00495 __COUT__ << "Unauthorized Request made, security sequence doesn't match!" << std::endl;
00496 return;
00497 }
00498 else
00499 {
00500 __COUT__ << "***Successfully authenticated security sequence." << std::endl;
00501 }
00502
00503
00504
00505
00506 if(submittedSecurity != "")
00507 {
00508 __COUT__ << "Selection exists!" << std::endl;
00509 __COUT__ << submittedSecurity << std::endl;
00510
00511 if(submittedSecurity == "ResetAllUserData")
00512 {
00513 WebUsers::deleteUserData();
00514 __COUT__ << "Turning URL Generation back to default!" << std::endl;
00515
00516
00517 std::ofstream newFile ((SEQUENCE_FILE_NAME).c_str());
00518 newFile << "4" << std::endl;
00519 newFile.close();
00520
00521 generateURL();
00522 std::thread([&](WizardSupervisor *ptr, std::string securityCode)
00523 {printURL(ptr,securityCode);},this,securityCode_).detach();
00524 *out << "Default_URL_Generation";
00525 }
00526 else if(submittedSecurity == "ResetAllUserTooltips")
00527 {
00528 WebUsers::resetAllUserTooltips();
00529 *out << submittedSecurity;
00530 return;
00531 }
00532 else if(submittedSecurity == "DigestAccessAuthentication" ||
00533 submittedSecurity == "NoSecurity")
00534 {
00535 std::ofstream writeSecurityFile;
00536
00537 writeSecurityFile.open(securityFileName.c_str());
00538 if(writeSecurityFile.is_open())
00539 writeSecurityFile << submittedSecurity;
00540 else
00541 __COUT__ << "Error writing file!" << std::endl;
00542
00543 writeSecurityFile.close();
00544 }
00545 else
00546 {
00547 __COUT_ERR__ << "Invalid submittedSecurity string: " <<
00548 submittedSecurity << std::endl;
00549 *out << "Error";
00550 return;
00551 }
00552 }
00553
00554
00555
00556 std::ifstream securityFile;
00557 std::string line;
00558 std::string security = "";
00559 int lineNumber = 0;
00560
00561 securityFile.open(securityFileName.c_str());
00562
00563 if(!securityFile)
00564 {
00565
00566
00567
00568
00569
00570 security = "DigestAccessAuthentication";
00571 }
00572 if(securityFile.is_open())
00573 {
00574
00575 while(std::getline(securityFile, line))
00576 {
00577 security += line;
00578 lineNumber++;
00579 }
00580
00581
00582
00583 securityFile.close();
00584 }
00585
00586 *out << security;
00587 }
00588
00589 void WizardSupervisor::UserSettings(xgi::Input * in, xgi::Output * out )
00590 throw (xgi::exception::Exception)
00591 {
00592
00593
00594 cgicc::Cgicc cgi(in);
00595 std::string submittedSequence = CgiDataUtilities::postData(cgi, "sequence");
00596 std::string securityFileName = SECURITY_FILE_NAME;
00597 std::string Command;
00598 if((Command = CgiDataUtilities::postData(cgi,"RequestType")) == "")
00599 Command = cgi("RequestType");
00600
00601 __COUT__ << Command << std::endl;
00602 __COUT__ << "We are vewing Users' Settings!" << std::endl;
00603
00604
00605 if(securityCode_.compare(submittedSequence) != 0)
00606 {
00607 __COUT__ << "Unauthorized Request made, security sequence doesn't match!" << std::endl;
00608 __COUT__ << submittedSequence << std::endl;
00609
00610 }
00611 else
00612 {
00613 __COUT__ << "***Successfully authenticated security sequence." << std::endl;
00614 }
00615
00616
00617
00618 HttpXmlDocument xmldoc;
00619 uint64_t activeSessionIndex;
00620 std::string user;
00621 uint8_t userPermissions;
00622
00623 if(Command != "")
00624 {
00625 __COUT__ << "Action exists!" << std::endl;
00626 __COUT__ << Command << std::endl;
00627
00628 if(Command == "Import")
00629 {
00630
00631
00632
00633
00634
00635
00636
00637
00638
00639
00640
00641
00642
00643
00644
00645 __COUT__ << cgi("Entry") << std::endl;
00646 __COUT__ << cgi("Filename") << std::endl;
00647 __COUT__ << cgi("Imported_File") << std::endl;
00648
00649
00650 const std::vector<cgicc::FormFile> files = cgi.getFiles();
00651 __COUT__ << "FormFiles: " << sizeof(files) << std::endl;
00652 __COUT__ << "Number of files: " << files.size() << std::endl;
00653
00654 for(unsigned int i = 0; i < files.size(); ++i)
00655 {
00656 std::string filename = USER_DATA_PATH + files[i].getFilename();
00657 __COUT__ << filename << std::endl;
00658 std::ofstream myFile;
00659 myFile.open(filename.c_str());
00660 files[0].writeToStream(myFile);
00661 }
00662
00663
00664 __COUT__ << files[0].getFilename() << std::endl;
00665 __COUT__ << "********************Files Begin********************" << std::endl;
00666 for (unsigned int i=0; i<files.size(); ++i)
00667 {
00668
00669 __COUT__ << files[i].getDataType() << std::endl;
00670
00671 }
00672 __COUT__ << "*********************Files End*********************" << std::endl;
00673
00674
00675
00676
00677 }
00678 else if(Command == "Export")
00679 {
00680 __SS__ << "This doesn't compile Dan." << __E__;
00681 __SS_THROW__;
00682
00683
00684
00685
00686
00687
00688
00689
00690
00691
00692
00693
00694
00695
00696
00697
00698
00699
00700
00701
00702
00703
00704
00705
00706
00707
00708
00709
00710
00711
00712
00713
00714
00715
00716
00717 }
00718 else
00719 {
00720 __COUT__ << "Command request not recognized: " << Command << std::endl;
00721 *out << "Error";
00722 return;
00723 }
00724 }
00725
00726
00727
00728
00729 *out << "test";
00730 return;
00731 }
00732
00733
00734
00735 std::string WizardSupervisor::validateUploadFileType(const std::string fileType)
00736 {
00737 for (unsigned int i=0; i<allowedFileUploadTypes_.size(); ++i)
00738 if (allowedFileUploadTypes_[i] == fileType)
00739 return matchingFileUploadTypes_[i];
00740
00741 return "";
00742 }
00743
00744
00745
00746
00747 void WizardSupervisor::cleanUpPreviews()
00748 {
00749 std::string userData = (std::string)USER_DATA_PATH;
00750
00751 DIR *dir = opendir(userData.c_str());
00752 if(!dir)
00753 {
00754 __COUT__ << "Error - User Data directory missing: " << userData << std::endl;
00755 return;
00756 }
00757
00758 struct dirent *entry;
00759 time_t dirCreateTime;
00760 unsigned int i;
00761
00762 while((entry = readdir(dir)))
00763 {
00764 if( strcmp(entry->d_name, ".") != 0 && strcmp(entry->d_name, "..") != 0
00765 && strcmp(entry->d_name, ".svn") != 0 )
00766 {
00767
00768 for(i=0;i<strlen(entry->d_name);++i)
00769 if(entry->d_name[i] == '_')
00770 { entry->d_name[i] = ' '; break; }
00771 sscanf(entry->d_name,"%li",&dirCreateTime);
00772
00773 if((time(0) - dirCreateTime) > USER_DATA_EXPIRATION_TIME)
00774 {
00775 __COUT__ << "Expired" << std::endl;
00776
00777 entry->d_name[i] = '_';
00778
00779 __COUT__ << "rm -rf " << USER_DATA_PATH + (std::string)entry->d_name << std::endl << std::endl;
00780 system(((std::string)("rm -rf " + userData + (std::string)entry->d_name)).c_str());
00781 }
00782 }
00783 }
00784
00785 closedir(dir);
00786 }
00787
00788
00789
00790
00791 void WizardSupervisor::savePostPreview(std::string &subject, std::string &text, const std::vector<cgicc::FormFile> &files, std::string creator,
00792 HttpXmlDocument *xmldoc)
00793 {
00794
00795
00796
00797
00798
00799
00800 char fileIndex[40];
00801 sprintf(fileIndex,"%lu_%lu",time(0),clock());
00802 std::string userDataPath = (std::string)USER_DATA_PATH + (std::string)fileIndex;
00803
00804 __COUT__ << "userDataPath " << userDataPath << std::endl;
00805 if(-1 == mkdir(userDataPath.c_str(),0755))
00806 {
00807 if(xmldoc) xmldoc->addTextElementToData(XML_STATUS,"Failed - directory could not be generated.");
00808 return;
00809 }
00810
00811
00812
00813
00814
00815
00816
00817
00818
00819
00820
00821
00822
00823
00824
00825
00826
00827
00828
00829
00830
00831
00832
00833
00834
00835
00836
00837
00838
00839
00840
00841
00842
00843
00844
00845
00846
00847
00848
00849
00850
00851
00852
00853
00854
00855
00856
00857
00858
00859
00860
00861
00862
00863
00864
00865
00866
00867
00868
00869
00870
00871
00872
00873
00874 }
00875
00876
00877 std::string WizardSupervisor::exec(const char* cmd)
00878 {
00879 std::array<char, 128> buffer;
00880 std::string result;
00881 std::shared_ptr<FILE> pipe(popen(cmd, "r"), pclose);
00882 if (!pipe) throw std::runtime_error("popen() failed!");
00883 while (!feof(pipe.get())) {
00884 if (fgets(buffer.data(), 128, pipe.get()) != nullptr)
00885 result += buffer.data();
00886 }
00887 return result;
00888 }
00889