1 #include "otsdaq-utilities/Logbook/LogbookSupervisor.h"
20 const std::string LOGBOOK_PATH = __ENV__(
"LOGBOOK_DATA_PATH") + std::string(
"/");
21 #define LOGBOOK_CATEGORY_LIST_PATH LOGBOOK_PATH + "category_list.xml"
22 #define LOGBOOK_CATEGORY_DIR_PREFACE "log_"
23 #define LOGBOOK_UPLOADS_PATH "uploads/"
24 #define LOGBOOK_LOGBOOKS_PATH "logbooks/"
25 #define LOGBOOK_PREVIEWS_PATH "previews/"
26 #define LOGBOOK_FILE_PREFACE "entries_"
27 #define LOGBOOK_FILE_EXTENSION ".xml"
29 #define ACTIVE_CATEGORY_PATH LOGBOOK_PATH + "active_category.txt"
30 #define REMOVE_CATEGORY_LOG_PATH LOGBOOK_PATH + "removed_categories.log"
32 #define XML_ADMIN_STATUS "logbook_admin_status"
33 #define XML_STATUS "logbook_status"
34 #define XML_MOST_RECENT_DAY "most_recent_day"
35 #define XML_CATEGORY_ROOT "categories"
36 #define XML_CATEGORY "category"
37 #define XML_ACTIVE_CATEGORY "active_category"
38 #define XML_CATEGORY_CREATE "create_time"
39 #define XML_CATEGORY_CREATOR "creator"
41 #define XML_LOGBOOK_ENTRY "logbook_entry"
42 #define XML_LOGBOOK_ENTRY_SUBJECT "logbook_entry_subject"
43 #define XML_LOGBOOK_ENTRY_TEXT "logbook_entry_text"
44 #define XML_LOGBOOK_ENTRY_FILE "logbook_entry_file"
45 #define XML_LOGBOOK_ENTRY_TIME "logbook_entry_time"
46 #define XML_LOGBOOK_ENTRY_CREATOR "logbook_entry_creator"
47 #define XML_LOGBOOK_ENTRY_HIDDEN "logbook_entry_hidden"
48 #define XML_LOGBOOK_ENTRY_HIDER "logbook_entry_hider"
49 #define XML_LOGBOOK_ENTRY_HIDDEN_TIME "logbook_entry_hidden_time"
51 #define XML_PREVIEW_INDEX "preview_index"
52 #define LOGBOOK_PREVIEW_FILE "preview.xml"
53 #define LOGBOOK_PREVIEW_UPLOAD_PREFACE "upload_"
58 #define __MF_SUBJECT__ "Logbook"
63 int sendmail(
const char* to,
const char* from,
const char* subject,
const char* message)
66 FILE* mailpipe = popen(
"/usr/lib/sendmail -t",
"w");
69 fprintf(mailpipe,
"To: %s\n", to);
70 fprintf(mailpipe,
"From: %s\n", from);
71 fprintf(mailpipe,
"Subject: %s\n\n", subject);
72 fwrite(message, 1, strlen(message), mailpipe);
73 fwrite(
".\n", 1, 2, mailpipe);
79 perror(
"Failed to invoke sendmail");
85 LogbookSupervisor::LogbookSupervisor(xdaq::ApplicationStub* stub)
87 , allowedFileUploadTypes_({
"image/png",
94 , matchingFileUploadTypes_(
95 {
"png",
"jpeg",
"gif",
"bmp",
"pdf",
"zip",
"txt"})
106 this, &LogbookSupervisor::MakeSystemLogEntry,
"MakeSystemLogEntry", XDAQ_NS_URI);
115 LogbookSupervisor::~LogbookSupervisor(
void) { destroy(); }
118 void LogbookSupervisor::init(
void)
125 std::string path = LOGBOOK_PATH;
126 DIR* dir = opendir(path.c_str());
129 else if(-1 == mkdir(path.c_str(), 0755))
132 std::stringstream ss;
133 ss << __COUT_HDR_FL__ <<
"Service directory creation failed: " << path
138 path = LOGBOOK_PATH + LOGBOOK_UPLOADS_PATH;
139 dir = opendir(path.c_str());
142 else if(-1 == mkdir((path).c_str(), 0755))
145 __SS__ <<
"Service directory creation failed: " << path << std::endl;
149 path = LOGBOOK_PATH + LOGBOOK_LOGBOOKS_PATH;
150 dir = opendir(path.c_str());
153 else if(-1 == mkdir(path.c_str(), 0755))
156 __SS__ <<
"Service directory creation failed: " << path << std::endl;
162 __COUT__ <<
"Active Category is " << activeCategory_ << std::endl;
163 mostRecentDayIndex_ = 0;
167 void LogbookSupervisor::destroy(
void)
173 void LogbookSupervisor::defaultPage(xgi::Input* , xgi::Output* out)
175 __COUT__ <<
" active category " << activeCategory_ << std::endl;
176 *out <<
"<!DOCTYPE HTML><html lang='en'><frameset col='100%' row='100%'><frame "
177 "src='/WebPath/html/Logbook.html?urn="
178 << this->getApplicationDescriptor()->getLocalId()
179 <<
"&active_category=" << activeCategory_ <<
"'></frameset></html>";
188 CorePropertySupervisorBase::setSupervisorProperty(
189 CorePropertySupervisorBase::SUPERVISOR_PROPERTIES.UserPermissionsThreshold,
191 "*=1 | CreateCategory=-1 | RemoveCategory=-1 | GetCategoryListAdmin=-1 "
192 "| SetActiveCategory=-1" +
193 " | AdminRemoveRestoreEntry=-1");
201 CorePropertySupervisorBase::setSupervisorProperty(
202 CorePropertySupervisorBase::SUPERVISOR_PROPERTIES.AutomatedRequestTypes,
204 CorePropertySupervisorBase::setSupervisorProperty(
205 CorePropertySupervisorBase::SUPERVISOR_PROPERTIES.NonXMLRequestTypes,
206 "LogImage | LogReport");
207 CorePropertySupervisorBase::setSupervisorProperty(
208 CorePropertySupervisorBase::SUPERVISOR_PROPERTIES.RequireUserLockRequestTypes,
209 "CreateCategory | RemoveCategory | PreviewEntry | AdminRemoveRestoreEntry");
219 const WebUsers::RequestUserInfo& userInfo)
221 __COUTTV__(requestType);
246 if(requestType ==
"CreateCategory")
264 std::string creator = userInfo.username_;
268 __COUT__ <<
"Created" << std::endl;
270 else if(requestType ==
"RemoveCategory")
282 std::string remover = userInfo.username_;
285 else if(requestType ==
"GetCategoryList")
289 if(userInfo.permissionLevel_ >=
291 "GetCategoryListAdmin"))
293 xmlOut.addTextElementToData(
"is_admin",
"0");
298 xmlOut.addTextElementToData(
"is_admin",
"1");
299 getCategories(&xmlOut);
301 else if(requestType ==
"SetActiveCategory")
314 else if(requestType ==
"RefreshLogbook")
320 uint32_t Duration = CgiDataUtilities::postDataAsInt(cgiIn,
"Duration");
323 sscanf(Date.c_str(),
"%li", &date);
325 __COUT__ <<
"date " << date <<
" duration " << Duration << std::endl;
326 std::stringstream str;
327 refreshLogbook(date, Duration, &xmlOut, (std::ostringstream*)&str);
328 __COUT__ << str.str() << std::endl;
330 else if(requestType ==
"PreviewEntry")
339 std::string EntryText = cgiIn(
"EntryText");
340 __COUT__ <<
"EntryText " << EntryText << std::endl << std::endl;
341 std::string EntrySubject = cgiIn(
"EntrySubject");
342 __COUT__ <<
"EntrySubject " << EntrySubject << std::endl << std::endl;
345 std::string creator = userInfo.username_;
347 savePostPreview(EntrySubject, EntryText, cgiIn.getFiles(), creator, &xmlOut);
351 else if(requestType ==
"ApproveEntry")
359 movePreviewEntry(PreviewNumber, Approve ==
"1", &xmlOut);
361 else if(requestType ==
"AdminRemoveRestoreEntry")
373 std::string hider = userInfo.username_;
375 hideLogbookEntry(EntryId, Hide, hider);
377 xmlOut.addTextElementToData(XML_ADMIN_STATUS,
"1");
380 __COUT__ <<
"requestType request not recognized." << std::endl;
390 const WebUsers::RequestUserInfo& )
396 if(requestType ==
"LogImage")
399 __COUT__ <<
" Get Log Image " << src << std::endl;
401 out <<
"<!DOCTYPE HTML><html lang='en'><frameset col='100%' row='100%'><frame "
402 "src='/WebPath/html/LogbookImage.html?urn="
403 << this->getApplicationDescriptor()->getLocalId() <<
"&src=" << src
404 <<
"'></frameset></html>";
406 else if(requestType ==
"LogReport")
409 __COUT__ <<
" Start Log Report for " << activeCategory << std::endl;
411 out <<
"<!DOCTYPE HTML><html lang='en'><header><title>ots Logbook "
412 "Reports</title></header><frameset col='100%' row='100%'><frame "
413 "src='/WebPath/html/LogbookReport.html?urn="
414 << this->getApplicationDescriptor()->getLocalId()
415 <<
"&activeCategory=" << activeCategory <<
"'></frameset></html>";
418 __COUT__ <<
"requestType request not recognized." << std::endl;
429 SOAPUtilities::receive(msg, parameters);
430 std::string EntryText = parameters.getValue(
"EntryText");
431 std::string SubjectText = parameters.getValue(
"SubjectText");
433 if(SubjectText ==
"")
434 SubjectText =
"System Log";
436 __COUT__ <<
"Received External Supervisor System Entry " << EntryText << std::endl;
437 __COUTV__(SubjectText);
438 __COUT__ <<
"Active Category is " << activeCategory_ << std::endl;
440 std::string retStr =
"Success";
443 logDirPath = (std::string)LOGBOOK_PATH + (std::string)LOGBOOK_LOGBOOKS_PATH +
444 (std::string)LOGBOOK_CATEGORY_DIR_PREFACE + activeCategory_;
446 char dayIndexStr[20];
449 xercesc::DOMElement* entryEl;
452 if(activeCategory_ ==
"")
455 "Warning - Currently, no Active Category. Turn off the Logbook XDAQ "
456 "Application to suppress this message.";
457 __COUT__ << retStr << std::endl;
462 dir = opendir(logDirPath.c_str());
465 retStr =
"Error - Active Category directory missing.";
466 __COUT__ << retStr << std::endl;
471 sprintf(dayIndexStr,
"%6.6lu", time(0) / (60 * 60 * 24));
473 logPath = logDirPath +
"/" + LOGBOOK_FILE_PREFACE + activeCategory_ +
"_" +
474 (std::string)dayIndexStr + LOGBOOK_FILE_EXTENSION;
475 __COUT__ <<
"logPath " << logPath << std::endl;
488 entryEl = logXml.addTextElementToData(XML_LOGBOOK_ENTRY);
505 return SOAPUtilities::makeSOAPMessageReference(
"SystemLogEntryStatusResponse",
550 std::string LogbookSupervisor::getActiveCategory()
552 FILE* fp = fopen(std::string((std::string)ACTIVE_CATEGORY_PATH).c_str(),
"r");
554 activeCategory_ =
"";
558 if(!fgets(line, 100, fp))
564 if(line[strlen(line) - 2] ==
'\r')
565 line[strlen(line) - 2] =
'\0';
566 else if(line[strlen(line) - 1] ==
'\n')
567 line[strlen(line) - 1] =
'\0';
569 activeCategory_ = line;
572 return activeCategory_;
578 void LogbookSupervisor::setActiveCategory(std::string category)
580 FILE* fp = fopen(std::string((std::string)ACTIVE_CATEGORY_PATH).c_str(),
"w");
583 __COUT__ <<
"FATAL ERROR!!! - file write" << std::endl;
587 fprintf(fp,
"%s", category.c_str());
590 if(activeCategory_ !=
"" &&
591 activeCategory_ != category)
592 theRemoteWebUsers_.makeSystemLogEntry(
593 "Category was made inactive.");
595 bool entryNeeded =
false;
597 activeCategory_ != category)
600 activeCategory_ = category;
601 __COUT__ <<
"Active Category set to " << activeCategory_ << std::endl;
604 theRemoteWebUsers_.makeSystemLogEntry(
605 "Category was made active.");
611 bool LogbookSupervisor::validateCategoryName(std::string& exp)
613 if(exp.length() < CATEGORY_NAME_MIN_LENTH || exp.length() > CATEGORY_NAME_MAX_LENTH)
615 for(
int i = 0; i < (int)exp.length(); ++i)
616 if(!((exp[i] >=
'a' && exp[i] <=
'z') || (exp[i] >=
'A' && exp[i] <=
'Z') ||
617 (exp[i] >=
'0' && exp[i] <=
'9') || (exp[i] ==
'-' || exp[i] ==
'_')))
619 exp = exp.substr(0, i) + exp.substr(i + 1);
630 void LogbookSupervisor::getCategories(
HttpXmlDocument* xmlOut, std::ostringstream* out)
636 __COUT__ <<
"Fatal Error - Category database." << std::endl;
637 __COUT__ <<
"Creating empty category database." << std::endl;
639 expXml.addTextElementToData((std::string)XML_CATEGORY_ROOT);
644 std::vector<std::string> exps;
648 xmlOut->addTextElementToData(XML_ACTIVE_CATEGORY, activeCategory_);
650 for(
unsigned int i = 0; i < exps.size(); ++i)
653 xmlOut->addTextElementToData(XML_CATEGORY, exps[i]);
655 *out << exps[i] << std::endl;
661 void LogbookSupervisor::createCategory(std::string category,
665 if(!validateCategoryName(category))
668 xmlOut->addTextElementToData(
669 XML_ADMIN_STATUS,
"Error - Category name must be 3-25 characters.");
673 __COUT__ <<
"category " << category << std::endl;
676 std::string dirPath = (std::string)LOGBOOK_PATH + (std::string)LOGBOOK_LOGBOOKS_PATH +
677 (std::string)LOGBOOK_CATEGORY_DIR_PREFACE + category;
679 __COUT__ <<
"dirPath " << dirPath << std::endl;
681 bool directoryExists =
false;
682 DIR* dir = opendir(dirPath.c_str());
686 directoryExists =
true;
694 xmlOut->addTextElementToData(XML_ADMIN_STATUS,
695 "Fatal Error - Category database.");
699 std::vector<std::string> exps;
702 for(
unsigned int i = 0; i < exps.size(); ++i)
703 if(category == exps[i])
706 xmlOut->addTextElementToData(
708 "Failed - Category, " + category +
", already exists.");
711 __COUT__ <<
"categories count: " << exps.size() << std::endl;
719 xercesc::DOMElement* expEl =
722 sprintf(createTime,
"%lu", time(0));
731 dirPath +=
"/" + (std::string)LOGBOOK_UPLOADS_PATH;
732 __COUT__ <<
"Checking uploads directory" << std::endl;
734 directoryExists =
false;
735 dir = opendir(dirPath.c_str());
738 __COUT__ <<
"Creating uploads directory" << std::endl;
739 if(-1 == mkdir(dirPath.c_str(), 0755))
742 xmlOut->addTextElementToData(XML_ADMIN_STATUS,
743 "Failed - uploads directory for " +
744 category +
" was not created.");
745 __COUT__ <<
"Uploads directory failure." << std::endl;
752 xmlOut->addTextElementToData(XML_ADMIN_STATUS,
753 "Directory already exists for " + category +
754 ", re-added to list of categories.");
757 __COUT__ <<
"Creating category and uploads directory at: " << dirPath << std::endl;
758 if(-1 == mkdir(dirPath.c_str(), 0755) ||
759 -1 == mkdir((dirPath +
"/" + (std::string)LOGBOOK_UPLOADS_PATH).c_str(), 0755))
762 xmlOut->addTextElementToData(
764 "Failed - directory, " + category +
", could not be created.");
769 xmlOut->addTextElementToData(XML_ADMIN_STATUS,
770 "Category, " + category +
", successfully created.");
777 void LogbookSupervisor::webUserSetActiveCategory(std::string category,
782 setActiveCategory(category);
784 xmlOut->addTextElementToData(XML_ADMIN_STATUS,
785 "Active category cleared successfully.");
793 xmlOut->addTextElementToData(XML_ADMIN_STATUS,
794 "Fatal Error - Category database.");
797 std::vector<std::string> exps;
801 for(i = 0; i < exps.size(); ++i)
802 if(category == exps[i])
808 xmlOut->addTextElementToData(
809 XML_ADMIN_STATUS,
"Failed - Category, " + category +
", not found.");
814 setActiveCategory(category);
816 xmlOut->addTextElementToData(
817 XML_ADMIN_STATUS,
"Active category set to " + category +
" successfully.");
824 void LogbookSupervisor::removeCategory(std::string category,
828 __COUT__ <<
"category " << category << std::endl;
835 xmlOut->addTextElementToData(XML_ADMIN_STATUS,
836 "Fatal Error - Category database.");
839 std::vector<std::string> exps;
843 for(i = 0; i < exps.size(); ++i)
844 if(category == exps[i])
850 xmlOut->addTextElementToData(
851 XML_ADMIN_STATUS,
"Failed - Category, " + category +
", not found.");
860 __COUT__ <<
"categories original count: " << expXml.
getChildrenCount(parent)
863 __COUT__ <<
"categories new count: " << expXml.
getChildrenCount(parent) << std::endl;
866 FILE* fp = fopen(((std::string)REMOVE_CATEGORY_LOG_PATH).c_str(),
"a");
870 xmlOut->addTextElementToData(XML_ADMIN_STATUS,
"Fatal Error - Remove log.");
874 "%s -- %s Category removed by %s.\n",
875 asctime(localtime(&((time_t
const&)(time(0))))),
883 if(activeCategory_ == category)
887 xmlOut->addTextElementToData(XML_ADMIN_STATUS,
888 "Category, " + category +
", successfully removed.");
897 void LogbookSupervisor::refreshLogbook(time_t date,
900 std::ostringstream* out,
901 std::string category)
904 category = activeCategory_;
906 xmlOut->addTextElementToData(XML_ACTIVE_CATEGORY, category);
909 std::string dirPath = (std::string)LOGBOOK_PATH + (std::string)LOGBOOK_LOGBOOKS_PATH +
910 (std::string)LOGBOOK_CATEGORY_DIR_PREFACE + category;
913 *out << __COUT_HDR_FL__ <<
"dirPath " << dirPath << std::endl;
915 DIR* dir = opendir(dirPath.c_str());
919 xmlOut->addTextElementToData(
920 XML_STATUS,
"Error - Directory for category, " + category +
", missing.");
922 *out << __COUT_HDR_FL__ <<
"Error - Directory missing" << std::endl;
926 unsigned int baseDay;
931 unsigned int extractedDay;
934 mostRecentDayIndex_ = 0;
935 while((drnt = readdir(dir)))
940 if(strcmp(&(drnt->d_name[strlen(drnt->d_name) - 4]),
".xml"))
943 for(finish = strlen(drnt->d_name) - 1; finish > 0; --finish)
944 if(drnt->d_name[finish] ==
'.')
949 *out << __COUT_HDR_FL__ <<
"failed to find day index finish "
953 for(start = finish - 1; start > 0; --start)
954 if(drnt->d_name[start - 1] ==
'_')
959 *out << __COUT_HDR_FL__ <<
"failed to find day index start "
963 drnt->d_name[finish] =
'\0';
964 extractedDay = atoi((
char*)(&(drnt->d_name[start])));
967 if(!mostRecentDayIndex_ || mostRecentDayIndex_ < extractedDay)
968 mostRecentDayIndex_ = extractedDay;
971 *out << __COUT_HDR_FL__
972 <<
"dirContents done, found most recent day: " << mostRecentDayIndex_
975 baseDay = mostRecentDayIndex_;
978 baseDay = (date / (60 * 60 * 24));
981 std::string entryPath;
982 char dayIndexStr[20];
988 for(uint32_t i = duration; i != 0; --i)
990 sprintf(dayIndexStr,
"%6.6u", baseDay - i + 1);
991 entryPath = dirPath +
"/" + LOGBOOK_FILE_PREFACE + category +
"_" +
992 (std::string)dayIndexStr + LOGBOOK_FILE_EXTENSION;
995 *out << __COUT_HDR_FL__ <<
"Directory Entry " << entryPath << std::endl;
997 fp = fopen(entryPath.c_str(),
"r");
1001 *out << __COUT_HDR_FL__ <<
"File not found" << std::endl;
1012 xmlOut->addTextElementToData(
1013 XML_STATUS,
"Critical Failure - log did not load. Notify admins.");
1015 *out << __COUT_HDR_FL__ <<
"Failure - log XML did not load" << std::endl;
1024 xmlOut->addTextElementToData(XML_STATUS,
"1");
1026 *out << __COUT_HDR_FL__ <<
"Today: " << time(0) / (60 * 60 * 24) << std::endl;
1028 sprintf(dayIndexStr,
"%lu", time(0) / (60 * 60 * 24) - mostRecentDayIndex_);
1030 xmlOut->addTextElementToData(XML_MOST_RECENT_DAY,
1038 void LogbookSupervisor::cleanUpPreviews()
1040 std::string previewPath =
1041 (std::string)LOGBOOK_PATH + (std::string)LOGBOOK_PREVIEWS_PATH;
1043 DIR* dir = opendir(previewPath.c_str());
1046 __COUT__ <<
"Error - Previews directory missing: " << previewPath << std::endl;
1050 struct dirent* entry;
1051 time_t dirCreateTime;
1058 if(strcmp(entry->d_name,
".") != 0 && strcmp(entry->d_name,
"..") != 0 &&
1059 strcmp(entry->d_name,
".svn") != 0)
1062 for(i = 0; i < strlen(entry->d_name); ++i)
1063 if(entry->d_name[i] ==
'_')
1065 entry->d_name[i] =
' ';
1068 sscanf(entry->d_name,
"%li", &dirCreateTime);
1070 if((time(0) - dirCreateTime) > LOGBOOK_PREVIEW_EXPIRATION_TIME)
1072 __COUT__ <<
"Expired" << std::endl;
1074 entry->d_name[i] =
'_';
1076 __COUT__ <<
"rm -rf " << previewPath + (std::string)entry->d_name
1080 ((std::string)(
"rm -rf " + previewPath + (std::string)entry->d_name))
1092 void LogbookSupervisor::savePostPreview(std::string& subject,
1094 const std::vector<cgicc::FormFile>& files,
1095 std::string creator,
1098 if(activeCategory_ ==
"")
1101 xmlOut->addTextElementToData(XML_STATUS,
1102 "Failed - no active category currently!");
1111 std::string previewPath = (std::string)LOGBOOK_PATH +
1112 (std::string)LOGBOOK_PREVIEWS_PATH + (std::string)fileIndex;
1114 __COUT__ <<
"previewPath " << previewPath << std::endl;
1115 if(-1 == mkdir(previewPath.c_str(), 0755))
1118 xmlOut->addTextElementToData(XML_STATUS,
1119 "Failed - preview could not be generated.");
1134 escapeLogbookEntry(text);
1135 escapeLogbookEntry(subject);
1136 __COUT__ <<
"~~subject " << subject << std::endl
1137 <<
"~~text " << text << std::endl
1142 previewXml.addTextElementToData(XML_LOGBOOK_ENTRY);
1144 XML_LOGBOOK_ENTRY_TIME, fileIndex, XML_LOGBOOK_ENTRY);
1146 xmlOut->addTextElementToData(XML_LOGBOOK_ENTRY_TIME, fileIndex);
1148 XML_LOGBOOK_ENTRY_CREATOR, creator, XML_LOGBOOK_ENTRY);
1150 xmlOut->addTextElementToData(XML_LOGBOOK_ENTRY_CREATOR,
1154 xmlOut->addTextElementToData(XML_LOGBOOK_ENTRY_TEXT, text);
1156 XML_LOGBOOK_ENTRY_SUBJECT, subject, XML_LOGBOOK_ENTRY);
1158 xmlOut->addTextElementToData(XML_LOGBOOK_ENTRY_SUBJECT,
1161 __COUT__ <<
"file size " << files.size() << std::endl;
1163 std::string filename;
1164 std::ofstream myfile;
1165 for(
unsigned int i = 0; i < files.size(); ++i)
1168 XML_LOGBOOK_ENTRY_FILE, files[i].getDataType(), XML_LOGBOOK_ENTRY);
1170 xmlOut->addTextElementToData(XML_LOGBOOK_ENTRY_FILE,
1171 files[i].getDataType());
1173 if((filename = validateUploadFileType(files[i].getDataType())) ==
1177 xmlOut->addTextElementToData(
1179 "Failed - invalid file type, " + files[i].getDataType() +
".");
1184 sprintf(fileIndex,
"%d", i);
1185 filename = previewPath +
"/" + (std::string)LOGBOOK_PREVIEW_UPLOAD_PREFACE +
1186 (std::string)fileIndex +
"." + filename;
1188 __COUT__ <<
"file " << i <<
" - " << filename << std::endl;
1189 myfile.open(filename.c_str());
1190 if(myfile.is_open())
1192 files[i].writeToStream(myfile);
1198 previewXml.
saveXmlDocument(previewPath +
"/" + (std::string)LOGBOOK_PREVIEW_FILE);
1201 xmlOut->addTextElementToData(XML_STATUS,
"1");
1203 xmlOut->addTextElementToData(XML_PREVIEW_INDEX,
1213 void LogbookSupervisor::movePreviewEntry(std::string previewNumber,
1217 __COUT__ <<
"previewNumber " << previewNumber
1218 << (approve ?
" Accepted" :
" Cancelled") << std::endl;
1220 std::string sysCmd, previewPath = (std::string)LOGBOOK_PATH +
1221 (std::string)LOGBOOK_PREVIEWS_PATH + previewNumber;
1228 previewXml.
loadXmlDocument(previewPath +
"/" + (std::string)LOGBOOK_PREVIEW_FILE);
1230 std::string logPath,
1231 logDirPath = (std::string)LOGBOOK_PATH + (std::string)LOGBOOK_LOGBOOKS_PATH +
1232 (std::string)LOGBOOK_CATEGORY_DIR_PREFACE + activeCategory_;
1235 DIR* dir = opendir(logDirPath.c_str());
1238 __COUT__ <<
"Error - Active Category directory missing: " << logPath
1244 char dayIndexStr[20];
1245 sprintf(dayIndexStr,
"%6.6lu", time(0) / (60 * 60 * 24));
1247 logPath = logDirPath +
"/" + LOGBOOK_FILE_PREFACE + activeCategory_ +
"_" +
1248 (std::string)dayIndexStr + LOGBOOK_FILE_EXTENSION;
1249 __COUT__ <<
"logPath " << logPath << std::endl;
1267 std::vector<std::string> fileTypes;
1269 std::string entryTimeLabel = previewXml.
getMatchingValue(XML_LOGBOOK_ENTRY_TIME);
1270 std::string fileExtension, previewFilename, logFilename;
1272 for(
unsigned int i = 0; i < fileTypes.size(); ++i)
1274 if((fileExtension = validateUploadFileType(fileTypes[i])) ==
1277 __COUT__ <<
"Failed - invalid file type: " << fileTypes[i] << std::endl;
1282 sprintf(fileIndex,
"%d", i);
1283 previewFilename = (std::string)LOGBOOK_PREVIEW_UPLOAD_PREFACE +
1284 (std::string)fileIndex +
"." + fileExtension;
1285 logFilename = (std::string)LOGBOOK_PREVIEW_UPLOAD_PREFACE + entryTimeLabel +
1286 "_" + (std::string)fileIndex +
"." + fileExtension;
1288 sysCmd =
"mv " + (previewPath +
"/" + previewFilename) +
" " +
1289 (logDirPath +
"/" + (std::string)LOGBOOK_UPLOADS_PATH + logFilename);
1290 __COUT__ << sysCmd << std::endl;
1291 system(sysCmd.c_str());
1296 sysCmd =
"rm -rf " + previewPath;
1297 __COUT__ << sysCmd << std::endl << std::endl;
1298 system(sysCmd.c_str());
1304 std::string LogbookSupervisor::validateUploadFileType(
const std::string fileType)
1306 for(
unsigned int i = 0; i < allowedFileUploadTypes_.size(); ++i)
1307 if(allowedFileUploadTypes_[i] == fileType)
1308 return matchingFileUploadTypes_[i];
1317 void LogbookSupervisor::escapeLogbookEntry(std::string& )
1331 void LogbookSupervisor::hideLogbookEntry(
const std::string& entryId,
1333 const std::string& hider)
1335 __COUT__ <<
"Hide=" << hide <<
" for entryid " << entryId << std::endl;
1338 char dayIndexStr[20];
1340 for(i = 0; i < entryId.length(); ++i)
1341 if(entryId[i] ==
'_')
1343 dayIndexStr[i] =
'\0';
1347 dayIndexStr[i] = entryId[i];
1349 sscanf(dayIndexStr,
"%li", &days);
1350 days /= 60 * 60 * 24;
1351 sprintf(dayIndexStr,
"%6.6lu", days);
1353 std::string logDirPath = (std::string)LOGBOOK_PATH +
1354 (std::string)LOGBOOK_LOGBOOKS_PATH +
1355 (std::string)LOGBOOK_CATEGORY_DIR_PREFACE + activeCategory_;
1356 std::string logPath = logDirPath +
"/" + LOGBOOK_FILE_PREFACE + activeCategory_ +
1357 "_" + (std::string)dayIndexStr + LOGBOOK_FILE_EXTENSION;
1359 __COUT__ <<
"logPath=" << logPath << std::endl;
1365 __COUT__ <<
"Failure - log XML did not load" << std::endl;
1369 std::vector<std::string> allEntryIds;
1371 for(i = 0; i < allEntryIds.size(); ++i)
1372 if(allEntryIds[i] == entryId)
1374 if(i == allEntryIds.size())
1376 __COUT__ <<
"Failure - entry not found" << std::endl;
1384 XML_LOGBOOK_ENTRY, i);
1394 __COUT__ <<
"Hidden tag already applied to entry." << std::endl;
1398 XML_LOGBOOK_ENTRY_HIDDEN,
1402 XML_LOGBOOK_ENTRY_HIDER, hider, hiddenParentEl);
1403 sprintf(dayIndexStr,
"%lu", time(0));
1405 XML_LOGBOOK_ENTRY_HIDDEN_TIME, dayIndexStr, hiddenParentEl);
1411 __COUT__ <<
"Entry already was not hidden." << std::endl;
1419 __COUT__ <<
"Success." << std::endl;
static std::string postData(cgicc::Cgicc &cgi, const std::string &needle)
static std::string getData(cgicc::Cgicc &cgi, const std::string &needle)
WebUsers::permissionLevel_t getSupervisorPropertyUserPermissionsThreshold(const std::string &requestType)
xercesc::DOMElement * getMatchingElement(const std::string &field, const unsigned int occurance=0)
void getAllMatchingValues(const std::string &field, std::vector< std::string > &retVec)
xercesc::DOMElement * getMatchingElementInSubtree(xercesc::DOMElement *currEl, const std::string &field, const unsigned int occurance=0)
void copyDataChildren(HttpXmlDocument &document)
bool loadXmlDocument(const std::string &filePath)
unsigned int getChildrenCount(xercesc::DOMElement *parent=0)
std::string getMatchingValue(const std::string &field, const unsigned int occurance=0)
xoap::MessageReference MakeSystemLogEntry(xoap::MessageReference msg)
External Supervisor XOAP handlers.
virtual void request(const std::string &requestType, cgicc::Cgicc &cgiIn, HttpXmlDocument &xmlOut, const WebUsers::RequestUserInfo &userInfo) override
virtual void forceSupervisorPropertyValues(void) override
override to force supervisor property values (and ignore user settings)
virtual void setSupervisorPropertyDefaults(void) override
override to control supervisor specific defaults
virtual void nonXmlRequest(const std::string &requestType, cgicc::Cgicc &cgiIn, std::ostream &out, const WebUsers::RequestUserInfo &userInfo) override
void addParameter(const std::string name, const std::string value)
xercesc::DOMElement * addTextElementToParent(const std::string &childName, const std::string &childText, xercesc::DOMElement *parent)
void recursiveRemoveChild(xercesc::DOMElement *childEl, xercesc::DOMElement *parentEl)
void saveXmlDocument(const std::string &filePath)
void INIT_MF(const char *name)