19#include <condition_variable>
39#define DEFAULT_REFRESH 60
72 for (
int i=0;
i<3;
i++) {
79 for (
int i=0;
i<3;
i++) {
97extern const char *
mname[];
129 {
".ASC",
"text/plain" },
130 {
".CSS",
"text/css" },
131 {
".CSV",
"text/csv" },
132 {
".HTM",
"text/html" },
133 {
".HTML",
"text/html" },
134 {
".TXT",
"text/plain" },
136 {
".BMP",
"image/bmp" },
137 {
".GIF",
"image/gif" },
138 {
".ICO",
"image/x-icon" },
139 {
".JPEG",
"image/jpeg" },
140 {
".JPG",
"image/jpeg" },
141 {
".PNG",
"image/png" },
142 {
".SVG",
"image/svg+xml" },
143 {
".TIF",
"image/tiff" },
144 {
".TIFF",
"image/tiff" },
146 {
".MID",
"audio/midi" },
147 {
".MP3",
"audio/mpeg" },
148 {
".OGA",
"audio/ogg" },
149 {
".OGG",
"audio/ogg" },
150 {
".WAV",
"audio/wav" },
152 {
".BIN",
"application/octet-stream" },
153 {
".BZ",
"application/x-bzip" },
154 {
".BZ2",
"application/x-bzip2" },
155 {
".DOC",
"application/msword" },
156 {
".EPS",
"application/postscript" },
157 {
".GZ",
"application/gzip" },
158 {
".JS",
"application/javascript" },
159 {
".JSON",
"application/json" },
160 {
".MJS",
"application/javascript" },
161 {
".PDF",
"application/pdf" },
162 {
".PHP",
"application/x-httpd-php" },
163 {
".RTF",
"application/rtf" },
164 {
".PS",
"application/postscript" },
165 {
".ROOT",
"application/octet-stream" },
166 {
".XLS",
"application/x-msexcel" },
167 {
".XML",
"application/xml" },
168 {
".ZIP",
"application/zip" },
170 {
".ODP",
"application/vnd.oasis.opendocument.presentation" },
171 {
".ODS",
"application/vnd.oasis.opendocument.spreadsheet" },
172 {
".ODT",
"application/vnd.oasis.opendocument.text" },
182 std::string mimetype;
184 if (mimetype.length() > 0) {
211#define HTTP_ENCODING "UTF-8"
216 0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A,
217 0x00, 0x00, 0x00, 0x0D, 0x49, 0x48, 0x44, 0x52,
218 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x10,
219 0x08, 0x02, 0x00, 0x00, 0x00, 0x90, 0x91, 0x68,
220 0x36, 0x00, 0x00, 0x00, 0x07, 0x74, 0x49, 0x4D,
221 0x45, 0x07, 0xD4, 0x0B, 0x1A, 0x08, 0x37, 0x07,
222 0x0D, 0x7F, 0x16, 0x5C, 0x00, 0x00, 0x00, 0x09,
223 0x70, 0x48, 0x59, 0x73, 0x00, 0x00, 0x2E, 0x23,
224 0x00, 0x00, 0x2E, 0x23, 0x01, 0x78, 0xA5, 0x3F,
225 0x76, 0x00, 0x00, 0x00, 0x04, 0x67, 0x41, 0x4D,
226 0x41, 0x00, 0x00, 0xB1, 0x8F, 0x0B, 0xFC, 0x61,
227 0x05, 0x00, 0x00, 0x01, 0x7D, 0x49, 0x44, 0x41,
228 0x54, 0x78, 0xDA, 0x63, 0xFC, 0xFF, 0xFF, 0x3F,
229 0x03, 0x29, 0x80, 0x09, 0xAB, 0xE8, 0xD2, 0x65,
230 0x77, 0x36, 0x6F, 0x7E, 0x8A, 0x5D, 0xC7, 0x7F,
231 0x0C, 0x30, 0x67, 0xEE, 0x0D, 0x56, 0xCE, 0xCD,
232 0x5C, 0xBC, 0x3B, 0xB6, 0x6D, 0x7F, 0x81, 0x29,
233 0xCB, 0x88, 0xE6, 0x24, 0x20, 0x57, 0x50, 0x7C,
234 0xDD, 0xCF, 0x1F, 0x6C, 0x40, 0xCB, 0xB5, 0xB5,
235 0x05, 0xCF, 0x1C, 0xB7, 0x42, 0xB3, 0x80, 0x05,
236 0x8D, 0xCF, 0xC8, 0xC8, 0x58, 0x5A, 0x2A, 0xFB,
237 0xF6, 0x4D, 0x37, 0x1B, 0xAB, 0xA0, 0xB4, 0x4C,
238 0x0A, 0x51, 0x4E, 0x02, 0x82, 0x85, 0xCB, 0x12,
239 0x0E, 0x1D, 0xAB, 0xC7, 0x2A, 0xC5, 0x82, 0x69,
240 0xC4, 0xAF, 0x5F, 0x7F, 0x1E, 0x3F, 0xF8, 0xCD,
241 0xCB, 0xF1, 0xF5, 0xEF, 0xDF, 0x7F, 0xCC, 0xCC,
242 0x4C, 0x84, 0x6D, 0x98, 0x59, 0xD5, 0xEB, 0xCF,
243 0xA5, 0x16, 0xC4, 0xAB, 0x71, 0x72, 0xCB, 0x21,
244 0x4C, 0x59, 0x74, 0x03, 0x5E, 0x3F, 0x7F, 0xB3,
245 0x6B, 0xD6, 0x22, 0x46, 0xA6, 0x7F, 0x0C, 0x0C,
246 0x7F, 0xD7, 0x75, 0x4D, 0xFB, 0xF1, 0xFD, 0x27,
247 0x81, 0x78, 0xB8, 0x7D, 0xE9, 0x0A, 0xCB, 0xFF,
248 0xDF, 0x4C, 0x8C, 0x8C, 0x40, 0xF6, 0xAD, 0x4B,
249 0x67, 0x1F, 0xDE, 0xBD, 0x8B, 0x45, 0x03, 0x3C,
250 0x60, 0x8F, 0x9D, 0xD8, 0xB3, 0xEB, 0x74, 0xB5,
251 0x90, 0x26, 0x07, 0x03, 0x48, 0xE4, 0x3F, 0x8F,
252 0xF6, 0xFF, 0x1B, 0x0F, 0x9A, 0x1E, 0x3E, 0x3A,
253 0xFB, 0xF3, 0xDB, 0x8F, 0xB7, 0x0F, 0x9E, 0x43,
254 0x83, 0xF1, 0xCF, 0xDF, 0x3F, 0x8A, 0x29, 0xCE,
255 0x3F, 0x7F, 0xFD, 0xFC, 0xCF, 0xF0, 0xDF, 0x98,
256 0xE9, 0xB5, 0x8F, 0xBD, 0x8A, 0x3C, 0x6F, 0xEC,
257 0xB9, 0x2D, 0x47, 0xFE, 0xFC, 0xFF, 0x6F, 0x16,
258 0x6C, 0xF3, 0xEC, 0xD3, 0x1C, 0x2E, 0x96, 0xEF,
259 0xBF, 0xAB, 0x7E, 0x32, 0x7D, 0xE2, 0x10, 0xCE,
260 0x88, 0xF4, 0x69, 0x2B, 0x60, 0xFC, 0xF4, 0xF5,
261 0x97, 0x78, 0x8A, 0x36, 0xD8, 0x44, 0x86, 0x18,
262 0x0D, 0xD7, 0x29, 0x95, 0x13, 0xD8, 0xD9, 0x58,
263 0xE1, 0x0E, 0xF8, 0xF1, 0xF3, 0xDB, 0xC6, 0xD6,
264 0xEC, 0x5F, 0x53, 0x8E, 0xBF, 0xFE, 0xC3, 0x70,
265 0x93, 0x8D, 0x6D, 0xDA, 0xCB, 0x0B, 0x4C, 0x3F,
266 0xFF, 0xFC, 0xFA, 0xCF, 0x0C, 0xB4, 0x09, 0x84,
267 0x54, 0xD5, 0x74, 0x91, 0x55, 0x03, 0x01, 0x07,
268 0x3B, 0x97, 0x96, 0x6E, 0xC8, 0x17, 0xFE, 0x7F,
269 0x4F, 0xF8, 0xFE, 0xBC, 0x95, 0x16, 0x60, 0x62,
270 0x62, 0x64, 0xE1, 0xE6, 0x60, 0x73, 0xD1, 0xB2,
271 0x7A, 0xFA, 0xE2, 0xF1, 0xDF, 0x3F, 0xFF, 0xC4,
272 0x78, 0x44, 0x31, 0xA3, 0x45, 0x2B, 0xD0, 0xE3,
273 0xF6, 0xD9, 0xE3, 0x2F, 0x2E, 0x9D, 0x29, 0xA9,
274 0xAC, 0x07, 0xA6, 0x03, 0xF4, 0xB4, 0x44, 0x10,
275 0x00, 0x00, 0x75, 0x65, 0x12, 0xB0, 0x49, 0xFF,
276 0x3F, 0x68, 0x00, 0x00, 0x00, 0x00, 0x49, 0x45,
277 0x4E, 0x44, 0xAE, 0x42, 0x60, 0x82
281 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x10, 0x10,
282 0x10, 0x00, 0x01, 0x00, 0x04, 0x00, 0x28, 0x01,
283 0x00, 0x00, 0x16, 0x00, 0x00, 0x00, 0x28, 0x00,
284 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x20, 0x00,
285 0x00, 0x00, 0x01, 0x00, 0x04, 0x00, 0x00, 0x00,
286 0x00, 0x00, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00,
287 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
288 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xB4, 0x0F,
289 0x0A, 0x00, 0x5C, 0x86, 0x4C, 0x00, 0x2F, 0x5E,
290 0x1A, 0x00, 0xBF, 0xD3, 0xD7, 0x00, 0x29, 0x17,
291 0x8D, 0x00, 0x50, 0xA7, 0xA4, 0x00, 0x59, 0x57,
292 0x7F, 0x00, 0xC6, 0xA3, 0xAC, 0x00, 0xFC, 0xFE,
293 0xFC, 0x00, 0x28, 0x12, 0x53, 0x00, 0x58, 0x7D,
294 0x72, 0x00, 0xC4, 0x3A, 0x34, 0x00, 0x3C, 0x3D,
295 0x69, 0x00, 0xC5, 0xB6, 0xB9, 0x00, 0x94, 0x92,
296 0x87, 0x00, 0x7E, 0x7A, 0xAA, 0x00, 0x88, 0x88,
297 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x81, 0x22,
298 0xD8, 0x88, 0x88, 0x88, 0xF6, 0xD8, 0x82, 0x22,
299 0xE8, 0x88, 0x88, 0x8D, 0x44, 0x98, 0x82, 0x22,
300 0xA8, 0x88, 0x88, 0x8F, 0x44, 0x48, 0x82, 0x22,
301 0x25, 0x76, 0x67, 0x55, 0x44, 0xF8, 0x88, 0x88,
302 0x3A, 0xC9, 0x9C, 0x53, 0x83, 0x88, 0x88, 0x88,
303 0x8D, 0x99, 0x99, 0x38, 0x88, 0x88, 0x88, 0x88,
304 0x88, 0x99, 0x9C, 0x88, 0x88, 0x88, 0x88, 0x88,
305 0x88, 0xF9, 0x9D, 0x88, 0x88, 0x88, 0x88, 0x88,
306 0x88, 0x8A, 0x58, 0x88, 0x88, 0x88, 0x88, 0x88,
307 0x88, 0x85, 0xD8, 0x88, 0x88, 0x88, 0x88, 0x88,
308 0x88, 0xEA, 0xAE, 0x88, 0x88, 0x88, 0x88, 0x88,
309 0x88, 0x00, 0x0B, 0x88, 0x88, 0x88, 0x88, 0x88,
310 0x88, 0x70, 0x0D, 0x88, 0x88, 0x88, 0x88, 0x88,
311 0x88, 0x87, 0xD8, 0x88, 0x88, 0x88, 0x88, 0x88,
312 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x00, 0x00,
313 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
314 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
315 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
316 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
317 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
318 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
319 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
320 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
332 int minor,
int major,
int text,
int label,
int grid,
double xmin,
double xmax);
334void show_header(
Return* r,
const char *title,
const char *method,
const char *path,
int refresh);
348 pp = (
char *) pattern;
378 return tv.tv_sec*1.0 +
tv.tv_usec/1000000.0;
426 if (
fRPC.length() > 0) {
439 std::vector<RequestTrace*>
fBuf;
475 for (
unsigned i=0;
i<
fBuf.size();
i++) {
484 for (
unsigned i=0;
i<
fBuf.size();
i++) {
509#define WEB_BUFFER_SIZE (6*1024*1024)
558 for (
int i=0;
i<1000;
i++) {
570 assert(!
"Cannot happen!");
586void rread(
const char* filename,
int fh,
int len)
630 for (
size_t i = 0;
i < len;
i++) {
634 char* p = (
char *) (
str +
i + 7);
637 for (
k = 0; *p && *p !=
' ' && *p !=
'\n';
k++,
i++)
696#define PARAM_LENGTH 256
697#define TEXT_SIZE 50000
730 printf(
"Error: parameter value too big\n");
750 printf(
"Error: parameter array too small\n");
866 }
else if (*p ==
'+') {
906 }
else if (*p ==
'+') {
944 for (p=
ps; *p!=0; p++)
945 printf(
"0x%02x ", (*p)&0xFF);
963 const char* p = text;
969 sprintf(buf,
"%%%02X", (*p)&0xFF);
977 for (p=text; *p!=0; p++)
978 printf(
"0x%02x ", (*p)&0xFF);
996 std::vector<std::string>
paths;
1002 paths.push_back(buf);
1010 paths.push_back(buf);
1015 paths.push_back(
cwd +
"/resources/");
1019 char *m =
getenv(
"MIDASSYS");
1021 paths.push_back(std::string(m) +
"/resources/");
1035 if (
strlen(filename) < 1) {
1036 cm_msg(
MERROR,
"open_resource_file",
"Invalid resource file name \'%s\' is too short",
1042 cm_msg(
MERROR,
"open_resource_file",
"Invalid resource file name \'%s\' starting with \'%c\' which is not allowed",
1048 cm_msg(
MERROR,
"open_resource_file",
"Invalid resource file name \'%s\' containing \'..\' which is not allowed",
1057 for (
unsigned i=0;
i<
paths.size();
i++) {
1058 std::string path =
paths[
i];
1059 if (path.length() < 1)
1094 cm_msg(
MERROR,
"open_resource_file",
"File \'%s\' for resource \'%s\' is a directory",
xpath.c_str(), filename);
1098 cm_msg(
MERROR,
"open_resource_file",
"File \'%s\' for resource \'%s\' is not a regular file, st_mode is 0x%08x",
xpath.c_str(), filename,
statbuf.st_mode);
1127 cm_msg(
MERROR,
"open_resource_file",
"Cannot find resource file \'%s\', tried %s", filename, s.c_str());
1136 const char* p = filename;
1154 if (
type.length() > 0)
1157 cm_msg(
MERROR,
"get_content_type",
"Unknown HTTP Content-Type for resource file \'%s\', file extension \'%s\'", filename,
ext_upper.c_str());
1159 return "text/plain";
1170 r->
rsprintf(
"HTTP/1.1 200 Document follows\r\n");
1172 r->
rsprintf(
"Accept-Ranges: bytes\r\n");
1177 now += (
int) (3600 * 24);
1180 const char* format =
"%A, %d-%b-%y %H:%M:%S GMT";
1217 r->
rsprintf(
"HTTP/1.1 404 Not Found\r\n");
1239 r->
rsprintf(
"HTTP/1.1 404 Not Found\r\n");
1243 r->
rsprintf(
"Error: resource file \"%s\" not found, see messages\n",
name.c_str());
1258 char *
str, buf[256];
1269 memset(&bind_addr, 0,
sizeof(bind_addr));
1270 bind_addr.sin_family =
AF_INET;
1271 bind_addr.sin_port =
htons((
short) 25);
1276 memcpy((
char *) &(bind_addr.sin_addr),
phe->h_addr,
phe->h_length);
1278 if (connect(s, (
const sockaddr*)&bind_addr,
sizeof(bind_addr)) < 0) {
1352 strftime(buf,
sizeof(buf),
"%a, %d %b %Y %H:%M:%S", &
tms);
1362 sprintf(
str,
"Content-Type: TEXT/PLAIN; charset=US-ASCII\r\n\r\n");
1368 const char* p = text;
1370 while (
strstr(p,
"\r\n.\r\n")) {
1418 r->
rsprintf(
"HTTP/1.1 302 Found\r\n");
1422 if (
strncmp(path,
"http:", 5) == 0)
1423 r->
rsprintf(
"Location: %s\r\n\r\n<html>redir</html>\r\n",
str);
1424 else if (
strncmp(path,
"https:", 6) == 0)
1425 r->
rsprintf(
"Location: %s\r\n\r\n<html>redir</html>\r\n",
str);
1427 r->
rsprintf(
"Location: %s\r\n\r\n<html>redir</html>\r\n",
str);
1436 r->
rsprintf(
"HTTP/1.1 307 Temporary Redirect\r\n");
1439 r->
rsprintf(
"Location: %s\r\n", path);
1441 r->
rsprintf(
"<html>redirect to %s</html>\r\n", path);
1464 const char* search_name =
sinfo->search_name;
1474 for (
i = 0; search_name[
i] ;
i++)
1485 r->
rsprintf(
"<tr><td class=\"ODBkey\"><a href=\"?cmd=odb&odb_path=/%s\">/%s</a></tr>\n",
path_encoded.c_str(), path.c_str());
1488 char* p =
const_cast<char *
>(path.data() + path.length() - 1);
1489 while (*p && *p !=
'/')
1496 size =
sizeof(
data);
1504 r->
rsprintf(
"<tr><td class=\"ODBkey\">");
1512 r->
rsprintf(
"<tr><td rowspan=%d class=\"ODBkey\">",
i);
1516 size =
sizeof(
data);
1547 r->
rsprintf(
"<script type=\"text/javascript\" src=\"midas.js\"></script>\n");
1548 r->
rsprintf(
"<script type=\"text/javascript\" src=\"mhttpd.js\"></script>\n");
1551 r->
rsprintf(
"<table class=\"mtable\" style=\"width: 95%%\">\n");
1553 r->
rsprintf(
" <td class=\"mtableheader\">MIDAS Help Page</td>\n");
1560 r->
rsprintf(
" <td style=\"text-align:right;\">Documentation:</td>\n");
1561 r->
rsprintf(
" <td style=\"text-align:left;\"><a href=\"https://midas.triumf.ca\">https://midas.triumf.ca</a></td>\n");
1564 r->
rsprintf(
" <td style=\"text-align:right;\">Discussion Forum:</td>\n");
1565 r->
rsprintf(
" <td style=\"text-align:left;\"><a href=\"https://midas.triumf.ca/forum/\">https://midas.triumf.ca/forum/</a></td>\n");
1568 r->
rsprintf(
" <td style=\"text-align:right;\">Code:</td>\n");
1569 r->
rsprintf(
" <td style=\"text-align:left;\"><a href=\"https://bitbucket.org/tmidas/midas/\">https://bitbucket.org/tmidas/midas/</a></td>\n");
1572 r->
rsprintf(
" <td style=\"text-align:right;\">Report a bug:</td>\n");
1573 r->
rsprintf(
" <td style=\"text-align:left;\"><a href=\"https://bitbucket.org/tmidas/midas/issues/\">https://bitbucket.org/tmidas/midas/issues/</a></td>\n");
1577 r->
rsprintf(
" <td style=\"text-align:right;\">Version:</td>\n");
1581 r->
rsprintf(
" <td style=\"text-align:right;\">Revision:</td>\n");
1583 std::string
url =
"https://bitbucket.org/tmidas/midas/commits/";
1589 std::string::size_type pos =
rev.find(
"-g");
1590 if (pos != std::string::npos) {
1591 std::string
hash =
rev.substr(pos+2);
1592 pos =
hash.find(
"-dirty");
1593 if (pos != std::string::npos) {
1596 pos =
hash.find(
" ");
1597 if (pos != std::string::npos) {
1601 r->
rsprintf(
" <td style=\"text-align:left;\"><a href=\"%s\">%s</a></td>\n",
url.c_str(),
rev.c_str());
1603 r->
rsprintf(
" <td style=\"text-align:left;\">%s</td>\n",
rev.c_str());
1608 r->
rsprintf(
" <td style=\"text-align:right;\">MIDASSYS:</td>\n");
1610 if (!s) s =
"(unset)";
1612 r->
rsprintf(
" <td style=\"text-align:left;\">%s</td>\n",
str);
1616 r->
rsprintf(
" <td style=\"text-align:right;\">mhttpd current directory:</td>\n");
1618 r->
rsprintf(
" <td style=\"text-align:left;\">%s</td>\n",
cwd.c_str());
1622 r->
rsprintf(
" <td style=\"text-align:right;\">Exptab file:</td>\n");
1627 r->
rsprintf(
" <td style=\"text-align:right;\">Experiment:</td>\n");
1632 r->
rsprintf(
" <td style=\"text-align:right;\">Experiment directory:</td>\n");
1640 if (
list.size() == 1) {
1642 r->
rsprintf(
" <td style=\"text-align:right;\">System logfile:</td>\n");
1645 r->
rsprintf(
" <td style=\"text-align:left;\">%s</td>\n", s.c_str());
1649 r->
rsprintf(
" <td style=\"text-align:right;\">Logfiles:</td>\n");
1650 r->
rsprintf(
" <td style=\"text-align:left;\">\n");
1651 for (
unsigned i=0 ;
i<
list.size() ;
i++) {
1664 r->
rsprintf(
" <td style=\"text-align:right;\">Image history:</td>\n");
1669 r->
rsprintf(
" <td style=\"text-align:right;\">Resource paths:</td>\n");
1670 r->
rsprintf(
" <td style=\"text-align:left;\">");
1690 r->
rsprintf(
" <td style=\"text-align:right;\">midas.css:</td>\n");
1692 r->
rsprintf(
" <td style=\"text-align:left;\">%s</td>\n", path.c_str());
1694 r->
rsprintf(
" <td style=\"text-align:left;\">NOT FOUND</td>\n");
1698 r->
rsprintf(
" <td style=\"text-align:right;\">midas.js:</td>\n");
1700 r->
rsprintf(
" <td style=\"text-align:left;\">%s</td>\n", path.c_str());
1702 r->
rsprintf(
" <td style=\"text-align:left;\">NOT FOUND</td>\n");
1706 r->
rsprintf(
" <td style=\"text-align:right;\">controls.js:</td>\n");
1708 r->
rsprintf(
" <td style=\"text-align:left;\">%s</td>\n", path.c_str());
1710 r->
rsprintf(
" <td style=\"text-align:left;\">NOT FOUND</td>\n");
1714 r->
rsprintf(
" <td style=\"text-align:right;\">mhttpd.js:</td>\n");
1716 r->
rsprintf(
" <td style=\"text-align:left;\">%s</td>\n", path.c_str());
1718 r->
rsprintf(
" <td style=\"text-align:left;\">NOT FOUND</td>\n");
1722 r->
rsprintf(
" <td style=\"text-align:right;\">obsolete.js:</td>\n");
1724 r->
rsprintf(
" <td style=\"text-align:left;\">%s</td>\n", path.c_str());
1726 r->
rsprintf(
" <td style=\"text-align:left;\">NOT FOUND</td>\n");
1730 r->
rsprintf(
" <td style=\"text-align:right;\">Obsolete mhttpd.css:</td>\n");
1732 r->
rsprintf(
" <td style=\"text-align:left;\">%s</td>\n", path.c_str());
1734 r->
rsprintf(
" <td style=\"text-align:left;\">NOT FOUND</td>\n");
1738 r->
rsprintf(
" <td style=\"text-align:right;\">JSON-RPC schema:</td>\n");
1739 r->
rsprintf(
" <td style=\"text-align:left;\"><a href=\"?mjsonrpc_schema\">json format</a> or <a href=\"?mjsonrpc_schema_text\">text table format</a></td>\n");
1743 r->
rsprintf(
" <td style=\"text-align:right;\">JavaScript examples:</td>\n");
1744 r->
rsprintf(
" <td style=\"text-align:left;\"><a href=\"?cmd=example\">example.html</a></td>\n");
1748 r->
rsprintf(
" <td style=\"text-align:right;\">Custom page example:</td>\n");
1749 r->
rsprintf(
" <td style=\"text-align:left;\"><a href=\"?cmd=custom_example\">custom_example.html</a></td>\n");
1753 r->
rsprintf(
" <td style=\"text-align:right;\">MPlot custom plot examples:</td>\n");
1754 r->
rsprintf(
" <td style=\"text-align:left;\"><a href=\"?cmd=plot_example\">plot_example.html</a></td>\n");
1762 r->
rsprintf(
"<table class=\"mtable\" style=\"width: 95%%\">\n");
1764 r->
rsprintf(
" <td class=\"mtableheader\">Contributions</td>\n");
1768 r->
rsprintf(
"Pierre-Andre Amaudruz - Sergio Ballestrero - Suzannah Daviel - Peter Green - Qing Gu - Greg Hackman - Gertjan Hofman - Paul Knowles - Exaos Lee - Thomas Lindner - Shuoyi Ma - Rudi Meier - Bill Mills - Glenn Moloney - Dave Morris - John M O'Donnell - Konstantin Olchanski - Chris Pearson - Renee Poutissou - Stefan Ritt - Zaher Salman - Ryu Sawada - Tamsen Schurman - Ben Smith - Andreas Suter - Jan M. Wouters - Piotr Adam Zolnierczuk\n");
1788 r->
rsprintf(
"HTTP/1.1 200 Document follows\r\n");
1790 r->
rsprintf(
"Cache-control: private, max-age=0, no-cache\r\n");
1791 r->
rsprintf(
"Expires: Fri, 01 Jan 1983 00:00:00 GMT\r\n");
1794 r->
rsprintf(
"<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\n");
1798 r->
rsprintf(
"<link rel=\"icon\" href=\"favicon.png\" type=\"image/png\" />\n");
1799 r->
rsprintf(
"<link rel=\"stylesheet\" href=\"mhttpd.css\" type=\"text/css\" />\n");
1800 r->
rsprintf(
"<link rel=\"stylesheet\" href=\"midas.css\" type=\"text/css\" />\n");
1804 r->
rsprintf(
"<meta http-equiv=\"Refresh\" content=\"%02d\">\n", refresh);
1806 r->
rsprintf(
"<title>%s</title></head>\n", title);
1813 (
"<body><form name=\"form1\" method=\"POST\" action=\"%s\" enctype=\"multipart/form-data\">\n\n",
1816 r->
rsprintf(
"<body><form name=\"form1\" method=\"GET\" action=\"%s\">\n\n",
str);
1829 r->
rsprintf(
"HTTP/1.1 200 Document follows\r\n");
1831 r->
rsprintf(
"Access-Control-Allow-Origin: *\r\n");
1832 r->
rsprintf(
"Cache-control: private, max-age=0, no-cache\r\n");
1833 r->
rsprintf(
"Expires: Fri, 01 Jan 1983 00:00:00 GMT\r\n");
1842 r->
rsprintf(
"HTTP/1.1 200 Document follows\r\n");
1847 r->
rsprintf(
"<link rel=\"stylesheet\" href=\"mhttpd.css\" type=\"text/css\" />\n");
1848 r->
rsprintf(
"<title>MIDAS error</title></head>\n");
1849 r->
rsprintf(
"<body><H1>%s</H1></body></html>\n", error);
1857 r->
rsprintf(
"HTTP/1.1 404 Not Found\r\n");
1859 r->
rsprintf(
"Content-Type: text/plain\r\n");
1862 r->
rsprintf(
"MIDAS error: %s\n", error);
1870 r->
rsprintf(
"window.addEventListener(\"load\", function(e) { mhttpd_init('%s', 1000); });\n",
cur_page);
1873 r->
rsprintf(
"<!-- header and side navigation will be filled in mhttpd_init -->\n");
1874 r->
rsprintf(
"<div id=\"mheader\"></div>\n");
1875 r->
rsprintf(
"<div id=\"msidenav\"></div>\n");
1876 r->
rsprintf(
"<div id=\"mmain\">\n");
1886 cm_msg(
MERROR,
"check_obsolete_odb",
"ODB \"%s\" is obsolete, please delete it.", odb_path);
1940 cm_msg(
MERROR,
"init_mhttpd_odb",
"ODB \"/Experiment/Base URL\" is obsolete, please delete it.");
1945 cm_msg(
MERROR,
"init_mhttpd_odb",
"ODB \"/Experiment/CSS File\" is obsolete, please delete it.");
1950 cm_msg(
MERROR,
"init_mhttpd_odb",
"ODB \"/Experiment/JS File\" is obsolete, please delete it.");
1955 cm_msg(
MERROR,
"init_mhttpd_odb",
"ODB \"/Experiment/Start-Stop Buttons\" is obsolete, please delete it.");
1959 odb->RB(
"Experiment/Pause-Resume Buttons", &
xdefault,
true);
1961#ifdef HAVE_MONGOOSE616
1970 cm_msg(
MERROR,
"init_mhttpd_odb",
"ODB \"/Logger/Message file\" is obsolete, please delete it and use \"/Logger/Message dir\" and \"/Logger/message file date format\" instead.");
1994 size =
sizeof(
BOOL);
2021 size_t len =
strlen(text);
2022 for (
size_t i = 0;
i < len;
i++) {
2050 size_t len =
strlen(text);
2051 for (
size_t i = 0;
i < len;
i++) {
2080 size_t len =
strlen(text);
2081 for (
size_t i = 0;
i < len;
i++) {
2105 size_t len =
strlen(text);
2106 for (
size_t i = 0;
i < len;
i++) {
2152 bout +=
"<table border=3 cellpadding=1 class=\"dialogTable\">\n";
2177 size =
sizeof(
data);
2192 bout +=
"</td><td>";
2196 bout +=
")</td></tr>\n";
2200 bout +=
"</td></tr>\n";
2207 size =
sizeof(
data);
2229 bout +=
")<br></td></tr>\n";
2236 bout +=
"<br></td></tr>\n";
2243 bout +=
"</table>\n";
2250 char path[256],
path1[256];
2265 for (
int i = 0;
i < 3;
i++) {
2273 while (
strchr(path,
'\\'))
2274 *
strchr(path,
'\\') =
'/';
2300 }
else if (
strncmp(path,
"/HS/", 4) == 0) {
2301 char* buf = (
char*)
M_MALLOC(100000);
2326 pp->unsetparam(
"scale");
2327 pp->unsetparam(
"offset");
2328 pp->unsetparam(
"width");
2329 pp->unsetparam(
"index");
2331 r->
rsprintf(
"HTTP/1.1 200 Document follows\r\n");
2336 r->
rsprintf(
"<link rel=\"icon\" href=\"favicon.png\" type=\"image/png\" />\n");
2337 r->
rsprintf(
"<link rel=\"stylesheet\" href=\"midas.css\" type=\"text/css\" />\n");
2338 r->
rsprintf(
"<link rel=\"stylesheet\" href=\"mhttpd.css\" type=\"text/css\" />\n");
2339 r->
rsprintf(
"<title>ELog Error</title></head>\n");
2340 r->
rsprintf(
"<i>Error: Attachment file <i>%s</i> not valid.</i><p>\n",
pp->getparam(
str));
2341 r->
rsprintf(
"Please go back and enter a proper filename (use the <b>Browse</b> button).\n");
2342 r->
rsprintf(
"<body></body></html>\n");
2353 mstrlcpy(tag,
pp->getparam(
"orig"),
sizeof(tag));
2357 pp->getparam(
"author"),
2358 pp->getparam(
"type"),
2359 pp->getparam(
"system"),
2360 pp->getparam(
"subject"),
2361 pp->getparam(
"text"),
2362 pp->getparam(
"orig"),
2363 *
pp->getparam(
"html") ?
"HTML" :
"plain",
2391 str +=
"/Elog/Email ";
2393 str +=
pp->getparam(
"type");
2395 str +=
pp->getparam(
"system");
2402 show_error(r,
"No SMTP host defined under /Elog/SMTP host");
2418 mail_text +=
"A new entry has been submitted by ";
2467 r->
rsprintf(
"HTTP/1.1 302 Found\r\n");
2476 r->
rsprintf(
"Location: ?cmd=Show+elog&tag=%s&%s\n\n<html>redir</html>\r\n", tag,
mail_param + 1);
2478 r->
rsprintf(
"Location: ?cmd=Show+elog&tag=%s\n\n<html>redir</html>\r\n", tag);
2512 r->
rsprintf(
"HTTP/1.1 200 Document follows\r\n");
2514 r->
rsprintf(
"Accept-Ranges: bytes\r\n");
2579 if (
pp->getparam(
"eq"))
2582 if (
pp->getparam(
"group") && *
pp->getparam(
"group"))
2618 r->
rsprintf(
"<script type=\"text/javascript\" src=\"midas.js\"></script>\n");
2619 r->
rsprintf(
"<script type=\"text/javascript\" src=\"mhttpd.js\"></script>\n");
2620 r->
rsprintf(
"<script type=\"text/javascript\" src=\"obsolete.js\"></script>\n");
2625 r->
rsprintf(
"<tr><td colspan=15>\n");
2628 r->
rsprintf(
"<input type=submit name=cmd value=Set>\n");
2633 r->
rsprintf(
"<table class=\"ODBtable\" style=\"max-width:700px;\">");
2637 r->
rsprintf(
"<tr><td class=\"subStatusTitle\" colspan=15><i>Equipment:</i> \n");
2693 r->
rsprintf(
"<tr><td colspan=15><i>Groups:</i> ");
2697 r->
rsprintf(
"<b>All</b> ");
2746 r->
rsprintf(
"<i>ODB:</i> ");
2767 if (
i == 0 ||
i > 15) {
2774 r->
rsprintf(
"<tr class=\"subStatusTitle\"><th colspan=%d>Names",
colspan);
2777 for (
int i = 0;;
i++) {
2801 for (
int i = 0;
i < num_values;
i++) {
2828 for (
int j = 0;;
j++) {
2841 size =
sizeof(
data);
2846 if (n_var ==
i_set) {
2860 r->
rsprintf(
"<input type=text size=10 maxlenth=80 name=value value=\"%s\">\n",
data_str.c_str());
2861 r->
rsprintf(
"<input type=submit size=20 name=cmd value=Set>\n");
2862 r->
rsprintf(
"<input type=hidden name=index value=%d>\n",
i_edit);
2867 r->
rsprintf(
"<a href=\"#\" onClick=\"ODBInlineEdit(this.parentNode,\'%s\', 0);return false;\" >%s</a>", odb_path,
data_str.c_str());
2878 r->
rsprintf(
"<tr><td colspan=15><i>Groups:</i> ");
2882 r->
rsprintf(
"<b>All</b> ");
2884 r->
rsprintf(
"<a href=\"?cmd=eqtable&eq=%s\">All</a> ",
eq_name);
2893 for (
int i = 0;;
i++) {
2911 r->
rsprintf(
"<i>ODB:</i> ");
2924 mstrlcpy(style,
"ODBtableEven",
sizeof(style));
2926 mstrlcpy(style,
"ODBtableOdd",
sizeof(style));
2938 r->
rsprintf(
"<tr class=\"subStatusTitle\"><th colspan=9>Names<th>%s</tr>\n",
varkey.name);
2954 r->
rsprintf(
"<tr class=\"%s\"><td colspan=9>%s<br></tr>\n", style,
key.
name);
2958 size =
sizeof(
data);
2971 (
"<tr class=\"%s\" ><td colspan=9>%s<td align=center>%s (%s)<br></tr>\n",
2974 r->
rsprintf(
"<tr class=\"%s\"><td colspan=9>%s<td align=center>%s<br></tr>\n",
2983 size =
sizeof(
data);
3014 if (
varkey.num_values > 1000)
3015 r->
rsprintf(
"<tr class=\"%s\"><td colspan=9>%s<td align=center><i>... %d values ...</i>",
3018 for (
j = 0;
j <
varkey.num_values;
j++) {
3021 mstrlcpy(style,
"ODBtableEven",
sizeof(style));
3023 mstrlcpy(style,
"ODBtableOdd",
sizeof(style));
3027 size =
sizeof(
name);
3037 r->
rsprintf(
"<tr class=\"%s\"><td colspan=9>%s", style,
name);
3039 size =
sizeof(
data);
3044 if (n_var ==
i_set) {
3058 r->
rsprintf(
"<td align=center><input type=text size=10 maxlenth=80 name=value value=\"%s\">\n",
data_str.c_str());
3059 r->
rsprintf(
"<input type=submit size=20 name=cmd value=Set></tr>\n");
3060 r->
rsprintf(
"<input type=hidden name=index value=%d>\n",
i_edit);
3061 r->
rsprintf(
"<input type=hidden name=cmd value=Set>\n");
3067 r->
rsprintf(
"<a href=\"#\" onClick=\"ODBInlineEdit(this.parentNode,\'%s\', 0);return false;\" >%s</a>", odb_path,
data_str.c_str());
3101 strcpy(
type,
"text");
3103 while (*p && *p !=
'<')
3111 while (*p && ((*p ==
' ') ||
iscntrl(*p)))
3129 while (*p && ((*p ==
' ') ||
iscntrl(*p)))
3139 while (*p && *p !=
'\"')
3145 while (*p && *p !=
' ' && *p !=
'>')
3158 while (*p && *p !=
'\"')
3164 while (*p && *p !=
' ' && *p !=
'>')
3185 while (*p && *p !=
' ' && *p !=
'>')
3197 while (*p && *p !=
'\"')
3203 while (*p && *p !=
' ' && *p !=
'>')
3214 while (*p && *p !=
'\"')
3220 while (*p && *p !=
' ' && *p !=
'>')
3230 while (*
pt && *
pt !=
'\"')
3236 while (*
pt && *
pt !=
' ' && *
pt !=
'>')
3254 while (*p && ((*p ==
' ') ||
iscntrl(*p)))
3261 }
while (*p !=
'>');
3266 while (*p && *p !=
'>')
3302 if (*p && *p ==
']') {
3314 size =
sizeof(
data);
3318 if (format &&
strlen(format)>0)
3325 if (
pp->isparam(
"cbi"))
3327 if (n_var ==
i_set) {
3352 options +=
"onClick=\"o=document.createElement('input');o.type='hidden';o.name='cbi';o.value='";
3354 options +=
"';document.form1.appendChild(o);";
3355 options +=
"document.form1.submit();\" ";
3367 if (n_var ==
i_set) {
3375 size =
sizeof(
data);
3381 r->
rsprintf(
"<input type=text size=10 maxlength=80 name=value value=\"%s\">\n",
data_str.c_str());
3382 r->
rsprintf(
"<input type=submit size=20 name=cmd value=Set>\n");
3383 r->
rsprintf(
"<input type=hidden name=index value=%d>\n", n_var);
3384 r->
rsprintf(
"<input type=hidden name=cmd value=Set>\n");
3392 r->
rsprintf(
"<a onClick=\"promptpwd('%s?cmd=Edit&index=%d&pnam=%s')\" href=\"#\">", path, n_var,
pwd);
3394 r->
rsprintf(
"<a href=\"%s?cmd=Edit&index=%d\" %s>", path, n_var,
tail);
3401 }
else if (
edit == 2) {
3429 "Src = STRING : [256] ",
3430 "Format = STRING : [32] %1.1f",
3431 "Font = STRING : [32] Medium",
3435 "FGColor = STRING : [8] 000000",
3436 "BGColor = STRING : [8] FFFFFF",
3469 "Src = STRING : [256] ",
3473 "Height = INT : 100",
3474 "Direction = INT : 0",
3476 "Logscale = BOOL : n",
3478 "Max = DOUBLE : 10",
3479 "FGColor = STRING : [8] 000000",
3480 "BGColor = STRING : [8] FFFFFF",
3481 "BDColor = STRING : [8] 808080",
3487 int x, y, width, height, direction,
axis;
3501 int i,
n, size, ivalue;
3508 if (src[
i] ==
'>' || src[
i] ==
'&')
3519 cm_msg(
MERROR,
"evaluate_src",
"Invalid Src key \"%s\" for Fill \"%s\"",
3525 size =
sizeof(
data);
3532 *fvalue = (
value[0] ==
'y');
3538 if (src[
i] ==
'>' && src[
i+1] ==
'>') {
3541 while (src[
i] ==
' ' ||
isdigit(src[
i]))
3543 ivalue = (
int)*fvalue;
3548 if (src[
i] ==
'&') {
3550 while (src[
i] ==
' ')
3552 if (src[
i] ==
'0' && src[
i+1] ==
'x')
3556 while (src[
i] ==
' ' ||
isxdigit(src[
i]) || src[
i] ==
'x')
3558 ivalue = (
int)*fvalue;
3574 if (filename[0] ==
'/')
3593 cm_msg(
MERROR,
"add_custom_path",
"ODB /Custom/Path has a forbidden value \"%s\", please change it",
custom_path.c_str());
3612 std::string filename;
3631 sprintf(
str,
"show_custom_file: Invalid custom page: \"/Custom/%s\" not found in ODB",
name);
3674 char str[256],
data[256], src[256];
3675 int i,
index,
length,
status, size, width, height,
bgcol,
fgcol,
bdcol, r,
g, b, x, y;
3677 double fvalue,
ratio;
3700 std::string filename;
3716 sprintf(
str,
"show_custom_gif: File \"%s\" is not a GIF image", filename.c_str());
3733 size =
sizeof(label);
3736 cm_msg(
MERROR,
"show_custom_gif",
"Cannot open data record for label \"%s\"",
3741 if (label.
src[0] == 0) {
3748 cm_msg(
MERROR,
"show_custom_gif",
"Invalid Src key \"%s\" for label \"%s\"",
3754 size =
sizeof(
data);
3797 height =
pfont->h + 2 + 2;
3799 if (label.
align == 0) {
3802 label.
y + height,
bgcol);
3806 }
else if (label.
align == 1) {
3809 label.
y + height,
bgcol);
3811 label.
y + height,
fgcol);
3816 label.
y + height,
bgcol);
3837 cm_msg(
MERROR,
"show_custom_gif",
"Cannot open data record for bar \"%s\"",
3842 if (
bar.src[0] == 0) {
3849 cm_msg(
MERROR,
"show_custom_gif",
"Invalid Src key \"%s\" for bar \"%s\"",
3855 size =
sizeof(
data);
3863 sscanf(
bar.fgcolor,
"%02x%02x%02x", &r, &
g, &b);
3868 sscanf(
bar.bgcolor,
"%02x%02x%02x", &r, &
g, &b);
3873 sscanf(
bar.bdcolor,
"%02x%02x%02x", &r, &
g, &b);
3892 if (
bar.direction == 0) {
3906 -5, -7, -8, 0,
bar.min,
bar.max,
bar.logscale);
3907 else if (
bar.axis == 2)
3909 bar.height, 3, 5, 7, 10, 0,
bar.min,
bar.max,
bar.logscale);
3924 haxis(
im,
gdFontSmall,
bdcol, 0,
bar.x,
bar.y,
bar.height, -3, -5, -7, -18,
3926 else if (
bar.axis == 2)
3928 5, 7, 8, 0,
bar.min,
bar.max);
3960 size =
sizeof(
data);
3963 cm_msg(
MERROR,
"show_custom_gif",
"No \"Limits\" entry for Fill \"%s\"",
3967 for (
i = 0;
i < size / (
int)
sizeof(
double);
i++)
3968 if (*((
double *)
data +
i) > fvalue)
3975 cm_msg(
MERROR,
"show_custom_gif",
"No \"Fillcolors\" entry for Fill \"%s\"",
3980 size =
sizeof(
data);
3981 strcpy(
data,
"FFFFFF");
3999 rr->rsprintf(
"HTTP/1.1 200 Document follows\r\n");
4002 rr->rsprintf(
"Content-Type: image/gif\r\n");
4003 rr->rsprintf(
"Content-Length: %d\r\n",
length);
4004 rr->rsprintf(
"Cache-control: private, max-age=0, no-cache\r\n");
4005 rr->rsprintf(
"Expires: Fri, 01-Jan-1983 00:00:00 GMT\r\n\r\n");
4017 { 9999,
"mhttpd_jrpc_rev0", {
4039 r->
rsprintf(
"<INVALID_ARGUMENTS>");
4087 size =
sizeof(client_name);
4104 r->
rsprintf(
"client %s", client_name);
4142 { 9998,
"mhttpd_jrpc_rev1", {
4166 r->
rsprintf(
"<INVALID_ARGUMENTS>");
4217 for (
int i=0; ;
i++) {
4230 size =
sizeof(client_name);
4323 const char *cmd = p->
getparam(
"rcmd");
4328 r->
rsprintf(
"<INVALID_ARGUMENTS>");
4348 r->
rsprintf(
"<RPC_CONNECT_ERROR>%d</RPC_CONNECT_ERROR>",
status);
4387 size =
sizeof(
data);
4398 if (format && format[0])
4410 r->
rsputs(
"<DB_OUT_OF_RANGE>");
4469 std::vector<std::string> odb;
4504 for (
int i=0 ; ;
i++) {
4514 printf(
"command [%s], encoding %d [%s], jsonp %d, single %d, multiple %d, odb array size %d\n",
cmd_parameter.c_str(),
encoding,
encoding_parameter.c_str(),
jsonp,
single,
multiple, (
int)odb.size());
4522 ppath +=
"/Custom/Pwd/";
4547 const char* ptr = p->
getparam(
"value");
4548 for (
i=0 ; ptr !=
NULL ;
i++) {
4549 size =
sizeof(
data);
4559 size =
sizeof(
data);
4588 size =
sizeof(
data);
4625 r->
rsputs(
"<DB_NO_KEY>");
4649 r->
rsputs(
"<DB_NO_KEY>");
4669 const char* fmt =
NULL;
4674 }
else if (p->
isparam(
"format")) {
4738 r->
rsputs(
"<DB_NO_KEY>");
4755 for (
int i=0 ; ;
i++) {
4764 r->
rsputs(
"</data>\n<data>\n");
4777 r->
rsputs(
"<DB_NO_KEY/>\n");
4783 r->
rsputs(
"<DB_NO_KEY>\n");
4793 const char* s =
strstr(buf,
"-->");
4811 r->
rsputs(
"</data>\n</jcopy>\n");
4847 for (
unsigned i=0;
i<odb.size();
i++) {
4862 r->
rsputs(
"<DB_NO_KEY>\n");
4929 for (
unsigned i=0;
i<odb.size();
i++) {
5018 for (
unsigned i=0;
i<odb.size();
i++) {
5115 for (
unsigned i=0;
i<odb.size();
i++) {
5177 for (
unsigned i=0;
i<odb.size();
i++) {
5238 for (
unsigned i=0;
i<odb.size();
i++) {
5302 for (
unsigned i=0;
i<odb.size();
i++) {
5372 mstrlcpy(user,
"javascript_commands",
sizeof(user));
5384 r->
rsputs(
"Message successfully created\n");
5428 std::string path =
pp->getparam(
"page");
5431 show_error_404(r,
"show_custom_page: Invalid custom page: \"page\" parameter is empty");
5435 if (
strstr(path.c_str(),
"..")) {
5437 str +=
"Invalid custom page name \'";
5439 str +=
"\' contains \'..\'";
5444 if (
strstr(path.c_str(),
".gif")) {
5449 if (
strchr(path.c_str(),
'.')) {
5456 std::string
xpath = std::string(
"/Custom/") + path;
5459 xpath = std::string(
"/Custom/") + path +
"&";
5462 xpath = std::string(
"/Custom/") + path +
"!";
5540 if (
pwd[0] && n_var ==
atoi(
pp->getparam(
"index"))) {
5547 ppath +=
"/Custom/Pwd/";
5548 if (
pp->getparam(
"pnam") && *
pp->getparam(
"pnam")) {
5549 ppath +=
pp->getparam(
"pnam");
5564 }
while (p !=
NULL);
5570 if (
pp->getparam(
"pnam") && *
pp->getparam(
"pnam")) {
5572 ppath +=
"/Custom/Pwd/";
5573 ppath +=
pp->getparam(
"pnam");
5582 std::string
podb =
pp->getparam(
"odb");
5583 std::string::size_type pos =
podb.find(
'[');
5584 if (pos != std::string::npos) {
5595 size =
sizeof(
data);
5613 r->
rsprintf(
"HTTP/1.1 200 Document follows\r\n");
5634 }
while (p !=
NULL);
5645 std::string
str =
msprintf(
"Invalid custom page: Page \"%s\" not found in ODB", path.c_str());
5656 int c,
n, a, f,
d,
q, x, r,
ia, id, w;
5678 size =
sizeof(client_name);
5685 if (client_name[0]) {
5693 rr->rsprintf(
"HTTP/1.1 200 Document follows\r\n");
5695 rr->rsprintf(
"Content-Type: text/html; charset=%s\r\n\r\n",
HTTP_ENCODING);
5697 rr->rsprintf(
"<html><head>\n");
5698 rr->rsprintf(
"<link rel=\"icon\" href=\"favicon.png\" type=\"image/png\" />\n");
5699 rr->rsprintf(
"<link rel=\"stylesheet\" href=\"midas.css\" type=\"text/css\" />\n");
5700 rr->rsprintf(
"<link rel=\"stylesheet\" href=\"mhttpd.css\" type=\"text/css\" />\n");
5701 rr->rsprintf(
"<title>MIDAS CAMAC interface</title></head>\n");
5702 rr->rsprintf(
"<body><form method=\"GET\" action=\"CNAF\">\n\n");
5710 rr->rsprintf(
"<table border=3 cellpadding=1>\n");
5711 rr->rsprintf(
"<tr><th colspan=3>MIDAS experiment \"%s\"",
str);
5713 if (client_name[0] == 0)
5714 rr->rsprintf(
"<th colspan=3 class=\"redLight\">No CAMAC server running</tr>\n");
5715 else if (
hconn == 0)
5716 rr->rsprintf(
"<th colspan=3 class=\"redLight\">Cannot connect to %s</tr>\n", client_name);
5718 rr->rsprintf(
"<th colspan=3>CAMAC server: %s</tr>\n", client_name);
5722 a = f =
d =
q = x = 0;
5728 rr->rsprintf(
"<tr><td colspan=3>\n");
5729 rr->rsprintf(
"<input type=submit name=cmd value=Execute>\n");
5731 rr->rsprintf(
"<td colspan=3>\n");
5732 rr->rsprintf(
"<input type=submit name=cmd value=ODB>\n");
5733 rr->rsprintf(
"<input type=submit name=cmd value=Status>\n");
5734 rr->rsprintf(
"<input type=submit name=cmd value=Help>\n");
5735 rr->rsprintf(
"</tr>\n\n");
5738 rr->rsprintf(
"<tr><th>N");
5739 rr->rsprintf(
"<th>A");
5740 rr->rsprintf(
"<th>F");
5741 rr->rsprintf(
"<th colspan=3>Data");
5746 const char* cmd = p->
getparam(
"cmd");
5748 rpc_client_call(
hconn,
RPC_CNAF16,
CNAF_CRATE_CLEAR, 0, 0, 0, 0, 0, &
d, &size, &x,
5751 rr->rsprintf(
"<tr><td colspan=6 class=\"greenLight\">C cycle executed sucessfully</tr>\n");
5753 rpc_client_call(
hconn,
RPC_CNAF16,
CNAF_CRATE_ZINIT, 0, 0, 0, 0, 0, &
d, &size, &x,
5756 rr->rsprintf(
"<tr><td colspan=6 class=\"greenLight\">Z cycle executed sucessfully</tr>\n");
5758 rpc_client_call(
hconn,
RPC_CNAF16,
CNAF_INHIBIT_CLEAR, 0, 0, 0, 0, 0, &
d, &size, &x,
5762 (
"<tr><td colspan=6 class=\"greenLight\">Clear inhibit executed sucessfully</tr>\n");
5764 rpc_client_call(
hconn,
RPC_CNAF16,
CNAF_INHIBIT_SET, 0, 0, 0, 0, 0, &
d, &size, &x,
5768 (
"<tr><td colspan=6 class=\"greenLight\">Set inhibit executed sucessfully</tr>\n");
5793 for (
i = 0;
i < r;
i++) {
5799 rpc_client_call(
hconn,
RPC_CNAF24,
CNAF, 0,
c,
n, a, f, &
d, &size, &x,
5812 status =
rpc_client_call(
hconn,
RPC_CNAF24,
CNAF, 0,
c,
n, a, f, &
d, &size, &x, &
q);
5819 (
"<tr><td colspan=6 class=\"redLight\">Error executing function, code = %d</tr>",
5822 rr->rsprintf(
"<tr align=center><td>%d",
n);
5823 rr->rsprintf(
"<td>%d", a);
5824 rr->rsprintf(
"<td>%d", f);
5825 rr->rsprintf(
"<td colspan=3>%d / 0x%04X Q%d X%d",
d,
d,
q, x);
5838 (
"<tr align=center><td><input type=text size=3 name=N value=%d>\n",
5840 rr->rsprintf(
"<td><input type=text size=3 name=A value=%d>\n", a);
5841 rr->rsprintf(
"<td><input type=text size=3 name=F value=%d>\n", f);
5843 (
"<td colspan=3><input type=text size=8 name=D value=%d></tr>\n",
5847 rr->rsprintf(
"<tr><td colspan=2>Repeat");
5848 rr->rsprintf(
"<td><input type=text size=3 name=R value=%d>\n", r);
5851 (
"<td align=center colspan=3><input type=submit name=cmd value=\"C cycle\">\n");
5852 rr->rsprintf(
"<input type=submit name=cmd value=\"Z cycle\">\n");
5854 rr->rsprintf(
"<tr><td colspan=2>Repeat delay [ms]");
5855 rr->rsprintf(
"<td><input type=text size=3 name=W value=%d>\n", w);
5858 (
"<td align=center colspan=3><input type=submit name=cmd value=\"Set inhibit\">\n");
5859 rr->rsprintf(
"<input type=submit name=cmd value=\"Clear inhibit\">\n");
5861 rr->rsprintf(
"<tr><td colspan=2>Data increment");
5862 rr->rsprintf(
"<td><input type=text size=3 name=ID value=%d>\n",
id);
5865 (
"<td colspan=3 align=center>Branch <input type=text size=3 name=B value=0>\n");
5867 rr->rsprintf(
"<tr><td colspan=2>A increment");
5868 rr->rsprintf(
"<td><input type=text size=3 name=IA value=%d>\n",
ia);
5871 (
"<td colspan=3 align=center>Crate <input type=text size=3 name=C value=%d>\n",
5874 rr->rsprintf(
"</table></body>\r\n");
5994 for (
i = 0;
i < 8;
i++)
5995 if (*((
unsigned char *)
pdata) & (0x80 >>
i))
6059static int cmp_int(
const void *a,
const void *b)
6061 return *((
int *)a) > *((
int *)b);
6139 size =
sizeof(address);
6172 int i,
j,
n,
ind,
fi, fd,
status, size,
n_addr, *
addr,
cur_node, adr,
show_hidden;
6196 sprintf(errorstr,
"No submaster defined under /MSCB/Submaster");
6255 for (
i=0 ;
i<0x10000 ;
i++)
6257 for (
i=0 ;
i<1000 ;
i++)
6259 for (
i=0 ;
i<0x10000 ;
i+=100)
6261 for (
i=0 ;
i<0x10000 ;
i+= 0x100)
6263 for (
i=0xFF00 ;
i<0x10000 ;
i++)
6344 if (
value[1] ==
'x')
6367 r->
rsprintf(
"<script type=\"text/javascript\" src=\"midas.js\"></script>\n");
6368 r->
rsprintf(
"<script type=\"text/javascript\" src=\"mhttpd.js\"></script>\n");
6372 r->
rsprintf(
"<style type=\"text/css\">\r\n");
6373 r->
rsprintf(
"select { width:150px; background-color:#FFFFE0; font-size:12px; }\r\n");
6375 r->
rsprintf(
" background-color:#E0E0E0; text-align:center; font-weight:bold;\r\n");
6377 r->
rsprintf(
" vertical-align:top;\r\n");
6378 r->
rsprintf(
" font-size:16px;\r\n");
6379 r->
rsprintf(
" border-right:1px solid #808080;\r\n");
6382 r->
rsprintf(
" background-color:#E0E0E0; text-align:center; font-weight:bold;\r\n");
6384 r->
rsprintf(
" vertical-align:top;\r\n");
6385 r->
rsprintf(
" font-size:16px;\r\n");
6386 r->
rsprintf(
" border-right:1px solid #808080;\r\n");
6389 r->
rsprintf(
" background-color:#E0E0E0; text-align:center; font-weight:bold;\r\n");
6391 r->
rsprintf(
" vertical-align:top;\r\n");
6392 r->
rsprintf(
" font-size:10px;\r\n");
6396 r->
rsprintf(
" font-weight:bold;\r\n");
6397 r->
rsprintf(
" font-size:12px;\r\n");
6400 r->
rsprintf(
" background-color:#F0F0F0;\r\n");
6402 r->
rsprintf(
" font-size:12px;\r\n");
6403 r->
rsprintf(
" border:1px solid #808080;\r\n");
6404 r->
rsprintf(
" border-right:1px solid #FFFFFF;\r\n");
6405 r->
rsprintf(
" border-bottom:1px solid #FFFFFF;\r\n");
6409 r->
rsprintf(
" font-size:12px;\r\n");
6414 r->
rsprintf(
"<script type=\"text/javascript\">\r\n");
6415 r->
rsprintf(
"function mscb_edit(index, value)\r\n");
6417 r->
rsprintf(
" var new_value = prompt('Please enter new value', value);\r\n");
6418 r->
rsprintf(
" if (new_value != undefined) {\r\n");
6426 r->
rsprintf(
"<table class=\"mtable\">");
6427 r->
rsprintf(
"<tr><th class=\"mtableheader\" colspan=2>MSCB</th><tr>");
6431 r->
rsprintf(
"<tr><td colspan=2>\n");
6432 r->
rsprintf(
"<table width=100%%><tr>\n");
6433 r->
rsprintf(
"<td><input type=button value=Reload onclick=\"window.location.search='?cmd=mscb&subm=%s&node=%d&rnd=%d'\"></td>\n",
cur_subm_name,
cur_node,
rand());
6435 r->
rsprintf(
"<tr><td colspan=\"2\" cellpadding=\"0\" cellspacing=\"0\">\r\n");
6439 r->
rsprintf(
"<h1>No MSCB Submasters defined in ODB</h1>\r\n");
6450 r->
rsprintf(
"<table width=\"100%%\" cellpadding=\"0\" cellspacing=\"0\">");
6453 r->
rsprintf(
"<tr><td class=\"subm\">\r\n");
6465 r->
rsprintf(
"<select name=\"subm\" id=\"subm\" size=%d ",
i);
6466 r->
rsprintf(
"onChange=\"window.location.search='?cmd=mscb&subm='+document.getElementById('subm').value;\">\r\n");
6476 size =
sizeof(comment);
6492 r->
rsprintf(
"<td class=\"node\">\r\n");
6495 r->
rsprintf(
"<script type=\"text/javascript\">\n");
6497 r->
rsprintf(
"function rescan()\n");
6499 r->
rsprintf(
" flag = confirm('Rescan can take up to one minute.');\n");
6500 r->
rsprintf(
" if (flag == true)\n");
6506 r->
rsprintf(
"<input type=button name=cmd value=\"Rescan\" onClick=\"rescan();\">");
6510 r->
rsprintf(
"No submaster found in ODB\r\n");
6545 r->
rsprintf(
"<select name=\"node\" id=\"node\" size=%d ",
i);
6546 r->
rsprintf(
"onChange=\"window.location.search='?cmd=mscb&subm=%s&node='+document.getElementById('node').value;\">\r\n",
cur_subm_name);
6568 size =
sizeof(comment);
6577 r->
rsprintf(
"<option selected>%s</option>\r\n",
str);
6585 r->
rsprintf(
"<td class=\"vars\">\r\n");
6602 r->
rsprintf(
"<tr><td colspan=3><b>Invalid password</b></td>");
6604 r->
rsprintf(
"<tr><td colspan=3><b>Submaster does not respond</b></td>");
6612 r->
rsprintf(
"<tr><td colspan=3><b>No response from node</b></td>");
6617 r->
rsprintf(
"<tr><td colspan=3><b>No response from node</b></td>");
6622 r->
rsprintf(
"<tr><td class=\"v1\">Node name<td colspan=2 class=\"v2\">%s</tr>\n",
tr16);
6623 r->
rsprintf(
"<tr><td class=\"v1\">GIT revision<td colspan=2 class=\"v2\">%d</tr>\n",
info.revision);
6625 if (
info.rtc[0] &&
info.rtc[0] != 0xFF) {
6626 for (
i=0 ;
i<6 ;
i++)
6628 r->
rsprintf(
"<tr><td class=\"v1\">Real Time Clock<td colspan=2 class=\"v2\">%02d-%02d-%02d %02d:%02d:%02d</td>\n",
6635 r->
rsprintf(
"<tr><td class=\"v1\">Uptime<td colspan=2 class=\"v2\">%dd %02dh %02dm %02ds</tr>\n",
6640 r->
rsprintf(
"<tr><td colspan=3><hr></td></tr>\r\n");
6643 for (
i=0 ;
i <
info.n_variables ;
i++) {
6648 if (
i <
info.n_variables) {
6651 r->
rsprintf(
"<tr><td colspan=3><input type=checkbox%s name=\"hidden\" value=\"1\"",
str);
6652 r->
rsprintf(
"onChange=\"window.location.search=?cmd=mscb&subm=%s&node=%d&hidden=1\">Display hidden variables<hr></td></tr>\r\n",
cur_subm_name,
cur_node);
6656 for (
fi=0 ;
fi <
info.n_variables ; ) {
6657 for (
i=
fi,size=0 ;
i <
info.n_variables && size < 100;
i++) {
6662 size =
sizeof(
dbuf);
6665 r->
rsprintf(
"<tr><td colspan=3><b>Error reading data from node</b></td>");
6675 r->
rsprintf(
"<tr><td class=\"v1\">%s</td>\r\n",
tr8);
6676 r->
rsprintf(
"<td class=\"v2\">\r\n");
6679 r->
rsprintf(
"<a href=\"#\" onClick=\"mscb_edit(%d,'%s')\">%s</a>",
6692 r->
rsprintf(
"</td></tr></table>\r\n");
6693 r->
rsprintf(
"</td></tr></table>\r\n");
6694 r->
rsprintf(
"</td></tr></table>\r\n");
6695 r->
rsprintf(
"</div></body></html>\r\n");
6704 r->
rsprintf(
"HTTP/1.1 200 Document follows\r\n");
6709 r->
rsprintf(
"<link rel=\"icon\" href=\"favicon.png\" type=\"image/png\" />\n");
6710 r->
rsprintf(
"<link rel=\"stylesheet\" href=\"midas.css\" type=\"text/css\" />\n");
6711 r->
rsprintf(
"<link rel=\"stylesheet\" href=\"mhttpd.css\" type=\"text/css\" />\n");
6712 r->
rsprintf(
"<title>Enter password</title></head><body>\n\n");
6714 r->
rsprintf(
"<form method=\"GET\" action=\".\">\n\n");
6717 r->
rsprintf(
"<table class=\"headerTable\"><tr><td></td><tr></table>\n");
6719 r->
rsprintf(
"<table class=\"dialogTable\">\n");
6721 r->
rsprintf(
"<tr><th class=\"redLight\">Wrong password!</tr>\n");
6723 r->
rsprintf(
"<tr><th>Please enter password</tr>\n");
6724 r->
rsprintf(
"<tr><td align=center><input type=password name=pwd></tr>\n");
6725 r->
rsprintf(
"<tr><td align=center><input type=submit value=Submit></tr>");
6751 r->
rsprintf(
"HTTP/1.1 200 Document follows\r\n");
6756 r->
rsprintf(
"<link rel=\"icon\" href=\"favicon.png\" type=\"image/png\" />\n");
6757 r->
rsprintf(
"<link rel=\"stylesheet\" href=\"midas.css\" type=\"text/css\" />\n");
6758 r->
rsprintf(
"<link rel=\"stylesheet\" href=\"mhttpd.css\" type=\"text/css\" />\n");
6759 r->
rsprintf(
"<title>Enter password</title></head><body>\n\n");
6761 r->
rsprintf(
"<form method=\"GET\" action=\".\">\n\n");
6765 r->
rsprintf(
"<input type=hidden name=redir value=\"%s\">\n",
redir);
6768 r->
rsprintf(
"<table class=\"headerTable\"><tr><td></td><tr></table>\n");
6770 r->
rsprintf(
"<table class=\"dialogTable\">\n");
6773 r->
rsprintf(
"<tr><th class=\"redLight\">Wrong password!</tr>\n");
6776 (
"<tr><th>Please enter password to obtain write access</tr>\n");
6777 r->
rsprintf(
"<tr><td align=center><input type=password name=wpwd></tr>\n");
6778 r->
rsprintf(
"<tr><td align=center><input type=submit value=Submit></tr>");
6819 r->
rsprintf(
"<script type=\"text/javascript\" src=\"midas.js\"></script>\n");
6820 r->
rsprintf(
"<script type=\"text/javascript\" src=\"mhttpd.js\"></script>\n");
6821 r->
rsprintf(
"<script type=\"text/javascript\" src=\"obsolete.js\"></script>\n");
6822 r->
rsprintf(
"<script type=\"text/javascript\" src=\"controls.js\"></script>\n");
6841 while (*p && *p !=
'/')
6866 r->
rsprintf(
"<table class=\"mtableheader\">\n");
6868 r->
rsprintf(
"<input type=button value=ELog onclick=\"self.location=\'?cmd=Alarms\';\">\n");
6869 r->
rsprintf(
"</td></tr></table>\n\n");
6875 r->
rsprintf(
"<table class=\"mtable\" style=\"border-spacing:0px;\">\n");
6876 r->
rsprintf(
"<tr><th colspan=%d class=\"mtableheader\">Online Database Browser</tr>\n",
colspan);
6880 r->
rsprintf(
"<input type=button value=Find onclick=\"self.location=\'?cmd=Find\';\">\n");
6881 r->
rsprintf(
"<input type=button value=Create onclick=\"dlgShow('dlgCreate')\">\n");
6882 r->
rsprintf(
"<input type=button value=Link onclick=\"dlgShow('dlgLink')\">\n");
6883 r->
rsprintf(
"<input type=button value=Delete onclick=\"dlgShow('dlgDelete')\">\n");
6884 r->
rsprintf(
"<input type=button value=\"Create Elog from this page\" onclick=\"self.location=\'?cmd=Create Elog from this page&odb_path=%s\';\">\n",
urlEncode(
odbpath.c_str()).c_str());
6885 r->
rsprintf(
"<input type=button value=\"Show open records\" onclick=\"self.location=\'?cmd=odb_sor&odb_path=%s\';\">\n",
urlEncode(
odbpath.c_str()).c_str());
6886 r->
rsprintf(
"<input type=button value=\"Show ODB clients\" onclick=\"self.location=\'?cmd=odb_scl\';\">\n");
6892 std::string dd =
"";
6894 dd +=
"<!-- Demo dialog -->\n";
6895 dd +=
"<div id=\"dlgDelete\" class=\"dlgFrame\">\n";
6896 dd +=
"<div class=\"dlgTitlebar\">Delete ODB entry</div>\n";
6897 dd +=
"<div class=\"dlgPanel\">\n";
6898 dd +=
"<div id=odbpath>";
6900 dd += MJsonNode::Encode(
odbpath.c_str());
6903 dd +=
"<div><br></div>\n";
6905 dd +=
"<table class=\"dialogTable\">\n";
6906 dd +=
"<th colspan=2>Delete ODB entries:</th>\n";
6916 r->
rsprintf(
"<a href=\"?cmd=oldodb\">/</a> \n");
6925 while (*p && *p !=
'/')
6930 if (
pd.length() > 0)
6945 r->
rsprintf(
"<tr class=\"titleRow\">\n");
6946 r->
rsprintf(
"<th class=\"ODBkey\">Key</th>\n");
6947 r->
rsprintf(
"<th class=\"ODBvalue\">Value ");
6948 r->
rsprintf(
"<script type=\"text/javascript\">\n");
6949 r->
rsprintf(
"function expand()\n");
6951 r->
rsprintf(
" var n = document.getElementsByName('ext');\n");
6952 r->
rsprintf(
" for (i=0 ; i<n.length ; i++) {\n");
6953 r->
rsprintf(
" if (n[i].style.display == 'none')\n");
6954 r->
rsprintf(
" n[i].style.display = 'table-cell';\n");
6956 r->
rsprintf(
" n[i].style.display = 'none';\n");
6958 r->
rsprintf(
" if (document.getElementById('expp').expflag === true) {\n");
6959 r->
rsprintf(
" document.getElementById('expp').expflag = false;\n");
6960 r->
rsprintf(
" document.getElementById('expp').innerHTML = '⇥';\n");
6962 r->
rsprintf(
" document.getElementById('expp').expflag = true;\n");
6963 r->
rsprintf(
" document.getElementById('expp').innerHTML = '⇤';\n");
6967 r->
rsprintf(
"<div style=\"display:inline;float:right\"><a id=\"expp\"href=\"#\" onClick=\"expand();return false;\">⇥</div>");
6969 r->
rsprintf(
"<th class=\"ODBvalue\" name=\"ext\" style=\"display:none\">Type</th>\n");
6970 r->
rsprintf(
"<th class=\"ODBvalue\" name=\"ext\" style=\"display:none\">#Val</th>\n");
6971 r->
rsprintf(
"<th class=\"ODBvalue\" name=\"ext\" style=\"display:none\">Size</th>\n");
6972 r->
rsprintf(
"<th class=\"ODBvalue\" name=\"ext\" style=\"display:none\">Written</th>\n");
6973 r->
rsprintf(
"<th class=\"ODBvalue\" name=\"ext\" style=\"display:none\">Mode</th>\n");
6977 for (
int i = 0;;
i++) {
6988 mstrlcpy(style,
"ODBtableEven",
sizeof(style));
6990 mstrlcpy(style,
"ODBtableOdd",
sizeof(style));
6998 if (odb_path.length() > 0 && odb_path[odb_path.length() - 1] !=
'/')
7032 enc_ref +=
"?cmd=Set&odb_path=";
7038 enc_ref +=
"?cmd=Set&odb_path=";
7045 enc_ref +=
"?cmd=Set&odb_path=";
7051 r->
rsprintf(
"<tr><td class=\"yellowLight\">");
7072 size =
sizeof(
data);
7083 if (size ==
sizeof(
data)) {
7105 r->
rsprintf(
"<td class=\"ODBkey\">\n");
7108 r->
rsprintf(
"<td class=\"%s\">\n", style);
7112 r->
rsprintf(
"<a href=\"%s\" onClick=\"ODBInlineEdit(this.parentNode,\'%s\');return false;\" ",
enc_ref.c_str(), odb_path.c_str());
7113 r->
rsprintf(
"onFocus=\"ODBInlineEdit(this.parentNode,\'%s\');\">%s (%s)</a>\n", odb_path.c_str(),
data_str.c_str(),
hex_str.c_str());
7116 r->
rsprintf(
"<td class=\"ODBkey\">\n");
7121 r->
rsprintf(
"<a href=\"%s\" onClick=\"ODBInlineEdit(this.parentNode,\'%s\');return false;\" ",
enc_ref.c_str(), odb_path.c_str());
7122 r->
rsprintf(
"onFocus=\"ODBInlineEdit(this.parentNode,\'%s\');\">%s (%s)</a>\n", odb_path.c_str(),
data_str.c_str(),
hex_str.c_str());
7128 r->
rsprintf(
"<td class=\"ODBkey\">");
7131 r->
rsprintf(
"<td class=\"ODBkey\">%s<td class=\"%s\">",
keyname.c_str(), style);
7141 r->
rsprintf(
"<td class=\"ODBkey\">\n");
7146 r->
rsprintf(
"<a href=\"%s\" onClick=\"ODBInlineEdit(this.parentNode,\'%s\');return false;\" ",
enc_ref.c_str(), odb_path.c_str());
7147 r->
rsprintf(
"onFocus=\"ODBInlineEdit(this.parentNode,\'%s\');\">", odb_path.c_str());
7152 r->
rsprintf(
"<td class=\"ODBkey\">%s<td class=\"%s\">",
keyname.c_str(), style);
7156 r->
rsprintf(
"<a href=\"%s\" onClick=\"ODBInlineEdit(this.parentNode,\'%s\');return false;\" ",
enc_ref.c_str(), odb_path.c_str());
7157 r->
rsprintf(
"onFocus=\"ODBInlineEdit(this.parentNode,\'%s\');\">", odb_path.c_str());
7166 r->
rsprintf(
"<td class=\"ODBkey\" name=\"ext\" style=\"display:none\">");
7170 r->
rsprintf(
"<td class=\"ODBkey\" name=\"ext\" style=\"display:none\">");
7174 r->
rsprintf(
"<td class=\"ODBkey\" name=\"ext\" style=\"display:none\">");
7178 r->
rsprintf(
"<td class=\"ODBkey\" name=\"ext\" style=\"display:none\">");
7182 else if (
delta < 3600)
7184 else if (
delta < 86400)
7186 else if (
delta < 86400 * 99)
7192 r->
rsprintf(
"<td class=\"ODBkey\" name=\"ext\" style=\"display:none\">");
7208 r->
rsprintf(
"<tr><td class=\"ODBkey\">%s<td class=\"%s\"><span style=\"font-style: italic\"><a href=\"?cmd=oldodb&odb_path=%s&all=1\">... %d values ...</a></span>\n",
keyname.c_str(), style,
enc_full_path.c_str(),
key.
num_values);
7218 mstrlcpy(style,
"ODBtableEven",
sizeof(style));
7220 mstrlcpy(style,
"ODBtableOdd",
sizeof(style));
7223 size =
sizeof(
data);
7235 if (size ==
sizeof(
data)) {
7247 enc_ref +=
"?cmd=Set&odb_path=";
7262 r->
rsprintf(
"<td class=\"%s\">[%d] ", style,
j);
7266 r->
rsprintf(
"<a href=\"%s\" onClick=\"ODBInlineEdit(this.parentNode,\'%s\');return false;\" ",
enc_ref.c_str(),
tmpstr.c_str());
7267 r->
rsprintf(
"onFocus=\"ODBInlineEdit(this.parentNode,\'%s\');\">",
tmpstr.c_str());
7276 r->
rsprintf(
"<td class=\"ODBkey\" name=\"ext\" style=\"display:none\" rowspan=%d>",
key.
num_values);
7280 r->
rsprintf(
"<td class=\"ODBkey\" name=\"ext\" style=\"display:none\" rowspan=%d>",
key.
num_values);
7284 r->
rsprintf(
"<td class=\"ODBkey\" name=\"ext\" style=\"display:none\" rowspan=%d>",
key.
num_values);
7288 r->
rsprintf(
"<td class=\"ODBkey\" name=\"ext\" style=\"display:none\" rowspan=%d>",
key.
num_values);
7292 else if (
delta < 3600)
7294 else if (
delta < 86400)
7296 else if (
delta < 86400 * 99)
7302 r->
rsprintf(
"<td class=\"ODBkey\" name=\"ext\" style=\"display:none\" rowspan=%d>",
key.
num_values);
7335 dd +=
"<tr><td style=\"text-align:left;\" align=left><input align=left type=checkbox id=delete";
7339 dd += MJsonNode::Encode(
name.c_str());
7343 dd +=
"</input></td></tr>\n";
7347 dd +=
"<input type=button value=Delete onClick='mhttpd_delete_page_handle_delete(event);'>\n";
7348 dd +=
"<input type=button value=Cancel onClick='mhttpd_delete_page_handle_cancel(event);'>\n";
7356 std::string cd =
"";
7358 cd +=
"<!-- Demo dialog -->\n";
7359 cd +=
"<div id=\"dlgCreate\" class=\"dlgFrame\">\n";
7360 cd +=
"<div class=\"dlgTitlebar\">Create ODB entry</div>\n";
7361 cd +=
"<div class=\"dlgPanel\">\n";
7363 cd +=
"<div id=odbpath>";
7365 cd += MJsonNode::Encode(
odbpath.c_str());
7368 cd +=
"<div><br></div>\n";
7370 cd +=
"<table class=\"dialogTable\">\n";
7371 cd +=
"<th colspan=2>Create ODB entry:</th>\n";
7375 cd +=
"<select type=text size=1 id=create_tid name=type>";
7376 cd +=
"<option value=7>Integer (32-bit)";
7377 cd +=
"<option value=9>Float (4 Bytes)";
7378 cd +=
"<option value=12>String";
7379 cd +=
"<option selected value=15>Subdirectory";
7380 cd +=
"<option value=1>Byte";
7381 cd +=
"<option value=2>Signed byte";
7382 cd +=
"<option value=3>Character (8-bit)";
7383 cd +=
"<option value=4>Word (16-bit)";
7384 cd +=
"<option value=5>Short integer (16-bit)";
7385 cd +=
"<option value=6>Double Word (32-bit)";
7386 cd +=
"<option value=8>Boolean";
7387 cd +=
"<option value=10>Double float (8 Bytes)";
7391 cd +=
"<tr><td>Name<td><input type=text size=31 maxlength=31 id=create_name name=value></tr>\n";
7392 cd +=
"<tr><td>Array size<td><input type=text size=31 maxlength=31 id=create_array_length name=index value=1></tr>\n";
7393 cd +=
"<tr><td>String length<td><input type=text size=31 maxlength=31 id=create_strlen name=strlen value=32></tr>\n";
7395 cd +=
"<input type=button value=Create onClick='mhttpd_create_page_handle_create(event);'>\n";
7396 cd +=
"<input type=button value=Cancel onClick='mhttpd_create_page_handle_cancel(event);'>\n";
7404 std::string
ld =
"";
7406 ld +=
"<!-- Demo dialog -->\n";
7407 ld +=
"<div id=\"dlgLink\" class=\"dlgFrame\">\n";
7408 ld +=
"<div class=\"dlgTitlebar\">Create a link to an ODB entry</div>\n";
7409 ld +=
"<div class=\"dlgPanel\">\n";
7411 ld +=
"<div id=link_odbpath>";
7413 ld += MJsonNode::Encode(
odbpath.c_str());
7416 ld +=
"<div><br></div>\n";
7418 ld +=
"<table class=\"dialogTable\">\n";
7419 ld +=
"<th colspan=2>Create a link to an ODB entry:</th>\n";
7420 ld +=
"<tr><td>Name<td><input type=text size=31 maxlength=31 id=link_name name=value></tr>\n";
7421 ld +=
"<tr><td>Link target<td><input type=text size=31 maxlength=256 id=link_target name=target></tr>\n";
7423 ld +=
"<input type=button value=Link onClick='mhttpd_link_page_handle_link(event);'>\n";
7424 ld +=
"<input type=button value=Cancel onClick='mhttpd_link_page_handle_cancel(event);'>\n";
7442 std::string odb_path =
pp->getparam(
"odb_path");
7449 if (!
pp->isparam(
"value") && !*
pp->getparam(
"text")) {
7452 r->
rsprintf(
"Error: cannot find key %s<P>\n", odb_path.c_str());
7462 r->
rsprintf(
"<table class=\"dialogTable\">");
7465 r->
rsprintf(
"<input type=hidden name=index value=\"%d\">\n",
index);
7470 r->
rsprintf(
"<input type=hidden name=group value=\"%s\">\n",
group);
7472 r->
rsprintf(
"<input type=hidden name=odb_path value=\"%s\">\n", odb_path.c_str());
7480 str1 = odb_path.c_str();
7482 r->
rsprintf(
"<tr><th colspan=2>Set new value - type = %s</tr>\n",
data_str1.c_str());
7486 size =
sizeof(
data);
7494 r->
rsprintf(
"<textarea rows=20 cols=80 name=\"text\">\n");
7499 if ((
int)
data_str.length() > size)
7504 r->
rsprintf(
"<input type=\"text\" size=%d maxlength=256 name=\"value\" value=\"", size);
7511 r->
rsprintf(
"<tr><td align=center colspan=2>");
7512 r->
rsprintf(
"<input type=submit name=cmd value=Set>");
7513 r->
rsprintf(
"<input type=submit name=cmd value=Cancel>");
7517 r->
rsprintf(
"<input type=hidden name=cmd value=Set>\n");
7528 r->
rsprintf(
"Error: cannot find key %s<P>\n", odb_path.c_str());
7535 if (
pp->getparam(
"text") && *
pp->getparam(
"text"))
7557 r->
rsprintf(
"<h2>Write access not allowed</h2>\n");
7573 if (
value[0] == 0) {
7581 r->
rsprintf(
"<table class=\"dialogTable\">");
7583 r->
rsprintf(
"<tr><th colspan=2>Find string in Online Database</tr>\n");
7584 r->
rsprintf(
"<tr><td>Enter substring (case insensitive)\n");
7586 r->
rsprintf(
"<td><input type=\"text\" size=\"20\" maxlength=\"80\" name=\"value\">\n");
7589 r->
rsprintf(
"<tr><td align=center colspan=2>");
7590 r->
rsprintf(
"<input type=submit name=cmd value=Find>");
7591 r->
rsprintf(
"<input type=submit name=cmd value=Cancel>");
7595 r->
rsprintf(
"<input type=hidden name=cmd value=Find>");
7603 r->
rsprintf(
"<table class=\"mtable\">\n");
7604 r->
rsprintf(
"<tr><th colspan=2 class=\"mtableheader\">");
7605 r->
rsprintf(
"Results of search for substring \"%s\"</tr>\n",
value);
7606 r->
rsprintf(
"<tr><th class=\"titlerow\">Key<th>Value</tr>\n");
7628#define LN10 2.302585094
7629#define LOG2 0.301029996
7630#define LOG5 0.698970005
7633 int x1,
int y1,
int width,
7634 int minor,
int major,
int text,
int label,
int grid,
double xmin,
double xmax)
7639 double base[] = { 1, 2, 5, 10, 20, 50, 100, 200, 500, 1000 };
7641 if (xmax <= xmin || width <= 0)
7645 dx = (xmax - xmin) / (
double) (width / 5);
7764 sprintf(result,
"%02d %s %02d %02d:%02d:%02d",
7767 else if (
base < 3600 * 24)
7768 sprintf(result,
"%02d %s %02d %02d:%02d",
7775 else if (
base < 3600 * 3)
7777 else if (
base < 3600 * 24)
7778 sprintf(result,
"%02d %s %02d %02d:%02d",
7786 int x1,
int y1,
int width,
int xr,
7787 int minor,
int major,
int text,
int label,
int grid,
double xmin,
double xmax)
7792 const int base[] = { 1, 5, 10, 60, 300, 600, 1800, 3600, 3600 * 6, 3600 * 12, 3600 * 24, 0 };
7797 if (xmax <= xmin || width <= 0)
7810 dx = (
int) ((xmax - xmin) / (
double) (width / 5) + 0.5);
7907 int x1,
int y1,
int width,
7915 const double base[] = { 1, 2, 5, 10, 20, 50, 100, 200, 500, 1000 };
7978 if (
x1 != 0 ||
y1 != 0)
7998 if (
x1 != 0 ||
y1 != 0) {
8026 if (
x1 != 0 ||
y1 != 0) {
8042 if (
x1 != 0 ||
y1 != 0) {
8050 if (
x1 != 0 ||
y1 != 0) {
8120 for (; *
str != 0;
str++) {
8136 sprintf(buf,
"%.0f", (
double)t);
8149 cm_msg(
MINFO,
"history_watch_callback",
"History configuration may have changed, will reconnect");
8216 cm_msg(
MERROR,
"get_history",
"Cannot configure history, hs_get_history() status %d",
status);
8234#define ALLOC(t,n) (t*)calloc(sizeof(t),(n))
8235#define DELETE(x) if (x) { free(x); (x)=NULL; }
8236#define DELETEA(x, n) if (x) { for (int i=0; i<(n); i++) { free((x)[i]); (x)[i]=NULL; }; DELETE(x); }
8237#define STRDUP(x) strdup(x)
8320#define READ_HISTORY_DATA 0x1
8321#define READ_HISTORY_RUNMARKER 0x2
8322#define READ_HISTORY_LAST_WRITTEN 0x4
8382 cm_msg(
MERROR,
"read_history",
"Cannot find \'/History/Display\' in ODB, status %d",
status);
8389 cm_msg(
MERROR,
"read_history",
"Cannot find \'%s\' in ODB, status %d", path,
status);
8395 cm_msg(
MERROR,
"read_history",
"Cannot find \'%s/Variables\' in ODB, status %d", path,
status);
8403 data->Allocate(
hp.vars.size()+2);
8405 data->tstart = tstart;
8407 data->scale = scale;
8409 for (
size_t i=0;
i<
hp.vars.size();
i++) {
8457 data->var_index[
data->nvars+0] = 0;
8458 data->var_index[
data->nvars+1] = 0;
8460 data->odb_index[
data->nvars+0] = -1;
8461 data->odb_index[
data->nvars+1] = -2;
8466 bool get_last_written =
false;
8480 printf(
"read_history: nvars %d, hs_read() status %d\n",
data->nvars,
status);
8481 for (
int i=0;
i<
data->nvars;
i++) {
8482 printf(
"read_history: %d: event [%s], var [%s], index %d, odb index %d, status %d, num_entries %d\n",
i,
data->event_names[
i],
data->var_names[
i],
data->var_index[
i],
data->odb_index[
i],
data->status[
i],
data->num_entries[
i]);
8487 cm_msg(
MERROR,
"read_history",
"Complete history failure, hs_read() status %d, see messages",
status);
8491 for (
int i=0;
i<
data->nvars;
i++) {
8493 get_last_written =
true;
8500 get_last_written =
true;
8502 if (get_last_written) {
8503 data->have_last_written =
true;
8511 data->last_written);
8514 data->have_last_written =
false;
8550 if (!
hsdata->have_last_written) {
8599 printf(
"get_hist_last_written: elapsed time %f ms\n", tend-tstart);
8605 int width,
int height,
8609 int labels,
const char *bgcolor,
const char *fgcolor,
const char *
gridcolor)
8653 std::vector<int> var_index; var_index.resize(
hp.vars.size());
8655 for (
size_t i=0;
i<
hp.vars.size();
i++) {
8657 const char *
vp =
strchr(
hp.vars[
i].tag_name.c_str(),
'[');
8684 sscanf(bgcolor,
"%02x%02x%02x", &r, &
g, &b);
8686 sscanf(fgcolor,
"%02x%02x%02x", &r, &
g, &b);
8725 sprintf(
str,
"History is not configured, see messages");
8749 if (
hp.vars.empty()) {
8764 for (
i = 0;
i < (
int)
hp.vars.size();
i++) {
8825 if (
hp.vars[
i].colour[0] ==
'#') {
8826 const char*
str =
hp.vars[
i].colour.c_str();
8953 while (p >
str && *p !=
' ')
8955 std::string key_name = p + 1;
8993 std::string key_name =
key.
name;
8997 path +=
"Settings/Names ";
9079 if (
hp.enable_factor) {
9089 if (
hp.enable_factor) {
9109 if (
hp.show_run_markers)
9115 sprintf(
str,
"Complete history failure, read_history() status %d, see messages",
status);
9144 for (
int j=0;
j<
hsdata->num_entries[
k];
j++) {
9161 if (
hp.enable_factor) {
9162 yy =
hp.vars[
i].factor * (
yy -
hp.vars[
i].voffset) +
hp.vars[
i].offset;
9186 assert(x[
i].size() == y[
i].size());
9215 if (
hp.zero_ylow &&
ymin > 0)
9276 aoffset =
vaxis(
im,
gdFontSmall,
fgcol,
gridcol, 0, 0, height, -3, -5, -7, -8, 0,
ymin,
ymax,
logaxis);
9287 taxis(
im,
gdFontSmall,
fgcol,
gridcol,
x1,
y1,
x2 -
x1, width, 3, 5, 9, 10, 0, (
double)
starttime, (
double)
endtime);
9289 vaxis(
im,
gdFontSmall,
fgcol,
gridcol,
x1,
y1,
y1 -
y2, -3, -5, -7, -8,
x2 -
x1,
ymin,
ymax,
logaxis);
9298 if ( (0) &&
hp.show_run_markers) {
9300 const char* event_names[] = {
9361 if (
dbuf[0][
j] == 1)
9363 else if (
dbuf[0][
j] == 2)
9365 else if (
dbuf[0][
j] == 3)
9388 if (num_entries[0]) {
9395 if (num_entries[1]) {
9404 if (
hp.show_run_markers) {
9410 if (
hsdata->odb_index[
k] == -1)
9413 if (
hsdata->odb_index[
k] == -2)
9429 printf(
"read run info: indexes: %d, %d, status: %d, %d, entries: %d, %d\n",
index_state,
index_run_number,
hsdata->status[
index_state],
hsdata->status[
index_run_number],
hsdata->num_entries[
index_state],
hsdata->num_entries[
index_run_number]);
9470 else if (
state == 2)
9472 else if (
state == 3)
9496 for (
i = 0;
i < (
int)
hp.vars.size();
i++) {
9611 for (
i = 0;
i < (
int)
hp.vars.size();
i++) {
9622 std::string
str =
hp.vars[
i].label.c_str();
9625 if (
hp.enable_factor) {
9626 str =
hp.vars[
i].tag_name;
9628 if (
hp.vars[
i].voffset > 0)
9630 else if (
hp.vars[
i].voffset < 0)
9633 if (
hp.vars[
i].factor != 1) {
9634 if (
hp.vars[
i].voffset == 0)
9641 if (
hp.vars[
i].offset > 0)
9643 else if (
hp.vars[
i].offset < 0)
9647 str =
hp.vars[
i].tag_name;
9659 printf(
"graph %d: odb index %d, n_point %d, num_entries %d, have_last_written %d %d, status %d, var_status [%s]\n",
i,
k,
n_point[
i],
hsdata->num_entries[
k],
hsdata->have_last_written, (
int)
hsdata->last_written[
k],
hsdata->status[
k],
var_status[
i]);
9662 if (
hp.show_values) {
9666 }
else if (
hsdata->num_entries[
k] > 0) {
9668 }
else if (
hsdata->have_last_written) {
9669 if (
hsdata->last_written[
k]) {
9722 if (buffer ==
NULL) {
9723 rr->rsprintf(
"HTTP/1.1 200 Document follows\r\n");
9726 rr->rsprintf(
"Content-Type: image/gif\r\n");
9727 rr->rsprintf(
"Content-Length: %d\r\n",
length);
9728 rr->rsprintf(
"Cache-control: private, max-age=0, no-cache\r\n");
9729 rr->rsprintf(
"Expires: Fri, 01-Jan-1983 00:00:00 GMT\r\n\r\n");
9733 if (
length > *buffer_size) {
9734 printf(
"return buffer too small\n");
9803 for (
i = 0;
i < 12;
i++)
9813 if (
tms.tm_year < 90)
9822 for (
i = 0;
i < 12;
i++)
9832 if (
tms.tm_year < 90)
9841 redir +=
"?cmd=oldhistory&";
9881 r->
rsprintf(
"<tr><td colspan=2>\n");
9882 r->
rsprintf(
"<input type=hidden name=cmd value=OldHistory>\n");
9883 r->
rsprintf(
"<input type=submit name=hcmd value=Query>\n");
9884 r->
rsprintf(
"<input type=submit name=hcmd value=Cancel>\n");
9886 r->
rsprintf(
"<input type=hidden name=group value=\"%s\">\n", p->
getparam(
"group"));
9888 r->
rsprintf(
"<input type=hidden name=panel value=\"%s\">\n", p->
getparam(
"panel"));
9890 r->
rsprintf(
"<input type=hidden name=htime value=\"%s\">\n", p->
getparam(
"htime"));
9892 r->
rsprintf(
"<input type=hidden name=hscale value=\"%s\">\n", p->
getparam(
"hscale"));
9894 r->
rsprintf(
"<input type=hidden name=hindex value=\"%s\">\n", p->
getparam(
"hindex"));
9898 r->
rsprintf(
"<table class=\"dialogTable\">");
9902 tms.tm_year += 1900;
9904 r->
rsprintf(
"<tr><td nowrap>Start date:</td>");
9906 r->
rsprintf(
"<td>Month: <select name=\"m1\">\n");
9907 r->
rsprintf(
"<option value=\"\">\n");
9908 for (
i = 0;
i < 12;
i++)
9909 if (
i ==
tms.tm_mon)
9915 r->
rsprintf(
" Day: <select name=\"d1\">");
9916 r->
rsprintf(
"<option selected value=\"\">\n");
9917 for (
i = 0;
i < 31;
i++)
9918 if (
i + 1 ==
tms.tm_mday)
9919 r->
rsprintf(
"<option selected value=%d>%d\n",
i + 1,
i + 1);
9921 r->
rsprintf(
"<option value=%d>%d\n",
i + 1,
i + 1);
9928 r->
rsprintf(
" Hour: <input type=\"text\" size=5 maxlength=5 name=\"h1\" value=\"%d\">",
start_hour);
9930 r->
rsprintf(
" Year: <input type=\"text\" size=5 maxlength=5 name=\"y1\" value=\"%d\">",
tms.tm_year);
9933 r->
rsprintf(
"<tr><td nowrap>End date:</td>");
9936 tms.tm_year += 1900;
9938 r->
rsprintf(
"<td>Month: <select name=\"m2\">\n");
9939 r->
rsprintf(
"<option value=\"\">\n");
9940 for (
i = 0;
i < 12;
i++)
9941 if (
i ==
tms.tm_mon)
9947 r->
rsprintf(
" Day: <select name=\"d2\">");
9948 r->
rsprintf(
"<option selected value=\"\">\n");
9949 for (
i = 0;
i < 31;
i++)
9950 if (
i + 1 ==
tms.tm_mday)
9951 r->
rsprintf(
"<option selected value=%d>%d\n",
i + 1,
i + 1);
9953 r->
rsprintf(
"<option value=%d>%d\n",
i + 1,
i + 1);
9960 r->
rsprintf(
" Hour: <input type=\"text\" size=5 maxlength=5 name=\"h2\" value=\"%d\">",
end_hour);
9962 r->
rsprintf(
" Year: <input type=\"text\" size=5 maxlength=5 name=\"y2\" value=\"%d\">",
tms.tm_year);
9978 const char*sa = (
const char*)a;
9979 const char*
sb = (
const char*)b;
9988 printf(
"compare [%s] and [%s]\n", sa,
sb);
9991 if (sa[
i]==0 &&
sb[
i]==0)
10012 if (sa[
i]==
sb[
i]) {
10017 printf(
"index %d, char [%c] [%c]\n",
i, sa[
i],
sb[
i]);
10021 else if (
sb[
i] == 0)
10035 return cmp_names(a.c_str(), b.c_str()) < 0;
10049static int cmp_tags(
const void *a,
const void *b)
10051 const TAG*sa = (
const TAG*)a;
10088 str =
"bad_xdb_find_key";
10108 printf(
"hist plot: %d variables\n", (
int)
hp.vars.size());
10109 printf(
"timescale: %s, minimum: %f, maximum: %f, zero_ylow: %d, log_axis: %d, show_run_markers: %d, show_values: %d, show_fill: %d, show_factor %d, enable_factor: %d\n",
hp.timescale.c_str(),
hp.minimum,
hp.maximum,
hp.zero_ylow,
hp.log_axis,
hp.show_run_markers,
hp.show_values,
hp.show_fill,
hp.show_factor,
hp.enable_factor);
10111 for (
size_t i=0;
i<
hp.vars.size();
i++) {
10112 printf(
"var[%d] event [%s][%s] formula [%s], colour [%s] label [%s] show_raw_value %d factor %f offset %f voffset %f order %d\n", (
int)
i,
hp.vars[
i].event_name.c_str(),
hp.vars[
i].tag_name.c_str(),
hp.vars[
i].formula.c_str(),
hp.vars[
i].colour.c_str(),
hp.vars[
i].label.c_str(),
hp.vars[
i].show_raw_value,
hp.vars[
i].factor,
hp.vars[
i].offset ,
hp.vars[
i].voffset,
hp.vars[
i].order);
10118 const char*
const colour[] =
10120 "#00AAFF",
"#FF9000",
"#FF00A0",
"#00C030",
10121 "#A0C0D0",
"#D0A060",
"#C04010",
"#807060",
10122 "#F0C000",
"#2090A0",
"#D040D0",
"#90B000",
10123 "#B0B040",
"#B0B0FF",
"#FFA0A0",
"#A0FFA0",
10126 for (
int i=0; colour[
i];
i++) {
10129 for (
size_t j=0;
j<
hp.vars.size();
j++)
10130 if (
hp.vars[
j].colour == colour[
i]) {
10145 for (
size_t i=0;
i<
hp.vars.size();
i++)
10146 if (
hp.vars[
i].order > order)
10147 order =
hp.vars[
i].order;
10155 std::vector<size_t>
colons;
10163 if (
colons.size() == 0) {
10197 std::string path =
"History/Display/";
10202 MVOdb*
o = odb->Chdir(path.c_str());
10207 o->RS(
"Timescale", &
hp->timescale);
10208 o->RD(
"Minimum", &
hp->minimum);
10209 o->RD(
"Maximum", &
hp->maximum);
10210 o->RB(
"Zero ylow", &
hp->zero_ylow);
10211 o->RB(
"Log axis", &
hp->log_axis);
10212 o->RB(
"Zero ylow", &
hp->zero_ylow);
10213 o->RB(
"Show run markers", &
hp->show_run_markers);
10214 o->RB(
"Show values", &
hp->show_values);
10215 o->RB(
"Show fill", &
hp->show_fill);
10216 o->RB(
"Show factor", &
hp->show_factor);
10270 for (
size_t i=0;
i<
num;
i++) {
10285 if (
hp->enable_factor && v.
formula.empty()) {
10291 hp->vars.push_back(v);
10307 hp->show_run_markers = *p->
getparam(
"run_markers");
10308 hp->show_values = *p->
getparam(
"show_values");
10310 hp->show_factor = *p->
getparam(
"show_factor");
10364 hp->vars.push_back(v);
10369 if (
hp->vars[
index].order < 0)
10385 if (
par.length() < 1)
10388 std::string event_name, tag_name;
10391 if (tag_name ==
"")
10401 hp.vars.push_back(v);
10408 cm_msg(
MERROR,
"SaveHistPlotToOdb",
"Error: Cannot write history plot to ODB, group \"%s\", panel \"%s\", invalid group name",
group,
panel);
10413 cm_msg(
MERROR,
"SaveHistPlotToOdb",
"Error: Cannot write history plot to ODB, group \"%s\", panel \"%s\", invalid panel name",
group,
panel);
10417 std::string path =
"History/Display/";
10425 MVOdb*
o = odb->Chdir(path.c_str(),
true);
10427 o->WS(
"Timescale",
hp.timescale.c_str());
10428 o->WD(
"Minimum",
hp.minimum);
10429 o->WD(
"Maximum",
hp.maximum);
10430 o->WB(
"Zero ylow",
hp.zero_ylow);
10431 o->WB(
"Log axis",
hp.log_axis);
10432 o->WB(
"Show run markers",
hp.show_run_markers);
10433 o->WB(
"Show values",
hp.show_values);
10434 o->WB(
"Show fill",
hp.show_fill);
10435 o->WB(
"Show factor and offset",
hp.show_factor);
10447 for (
size_t i=0;
i<
hp.vars.size();
i++) {
10448 hist_vars.push_back(
hp.vars[
i].event_name +
":" +
hp.vars[
i].tag_name);
10458 if (
hp.vars.size() > 0) {
10468 o->Delete(
"Variables");
10469 o->Delete(
"Formula");
10470 o->Delete(
"Colour");
10471 o->Delete(
"Label");
10472 o->Delete(
"Show raw value");
10473 o->Delete(
"Factor");
10474 o->Delete(
"Offset");
10475 o->Delete(
"VOffset");
10487 for (
unsigned i=0;
i<
hp.vars.size();
i++) {
10488 if (
hp.vars[
i].order <= 0) {
10489 hp.vars.erase(
hp.vars.begin() +
i);
10503 for (
size_t i=1;
i<
hp.vars.size();
i++) {
10504 if (
hp.vars[
i-1].order >=
hp.vars[
i].order) {
10533 strcpy(
hcmd,
"Refresh");
10573 r->
rsprintf(
"<table class=\"mtable\">");
10575 r->
rsprintf(
"<tr><th colspan=11 class=\"subStatusTitle\">History Panel \"%s\" / \"%s\"</th></tr>\n",
hgroup,
hpanel);
10578 r->
rsprintf(
"<tr><td colspan=11>\n");
10580 r->
rsprintf(
"<input type=button value=Refresh ");
10581 r->
rsprintf(
"onclick=\"document.form1.hcmd.value='Refresh';document.form1.submit()\">\n");
10583 r->
rsprintf(
"<input type=button value=Save ");
10584 r->
rsprintf(
"onclick=\"document.form1.hcmd.value='Save';document.form1.submit()\">\n");
10587 r->
rsprintf(
"<input type=button value=Cancel ");
10588 std::string
url =
"?cmd=oldhistory&group=";
10592 url +=
"&hcmd=Cancel";
10597 r->
rsprintf(
"onclick=\"window.location.search='%s'\">\n",
url.c_str());
10600 r->
rsprintf(
"<input type=button value=\"Edit in ODB\"");
10601 std::string
url =
"?cmd=odb&odb_path=";
10602 url +=
"/History/Display/";
10606 r->
rsprintf(
"onclick=\"window.location.search='%s'\">\n",
url.c_str());
10609 r->
rsprintf(
"<input type=button value=\"Edit in new editor\"");
10610 std::string
url =
"?cmd=hs_edit";
10619 r->
rsprintf(
"onclick=\"window.location.search='%s'\">\n",
url.c_str());
10621 r->
rsprintf(
"<input type=button value=\"Clear history cache\"");
10622 r->
rsprintf(
"onclick=\"document.form1.hcmd.value='Clear history cache';document.form1.submit()\">\n");
10623 r->
rsprintf(
"<input type=button value=\"Delete panel\"");
10624 r->
rsprintf(
"onclick=\"window.location.search='?cmd=oldhistory&group=%s&panel=%s&hcmd=Delete%%20panel'\">\n",
hgroup,
hpanel);
10627 r->
rsprintf(
"<tr><td colspan=11>\n");
10631 r->
rsprintf(
"<input type=checkbox %s name=sort_vars value=1 onclick=\"this.form.submit();\">Sort variable names",
sort_vars?
"checked":
"");
10635 r->
rsprintf(
" <input type=checkbox %s name=old_vars value=1 onclick=\"this.form.submit();\">Show deleted and renamed variables",
old_vars?
"checked":
"");
10637 if (
hp.show_factor)
10638 r->
rsprintf(
" <input type=checkbox checked name=show_factor value=1 onclick=\"document.form1.hcmd.value='Refresh';document.form1.submit()\">");
10640 r->
rsprintf(
" <input type=checkbox name=show_factor value=1 onclick=\"document.form1.hcmd.value='Refresh';document.form1.submit()\">");
10641 r->
rsprintf(
"Show factor and offset\n");
10644 r->
rsprintf(
"<input type=hidden name=cmd value=Oldhistory>\n");
10645 r->
rsprintf(
"<input type=hidden name=hcmd value=Refresh>\n");
10646 r->
rsprintf(
"<input type=hidden name=panel value=\"%s\">\n",
hpanel);
10647 r->
rsprintf(
"<input type=hidden name=group value=\"%s\">\n",
hgroup);
10650 r->
rsprintf(
"<input type=hidden name=redir value=\"%s\">\n", p->
getparam(
"redir"));
10654 r->
rsprintf(
"<tr><td colspan=4 style='text-align:right'>Time scale (in units 'm', 'h', 'd'):</td>\n");
10655 r->
rsprintf(
"<td colspan=3><input type=text size=12 name=timescale value=%s></td><td colspan=4></td></tr>\n",
hp.timescale.c_str());
10657 r->
rsprintf(
"<tr><td colspan=4 style='text-align:right'>Minimum (set to '-inf' for autoscale):</td>\n");
10658 r->
rsprintf(
"<td colspan=3><input type=text size=12 name=minimum value=%f></td><td colspan=4></td></tr>\n",
hp.minimum);
10660 r->
rsprintf(
"<tr><td colspan=4 style='text-align:right'>Maximum (set to 'inf' for autoscale):</td>\n");
10661 r->
rsprintf(
"<td colspan=3><input type=text size=12 name=maximum value=%f></td><td colspan=4></td></tr>\n",
hp.maximum);
10663 r->
rsprintf(
"<tr><td colspan=11>");
10666 r->
rsprintf(
"<input type=checkbox checked name=zero_ylow value=1>");
10668 r->
rsprintf(
"<input type=checkbox name=zero_ylow value=1>");
10669 r->
rsprintf(
"Zero Y; axis\n");
10672 r->
rsprintf(
"<input type=checkbox checked name=log_axis value=1>");
10674 r->
rsprintf(
"<input type=checkbox name=log_axis value=1>");
10675 r->
rsprintf(
"Logarithmic Y axis\n");
10677 if (
hp.show_run_markers)
10678 r->
rsprintf(
" <input type=checkbox checked name=run_markers value=1>");
10680 r->
rsprintf(
" <input type=checkbox name=run_markers value=1>");
10681 r->
rsprintf(
"Show run markers\n");
10683 if (
hp.show_values)
10684 r->
rsprintf(
" <input type=checkbox checked name=show_values value=1>");
10686 r->
rsprintf(
" <input type=checkbox name=show_values value=1>");
10687 r->
rsprintf(
"Show values of variables\n");
10690 r->
rsprintf(
" <input type=checkbox checked name=show_fill value=1>");
10692 r->
rsprintf(
" <input type=checkbox name=show_fill value=1>");
10693 r->
rsprintf(
"Show graph fill\n");
10712 std::vector<std::string>
events;
10721 for (
unsigned i=0;
i<
events.size();
i++)
10730 r->
rsprintf(
"<tr><th colspan=8 class=\"subStatusTitle\">List of available history variables</th></tr>\n");
10731 r->
rsprintf(
"<tr><th colspan=1>Sel<th colspan=1>Equipment<th colspan=1>Event<th colspan=1>Variable</tr>\n");
10737 for (
unsigned e=0;
e<
events.size();
e++) {
10741 if (
eqname.length() < 1)
10767 r->
rsprintf(
"<td><input type=submit name=cmdx value=\"%s\"></td>\n",
qcmd.c_str());
10775 r->
rsprintf(
"<tr><input type=hidden name=\"%s\" value=%d></tr>\n",
qcmd.c_str(), 1);
10794 r->
rsprintf(
"<td><input type=submit name=cmdx value=\"%s\"></td>\n",
rcmd.c_str());
10799 r->
rsprintf(
"<tr><input type=hidden name=\"%s\" value=%d></tr>\n",
rcmd.c_str(), 1);
10803 std::vector<TAG> tags;
10810 std::sort(tags.begin(), tags.end(),
cmp_tags);
10812 for (
unsigned v=0; v<tags.size(); v++) {
10814 for (
unsigned j=0;
j<tags[v].n_data;
j++) {
10817 if (tags[v].n_data == 1)
10846 r->
rsprintf(
"<input type=hidden name=seln value=%d>\n",
i);
10847 r->
rsprintf(
"<input type=submit value=\"Add Selected\">\n");
10852 r->
rsprintf(
"<tr><td colspan=11 style='text-align:left'>New history: displayed_value = formula(history_value)</td></tr>\n");
10853 r->
rsprintf(
"<tr><td colspan=11 style='text-align:left'>Old history: displayed_value = offset + factor*(history_value - voffset)</td></tr>\n");
10854 r->
rsprintf(
"<tr><td colspan=11 style='text-align:left'>Formula format: \"3*x+4\", \"10*Math.sin(x)\", etc. all javascript math functions can be used</td></tr>\n");
10855 r->
rsprintf(
"<tr><td colspan=11 style='text-align:left'>To display the raw history value instead of computed formula or offset value, check the \"raw\" checkbox</td></tr>\n");
10856 r->
rsprintf(
"<tr><td colspan=11 style='text-align:left'>To reorder entries: enter new ordering in the \"order\" column and press \"refresh\"</td></tr>\n");
10857 r->
rsprintf(
"<tr><td colspan=11 style='text-align:left'>To delete entries: enter \"-1\" or leave blank the \"order\" column and press \"refresh\"</td></tr>\n");
10860 r->
rsprintf(
"<th>Col<th>Event<th>Variable<th>Formula<th>Colour<th>Label<th>Raw<th>Order");
10861 if (
hp.show_factor) {
10862 r->
rsprintf(
"<th>Factor<th>Offset<th>VOffset");
10868 size_t nvars =
hp.vars.size();
10873 if (
index < nvars) {
10874 if (
hp.vars[
index].colour.empty())
10876 r->
rsprintf(
"<td style=\"background-color:%s\"> <td>\n",
hp.vars[
index].colour.c_str());
10883 r->
rsprintf(
"<select name=\"event%d\" size=1 onChange=\"document.form1.submit()\">\n", (
int)
index);
10888 r->
rsprintf(
"<option value=\"/empty\"><empty>\n");
10890 if (
index==nvars) {
10891 for (
unsigned e=0;
e<
events.size();
e++) {
10892 const char *p =
events[
e].c_str();
10893 r->
rsprintf(
"<option value=\"%s\">%s\n", p, p);
10896 r->
rsprintf(
"<option selected value=\"%s\">%s\n",
hp.vars[
index].event_name.c_str(),
hp.vars[
index].event_name.c_str());
10897 r->
rsprintf(
"<option>(%d events omitted)\n", (
int)
events.size());
10899 bool found =
false;
10900 for (
unsigned e=0;
e<
events.size();
e++) {
10901 const char *s =
"";
10902 const char *p =
events[
e].c_str();
10907 r->
rsprintf(
"<option %s value=\"%s\">%s\n", s, p, p);
10910 const char *p =
hp.vars[
index].event_name.c_str();
10911 r->
rsprintf(
"<option selected value=\"%s\">%s\n", p, p);
10920 if (
index < nvars) {
10926 std::vector<TAG> tags;
10944 std::sort(tags.begin(), tags.end(),
cmp_tags);
10947 printf(
"Event [%s] %d tags\n",
hp.vars[
index].event_name.c_str(), (
int)tags.size());
10949 for (
unsigned v=0; v<tags.size(); v++) {
10955 for (
unsigned v=0; v<tags.size(); v++)
10961 for (
unsigned v=0; v<tags.size(); v++) {
10963 for (
unsigned j=0;
j<tags[v].n_data;
j++) {
10966 if (tags[v].n_data == 1)
10988 if (
hp.vars[
index].tag_name.length() > 0)
10989 r->
rsprintf(
"<option selected value=\"%s\">%s\n",
hp.vars[
index].tag_name.c_str(),
hp.vars[
index].tag_name.c_str());
10992 r->
rsprintf(
"<td><input type=text size=15 maxlength=256 name=\"form%d\" value=%s></td>\n", (
int)
index,
hp.vars[
index].formula.c_str());
10993 r->
rsprintf(
"<td><input type=text size=8 maxlength=10 name=\"col%d\" value=%s></td>\n", (
int)
index,
hp.vars[
index].colour.c_str());
10995 if (
hp.vars[
index].show_raw_value)
10996 r->
rsprintf(
"<td><input type=checkbox checked name=\"raw%d\" value=1></td>", (
int)
index);
10998 r->
rsprintf(
"<td><input type=checkbox name=\"raw%d\" value=1></td>", (
int)
index);
10999 r->
rsprintf(
"<td><input type=text size=3 maxlength=32 name=\"ord%d\" value=\"%d\"></td>\n", (
int)
index,
hp.vars[
index].order);
11000 if (
hp.show_factor) {
11001 r->
rsprintf(
"<td><input type=text size=6 maxlength=32 name=\"factor%d\" value=\"%g\"></td>\n", (
int)
index,
hp.vars[
index].factor);
11002 r->
rsprintf(
"<td><input type=text size=6 maxlength=32 name=\"offset%d\" value=\"%g\"></td>\n", (
int)
index,
hp.vars[
index].offset);
11003 r->
rsprintf(
"<td><input type=text size=6 maxlength=32 name=\"voffset%d\" value=\"%g\"></td>\n", (
int)
index,
hp.vars[
index].voffset);
11005 r->
rsprintf(
"<input type=hidden name=\"factor%d\" value=\"%f\">\n", (
int)
index,
hp.vars[
index].factor);
11006 r->
rsprintf(
"<input type=hidden name=\"offset%d\" value=\"%f\">\n", (
int)
index,
hp.vars[
index].offset);
11007 r->
rsprintf(
"<input type=hidden name=\"voffset%d\" value=\"%f\">\n", (
int)
index,
hp.vars[
index].voffset);
11010 r->
rsprintf(
"<td colspan=2><input type=submit name=cmdx value=\"List all variables\"></td>\n");
11020 r->
rsprintf(
"</body></html>\r\n");
11055 std::string
ts =
"1h";
11099 for (
int i = 0;
i <
hsdata->nvars;
i++)
11105 for (
int i = 0;
i <
hsdata->nvars;
i++)
11106 if (
hsdata->odb_index[
i] >= 0)
11107 if (
hsdata->num_entries[
i] > 0)
11108 if ((t == 0) || (
hsdata->t[
i][0] > t))
11111 if (t == 0 &&
hsdata->nvars > 1) {
11112 show_error(r,
"No history available for choosen period");
11121 if (
hp.show_run_markers)
11122 for (
int i = 0;
i <
hsdata->nvars;
i++) {
11123 if (
hsdata->odb_index[
i] == -2) {
11127 }
else if (
hsdata->odb_index[
i] == -1) {
11135 r->
rsprintf(
"HTTP/1.1 200 Document follows\r\n");
11137 r->
rsprintf(
"Accept-Ranges: bytes\r\n");
11138 r->
rsprintf(
"Cache-control: private, max-age=0, no-cache\r\n");
11139 r->
rsprintf(
"Expires: Fri, 01 Jan 1983 00:00:00 GMT\r\n");
11140 r->
rsprintf(
"Content-Type: text/plain\r\n");
11141 r->
rsprintf(
"Content-disposition: attachment; filename=\"export.csv\"\r\n");
11146 r->
rsprintf(
"Time, Timestamp, Run, Run State, ");
11151 if (
hsdata->odb_index[
i] < 0)
11153 if (
hsdata->num_entries[
i] <= 0)
11177 for (
int i = 0;
i <
hsdata->nvars;
i++)
11183 for (
int i = 0 ;
i <
hsdata->nvars ;
i++)
11190 printf(
"step to time %d: ", (
int)t);
11191 for (
int i = 0;
i <
hsdata->nvars;
i++) {
11205 strcpy(fmt,
"%Y.%m.%d %H:%M:%S");
11218 for (
int i= 0 ;
i <
hsdata->nvars ;
i++)
11226 if (
hsdata->odb_index[
i] < 0)
11238 for (
int i = 0 ;
i <
hsdata->nvars ;
i++)
11284 redir +=
"?cmd=oldhistory&group=";
11286 redir +=
"&panel=";
11303 redir +=
"?cmd=oldhistory&group=";
11305 redir +=
"&panel=";
11324 r->
rsprintf(
"<table class=\"dialogTable\">");
11325 r->
rsprintf(
"<tr><th class=\"subStatusTitle\" colspan=2>New History Item</th><tr>");
11326 r->
rsprintf(
"<tr><td align=center colspan=2>\n");
11327 r->
rsprintf(
"Select group: ");
11328 r->
rsprintf(
"<select id=\"group\" name=\"group\">\n");
11333 for (
i = 0;;
i++) {
11346 if (!
hkey ||
i == 0)
11347 r->
rsprintf(
"<option>Default</option>\n");
11350 r->
rsprintf(
"Or enter new group name: ");
11351 r->
rsprintf(
"<input type=text size=15 maxlength=31 id=new_group name=new_group>\n");
11353 r->
rsprintf(
"<tr><td align=center colspan=2>\n");
11354 r->
rsprintf(
"<br>Panel name: ");
11355 r->
rsprintf(
"<input type=text size=15 maxlength=31 id=panel name=panel><br><br>\n");
11358 r->
rsprintf(
"<tr><td align=center colspan=2>");
11359 std::string
str =
"?cmd=oldhistory&hcmd=createnew";
11360 str +=
"&new_group='+document.getElementById('new_group').value+'";
11361 str +=
"&group='+document.getElementById('group').value+'";
11362 str +=
"&panel='+document.getElementById('panel').value+'";
11363 r->
rsprintf(
"<input type=button value=Submit onclick=\"window.location.search='%s'\">\n",
str.c_str());
11369 r->
rsprintf(
"</body></html>\r\n");
11376 path +=
"/History/Display/";
11390 while (
hpanel[0] ==
' ') {
11424 std::string bgcolor =
"FFFFFF";
11428 std::string fgcolor =
"000000";
11441 else if (p->
isparam(
"htime"))
11481 generate_hist_graph(odb, r,
hgroup,
hpanel,
fbuffer, &
fsize, width, height,
endtime, scale,
index,
labels, bgcolor.c_str(), fgcolor.c_str(),
gridcolor.c_str());
11486 if (dir.length() > 0 && dir[dir.length()-1] !=
DIR_SEPARATOR)
11493 tms.tm_year % 100,
tms.tm_mon + 1,
tms.tm_mday,
11578 height = (
int)(0.625 * width);
11583 generate_hist_graph(odb, r,
hgroup,
hpanel, buffer, buffer_size, width, height,
endtime, scale,
index,
labels, bgcolor.c_str(), fgcolor.c_str(),
gridcolor.c_str());
11597 time_t last_written = 0;
11600 endtime = last_written + scale/2;
11606 time_t last_written = 0;
11610 endtime = last_written + scale/2;
11653 r->
rsprintf(
"<script type=\"text/javascript\" src=\"midas.js\"></script>\n");
11654 r->
rsprintf(
"<script type=\"text/javascript\" src=\"mhttpd.js\"></script>\n");
11657 r->
rsprintf(
"<table class=\"mtable\">");
11658 r->
rsprintf(
"<tr><th class=\"mtableheader\" colspan=2>History</th></tr>");
11664 path +=
"/History/Display/";
11670 r->
rsprintf(
"<h1>Error: History panel \"%s\" in group \"%s\" does not exist</h1>\n",
hpanel,
hgroup);
11674 r->
rsprintf(
"</body></html>\r\n");
11681 r->
rsprintf(
"<input type=hidden name=hscale id=hscale value=%d>\n", scale);
11686 path +=
"/History/Display/";
11690 path +=
"/Timescale";
11704 r->
rsprintf(
"<input type=hidden name=hscale id=hscale value=%s>\n",
scalestr.c_str());
11712 r->
rsprintf(
"<input type=hidden name=hwidth id=hwidth value=%s>\n",
pwidth);
11714 r->
rsprintf(
"<input type=hidden name=hheight id=hheight value=%s>\n",
pheight);
11716 r->
rsprintf(
"<input type=hidden name=hindex id=hindex value=%s>\n",
pindex);
11722 r->
rsprintf(
"<tr><td colspan=2><input type=\"button\" name=\"New\" value=\"New\" ");
11723 r->
rsprintf(
"onClick=\"window.location.href='?cmd=oldhistory&hcmd=New'\"></td></tr>\n");
11726 r->
rsprintf(
"<tr><td colspan=2 style=\"text-align:left;\">\n");
11728 r->
rsprintf(
"<b>Please select panel:</b><br>\n");
11731 r->
rsprintf(
"<table class=\"historyTable\">");
11734 r->
rsprintf(
"<tr><td colspan=2 class=\"titleCell\">\n");
11738 r->
rsprintf(
"<a href=\"?cmd=oldhistory&group=All\">ALL</a>\n");
11746 strcpy(
str,
"System:Trigger per sec.");
11766 for (
i = 0;;
i++) {
11782 r->
rsprintf(
"<tr><td class=\"titleCell\"><a href=\"?cmd=oldhistory&group=%s\">%s</a></td>\n<td>",
enc_name,
key.
name);
11784 for (
j = 0;;
j++) {
11800 r->
rsprintf(
"<small><b>%s</b></small> ",
ikey.name);
11813 r->
rsprintf(
"<tr><td colspan=2>\n");
11817 r->
rsprintf(
"<select title=\"Select group\" id=\"fgroup\" onChange=\"window.location.search='?cmd=oldhistory&group='+document.getElementById('fgroup').value;\">\n");
11822 for (
i = 0;;
i++) {
11842 r->
rsprintf(
"<option selected value=\"%s\">%s\n",
"ALL",
"ALL");
11844 r->
rsprintf(
"<option value=\"%s\">%s\n",
"ALL",
"ALL");
11848 r->
rsprintf(
" Panel:\n");
11849 r->
rsprintf(
"<select title=\"Select panel\" id=\"fpanel\" ");
11850 r->
rsprintf(
"onChange=\"window.location.search='?cmd=oldhistory&group='+document.getElementById('fgroup').value+");
11851 r->
rsprintf(
"'&panel='+document.getElementById('fpanel').value;\">\n");
11855 for (
i = 0;;
i++) {
11874 r->
rsprintf(
"<option value=\"\">- all -\n");
11876 r->
rsprintf(
"<option selected value=\"\">- all -\n");
11882 r->
rsprintf(
"<input type=submit value=\"Go\">\n");
11885 r->
rsprintf(
" <input type=\"button\" name=\"New\" value=\"New\" ");
11886 r->
rsprintf(
"onClick=\"window.location.href='?cmd=oldhistory&hcmd=New&group=%s'\">\n",
hgroup);
11888 r->
rsprintf(
"<input type=\"button\" name=\"Cmd\" value=\"Reset\" onClick=\"window.location.href='?cmd=oldhistory&hcmd=Reset&group=%s&panel=%s'\">\n",
hgroup,
hpanel);
11890 r->
rsprintf(
"<input type=\"button\" name=\"Cmd\" value=\"Query\" onClick=\"window.location.href='?cmd=oldhistory&hcmd=Query&group=%s&panel=%s'\">\n",
hgroup,
hpanel);
11897 r->
rsprintf(
"<input type=\"button\" name=\"Cmd\" value=\"New history\" onClick=\"window.location.href='?cmd=history&group=%s&panel=%s&A=%.0f&B=%.0f'\">\n",
hgroup,
hpanel,
xstarttime,
xendtime);
11910 path +=
"/History/Display/";
11914 for (
i = 0 ;;
i++) {
11927 ref +=
"graph.gif?width=";
11929 ref +=
"&cmd=oldhistory&group=";
11935 ref2 +=
"?cmd=oldhistory&group=";
11950 r->
rsprintf(
"<tr><td><a href=\"%s\"><img src=\"%s\"></a>\n",
ref2.c_str(),
ref.c_str());
11952 r->
rsprintf(
"<td><a href=\"%s\"><img src=\"%s\"></a></tr>\n",
ref2.c_str(),
ref.c_str());
11966 path +=
"/History/Display/";
11970 path +=
"/Buttons";
11977 cm_msg(
MERROR,
"show_hist_page",
"Cannot create history panel with invalid ODB path \"%s\"", path.c_str());
11984 r->
rsprintf(
"function histDisp(p) {\n");
11986 r->
rsprintf(
" params += '&'+p;\n");
11987 r->
rsprintf(
" if (document.getElementById(\'hscale\') !== null)\n");
11988 r->
rsprintf(
" params += '&hscale='+document.getElementById(\'hscale\').value;\n");
11989 r->
rsprintf(
" if (document.getElementById(\'htime\') !== null)\n");
11990 r->
rsprintf(
" params += '&htime='+document.getElementById(\'htime\').value;\n");
11991 r->
rsprintf(
" if (document.getElementById(\'hwdith\') !== null)\n");
11992 r->
rsprintf(
" params += '&hwidth='+document.getElementById(\'hwidth\').value;\n");
11993 r->
rsprintf(
" if (document.getElementById(\'hindex\') !== null)\n");
11994 r->
rsprintf(
" params += '&hindex='+document.getElementById(\'hindex\').value;\n");
11995 r->
rsprintf(
" window.location.search = params;\n");
12003 size =
sizeof(
str);
12005 r->
rsprintf(
"<input type=\"button\" title=\"display last %s\" value=%s onclick=\"histDisp('scale=%s')\">\n",
str,
str,
str);
12008 r->
rsprintf(
"<input type=\"button\" value=\"<<<\" title=\"go back in time to last available data for all variables on the plot\" onclick=\"histDisp('shift=leftmaxall')\">");
12009 r->
rsprintf(
"<input type=\"button\" value=\"<<\" title=\"go back in time to last available data\" onclick=\"histDisp('shift=leftmax')\">");
12010 r->
rsprintf(
"<input type=\"button\" value=\"<\" title=\"go back in time\" onclick=\"histDisp('shift=left')\">");
12012 r->
rsprintf(
"<input type=\"button\" value=\" + \" title=\"zoom in\" onclick=\"histDisp('shift=zoomin')\">");
12013 r->
rsprintf(
"<input type=\"button\" value=\" - \" title=\"zoom out\" onclick=\"histDisp('shift=zoomout')\">");
12016 r->
rsprintf(
"<input type=\"button\" value=\">\" title=\"go forward in time\" onclick=\"histDisp('shift=right')\">");
12017 r->
rsprintf(
"<input type=\"button\" value=\">>\" title=\"go to currently updated fresh data\" onclick=\"histDisp('shift=rightmax')\">");
12021 r->
rsprintf(
"<input type=\"button\" value=\"Large\" title=\"large display\" onclick=\"histDisp('width=Large')\">\n");
12022 r->
rsprintf(
"<input type=\"button\" value=\"Small\" title=\"large display\" onclick=\"histDisp('width=Small')\">\n");
12023 r->
rsprintf(
"<input type=\"button\" value=\"Create Elog\" title=\"large display\" onclick=\"histDisp('hcmd=Create Elog')\">\n");
12024 r->
rsprintf(
"<input type=\"button\" value=\"Config\" title=\"large display\" onclick=\"histDisp('hcmd=Config')\">\n");
12025 r->
rsprintf(
"<input type=\"button\" value=\"Export\" title=\"large display\" onclick=\"histDisp('hcmd=Export')\">\n");
12037 std::string
wi =
"640";
12049 path +=
"/History/Display/";
12053 path +=
"/Variables";
12066 ref +=
"?cmd=oldhistory&group=";
12077 r->
rsprintf(
" <area shape=rect coords=\"%d,%d,%d,%d\" href=\"%s\">\r\n", 30, 31 + 23 *
i, 150, 30 + 23 *
i + 17,
ref.c_str());
12081 std::string
ref =
"?cmd=oldhistory&group=";
12100 r->
rsprintf(
" <area shape=rect coords=\"%d,%d,%d,%d\" href=\"%s\">\r\n", 0, 0, width, 20,
ref.c_str());
12111 ref +=
"graph.gif?cmd=oldhistory&group=";
12118 r->
rsprintf(
"<tr><td colspan=2><img src=\"%s\" usemap=\"#%s\"></tr>\n",
ref.c_str(),
hpanel);
12125 for (
i = 0,
k = 0;;
i++) {
12137 for (
j = 0;;
j++,
k++) {
12151 ref +=
"graph.gif?width=Small";
12152 ref +=
"&cmd=oldhistory&group=";
12158 ref2 +=
"?cmd=oldhistory&group=";
12173 r->
rsprintf(
"<tr><td><a href=\"%s\"><img src=\"%s\"></a>\n",
ref2.c_str(),
ref.c_str());
12175 r->
rsprintf(
"<td><a href=\"%s\"><img src=\"%s\"></a></tr>\n",
ref2.c_str(),
ref.c_str());
12182 r->
rsprintf(
"</body></html>\r\n");
12191 const unsigned char *
picon;
12192 char str[256], format[256];
12198 }
else if (
strstr(
icon,
"favicon.png") != 0) {
12204 r->
rsprintf(
"HTTP/1.1 200 Document follows\r\n");
12206 r->
rsprintf(
"Accept-Ranges: bytes\r\n");
12210 now += (
int) (3600 * 24);
12213 strcpy(format,
"%A, %d-%b-%y %H:%M:%S GMT");
12218 r->
rsprintf(
"Content-Type: image/x-icon\r\n");
12220 r->
rsprintf(
"Content-Type: image/png\r\n");
12274 const char* password = p->
getparam(
"pwd");
12276 const char* command = p->
getparam(
"cmd");
12299 if (!password[0] &&
hkey) {
12301 int size =
sizeof(
str);
12317 r->
rsprintf(
"HTTP/1.1 302 Found\r\n");
12331 r->
rsprintf(
"Set-Cookie: midas_pwd=%s; path=/; expires=%s\r\n",
12334 r->
rsprintf(
"Location: ./\n\n<html>redir</html>\r\n");
12343 r->
rsprintf(
"HTTP/1.1 302 Found\r\n");
12360 r->
rsprintf(
"Location: %s\n\n<html>redir</html>\r\n",
str);
12445 path +=
"/Script/";
12471 path +=
"/CustomScript/";
12472 path += p->
getparam(
"customscript");
12499 std::string filename =
custom[
"Status"];
12661 show_error(r,
"MSCB support not compiled into this version of mhttpd");
12679 if (
strncmp(command,
"Trigger", 7) == 0) {
12698 path +=
"/Equipment/";
12700 path +=
"/Common/Frontend name";
12707 path +=
"/Equipment/";
12709 path +=
"/Common/Event ID";
12716 str +=
"Frontend \"";
12718 str +=
"\" not running!";
12725 str +=
"Cannot connect to frontend \"";
12747 if (
strncmp(command,
"Next Subrun", 11) == 0) {
12834 if (
equal_ustring(command,
"Create ELog from this page")) {
12836 redir +=
"?cmd=New+elog";
12837 redir +=
"&odb_path=";
12863 r->
rsprintf(
"HTTP/1.1 302 Found\r\n");
12870 now += 3600 * 24 * 365;
12878 r->
rsprintf(
"Set-Cookie: midas_refr=%d; path=/; expires=%s\r\n", refresh,
str);
12879 r->
rsprintf(
"Location: ./\r\n\r\n<html>redir</html>\r\n");
12928 int size =
sizeof(
str);
12930 if (
strcmp(
c->cookie_wpwd.c_str(),
str) == 0)
12936 std::string odb_path;
12938 odb_path = p->
getparam(
"odb_path");
12969 if ((command[0]==0) &&
dec_path[0]) {
12971 std::string
new_url =
"./?cmd=odb";
12978 if ((command[0]==0) &&
dec_path[0]) {
12984 for (
const char* s =
dec_path; *s; s++) {
13027 std::string odb_path;
13032 odb_path +=
"/Custom/Images/";
13034 odb_path +=
"/Background";
13043 str +=
"Invalid custom gif name \'";
13045 str +=
"\' contains \'..\'";
13059 odb_path +=
"/Custom/";
13070 odb_path +=
"/Custom/";
13082 odb_path +=
"/Custom/";
13100 str +=
"Invalid custom page name \'";
13102 str +=
"\' contains \'..\'";
13122 str +=
"Invalid custom file name \'";
13124 str +=
"\' contains \'..\'";
13162 r->
rsprintf(
"HTTP/1.1 400 Bad Request\r\n");
13166 r->
rsprintf(
"Error: Invalid URL \"%s\" or query \"%s\" or command \"%s\"\n", p->
getparam(
"path"), p->
getparam(
"query"), command);
13173 int len =
strlen(query_string);
13174 char *buf = (
char *)
malloc(len+1);
13175 memcpy(buf, query_string, len+1);
13178 while (p !=
NULL) {
13203 param->initparam();
13208 mstrlcpy(path,
string + 1,
sizeof(path));
13214 param->setparam(
"path", path);
13216 assert(query_string !=
NULL);
13220 param->setparam(
"query", query_string);
13227 param->freeparam();
13246 mstrlcpy(path, header + 1,
sizeof(path));
13252 param->setparam(
"path", path);
13256 const char*
pinit = string;
13262 if (
strstr(
string, boundary))
13266 printf(
"decode_post: -->[%s]<--\n",
string);
13270 if (
strstr(
string,
"name=")) {
13272 if (*
pitem ==
'\"')
13288 if (
strstr(p,
"\r\n\r\n"))
13289 string =
strstr(p,
"\r\n\r\n") + 4;
13290 else if (
strstr(p,
"\r\r\n\r\r\n"))
13291 string =
strstr(p,
"\r\r\n\r\r\n") + 6;
13308 const char*
ptmp = string;
13309 const char* p =
NULL;
13311 while (*
ptmp !=
'-')
13332 char* buf = (
char*)
malloc(size+1);
13336 memcpy(buf,
string, size);
13346 const char* p =
pitem;
13347 if (
strstr(p,
"\r\n\r\n"))
13348 p =
strstr(p,
"\r\n\r\n") + 4;
13349 else if (
strstr(p,
"\r\r\n\r\r\n"))
13350 p =
strstr(p,
"\r\r\n\r\r\n") + 6;
13356 char*
pb = (
char*)(
strstr(p, boundary));
13361 while (*
ptmp ==
'-' || *
ptmp ==
'\n' || *
ptmp ==
'\r')
13372 while (*
string ==
'-' || *
string ==
'\n' || *
string ==
'\r')
13404 cm_msg(
MINFO,
"check_odb_records",
"ODB subtree /Runinfo corrected successfully");
13406 cm_msg(
MERROR,
"check_odb_records",
"Cannot correct ODB subtree /Runinfo, db_check_record() status %d",
status);
13410 cm_msg(
MERROR,
"check_odb_records",
"ODB subtree /Runinfo does not exist");
13413 cm_msg(
MINFO,
"check_odb_records",
"ODB subtree /Runinfo created successfully");
13415 cm_msg(
MERROR,
"check_odb_records",
"Cannot create ODB subtree /Runinfo, db_create_record() status %d",
status);
13419 cm_msg(
MERROR,
"check_odb_records",
"Cannot correct ODB subtree /Runinfo, db_check_record() status %d",
status);
13425 for (
i = 0 ;;
i++) {
13435 cm_msg(
MINFO,
"check_odb_records",
"ODB subtree /Equipment/%s/Common corrected successfully",
key.
name);
13437 cm_msg(
MERROR,
"check_odb_records",
"Cannot correct ODB subtree /Equipment/%s/Common, db_check_record() status %d",
key.
name,
status);
13440 cm_msg(
MERROR,
"check_odb_records",
"Cannot correct ODB subtree /Equipment/%s/Common, db_check_record() status %d",
key.
name,
status);
13460#ifdef HAVE_MONGOOSE6
13464#ifdef HAVE_MONGOOSE6
13465static const std::string
gOdbAllowedHosts =
"/Experiment/Security/mhttpd hosts/Allowed hosts";
13468#ifdef HAVE_MONGOOSE6
13472 cm_msg(
MINFO,
"load_allowed_hosts",
"Reloading mhttpd hosts access control list via hotlink callback");
13482 for (
int i=0; ;
i++) {
13491 if (s.length() < 1)
13509 cm_msg(
MERROR,
"load_allowed_hosts",
"Cannot resize the allowed hosts access control list, db_resize_string(%d) status %d",
new_size,
status);
13528 cm_msg(
MERROR,
"init_allowed_hosts",
"Cannot create the mhttpd hosts access control list, db_get_value_string() status %d",
status);
13535 cm_msg(
MERROR,
"init_allowed_hosts",
"Cannot find the mhttpd hosts access control list, db_find_key() status %d",
status);
13544 cm_msg(
MERROR,
"init_allowed_hosts",
"Cannot watch the mhttpd hosts access control list, db_watch() status %d",
status);
13585 printf(
"Rejecting connection from \'%s\'\n",
hname);
13603 memset(&bind_addr, 0,
sizeof(bind_addr));
13604 bind_addr.sin_family =
AF_INET;
13606 bind_addr.sin_port =
htons((
short) port);
13631 printf(
"mhttpd is listening on port %d\n", port);
13657 printf(
"file \"%s\": OK!\n", path.c_str());
13659 printf(
"file \"%s\": not found.\n", path.c_str());
13693#ifdef HAVE_MONGOOSE6
13697#ifdef HAVE_MONGOOSE616
13701extern void cs_md5(
char buf[33], ...);
13708#ifdef HAVE_MONGOOSE616
13712#ifdef HAVE_MONGOOSE6
13756 const char *nonce,
size_t nonce_len,
const char *nc,
13759 static const char colon[] =
":";
13760 static const size_t one = 1;
13764 cs_md5(
resp,
ha1,
ha1_len,
colon,
one, nonce,
nonce_len,
colon,
one, nc,
13789 "HTTP/1.1 401 Unauthorized\r\n"
13790 "WWW-Authenticate: Digest qop=\"auth\", "
13791 "realm=\"%s\", nonce=\"%lu\"\r\n"
13792 "Content-Length: 0\r\n\r\n",
13802 auth->passwd_filename = path;
13803 auth->passwords.clear();
13806 cm_msg(
MERROR,
"mongoose",
"mongoose web server cannot find password file \"%s\"", path.c_str());
13807 cm_msg(
MERROR,
"mongoose",
"please create password file: touch %s", path.c_str());
13830 if (
e.realm ==
auth->realm) {
13832 auth->passwords.push_back(
e);
13842#ifdef HAVE_MONGOOSE6
13845 assert(!
"this code is untested!");
13851 if (buf_size == 0) {
13853 buf = (
char*)
malloc(buf_size);
13854 assert(buf !=
NULL);
13864 if (size < buf_size) {
13865 std::string s = buf;
13870 buf_size = buf_size*2 + 16;
13871 buf = (
char*)
realloc(buf, buf_size);
13872 assert(buf !=
NULL);
13877#ifdef HAVE_MONGOOSE616
13885 assert(buf !=
NULL);
13886 std::string s = buf;
13914 if (user.length()<1)
return "";
13915 if (cnonce.length()<1)
return "";
13916 if (
response.length()<1)
return "";
13917 if (uri.length()<1)
return "";
13918 if (qop.length()<1)
return "";
13919 if (nc.length()<1)
return "";
13920 if (nonce.length()<1)
return "";
13942 for (
unsigned i=0;
i<
auth->passwords.size();
i++) {
13944 if (
e->username != user)
13946 if (
e->realm !=
auth->realm)
13955 nonce.c_str(), nonce.length(),
13956 nc.c_str(), nc.length(),
13957 cnonce.c_str(), cnonce.length(),
13958 qop.c_str(), qop.length(),
13963 return e->username;
13970#ifdef HAVE_MONGOOSE616
13981 std::string hostname;
14000 printf(
"%3d: %s \"%s\", ok %d, count_used %d, age created: %d, last_used %d",
14002 e->ipv4?
"IPv4":(
e->
ipv6?
"IPv6":
"????"),
14009 if (
e->gai_status) {
14010 printf(
", getnameinfo() status %d (%s)",
e->gai_status,
e->gai_strerror.c_str());
14032 printf(
"Rejecting connection from unknown address family %d (AF_xxx)\n", sa->
sa.sa_family);
14045 e->time_last_used =
now;
14052 e->time_last_used =
now;
14059 if (
e->time_last_used <
now - 24*60*60) {
14060 printf(
"hostlist: expire \"%s\", ok %d, age %d, count_used: %d\n",
e->hostname.c_str(),
e->ok, (
int)(
now -
e->time_last_used),
e->count_used);
14072 bool found =
false;
14083 e->time_created =
now;
14084 e->time_last_used =
now;
14099 if (
e->gai_status) {
14102 printf(
"Rejecting connection from \'%s\', getnameinfo() status %d (%s)\n",
hname,
e->gai_status,
e->gai_strerror.c_str());
14113 if (
e->hostname ==
"localhost.localdomain")
14115 else if (
e->hostname ==
"localhost")
14126 printf(
"Rejecting connection from \'%s\'\n",
hname);
14138 return std::string(s->
p, s->
len);
14180 printf(
"handle_event_mg: nc %p, ev %d, ev_data %p -> accept\n", nc,
ev,
ev_data);
14184 printf(
"handle_event_mg: nc %p, ev %d, ev_data %p -> recv %d, buffered %d bytes\n", nc,
ev,
ev_data, *(
int*)
ev_data, (
int)
io->len);
14193 printf(
"handle_event_mg: nc %p, ev %d, ev_data %p -> send %d bytes\n", nc,
ev,
ev_data, *(
int*)
ev_data);
14197 printf(
"handle_event_mg: nc %p, ev %d, ev_data %p -> close\n", nc,
ev,
ev_data);
14201 printf(
"handle_event_mg: nc %p, ev %d, ev_data %p\n", nc,
ev,
ev_data);
14210 char cookie_pwd[256];
14211 char cookie_wpwd[256];
14212 char cookie_cpwd[256];
14215 cookie_wpwd[0] = 0;
14216 cookie_cpwd[0] = 0;
14219 if (s.length() > 0) {
14220 mstrlcpy(cookie_pwd, s.c_str(),
sizeof(cookie_pwd));
14221 cookie_pwd[
strcspn(cookie_pwd,
" ;\r\n")] = 0;
14226 mstrlcpy(cookie_wpwd, s.c_str(),
sizeof(cookie_pwd));
14227 cookie_wpwd[
strcspn(cookie_wpwd,
" ;\r\n")] = 0;
14232 mstrlcpy(cookie_cpwd, s.c_str(),
sizeof(cookie_pwd));
14233 cookie_cpwd[
strcspn(cookie_cpwd,
" ;\r\n")] = 0;
14239 if (s.length() > 0)
14240 c->refresh =
atoi(s.c_str());
14248 c->cookie_pwd = cookie_pwd;
14249 c->cookie_wpwd = cookie_wpwd;
14250 c->cookie_cpwd = cookie_cpwd;
14253#define RESPONSE_SENT 1
14254#define RESPONSE_QUEUED 2
14255#define RESPONSE_501 3
14265#ifdef HAVE_MONGOOSE6
14283 printf(
"handle_decode_get: return buffer length %d bytes, strlen %d\n",
rr->return_length, (
int)
strlen(
rr->return_buffer));
14287 if (
rr->return_length == -1) {
14289#ifdef HAVE_MONGOOSE6
14296 if (
rr->return_length == 0)
14297 rr->return_length =
strlen(
rr->return_buffer);
14301#ifdef HAVE_MONGOOSE6
14305 mg_send(nc,
rr->return_buffer,
rr->return_length);
14307 if (!
strstr(
rr->return_buffer,
"Content-Length")) {
14321#ifdef HAVE_MONGOOSE616
14348 return ncud->ncseqno;
14360 bool mjsonrpc =
false;
14364 std::string query_string;
14392 std::thread* fThread =
NULL;
14395 std::deque<MongooseWorkObject*>
fQueue;
14396 std::condition_variable
fNotify;
14421 if (
to->fNc == nc) {
14459 if (
to->fNc == nc) {
14473 assert(
to->fNc == nc);
14475 to->fQueue.push_back(w);
14476 to->fMutex.unlock();
14477 to->fNotify.notify_one();
14485 w->http_get =
true;
14488 w->query_string = query_string;
14499 w->http_post =
true;
14502 w->query_string = query_string;
14504 w->post_boundary = boundary;
14515 w->mjsonrpc =
true;
14542 decode_get(
rr,
NULL, &w->cookies, w->uri.c_str(), w->query_string.c_str(), w->t);
14545 printf(
"handle_decode_get: return buffer length %d bytes, strlen %d\n",
rr->return_length, (
int)
strlen(
rr->return_buffer));
14549 if (
rr->return_length == -1) {
14556 if (
rr->return_length == 0)
14557 rr->return_length =
strlen(
rr->return_buffer);
14565 if (!
strstr(
rr->return_buffer,
"Content-Length")) {
14583 const char*
post_data = w->post_body.c_str();
14602 printf(
"handle_decode_post: return buffer length %d bytes, strlen %d\n",
rr->return_length, (
int)
strlen(
rr->return_buffer));
14604 if (
rr->return_length == -1) {
14610 if (
rr->return_length == 0)
14611 rr->return_length =
strlen(
rr->return_buffer);
14616 if (!
strstr(
rr->return_buffer,
"Content-Length")) {
14633 w->t->fRPC = w->post_body;
14651 reply->GetArrayBuffer(&ptr, &size);
14654 headers +=
"HTTP/1.1 200 OK\n";
14655 if (w->origin.length() > 0)
14656 headers +=
"Access-Control-Allow-Origin: " + w->origin +
"\n";
14658 headers +=
"Access-Control-Allow-Origin: *\n";
14659 headers +=
"Access-Control-Allow-Credentials: true\n";
14661 headers +=
"Content-Type: application/octet-stream\n";
14684 headers +=
"HTTP/1.1 200 OK\n";
14685 if (w->origin.length() > 0)
14686 headers +=
"Access-Control-Allow-Origin: " + w->origin +
"\n";
14688 headers +=
"Access-Control-Allow-Origin: *\n";
14689 headers +=
"Access-Control-Allow-Credentials: true\n";
14691 headers +=
"Content-Type: application/json\n";
14714 else if (w->http_post)
14716 else if (w->mjsonrpc)
14727 char boundary[256];
14730 if (
ct.length() > 0) {
14731 const char* s =
strstr(
ct.c_str(),
"boundary=");
14733 mstrlcpy(boundary, s+9,
sizeof(boundary));
14736#ifdef HAVE_MONGOOSE616
14750#ifdef HAVE_MONGOOSE6
14766 printf(
"handle_decode_post: return buffer length %d bytes, strlen %d\n",
rr->return_length, (
int)
strlen(
rr->return_buffer));
14768 if (
rr->return_length == -1) {
14769#ifdef HAVE_MONGOOSE6
14776 if (
rr->return_length == 0)
14777 rr->return_length =
strlen(
rr->return_buffer);
14779#ifdef HAVE_MONGOOSE6
14783 mg_send(nc,
rr->return_buffer,
rr->return_length);
14785 if (!
strstr(
rr->return_buffer,
"Content-Length")) {
14802 printf(
"handle_http_get: uri [%s], query [%s]\n", uri, query_string.c_str());
14804 if (query_string ==
"mjsonrpc_schema") {
14806 std::string
reply = s->Stringify();
14814 headers +=
"HTTP/1.1 200 OK\n";
14818 headers +=
"Access-Control-Allow-Origin: *\n";
14819 headers +=
"Access-Control-Allow-Credentials: true\n";
14821 headers +=
"Content-Type: application/json\n";
14838 if (query_string ==
"mjsonrpc_schema_text") {
14848 headers +=
"HTTP/1.1 200 OK\n";
14852 headers +=
"Access-Control-Allow-Origin: *\n";
14853 headers +=
"Access-Control-Allow-Credentials: true\n";
14855 headers +=
"Content-Type: text/plain\n";
14872#ifdef HAVE_MONGOOSE616
14886 printf(
"handle_http_post: uri [%s], query [%s], post data %d bytes\n", uri, query_string.c_str(), (
int)
post_data.length());
14888 if (query_string ==
"mjsonrpc") {
14894 headers +=
"HTTP/1.1 415 Unsupported Media Type\n";
14911#ifdef HAVE_MONGOOSE616
14920#ifdef HAVE_MONGOOSE6
14931#ifdef HAVE_MONGOOSE6
14938 reply->GetArrayBuffer(&ptr, &size);
14941 headers +=
"HTTP/1.1 200 OK\n";
14945 headers +=
"Access-Control-Allow-Origin: *\n";
14946 headers +=
"Access-Control-Allow-Credentials: true\n";
14948 headers +=
"Content-Type: application/octet-stream\n";
14972 headers +=
"HTTP/1.1 200 OK\n";
14976 headers +=
"Access-Control-Allow-Origin: *\n";
14977 headers +=
"Access-Control-Allow-Credentials: true\n";
14979 headers +=
"Content-Type: application/json\n";
15040 headers +=
"HTTP/1.1 200 OK\n";
15045 headers +=
"Access-Control-Allow-Origin: *\n";
15046 headers +=
"Access-Control-Allow-Headers: Content-Type\n";
15047 headers +=
"Access-Control-Allow-Credentials: true\n";
15048 headers +=
"Access-Control-Max-Age: 120\n";
15049 headers +=
"Content-Length: 0\n";
15050 headers +=
"Content-Type: text/plain\n";
15067#ifdef HAVE_MONGOOSE616
15079 printf(
"handle_http_message: method [%s] uri [%s] proto [%s]\n", method.c_str(), uri.c_str(),
mgstr(&msg->
proto).c_str());
15085 t->
fQuery = query_string;
15089 if (method ==
"OPTIONS" && query_string ==
"mjsonrpc" &&
mg_get_http_header(msg,
"Access-Control-Request-Method") !=
NULL) {
15112 printf(
"handle_http_message: auth user: \"%s\"\n", username.c_str());
15114 if (username.length() == 0) {
15116 printf(
"handle_http_message: method [%s] uri [%s] query [%s] proto [%s], sending auth request for realm \"%s\"\n", method.c_str(), uri.c_str(), query_string.c_str(),
mgstr(&msg->
proto).c_str(),
gAuthMg->
realm.c_str());
15128#ifdef HAVE_MONGOOSE616
15130 std::string::size_type
p1 = uri.find(
"/", 1);
15131 if (
p1 == uri.length()-1) {
15132 std::string
response =
"404 Not Found (Proxy name is missing)";
15138 std::string::size_type
p2 = uri.find(
"/",
p1+1);
15139 if (
p2 == std::string::npos) {
15140 std::string
response =
"404 Not Found (Proxy URL should end with a slash)";
15146 std::string p = uri.substr(
p1+1,
p2-
p1-1);
15148 if (p.length() < 1) {
15149 std::string
response =
"404 Not Found (Double-slash or Proxy name is too short)";
15158 std::string
response =
"404 Not Found (Proxy not found in ODB)";
15164 std::string
response =
"404 Not Found (Proxy commented-out in ODB)";
15170 std::string
response =
"404 Not Found (Proxy address should not end with a slash)";
15176 std::string
response =
"404 Not Found (Proxy address does not start with http";
15200 if (method ==
"GET")
15202 else if (method ==
"POST")
15207 printf(
"handle_http_message: sending 501 Not Implemented error\n");
15209 std::string
response =
"501 Not Implemented";
15220#ifdef HAVE_MONGOOSE6
15227 printf(
"handle_http_event_mg: nc %p, ev %d, ev_data %p -> http request\n", nc,
ev,
ev_data);
15232 printf(
"handle_http_event_mg: nc %p, ev %d, ev_data %p\n", nc,
ev,
ev_data);
15244 printf(
"handle_http_redirect: nc %p, ev %d, ev_data %p -> http request\n", nc,
ev,
ev_data);
15246 mg_printf(nc,
"HTTP/1.1 302 Found\r\nLocation: https://%s%s\r\n\r\n",
15247 ((std::string*)(nc->
user_data))->c_str(),
15254 printf(
"handle_http_redirect: nc %p, ev %d, ev_data %p\n", nc,
ev,
ev_data);
15260#ifdef HAVE_MONGOOSE616
15267static std::atomic_int
s_rseqno{1};
15328 if (
res->send_501) {
15329 std::string
response =
"501 Not Implemented";
15340 if (
res->close_flag) {
15347 res->w->send_done =
true;
15362 res.send_501 =
false;
15419 res.close_flag =
false;
15420 res.send_501 =
true;
15455 printf(
"handle_http_message: sending 501 Not Implemented error\n");
15459 req.w->t->fCompleted =
true;
15475 std::unique_lock<std::mutex>
ulm(
to->fMutex, std::defer_lock);
15477 to->fIsRunning =
true;
15483 while (
to->fQueue.empty()) {
15485 to->fNotify.wait(
ulm);
15495 w =
to->fQueue.front();
15496 to->fQueue.pop_front();
15505 printf(
"handle_http_message: sending 501 Not Implemented error\n");
15511 if (!w->send_done) {
15517 w->t->fCompleted =
true;
15525 to->fIsRunning =
false;
15546 printf(
"ev_handler: connection %p, event %d\n", nc,
ev);
15568 printf(
"ev_handler: connection %p, MG_EV_RECV, %d bytes\n", nc, *(
int*)
ev_data);
15577 printf(
"ev_handler: connection %p, MG_EV_SEND, %d bytes\n", nc, *(
int*)
ev_data);
15582 printf(
"ev_handler: connection %p, MG_EV_HTTP_CHUNK\n", nc);
15593 printf(
"ev_handler: connection %p, MG_EV_HTTP_REQUEST \"%s\" \"%s\"\n", nc,
mgstr(&msg->
method).c_str(),
mgstr(&msg->
uri).c_str());
15619#define FLAG_HTTPS MG_F_USER_1
15620#define FLAG_PASSWORDS MG_F_USER_2
15621#define FLAG_HOSTLIST MG_F_USER_3
15648 cm_msg(
MERROR,
"mongoose_listen",
"https port \"%s\" requested, but mhttpd compiled without MG_ENABLE_SSL", address);
15655 cm_msg(
MERROR,
"mongoose_listen",
"Cannot mg_bind address \"%s\"", address);
15667 cm_msg(
MERROR,
"mongoose_listen",
"please create SSL certificate file using openssl: cd $MIDASSYS; openssl req -new -nodes -newkey rsa:2048 -sha256 -out ssl_cert.csr -keyout ssl_cert.key -subj \"/C=/ST=/L=/O=midas/OU=mhttpd/CN=localhost\"; openssl x509 -req -days 365 -sha256 -in ssl_cert.csr -signkey ssl_cert.key -out ssl_cert.pem; cat ssl_cert.key >> ssl_cert.pem");
15668 cm_msg(
MERROR,
"mongoose_listen",
"or using certbot (recommened): setup certbot per Let's Encrypt instructions, certificates are typically saved in /etc/letsencrypt/live/$HOSTNAME/, copy fullchain.pem and privkey.pem to $MIDASSYS; cd $MIDASSYS; cat fullchain.pem privkey.pem > ssl_cert.pem");
15672 printf(
"Mongoose web server will use https certificate file \"%s\"\n",
cert_file.c_str());
15711 std::vector<std::string>
hostlist;
15727 odb->RSA(
"Host list", &
hostlist,
true, 10, 256);
15745 printf(
"mongoose_init: Error: Cannot initialize authorization object!\n");
15750 printf(
"Password protection is off\n");
15764 if (s.length() < 1)
15774 printf(
"Hostlist active, connections will be accepted only from: ");
15782 printf(
"Hostlist off, connections from anywhere will be accepted\n");
15845 cm_msg(
MERROR,
"mongoose_init",
"Failed to listen on a TCP port enabled in ODB /WebServer");
15859 printf(
"Mongoose web server shutting down\n");
15864 if (
s_mgr.active_connections) {
15878 to->fNotify.notify_one();
15882 for (
int i=0;
i<10;
i++) {
15887 if (
to->fIsRunning) {
15901 if (
to->fIsRunning) {
15902 cm_msg(
MERROR,
"mongoose",
"thread failed to shut down");
15905 to->fThread->join();
15906 delete to->fThread;
15930 printf(
"Mongoose web server shut down\n");
15935#ifdef HAVE_MONGOOSE6
15996 printf(
"Mongoose web server password portection is disabled: serving unencrypted http on port 80\n");
16008 cm_msg(
MERROR,
"mongoose",
"please create SSL certificate file: cd $MIDASSYS; openssl req -new -nodes -newkey rsa:2048 -sha256 -out ssl_cert.csr -keyout ssl_cert.key -subj \"/C=/ST=/L=/O=midas/OU=mhttpd/CN=localhost\"; openssl x509 -req -days 365 -sha256 -in ssl_cert.csr -signkey ssl_cert.key -out ssl_cert.pem; cat ssl_cert.key >> ssl_cert.pem");
16012 printf(
"Mongoose web server will use SSL certificate file \"%s\"\n",
cert_file.c_str());
16019 printf(
"Error: Cannot initialize authorization object!\n");
16024 printf(
"Mongoose web server will not use password protection\n");
16049 cm_msg(
MERROR,
"mongoose",
"Cannot create mg_connection for set-uid-root privileged port");
16054#ifdef MG_ENABLE_THREADS
16061 printf(
"mongoose web server is listening on the set-uid-root privileged port\n");
16073#ifdef MG_ENABLE_THREADS
16082 std::string s = hostname +
":" + std::string(
str);
16085 printf(
"mongoose web server is redirecting HTTP port %d to https://%s\n",
http_port, s.c_str());
16091 printf(
"mongoose web server is listening on the HTTP port %d\n",
http_port);
16095#ifdef MG_ENABLE_SSL
16105#ifdef MG_ENABLE_THREADS
16112 printf(
"mongoose web server is listening on the HTTPS port %d\n",
https_port);
16114 cm_msg(
MERROR,
"mongoose",
"https port %d requested, but mhttpd compiled without MG_ENABLE_SSL",
https_port);
16120 cm_msg(
MERROR,
"mongoose",
"cannot start: no ports defined");
16136 printf(
"stop_mg done!\n");
16151#ifdef HAVE_MONGOOSE6
16162#ifdef HAVE_MONGOOSE6
16179 doc->D(
"get current value of mhttpd http_trace");
16180 doc->P(
NULL, 0,
"there are no input parameters");
16192 doc->D(
"set new value of mhttpd http_trace");
16214#ifdef HAVE_MONGOOSE6
16218#ifdef HAVE_MONGOOSE616
16222 const char *
myname =
"mhttpd";
16231#ifdef HAVE_MONGOOSE6
16243 printf(
"mhttpd is running in setuid-root mode.\n");
16247 printf(
"Cannot open listening socket on TCP port %d, aborting.\n",
port80);
16254 printf(
"Cannot give up root privelege, aborting.\n");
16259 printf(
"Cannot give up root privelege, aborting.\n");
16273#ifdef HAVE_MONGOOSE6
16278 for (
int i = 1;
i <
argc;
i++) {
16281 else if (
argv[
i][0] ==
'-' &&
argv[
i][1] ==
'v')
16283 else if (
argv[
i][0] ==
'-' &&
argv[
i][1] ==
'E')
16285 else if (
argv[
i][0] ==
'-' &&
argv[
i][1] ==
'H') {
16287#ifdef HAVE_MONGOOSE6
16301 }
else if (
strcmp(
argv[
i],
"--no-trace-mg-recv") == 0) {
16303 }
else if (
strcmp(
argv[
i],
"--no-trace-mg-send") == 0) {
16305 }
else if (
strcmp(
argv[
i],
"--verbose-mg") == 0) {
16307#ifdef HAVE_MONGOOSE616
16308 }
else if (
strcmp(
argv[
i],
"--no-multithread") == 0) {
16310 }
else if (
strcmp(
argv[
i],
"--no-passwords") == 0) {
16312 }
else if (
strcmp(
argv[
i],
"--no-hostlist") == 0) {
16315 }
else if (
argv[
i][0] ==
'-') {
16318 if (
argv[
i][1] ==
'h')
16320 else if (
argv[
i][1] ==
'e')
16322 else if (
argv[
i][1] ==
'a') {
16323#ifdef HAVE_MONGOOSE6
16328 }
else if (
argv[
i][1] ==
'p') {
16329 printf(
"Option \"-p port_number\" for the old web server is obsolete.\n");
16330 printf(
"mongoose web server is the new default, port number is set in ODB or with \"--http port_number\".\n");
16331 printf(
"To run the obsolete old web server, please use \"--oldserver\" switch.\n");
16335 printf(
"usage: %s [-h Hostname[:port]] [-e Experiment] [-v] [-D] [-a Hostname]\n\n",
argv[0]);
16336 printf(
" -a add hostname to the hostlist of hosts allowed to connect to mhttpd\n");
16337 printf(
" -e experiment to connect to\n");
16338 printf(
" -h connect to midas server (mserver) on given host\n");
16339 printf(
" -v display verbose HTTP communication\n");
16340 printf(
" -D become a daemon\n");
16341 printf(
" -E only display ELog system\n");
16342 printf(
" -H only display history plots\n");
16343#ifdef HAVE_MONGOOSE6
16344 printf(
" --http port - bind to specified HTTP port (default is ODB \"/Experiment/midas http port\")\n");
16345 printf(
" --https port - bind to specified HTTP port (default is ODB \"/Experiment/midas https port\")\n");
16347 printf(
" --verbose-mg - trace mongoose web requests\n");
16348 printf(
" --trace-mg - trace mongoose events\n");
16349 printf(
" --no-trace-mg-recv - do not trace mongoose recv events\n");
16350 printf(
" --no-trace-mg-send - dop not trace mongoose send events\n");
16351#ifdef HAVE_MONGOOSE616
16352 printf(
" --no-multithread - disable mongoose multithreading\n");
16353 printf(
" --no-passwords - disable password protection\n");
16354 printf(
" --no-hostlist - disable access control host list\n");
16362 printf(
"Becoming a daemon...\n");
16368 FILE *
f =
fopen(
"/var/run/mhttpd.pid",
"w");
16376 myname =
"mhttpd_history";
16412 printf(
"check_odb_records() failed, see messages and midas.log, bye!\n");
16417#ifdef HAVE_MONGOOSE6
16419 printf(
"init_allowed_hosts() failed, see messages and midas.log, bye!\n");
16426 printf(
"mhttpd allowed hosts list: ");
16434 printf(
"mhttpd allowed hosts list is empty\n");
16457#ifdef HAVE_MONGOOSE6
16461 printf(
"could not start the mongoose web server, see messages and midas.log, bye!\n");
16467#ifdef HAVE_MONGOOSE616
16487 MVOdb*
o = odb->Chdir(
"WebServer",
true);
16491 printf(
"Error: Could not start the mongoose web server, see messages and midas.log, bye!\n");
16499#ifdef HAVE_MONGOOSE6
16504#ifdef HAVE_MONGOOSE616
char * attachment_buffer[3]
size_t attachment_size[3]
std::vector< AuthEntry > passwords
std::string passwd_filename
virtual int hs_read(time_t start_time, time_t end_time, time_t interval, int num_var, const char *const event_name[], const char *const tag_name[], const int var_index[], int num_entries[], time_t *time_buffer[], double *data_buffer[], int status[])=0
see hs_read(), returns HS_SUCCESS
virtual int hs_disconnect()=0
disconnect from history, returns HS_SUCCESS
virtual int hs_get_events(time_t time_from, std::vector< std::string > *pevents)=0
get list of events that exist(ed) at given time and later (value 0 means "return all events from begi...
virtual int hs_get_tags(const char *event_name, time_t time_from, std::vector< TAG > *ptags)=0
get list of history variables for given event (use event names returned by hs_get_events()) that exis...
virtual int hs_get_last_written(time_t start_time, int num_var, const char *const event_name[], const char *const tag_name[], const int var_index[], time_t last_written[])=0
virtual int hs_clear_cache()=0
clear internal cache, returns HS_SUCCESS
void unsetparam(const char *param)
const char * getparam(const char *param)
char _param[MAX_PARAM][PARAM_LENGTH]
void setparam(const char *param, const char *value)
BOOL isparam(const char *param)
std::string xgetparam(const char *param)
void AddTrace(RequestTrace *t)
void AddTraceMTS(RequestTrace *t)
std::vector< RequestTrace * > fBuf
else strcpy(return_buffer+strlen_retbuf, str)
int return_grow(size_t len)
vsprintf(str,(char *) format, argptr)
void rread(const char *filename, int fh, int len)
void rsprintf(const char *format,...) MATTRPRINTF(2
void rmemcpy(const void *buf, int len)
void rsputs2(const char *str)
void rsputs(const char *str)
assert(strlen(str)< sizeof(str))
static bool exists(const std::string &name)
INT al_get_alarms(std::string *presult)
INT cm_yield(INT millisec)
INT cm_get_experiment_database(HNDLE *hDB, HNDLE *hKeyClient)
INT cm_connect_client(const char *client_name, HNDLE *hConn)
INT cm_start_watchdog_thread()
INT cm_connect_experiment1(const char *host_name, const char *default_exp_name, const char *client_name, void(*func)(char *), INT odb_size, DWORD watchdog_timeout)
std::string cm_expand_env(const char *str)
int cm_exec_script(const char *odb_path_to_script)
INT cm_disconnect_experiment(void)
std::string cm_get_exptab_filename()
std::string cm_get_path()
std::string cm_get_history_path(const char *history_channel)
INT cm_get_environment(char *host_name, int host_name_size, char *exp_name, int exp_name_size)
const char * cm_get_version()
std::string cm_get_experiment_name()
const char * cm_get_revision()
INT cm_exist(const char *name, BOOL bUnique)
INT el_submit(int run, const char *author, const char *type, const char *syst, const char *subject, const char *text, const char *reply_to, const char *encoding, const char *afilename1, const char *buffer1, INT buffer_size1, const char *afilename2, const char *buffer2, INT buffer_size2, const char *afilename3, const char *buffer3, INT buffer_size3, char *tag, INT tag_size)
#define CM_WRONG_PASSWORD
#define DB_STRUCT_MISMATCH
#define DB_INVALID_HANDLE
#define DB_NO_MORE_SUBKEYS
void gdImageFilledPolygon(gdImagePtr im, gdPointPtr p, int n, int c)
void gdImageRectangle(gdImagePtr im, int x1, int y1, int x2, int y2, int color)
gdImagePtr gdImageCreate(int sx, int sy)
void gdImageString(gdImagePtr im, gdFontPtr f, int x, int y, const char *s, int color)
void gdImageFilledRectangle(gdImagePtr im, int x1, int y1, int x2, int y2, int color)
void gdImageLine(gdImagePtr im, int x1, int y1, int x2, int y2, int color)
gdImagePtr gdImageCreateFromGif(FILE *fd)
void gdImageStringUp(gdImagePtr im, gdFontPtr f, int x, int y, const char *s, int color)
void gdImageDestroy(gdImagePtr im)
gdFontPtr gdFontMediumBold
int gdImageColorClosest(gdImagePtr im, int r, int g, int b)
void gdImageGif(gdImagePtr im, gdGifBuffer *buffer)
void gdImageDashedLine(gdImagePtr im, int x1, int y1, int x2, int y2, int color)
int gdImageColorAllocate(gdImagePtr im, int r, int g, int b)
void gdImageInterlace(gdImagePtr im, int interlaceArg)
void gdImageFill(gdImagePtr im, int x, int y, int color)
void gdImageColorTransparent(gdImagePtr im, int color)
MJsonNode * mjsonrpc_decode_post_data(const char *post_data)
MJsonNode * mjsonrpc_make_result(MJsonNode *node)
MJsonNode * mjsonrpc_get_schema()
void mjsonrpc_set_std_mutex(void *mutex)
std::string mjsonrpc_schema_to_text(const MJsonNode *schema)
void mjsonrpc_add_handler(const char *method, mjsonrpc_handler_t *handler, bool needs_locking)
int mg_printf(struct mg_connection *, PRINTF_FORMAT_STRING(const char *fmt),...) PRINTF_ARGS(2
time_t mg_mgr_poll(struct mg_mgr *, int milli)
void mg_mgr_free(struct mg_mgr *)
char * cs_md5(char buf[33],...)
struct mg_str header_names[MG_MAX_HTTP_HEADERS]
#define MG_MAX_HTTP_HEADERS
#define MG_F_CLOSE_IMMEDIATELY
void mbuf_remove(struct mbuf *, size_t data_size)
void mg_mgr_init(struct mg_mgr *mgr, void *user_data)
void mg_send_head(struct mg_connection *n, int status_code, int64_t content_length, const char *extra_headers)
const char * mg_set_ssl(struct mg_connection *nc, const char *cert, const char *ca_cert)
void mg_broadcast(struct mg_mgr *, mg_event_handler_t func, void *, size_t)
struct mg_str header_values[MG_MAX_HTTP_HEADERS]
void mg_send(struct mg_connection *, const void *buf, int len)
struct mg_connection * next
void mg_register_http_endpoint(struct mg_connection *nc, const char *uri_path, mg_event_handler_t handler)
struct mg_str query_string
void mg_set_protocol_http_websocket(struct mg_connection *nc)
struct mg_connection * listener
struct mg_connection * mg_bind(struct mg_mgr *, const char *, mg_event_handler_t)
int mg_http_parse_header(struct mg_str *hdr, const char *var_name, char *buf, size_t buf_size)
struct mg_str mg_mk_str(const char *s)
void mg_enable_multithreading(struct mg_connection *nc)
struct mg_str * mg_get_http_header(struct http_message *hm, const char *name)
struct mg_connection * mg_add_sock(struct mg_mgr *, sock_t, mg_event_handler_t)
#define MG_F_SEND_AND_CLOSE
#define MG_EV_HTTP_REQUEST
std::string ss_gethostname()
INT ss_mutex_release(MUTEX_T *mutex)
time_t ss_mktime(struct tm *tms)
int ss_file_exist(const char *path)
INT ss_mutex_create(MUTEX_T **mutex, BOOL recursive)
INT recv_string(int sock, char *buffer, DWORD buffer_size, INT millisec)
std::string ss_replace_env_variables(const std::string &inputPath)
INT ss_daemon_init(BOOL keep_stdout)
INT ss_sleep(INT millisec)
char * ss_crypt(const char *buf, const char *salt)
void * ss_ctrlc_handler(void(*func)(int))
INT ss_mutex_wait_for(MUTEX_T *mutex, INT timeout)
INT cm_msg1(INT message_type, const char *filename, INT line, const char *facility, const char *routine, const char *format,...)
INT EXPRT cm_msg_facilities(STRING_LIST *list)
std::string cm_get_error(INT code)
INT cm_msg(INT message_type, const char *filename, INT line, const char *routine, const char *format,...)
INT cm_msg_retrieve2(const char *facility, time_t t, INT n_message, char **messages, int *num_messages)
void cm_msg_get_logfile(const char *fac, time_t t, std::string *filename, std::string *linkname, std::string *linktarget)
BOOL equal_ustring(const char *str1, const char *str2)
INT db_sprintfh(char *string, const void *data, INT data_size, INT idx, DWORD type)
INT db_get_data_index(HNDLE hDB, HNDLE hKey, void *data, INT *buf_size, INT idx, DWORD type)
INT db_delete_key(HNDLE hDB, HNDLE hKey, BOOL follow_links)
INT db_find_link(HNDLE hDB, HNDLE hKey, const char *key_name, HNDLE *subhKey)
INT db_get_value(HNDLE hDB, HNDLE hKeyRoot, const char *key_name, void *data, INT *buf_size, DWORD type, BOOL create)
INT db_reorder_key(HNDLE hDB, HNDLE hKey, INT idx)
std::string strcomb1(const char **list)
INT db_set_link_data(HNDLE hDB, HNDLE hKey, const void *data, INT buf_size, INT num_values, DWORD type)
INT db_get_path(HNDLE hDB, HNDLE hKey, char *path, INT buf_size)
INT db_get_record1(HNDLE hDB, HNDLE hKey, void *data, INT *buf_size, INT align, const char *rec_str)
INT db_copy(HNDLE hDB, HNDLE hKey, char *buffer, INT *buffer_size, const char *path)
INT db_set_link_data_index(HNDLE hDB, HNDLE hKey, const void *data, INT data_size, INT idx, DWORD type)
INT db_get_data(HNDLE hDB, HNDLE hKey, void *data, INT *buf_size, DWORD type)
INT db_create_key(HNDLE hDB, HNDLE hKey, const char *key_name, DWORD type)
INT db_check_record(HNDLE hDB, HNDLE hKey, const char *keyname, const char *rec_str, BOOL correct)
INT db_copy_xml(HNDLE hDB, HNDLE hKey, char *buffer, int *buffer_size, bool header)
INT db_scan_tree(HNDLE hDB, HNDLE hKey, INT level, INT(*callback)(HNDLE, HNDLE, KEY *, INT, void *), void *info)
INT db_get_key(HNDLE hDB, HNDLE hKey, KEY *key)
INT db_get_link(HNDLE hDB, HNDLE hKey, KEY *key)
INT EXPRT db_get_value_string(HNDLE hdb, HNDLE hKeyRoot, const char *key_name, int index, std::string *s, BOOL create, int create_string_length)
INT db_sprintff(char *string, const char *format, const void *data, INT data_size, INT idx, DWORD type)
INT db_set_data_index(HNDLE hDB, HNDLE hKey, const void *data, INT data_size, INT idx, DWORD type)
INT db_watch(HNDLE hDB, HNDLE hKey, void(*dispatcher)(INT, INT, INT, void *), void *info)
INT db_set_data(HNDLE hDB, HNDLE hKey, const void *data, INT buf_size, INT num_values, DWORD type)
INT db_enum_link(HNDLE hDB, HNDLE hKey, INT idx, HNDLE *subkey_handle)
INT db_sprintf(char *string, const void *data, INT data_size, INT idx, DWORD type)
INT db_copy_json_obsolete(HNDLE hDB, HNDLE hKey, char **buffer, int *buffer_size, int *buffer_end, int save_keys, int follow_links, int recurse)
INT db_set_value(HNDLE hDB, HNDLE hKeyRoot, const char *key_name, const void *data, INT data_size, INT num_values, DWORD type)
INT db_find_key(HNDLE hDB, HNDLE hKey, const char *key_name, HNDLE *subhKey)
INT db_get_link_data(HNDLE hDB, HNDLE hKey, void *data, INT *buf_size, DWORD type)
INT db_rename_key(HNDLE hDB, HNDLE hKey, const char *name)
INT db_get_key_time(HNDLE hDB, HNDLE hKey, DWORD *delta)
INT db_set_value_index(HNDLE hDB, HNDLE hKeyRoot, const char *key_name, const void *data, INT data_size, INT idx, DWORD type, BOOL trunc)
INT db_enum_key(HNDLE hDB, HNDLE hKey, INT idx, HNDLE *subkey_handle)
INT EXPRT db_resize_string(HNDLE hdb, HNDLE hKeyRoot, const char *key_name, int num_values, int max_string_length)
INT db_create_record(HNDLE hDB, HNDLE hKey, const char *orig_key_name, const char *init_str)
INT db_sscanf(const char *data_str, void *data, INT *data_size, INT i, DWORD tid)
INT db_set_num_values(HNDLE hDB, HNDLE hKey, INT num_values)
INT db_create_link(HNDLE hDB, HNDLE hKey, const char *link_name, const char *destination)
INT rpc_client_call(HNDLE hConn, DWORD routine_id,...)
INT rpc_register_functions(const RPC_LIST *new_list, RPC_HANDLER func)
static std::vector< RPC_LIST > rpc_list
const char * rpc_tid_name(INT id)
static std::string q(const char *s)
int hs_read_event_list(std::vector< std::string > *pevents)
int hs_find_reader_channel(HNDLE hDB, HNDLE *hKeyOut, int debug_flag)
int hs_get_history(HNDLE hDB, HNDLE hKey, int flags, int debug_flag, MidasHistoryInterface **mh)
BOOL debug
debug printouts
static void handle_event_mg(struct mg_connection *nc, int ev, void *ev_data)
static void SaveHistPlotToOdb(MVOdb *odb, const HistPlot &hp, const char *group, const char *panel)
static bool trace_mg_send
BOOL is_editable(char *eq_name, char *var_name)
const unsigned char favicon_png[]
void haxis(gdImagePtr im, gdFont *font, int col, int gcol, int x1, int y1, int width, int minor, int major, int text, int label, int grid, double xmin, double xmax)
static bool cmp_vars(const HistVar &a, const HistVar &b)
void output_key(Param *p, Return *r, HNDLE hkey, int index, const char *format)
void get_elog_url(char *url, int len)
static void DeleteHistPlotDeleted(HistPlot &hp)
static void LoadHistPlotFromParam(HistPlot *hp, Param *p)
static void add_rpc_functions()
INT check_odb_records(MVOdb *odb)
static int handle_http_post(struct mg_connection *nc, const http_message *msg, const char *uri, RequestTrace *t)
std::string get_content_type(const char *filename)
static const std::string find_header_mg(const struct http_message *msg, const char *name)
static void xmg_mkmd5resp(const char *method, size_t method_len, const char *uri, size_t uri_len, const char *ha1, size_t ha1_len, const char *nonce, size_t nonce_len, const char *nc, size_t nc_len, const char *cnonce, size_t cnonce_len, const char *qop, size_t qop_len, char *resp)
void strencode(Return *r, const char *text)
static MVOdb * gMimeTypesOdb
static const char default_type_list[20][NAME_LENGTH]
void show_eqtable_page(Param *pp, Return *r, int refresh)
static void history_watch_callback(HNDLE hDB, HNDLE hKey, int index, void *info)
void show_custom_file(Return *r, const char *name)
void show_find_page(Return *r, const char *value)
BOOL check_web_password(Return *r, HNDLE hDB, const char *dec_path, const char *password, const char *redir)
bool send_fp(Return *r, const std::string &path, FILE *fp)
std::vector< std::string > get_resource_paths()
static void SplitEventAndTagNames(std::string var_name, std::string &event_name, std::string &tag_name)
void decode_cookies(Cookies *c, const http_message *msg)
char * stristr(const char *str, const char *pattern)
void submit_elog(MVOdb *odb, Param *pp, Return *r, Attachment *a)
void show_query_page(Param *p, Return *r)
static void urlEncode(char *ps, int ps_size)
static std::string NextHistPlotColour(const HistPlot &hp)
std::string strencode2(const char *text)
void decode_get(Return *rr, char *string, const Cookies *c, const char *url, const char *query_string, RequestTrace *t)
static MJsonNode * get_http_trace(const MJsonNode *params)
void show_error(Return *r, const char *error)
static bool read_passwords(Auth *auth)
void redirect2(Return *r, const char *path)
static void show_cnaf_page(Param *p, Return *rr)
static void SaveMimetypes(MVOdb *odb)
void show_navigation_bar(Return *r, const char *cur_page)
void ctrlc_handler(int sig)
static void PrintHistPlot(const HistPlot &hp)
void javascript_commands(Param *p, Return *r, const char *cookie_cpwd)
static int handle_decode_post(struct mg_connection *nc, const http_message *msg, const char *uri, const char *query_string, RequestTrace *t)
std::string time_to_string(time_t t)
static std::string mgstr(const mg_str *s)
int vaxis(gdImagePtr im, gdFont *font, int col, int gcol, int x1, int y1, int width, int minor, int major, int text, int label, int grid, double ymin, double ymax, BOOL logaxis)
static bool mongoose_passwords_enabled(const struct mg_connection *nc)
static int cmp_names(const void *a, const void *b)
INT sendmail(const char *from_host, const char *smtp_host, const char *from, const char *to, const char *subject, const char *text)
int find_file_mg(const char *filename, std::string &path, FILE **fpp, bool trace)
void decode_query(Param *pp, const char *query_string)
static bool gDoReloadHistory
static std::string check_digest_auth(struct http_message *hm, Auth *auth)
static MidasHistoryInterface * gMh
static bool gDoSetupHistoryWatch
int get_hist_last_written(MVOdb *odb, const char *group, const char *panel, time_t endtime, int index, int want_all, time_t *plastwritten)
void taxis(gdImagePtr im, gdFont *font, int col, int gcol, int x1, int y1, int width, int xr, int minor, int major, int text, int label, int grid, double xmin, double xmax)
void show_password_page(Return *r, const char *dec_path, const char *password)
time_t string_to_time(const char *str)
void show_header(Return *r, const char *title, const char *method, const char *path, int refresh)
bool send_resource(Return *r, const std::string &name, bool generate_404=true)
void strencode3(Return *r, const char *text)
static std::vector< std::string > gAllowedHosts
bool send_file(Return *r, const std::string &path, bool generate_404=true)
static int xmg_check_nonce(const char *nonce)
void show_text_header(Return *r)
char * find_odb_tag(char *p, char *path, char *format, int *edit, char *type, char *pwd, char *tail)
static std::string UrlDecode(const char *p)
void strencode4(Return *r, const char *text)
void show_elog_attachment(Param *p, Return *r, const char *path)
void Unlock(RequestTrace *t)
int evaluate_src(char *key, char *src, double *fvalue)
void redirect(Return *r, const char *path)
static void urlDecode(char *p)
static std::string add_param_to_url(const char *name, const char *value)
#define READ_HISTORY_DATA
bool starts_with(const std::string &s1, const char *s2)
static const char * cgif_bar_str[]
static MidasHistoryInterface * get_history(bool reset=false)
void show_odb_tag(Param *pp, Return *r, const char *path, const char *keypath1, const char *format, int n_var, int edit, char *type, char *pwd, char *tail)
static int handle_http_get(struct mg_connection *nc, const http_message *msg, const char *uri, RequestTrace *t)
#define READ_HISTORY_RUNMARKER
std::string add_custom_path(const std::string &filename)
void sec_to_label(char *result, int sec, int base, int force_date)
void show_odb_page(Param *pp, Return *r, const char *dec_path, int write_access)
void send_icon(Return *r, const char *icon)
void Lock(RequestTrace *t)
void show_set_page(Param *pp, Return *r, const char *group, int index, const char *value)
void decode_post(Return *rr, const char *header, const char *string, const char *boundary, int length, const Cookies *c, const char *url, RequestTrace *t)
void show_hist_config_page(MVOdb *odb, Param *p, Return *r, const char *hgroup, const char *hpanel)
static const std::string find_cookie_mg(const struct http_message *msg, const char *cookie_name)
void do_jrpc(Param *p, Return *r)
const unsigned char favicon_ico[]
void init_mhttpd_odb(MVOdb *odb)
void check_obsolete_odb(HNDLE hDB, const char *odb_path)
void do_jrpc_rev1(Param *p, Return *r)
static RequestTraceBuf * gTraceBuf
const char * mhttpd_revision(void)
void show_hist_page(MVOdb *odb, Param *p, Return *r, const char *dec_path, char *buffer, int *buffer_size, int refresh)
static int handle_decode_get(struct mg_connection *nc, const http_message *msg, const char *uri, const char *query_string, RequestTrace *t)
void gen_odb_attachment(Return *r, const char *path, std::string &bout)
bool open_resource_file(const char *filename, std::string *ppath, FILE **pfp)
void redirect_307(Return *r, const char *path)
static std::string GetMimetype(const std::string &ext)
static double GetTimeSec()
void show_custom_page(Param *pp, Return *r, const char *cookie_cpwd)
static MJsonNode * set_http_trace(const MJsonNode *params)
const bool cmp_tags(const TAG &a, const TAG &b)
const bool cmp_events1(const std::string &a, const std::string &b)
#define READ_HISTORY_LAST_WRITTEN
int read_history(const HistPlot &hp, int index, int flags, time_t tstart, time_t tend, time_t scale, HistoryData *data)
static std::string toString(int i)
const MimetypeTableEntry gMimetypeTable[]
int time_to_sec(const char *str)
void show_help_page(Return *r, const char *dec_path)
void do_jrpc_rev0(Param *p, Return *r)
INT search_callback(HNDLE hDB, HNDLE hKey, KEY *key, INT level, void *info)
void init_menu_buttons(MVOdb *odb)
void generate_hist_graph(MVOdb *odb, Return *rr, const char *hgroup, const char *hpanel, char *buffer, int *buffer_size, int width, int height, time_t xendtime, int scale, int index, int labels, const char *bgcolor, const char *fgcolor, const char *gridcolor)
static const char * cgif_label_str[]
time_t mktime_with_dst(const struct tm *ptms)
int try_file_mg(const char *try_dir, const char *filename, std::string &path, FILE **fpp, bool trace)
void export_hist(MVOdb *odb, Return *r, const char *group, const char *panel, time_t endtime, int scale, int index, int labels)
static void xmg_http_send_digest_auth_request(struct mg_connection *c, const char *domain)
void interprete(Param *p, Return *r, Attachment *a, const Cookies *c, const char *dec_path, RequestTrace *t)
static const char default_system_list[20][NAME_LENGTH]
static void handle_http_options_cors(struct mg_connection *nc, const http_message *msg, RequestTrace *t)
static void SortHistPlotVars(HistPlot &hp)
const bool cmp_events(const std::string &a, const std::string &b)
int xdb_get_data_index(HNDLE hDB, const char *str, void *value, int size, int index, int tid)
void show_error_404(Return *r, const char *error)
static void handle_http_message(struct mg_connection *nc, http_message *msg)
static int xdb_find_key(HNDLE hDB, HNDLE dir, const char *str, HNDLE *hKey, int tid, int size)
static void AddHistPlotSelectedParam(HistPlot &hp, Param *p)
void show_custom_gif(Return *rr, const char *name)
static void LoadHistPlotFromOdb(MVOdb *odb, HistPlot *hp, const char *group, const char *panel)
static bool trace_mg_recv
static int NextHistPlotOrder(const HistPlot &hp)
bool ends_with_char(const std::string &s, char c)
std::string msprintf(const char *format,...)
#define DIR_SEPARATOR_STR
#define DEFAULT_WATCHDOG_TIMEOUT
#define MATTRPRINTF(a, b)
#define EQUIPMENT_COMMON_STR
std::vector< std::string > STRING_LIST
#define RUNINFO_STR(_name)
#define CNAF_INHIBIT_CLEAR
MidasHistoryInterface * mh
#define write(n, a, f, d)
int mg_http_parse_header2(struct mg_str *hdr, const char *var_name, char **buf, size_t buf_size)
int gettimeofday(struct timeval *tp, void *tzp)
TH1X EXPRT * h1_book(const char *name, const char *title, int bins, double min, double max)
std::vector< HistVar > vars
void Allocate(int xnvars)
static te_expr * base(state *s)
static te_expr * list(state *s)