1 #include "otsdaq/WizardSupervisor/WizardSupervisor.h"
3 #include "otsdaq/GatewaySupervisor/GatewaySupervisor.h"
5 #include "otsdaq/Macros/CoutMacros.h"
6 #include "otsdaq/MessageFacility/MessageFacility.h"
8 #include <xdaq/NamespaceURI.h>
9 #include "otsdaq/CgiDataUtilities/CgiDataUtilities.h"
10 #include "otsdaq/SOAPUtilities/SOAPCommand.h"
11 #include "otsdaq/SOAPUtilities/SOAPUtilities.h"
12 #include "otsdaq/WebUsersUtilities/WebUsers.h"
13 #include "otsdaq/XmlUtilities/HttpXmlDocument.h"
27 const std::string WizardSupervisor::WIZ_SUPERVISOR = __ENV__(
"OTS_CONFIGURATION_WIZARD_SUPERVISOR_SERVER");
28 const std::string WizardSupervisor::WIZ_PORT = __ENV__(
"PORT");
29 const std::string WizardSupervisor::SERVICE_DATA_PATH = __ENV__(
"SERVICE_DATA_PATH");
31 #define SECURITY_FILE_NAME WizardSupervisor::SERVICE_DATA_PATH + "/OtsWizardData/security.dat"
32 #define SEQUENCE_FILE_NAME WizardSupervisor::SERVICE_DATA_PATH + "/OtsWizardData/sequence.dat"
33 #define SEQUENCE_OUT_FILE_NAME WizardSupervisor::SERVICE_DATA_PATH + "/OtsWizardData/sequence.out"
34 #define USER_IMPORT_EXPORT_PATH WizardSupervisor::SERVICE_DATA_PATH + "/"
36 #define XML_STATUS "editUserData_status"
38 #define XML_ADMIN_STATUS "logbook_admin_status"
39 #define XML_MOST_RECENT_DAY "most_recent_day"
40 #define XML_EXPERIMENTS_ROOT "experiments"
41 #define XML_EXPERIMENT "experiment"
42 #define XML_ACTIVE_EXPERIMENT "active_experiment"
43 #define XML_EXPERIMENT_CREATE "create_time"
44 #define XML_EXPERIMENT_CREATOR "creator"
46 #define XML_LOGBOOK_ENTRY "logbook_entry"
47 #define XML_LOGBOOK_ENTRY_SUBJECT "logbook_entry_subject"
48 #define XML_LOGBOOK_ENTRY_TEXT "logbook_entry_text"
49 #define XML_LOGBOOK_ENTRY_FILE "logbook_entry_file"
50 #define XML_LOGBOOK_ENTRY_TIME "logbook_entry_time"
51 #define XML_LOGBOOK_ENTRY_CREATOR "logbook_entry_creator"
52 #define XML_LOGBOOK_ENTRY_HIDDEN "logbook_entry_hidden"
53 #define XML_LOGBOOK_ENTRY_HIDER "logbook_entry_hider"
54 #define XML_LOGBOOK_ENTRY_HIDDEN_TIME "logbook_entry_hidden_time"
56 #define XML_PREVIEW_INDEX "preview_index"
57 #define LOGBOOK_PREVIEW_FILE "preview.xml"
62 #define __MF_SUBJECT__ "Wizard"
65 const std::vector<std::string> WizardSupervisor::allowedFileUploadTypes_ = {
74 const std::vector<std::string> WizardSupervisor::matchingFileUploadTypes_ = {
87 WizardSupervisor::WizardSupervisor(xdaq::ApplicationStub* s)
88 : xdaq::Application(s)
90 , supervisorClass_(getApplicationDescriptor()->getClassName())
91 , supervisorClassNoNamespace_(
92 supervisorClass_.substr(supervisorClass_.find_last_of(
":") + 1, supervisorClass_.length() - supervisorClass_.find_last_of(
":")))
94 __COUT__ <<
"Constructor started." << __E__;
99 allSupervisorInfo_.init(getApplicationContext());
101 xgi::bind(
this, &WizardSupervisor::Default,
"Default");
102 xgi::bind(
this, &WizardSupervisor::verification,
"Verify");
103 xgi::bind(
this, &WizardSupervisor::request,
"Request");
104 xgi::bind(
this, &WizardSupervisor::requestIcons,
"requestIcons");
105 xgi::bind(
this, &WizardSupervisor::editSecurity,
"editSecurity");
106 xgi::bind(
this, &WizardSupervisor::UserSettings,
"UserSettings");
107 xgi::bind(
this, &WizardSupervisor::tooltipRequest,
"TooltipRequest");
108 xgi::bind(
this, &WizardSupervisor::toggleSecurityCodeGeneration,
"ToggleSecurityCodeGeneration");
109 xoap::bind(
this, &WizardSupervisor::supervisorSequenceCheck,
"SupervisorSequenceCheck", XDAQ_NS_URI);
110 xoap::bind(
this, &WizardSupervisor::supervisorLastTableGroupRequest,
"SupervisorLastTableGroupRequest", XDAQ_NS_URI);
114 GatewaySupervisor::indicateOtsAlive();
116 __COUT__ <<
"Constructor complete." << __E__;
120 WizardSupervisor::~WizardSupervisor(
void) { destroy(); }
123 void WizardSupervisor::init(
void)
126 mkdir((WizardSupervisor::SERVICE_DATA_PATH).c_str(), 0755);
127 mkdir((WizardSupervisor::SERVICE_DATA_PATH +
"/OtsWizardData").c_str(), 0755);
132 void WizardSupervisor::requestIcons(xgi::Input* in, xgi::Output* out)
134 cgicc::Cgicc cgi(in);
136 std::string submittedSequence = CgiDataUtilities::postData(cgi,
"sequence");
139 if(securityCode_.compare(submittedSequence) != 0)
141 __COUT__ <<
"Unauthorized Request made, security sequence doesn't match! " << time(0) << std::endl;
146 __COUT__ <<
"***Successfully authenticated security sequence. " << time(0) << std::endl;
159 *out <<
"Configure,CFG,0,1,icon-Configure.png,/urn:xdaq-application:lid=280/,/"
161 <<
",Table Editor,TBL,0,1,icon-ControlsDashboard.png,"
162 "/urn:xdaq-application:lid=280/?configWindowName=tableEditor,/"
164 <<
",Desktop Icon Editor,ICON,0,1,icon-IconEditor.png,"
165 "/WebPath/html/ConfigurationGUI_subset.html?urn=280&subsetBasePath=DesktopIconTable&"
166 "recordAlias=Icons&groupingFieldList=Status%2CForceOnlyOneInstance%2CRequiredPermissionLevel,/"
169 <<
",Edit User Accounts,USER,1,1,"
170 "/WebPath/images/dashboardImages/icon-Settings.png,/WebPath/html/UserSettings.html,/User Settings"
172 <<
",Security Settings,SEC,1,1,icon-SecuritySettings.png,"
173 "/WebPath/html/SecuritySettings.html,/User Settings"
175 <<
",Edit User Data,USER,1,1,icon-EditUserData.png,/WebPath/html/EditUserData.html,/User Settings"
179 <<
",Console,C,1,1,icon-Console.png,/urn:xdaq-application:lid=260/,/"
182 <<
",Front-end Wizard,CFG,0,1,icon-Configure.png,"
183 "/WebPath/html/RecordWiz_ConfigurationGUI.html?urn=280&recordAlias=Front%2Dend,Config Wizards"
185 <<
",Processor Wizard,CFG,0,1,icon-Configure.png,"
186 "/WebPath/html/RecordWiz_ConfigurationGUI.html?urn=280&recordAlias=Processor,Config Wizards"
188 <<
",artdaq Config Editor,CFG,0,1,icon-Configure.png,"
189 "/WebPath/html/ConfigurationGUI_artdaq.html?urn=280,Config Wizards"
191 <<
",Block Diagram,CFG,0,1,icon-Configure.png,"
192 "/WebPath/html/ConfigurationSubsetBlockDiagram.html?urn=280,Config Wizards"
195 <<
",Code Editor,CODE,0,1,icon-CodeEditor.png,/urn:xdaq-application:lid=240/,/"
198 <<
",State Machine Screenshot,FSM-SS,1,1,icon-Physics.gif,"
199 "/WebPath/images/windowContentImages/state_machine_screenshot.png,/Documentation"
202 <<
",Redmine Project for otsdaq,RED,2,1,../otsdaqIcons/android-icon-36x36.png,"
203 "https://cdcvs.fnal.gov/redmine/projects/otsdaq,/Documentation"
205 <<
",Homepage for otsdaq,OTS,2,1,../otsdaqIcons/android-icon-36x36.png,"
206 "https://otsdaq.fnal.gov,/Documentation"
232 void WizardSupervisor::verification(xgi::Input* in, xgi::Output* out)
234 cgicc::Cgicc cgi(in);
235 std::string submittedSequence = CgiDataUtilities::getData(cgi,
"code");
236 __COUT__ <<
"submittedSequence=" << submittedSequence <<
" " << time(0) << std::endl;
238 std::string securityWarning =
"";
240 if(securityCode_.compare(submittedSequence) != 0)
242 __COUT__ <<
"Unauthorized Request made, security sequence doesn't match!" << std::endl;
243 *out <<
"Invalid code.";
249 __COUT__ <<
"*** Successfully authenticated security sequence "
250 <<
"@ " << time(0) << std::endl;
255 securityWarning =
"&secure=False";
259 *out <<
"<!DOCTYPE HTML><html lang='en'><head><title>ots wiz</title>" << GatewaySupervisor::getIconHeaderString() <<
262 <<
"<frameset col='100%' row='100%'><frame src='/WebPath/html/Wizard.html?urn=" << this->getApplicationDescriptor()->getLocalId() << securityWarning
263 <<
"'></frameset></html>";
267 void WizardSupervisor::generateURL()
269 defaultSequence_ =
true;
272 FILE* fp = fopen((SEQUENCE_FILE_NAME).c_str(),
"r");
275 __COUT_INFO__ <<
"Sequence length file found: " << SEQUENCE_FILE_NAME << std::endl;
277 fgets(line, 100, fp);
278 sscanf(line,
"%d", &length);
283 defaultSequence_ =
false;
288 __COUT_INFO__ <<
"(Reverting to default wiz security) Sequence length file NOT found: " << SEQUENCE_FILE_NAME << std::endl;
292 __COUT__ <<
"Sequence length = " << length << std::endl;
296 const char alphanum[] =
298 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
299 "abcdefghijklmnopqrstuvwxyz";
301 for(
int i = 0; i < length; ++i)
303 securityCode_ += alphanum[rand() % (
sizeof(alphanum) - 1)];
306 __COUT__ << WizardSupervisor::WIZ_SUPERVISOR <<
":" << WizardSupervisor::WIZ_PORT
307 <<
"/urn:xdaq-application:lid=" << this->getApplicationDescriptor()->getLocalId() <<
"/Verify?code=" << securityCode_ << std::endl;
313 fp = fopen((SEQUENCE_OUT_FILE_NAME).c_str(),
"w");
316 fprintf(fp,
"%s", securityCode_.c_str());
320 __COUT_ERR__ <<
"Sequence output file NOT found: " << SEQUENCE_OUT_FILE_NAME << std::endl;
325 void WizardSupervisor::printURL(
WizardSupervisor* ptr, std::string securityCode)
331 std::this_thread::sleep_for(std::chrono::seconds(2));
332 __COUT__ << WizardSupervisor::WIZ_SUPERVISOR <<
":" << WizardSupervisor::WIZ_PORT
333 <<
"/urn:xdaq-application:lid=" << ptr->getApplicationDescriptor()->getLocalId() <<
"/Verify?code=" << securityCode << std::endl;
338 void WizardSupervisor::destroy(
void)
344 void WizardSupervisor::tooltipRequest(xgi::Input* in, xgi::Output* out)
346 cgicc::Cgicc cgi(in);
348 std::string Command = CgiDataUtilities::getData(cgi,
"RequestType");
351 std::string submittedSequence = CgiDataUtilities::postData(cgi,
"sequence");
354 if(securityCode_.compare(submittedSequence) != 0)
356 __COUT__ <<
"Unauthorized Request made, security sequence doesn't match!" << std::endl;
367 if(Command ==
"check")
369 WebUsers::tooltipCheckForUsername(WebUsers::DEFAULT_ADMIN_USERNAME,
371 CgiDataUtilities::getData(cgi,
"srcFile"),
372 CgiDataUtilities::getData(cgi,
"srcFunc"),
373 CgiDataUtilities::getData(cgi,
"srcId"));
375 else if(Command ==
"setNeverShow")
377 WebUsers::tooltipSetNeverShowForUsername(WebUsers::DEFAULT_ADMIN_USERNAME,
379 CgiDataUtilities::getData(cgi,
"srcFile"),
380 CgiDataUtilities::getData(cgi,
"srcFunc"),
381 CgiDataUtilities::getData(cgi,
"srcId"),
382 CgiDataUtilities::getData(cgi,
"doNeverShow") ==
"1" ?
true :
false,
383 CgiDataUtilities::getData(cgi,
"temporarySilence") ==
"1" ?
true :
false);
386 __COUT__ <<
"Command Request, " << Command <<
", not recognized." << std::endl;
388 xmldoc.outputXmlDocument((std::ostringstream*)out,
false,
true);
392 void WizardSupervisor::toggleSecurityCodeGeneration(xgi::Input* in, xgi::Output* out)
394 cgicc::Cgicc cgi(in);
396 std::string Command = CgiDataUtilities::getData(cgi,
"RequestType");
397 __COUT__ <<
"Got to Command = " << Command << std::endl;
399 std::string submittedSequence = CgiDataUtilities::postData(cgi,
"sequence");
402 if(securityCode_.compare(submittedSequence) != 0)
404 __COUT__ <<
"Unauthorized Request made, security sequence doesn't match!" << std::endl;
409 __COUT__ <<
"***Successfully authenticated security sequence." << std::endl;
415 if(Command ==
"TurnGenerationOn")
417 __COUT__ <<
"Turning automatic URL Generation on with a sequence depth of 16!" << std::endl;
418 std::ofstream outfile((SEQUENCE_FILE_NAME).c_str());
419 outfile <<
"16" << std::endl;
423 std::thread([&](
WizardSupervisor* ptr, std::string securityCode) { printURL(ptr, securityCode); },
this, securityCode_).detach();
425 xmldoc.addTextElementToData(
"Status",
"Generation_Success");
428 __COUT__ <<
"Command Request, " << Command <<
", not recognized." << std::endl;
430 xmldoc.outputXmlDocument((std::ostringstream*)out,
false,
true);
436 xoap::MessageReference WizardSupervisor::supervisorSequenceCheck(xoap::MessageReference message)
440 parameters.addParameter(
"sequence");
441 SOAPUtilities::receive(message, parameters);
443 std::string submittedSequence = parameters.getValue(
"sequence");
447 std::map<std::string , WebUsers::permissionLevel_t> permissionMap;
449 if(securityCode_ == submittedSequence)
450 permissionMap.emplace(
451 std::pair<std::string /*groupName*/, WebUsers::permissionLevel_t>(WebUsers::DEFAULT_USER_GROUP, WebUsers::PERMISSION_LEVEL_ADMIN));
454 __COUT__ <<
"Unauthorized Request made, security sequence doesn't match!" << std::endl;
456 permissionMap.emplace(
457 std::pair<std::string /*groupName*/, WebUsers::permissionLevel_t>(WebUsers::DEFAULT_USER_GROUP, WebUsers::PERMISSION_LEVEL_INACTIVE));
462 retParameters.addParameter(
"Permissions", StringMacros::mapToString(permissionMap));
464 return SOAPUtilities::makeSOAPMessageReference(
"SequenceResponse", retParameters);
472 xoap::MessageReference WizardSupervisor::supervisorLastTableGroupRequest(xoap::MessageReference message)
475 parameters.addParameter(
"ActionOfLastGroup");
476 SOAPUtilities::receive(message, parameters);
478 return GatewaySupervisor::lastTableGroupRequestHandler(parameters);
482 void WizardSupervisor::Default(xgi::Input* , xgi::Output* out)
484 __COUT__ <<
"Unauthorized Request made, security sequence doesn't match!" << std::endl;
485 *out <<
"Unauthorized Request.";
489 void WizardSupervisor::request(xgi::Input* in, xgi::Output* out)
491 cgicc::Cgicc cgiIn(in);
493 std::string submittedSequence = CgiDataUtilities::postData(cgiIn,
"sequence");
496 if(securityCode_.compare(submittedSequence) != 0)
498 __COUT__ <<
"Unauthorized Request made, security sequence doesn't match! " << time(0) << std::endl;
499 *out << WebUsers::REQ_NO_PERMISSION_RESPONSE.c_str();
504 __COUT__ <<
"***Successfully authenticated security sequence. " << time(0) << std::endl;
508 std::string requestType = CgiDataUtilities::getData(cgiIn,
"RequestType");
509 __COUTV__(requestType);
522 if(requestType ==
"gatewayLaunchOTS" || requestType ==
"gatewayLaunchWiz")
527 __COUT_WARN__ << requestType <<
" requestType received! " << __E__;
528 __MOUT_WARN__ << requestType <<
" requestType received! " << __E__;
532 if(requestType ==
"gatewayLaunchOTS")
533 GatewaySupervisor::launchStartOTSCommand(
"LAUNCH_OTS", &cfgMgr);
534 else if(requestType ==
"gatewayLaunchWiz")
535 GatewaySupervisor::launchStartOTSCommand(
"LAUNCH_WIZ", &cfgMgr);
537 else if(requestType ==
"addDesktopIcon")
539 GatewaySupervisor::handleAddDesktopIconRequest(
"admin", cgiIn, xmlOut);
541 else if(requestType ==
"getAppId")
543 GatewaySupervisor::handleGetApplicationIdRequest(&allSupervisorInfo_, cgiIn, xmlOut);
545 else if(requestType ==
"getSettings")
547 std::string accounts = CgiDataUtilities::getData(cgiIn,
"accounts");
549 __COUT__ <<
"Get Settings Request" << __E__;
550 __COUT__ <<
"accounts = " << accounts << __E__;
552 GatewaySupervisor::theWebUsers_.insertSettingsForUser(0 , &xmlOut, accounts ==
"1");
554 else if(requestType ==
"accountSettings")
556 std::string type = CgiDataUtilities::postData(cgiIn,
"type");
559 if(type ==
"updateAccount")
560 type_int = GatewaySupervisor::theWebUsers_.MOD_TYPE_UPDATE;
561 else if(type ==
"createAccount")
562 type_int = GatewaySupervisor::theWebUsers_.MOD_TYPE_ADD;
563 else if(type ==
"deleteAccount")
564 type_int = GatewaySupervisor::theWebUsers_.MOD_TYPE_DELETE;
566 std::string username = CgiDataUtilities::postData(cgiIn,
"username");
567 std::string displayname = CgiDataUtilities::postData(cgiIn,
"displayname");
568 std::string email = CgiDataUtilities::postData(cgiIn,
"useremail");
569 std::string permissions = CgiDataUtilities::postData(cgiIn,
"permissions");
570 std::string accounts = CgiDataUtilities::getData(cgiIn,
"accounts");
572 __COUT__ <<
"accountSettings Request" << __E__;
573 __COUT__ <<
"type = " << type <<
" - " << type_int << __E__;
574 __COUT__ <<
"username = " << username << __E__;
575 __COUT__ <<
"useremail = " << email << __E__;
576 __COUT__ <<
"displayname = " << displayname << __E__;
577 __COUT__ <<
"permissions = " << permissions << __E__;
579 GatewaySupervisor::theWebUsers_.modifyAccountSettings(0 , type_int, username, displayname, email, permissions);
581 __COUT__ <<
"accounts = " << accounts << __E__;
583 GatewaySupervisor::theWebUsers_.insertSettingsForUser(0 , &xmlOut, accounts ==
"1");
587 __SS__ <<
"requestType Request '" << requestType <<
"' not recognized." << __E__;
591 catch(
const std::runtime_error& e)
593 __SS__ <<
"An error was encountered handling requestType '" << requestType <<
"':" << e.what() << __E__;
594 __COUT__ <<
"\n" << ss.str();
595 xmlOut.addTextElementToData(
"Error", ss.str());
599 __SS__ <<
"An unknown error was encountered handling requestType '" << requestType <<
".' "
600 <<
"Please check the printouts to debug." << __E__;
601 __COUT__ <<
"\n" << ss.str();
602 xmlOut.addTextElementToData(
"Error", ss.str());
607 unsigned int occurance = 0;
608 std::string err = xmlOut.getMatchingValue(
"Error", occurance++);
611 __COUT_ERR__ <<
"'" << requestType <<
"' ERROR encountered: " << err << __E__;
612 __MOUT_ERR__ <<
"'" << requestType <<
"' ERROR encountered: " << err << __E__;
613 err = xmlOut.getMatchingValue(
"Error", occurance++);
618 xmlOut.outputXmlDocument((std::ostringstream*)out,
false ,
true );
623 void WizardSupervisor::editSecurity(xgi::Input* in, xgi::Output* out)
626 cgicc::Cgicc cgi(in);
627 std::string submittedSequence = CgiDataUtilities::postData(cgi,
"sequence");
628 std::string submittedSecurity = CgiDataUtilities::postData(cgi,
"selection");
631 if(securityCode_.compare(submittedSequence) != 0)
633 __COUT__ <<
"Unauthorized Request made, security sequence doesn't match!" << std::endl;
638 __COUT__ <<
"***Successfully authenticated security sequence." << std::endl;
642 if(submittedSecurity !=
"")
644 __COUT__ <<
"Selection exists!" << std::endl;
645 __COUT__ << submittedSecurity << std::endl;
647 if(submittedSecurity ==
"ResetAllUserData")
649 WebUsers::deleteUserData();
650 __COUT__ <<
"Turning URL Generation back to default!" << std::endl;
653 std::ofstream newFile((SEQUENCE_FILE_NAME).c_str());
654 newFile <<
"4" << std::endl;
658 std::thread([&](
WizardSupervisor* ptr, std::string securityCode) { printURL(ptr, securityCode); },
this, securityCode_).detach();
659 *out <<
"Default_URL_Generation";
661 else if(submittedSecurity ==
"ResetAllUserTooltips")
663 WebUsers::resetAllUserTooltips();
664 *out << submittedSecurity;
667 else if(submittedSecurity == WebUsers::SECURITY_TYPE_DIGEST_ACCESS || submittedSecurity == WebUsers::SECURITY_TYPE_NONE)
670 mkdir((WizardSupervisor::SERVICE_DATA_PATH).c_str(), 0755);
671 mkdir((WizardSupervisor::SERVICE_DATA_PATH +
"/OtsWizardData").c_str(), 0755);
673 std::ofstream writeSecurityFile;
675 writeSecurityFile.open((SECURITY_FILE_NAME).c_str());
676 if(writeSecurityFile.is_open())
677 writeSecurityFile << submittedSecurity;
680 __COUT_ERR__ <<
"Error writing file!" << std::endl;
685 writeSecurityFile.close();
689 __COUT_ERR__ <<
"Invalid submittedSecurity string: " << submittedSecurity << std::endl;
697 std::ifstream securityFile;
698 std::string security;
700 securityFile.open((SECURITY_FILE_NAME).c_str());
701 if(securityFile.is_open())
703 std::getline(securityFile, security);
704 securityFile.close();
707 security = WebUsers::SECURITY_TYPE_DEFAULT;
715 void WizardSupervisor::UserSettings(xgi::Input* in, xgi::Output* out)
718 cgicc::Cgicc cgi(in);
719 std::string submittedSequence = CgiDataUtilities::postData(cgi,
"sequence");
720 std::string securityFileName = SECURITY_FILE_NAME;
722 if((Command = CgiDataUtilities::postData(cgi,
"RequestType")) ==
"")
723 Command = cgi(
"RequestType");
725 __COUT__ << Command << std::endl;
726 __COUT__ <<
"We are vewing Users' Settings!" << std::endl;
729 if(securityCode_.compare(submittedSequence) != 0)
731 __COUT__ <<
"Unauthorized Request made, security sequence doesn't match!" << std::endl;
732 __COUT__ << submittedSequence << std::endl;
737 __COUT__ <<
"***Successfully authenticated security sequence." << std::endl;
748 __COUT__ <<
"Action exists!" << std::endl;
749 __COUT__ << Command << std::endl;
751 if(Command ==
"Import")
770 __COUT__ << cgi(
"Entry") << std::endl;
771 __COUT__ << cgi(
"Filename") << std::endl;
772 __COUT__ << cgi(
"Imported_File") << std::endl;
774 const std::vector<cgicc::FormFile> files = cgi.getFiles();
775 __COUT__ <<
"FormFiles: " <<
sizeof(files) << std::endl;
776 __COUT__ <<
"Number of files: " << files.size() << std::endl;
778 for(
unsigned int i = 0; i < files.size(); ++i)
780 std::string filename = USER_IMPORT_EXPORT_PATH + files[i].getFilename();
781 __COUT__ << filename << std::endl;
782 std::ofstream myFile;
783 myFile.open(filename.c_str());
784 files[0].writeToStream(myFile);
787 __COUT__ << files[0].getFilename() << std::endl;
788 __COUT__ <<
"********************Files Begin********************" << std::endl;
789 for(
unsigned int i = 0; i < files.size(); ++i)
791 __COUT__ << files[i].getDataType() << std::endl;
793 __COUT__ <<
"*********************Files End*********************" << std::endl;
799 else if(Command ==
"Export")
801 __SS__ <<
"This has been commented out due to problems compiling. Contact "
845 __COUT__ <<
"Command request not recognized: " << Command << std::endl;
857 std::string WizardSupervisor::validateUploadFileType(
const std::string fileType)
859 for(
unsigned int i = 0; i < allowedFileUploadTypes_.size(); ++i)
860 if(allowedFileUploadTypes_[i] == fileType)
861 return matchingFileUploadTypes_[i];
869 void WizardSupervisor::cleanUpPreviews()
871 std::string userData = (std::string)USER_IMPORT_EXPORT_PATH;
873 DIR* dir = opendir(userData.c_str());
876 __COUT__ <<
"Error - User Data directory missing: " << userData << std::endl;
880 struct dirent* entry;
881 time_t dirCreateTime;
884 while((entry = readdir(dir)))
886 if(strcmp(entry->d_name,
".") != 0 && strcmp(entry->d_name,
"..") != 0 && strcmp(entry->d_name,
".svn") != 0)
889 for(i = 0; i < strlen(entry->d_name); ++i)
890 if(entry->d_name[i] ==
'_')
892 entry->d_name[i] =
' ';
895 sscanf(entry->d_name,
"%li", &dirCreateTime);
897 if((time(0) - dirCreateTime) > USER_DATA_EXPIRATION_TIME)
899 __COUT__ <<
"Expired" << std::endl;
901 entry->d_name[i] =
'_';
903 __COUT__ <<
"rm -rf " << USER_IMPORT_EXPORT_PATH + (std::string)entry->d_name << std::endl << std::endl;
904 system(((std::string)(
"rm -rf " + userData + (std::string)entry->d_name)).c_str());
915 void WizardSupervisor::savePostPreview(
916 std::string& , std::string& ,
const std::vector<cgicc::FormFile>& , std::string ,
HttpXmlDocument* xmldoc)
925 sprintf(fileIndex,
"%lu_%lu", time(0),
927 std::string userDataPath = (std::string)USER_IMPORT_EXPORT_PATH + (std::string)fileIndex;
929 __COUT__ <<
"userDataPath " << userDataPath << std::endl;
930 if(-1 == mkdir(userDataPath.c_str(), 0755))
933 xmldoc->addTextElementToData(XML_STATUS,
"Failed - directory could not be generated.");