19#include <condition_variable>
39#define DEFAULT_REFRESH 60
74 for (
int i=0;
i<3;
i++) {
81 for (
int i=0;
i<3;
i++) {
99extern const char *
mname[];
131 {
".ASC",
"text/plain" },
132 {
".CSS",
"text/css" },
133 {
".CSV",
"text/csv" },
134 {
".HTM",
"text/html" },
135 {
".HTML",
"text/html" },
136 {
".TXT",
"text/plain" },
138 {
".BMP",
"image/bmp" },
139 {
".GIF",
"image/gif" },
140 {
".ICO",
"image/x-icon" },
141 {
".JPEG",
"image/jpeg" },
142 {
".JPG",
"image/jpeg" },
143 {
".PNG",
"image/png" },
144 {
".SVG",
"image/svg+xml" },
145 {
".TIF",
"image/tiff" },
146 {
".TIFF",
"image/tiff" },
148 {
".MID",
"audio/midi" },
149 {
".MP3",
"audio/mpeg" },
150 {
".OGA",
"audio/ogg" },
151 {
".OGG",
"audio/ogg" },
152 {
".WAV",
"audio/wav" },
154 {
".BIN",
"application/octet-stream" },
155 {
".BZ",
"application/x-bzip" },
156 {
".BZ2",
"application/x-bzip2" },
157 {
".DOC",
"application/msword" },
158 {
".EPS",
"application/postscript" },
159 {
".GZ",
"application/gzip" },
160 {
".JS",
"application/javascript" },
161 {
".JSON",
"application/json" },
162 {
".MJS",
"application/javascript" },
163 {
".PDF",
"application/pdf" },
164 {
".PHP",
"application/x-httpd-php" },
165 {
".RTF",
"application/rtf" },
166 {
".PS",
"application/postscript" },
167 {
".ROOT",
"application/octet-stream" },
168 {
".XLS",
"application/x-msexcel" },
169 {
".XML",
"application/xml" },
170 {
".ZIP",
"application/zip" },
172 {
".ODP",
"application/vnd.oasis.opendocument.presentation" },
173 {
".ODS",
"application/vnd.oasis.opendocument.spreadsheet" },
174 {
".ODT",
"application/vnd.oasis.opendocument.text" },
184 std::string mimetype;
186 if (mimetype.length() > 0) {
213#define HTTP_ENCODING "UTF-8"
218 0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A,
219 0x00, 0x00, 0x00, 0x0D, 0x49, 0x48, 0x44, 0x52,
220 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x10,
221 0x08, 0x02, 0x00, 0x00, 0x00, 0x90, 0x91, 0x68,
222 0x36, 0x00, 0x00, 0x00, 0x07, 0x74, 0x49, 0x4D,
223 0x45, 0x07, 0xD4, 0x0B, 0x1A, 0x08, 0x37, 0x07,
224 0x0D, 0x7F, 0x16, 0x5C, 0x00, 0x00, 0x00, 0x09,
225 0x70, 0x48, 0x59, 0x73, 0x00, 0x00, 0x2E, 0x23,
226 0x00, 0x00, 0x2E, 0x23, 0x01, 0x78, 0xA5, 0x3F,
227 0x76, 0x00, 0x00, 0x00, 0x04, 0x67, 0x41, 0x4D,
228 0x41, 0x00, 0x00, 0xB1, 0x8F, 0x0B, 0xFC, 0x61,
229 0x05, 0x00, 0x00, 0x01, 0x7D, 0x49, 0x44, 0x41,
230 0x54, 0x78, 0xDA, 0x63, 0xFC, 0xFF, 0xFF, 0x3F,
231 0x03, 0x29, 0x80, 0x09, 0xAB, 0xE8, 0xD2, 0x65,
232 0x77, 0x36, 0x6F, 0x7E, 0x8A, 0x5D, 0xC7, 0x7F,
233 0x0C, 0x30, 0x67, 0xEE, 0x0D, 0x56, 0xCE, 0xCD,
234 0x5C, 0xBC, 0x3B, 0xB6, 0x6D, 0x7F, 0x81, 0x29,
235 0xCB, 0x88, 0xE6, 0x24, 0x20, 0x57, 0x50, 0x7C,
236 0xDD, 0xCF, 0x1F, 0x6C, 0x40, 0xCB, 0xB5, 0xB5,
237 0x05, 0xCF, 0x1C, 0xB7, 0x42, 0xB3, 0x80, 0x05,
238 0x8D, 0xCF, 0xC8, 0xC8, 0x58, 0x5A, 0x2A, 0xFB,
239 0xF6, 0x4D, 0x37, 0x1B, 0xAB, 0xA0, 0xB4, 0x4C,
240 0x0A, 0x51, 0x4E, 0x02, 0x82, 0x85, 0xCB, 0x12,
241 0x0E, 0x1D, 0xAB, 0xC7, 0x2A, 0xC5, 0x82, 0x69,
242 0xC4, 0xAF, 0x5F, 0x7F, 0x1E, 0x3F, 0xF8, 0xCD,
243 0xCB, 0xF1, 0xF5, 0xEF, 0xDF, 0x7F, 0xCC, 0xCC,
244 0x4C, 0x84, 0x6D, 0x98, 0x59, 0xD5, 0xEB, 0xCF,
245 0xA5, 0x16, 0xC4, 0xAB, 0x71, 0x72, 0xCB, 0x21,
246 0x4C, 0x59, 0x74, 0x03, 0x5E, 0x3F, 0x7F, 0xB3,
247 0x6B, 0xD6, 0x22, 0x46, 0xA6, 0x7F, 0x0C, 0x0C,
248 0x7F, 0xD7, 0x75, 0x4D, 0xFB, 0xF1, 0xFD, 0x27,
249 0x81, 0x78, 0xB8, 0x7D, 0xE9, 0x0A, 0xCB, 0xFF,
250 0xDF, 0x4C, 0x8C, 0x8C, 0x40, 0xF6, 0xAD, 0x4B,
251 0x67, 0x1F, 0xDE, 0xBD, 0x8B, 0x45, 0x03, 0x3C,
252 0x60, 0x8F, 0x9D, 0xD8, 0xB3, 0xEB, 0x74, 0xB5,
253 0x90, 0x26, 0x07, 0x03, 0x48, 0xE4, 0x3F, 0x8F,
254 0xF6, 0xFF, 0x1B, 0x0F, 0x9A, 0x1E, 0x3E, 0x3A,
255 0xFB, 0xF3, 0xDB, 0x8F, 0xB7, 0x0F, 0x9E, 0x43,
256 0x83, 0xF1, 0xCF, 0xDF, 0x3F, 0x8A, 0x29, 0xCE,
257 0x3F, 0x7F, 0xFD, 0xFC, 0xCF, 0xF0, 0xDF, 0x98,
258 0xE9, 0xB5, 0x8F, 0xBD, 0x8A, 0x3C, 0x6F, 0xEC,
259 0xB9, 0x2D, 0x47, 0xFE, 0xFC, 0xFF, 0x6F, 0x16,
260 0x6C, 0xF3, 0xEC, 0xD3, 0x1C, 0x2E, 0x96, 0xEF,
261 0xBF, 0xAB, 0x7E, 0x32, 0x7D, 0xE2, 0x10, 0xCE,
262 0x88, 0xF4, 0x69, 0x2B, 0x60, 0xFC, 0xF4, 0xF5,
263 0x97, 0x78, 0x8A, 0x36, 0xD8, 0x44, 0x86, 0x18,
264 0x0D, 0xD7, 0x29, 0x95, 0x13, 0xD8, 0xD9, 0x58,
265 0xE1, 0x0E, 0xF8, 0xF1, 0xF3, 0xDB, 0xC6, 0xD6,
266 0xEC, 0x5F, 0x53, 0x8E, 0xBF, 0xFE, 0xC3, 0x70,
267 0x93, 0x8D, 0x6D, 0xDA, 0xCB, 0x0B, 0x4C, 0x3F,
268 0xFF, 0xFC, 0xFA, 0xCF, 0x0C, 0xB4, 0x09, 0x84,
269 0x54, 0xD5, 0x74, 0x91, 0x55, 0x03, 0x01, 0x07,
270 0x3B, 0x97, 0x96, 0x6E, 0xC8, 0x17, 0xFE, 0x7F,
271 0x4F, 0xF8, 0xFE, 0xBC, 0x95, 0x16, 0x60, 0x62,
272 0x62, 0x64, 0xE1, 0xE6, 0x60, 0x73, 0xD1, 0xB2,
273 0x7A, 0xFA, 0xE2, 0xF1, 0xDF, 0x3F, 0xFF, 0xC4,
274 0x78, 0x44, 0x31, 0xA3, 0x45, 0x2B, 0xD0, 0xE3,
275 0xF6, 0xD9, 0xE3, 0x2F, 0x2E, 0x9D, 0x29, 0xA9,
276 0xAC, 0x07, 0xA6, 0x03, 0xF4, 0xB4, 0x44, 0x10,
277 0x00, 0x00, 0x75, 0x65, 0x12, 0xB0, 0x49, 0xFF,
278 0x3F, 0x68, 0x00, 0x00, 0x00, 0x00, 0x49, 0x45,
279 0x4E, 0x44, 0xAE, 0x42, 0x60, 0x82
283 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x10, 0x10,
284 0x10, 0x00, 0x01, 0x00, 0x04, 0x00, 0x28, 0x01,
285 0x00, 0x00, 0x16, 0x00, 0x00, 0x00, 0x28, 0x00,
286 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x20, 0x00,
287 0x00, 0x00, 0x01, 0x00, 0x04, 0x00, 0x00, 0x00,
288 0x00, 0x00, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00,
289 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
290 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xB4, 0x0F,
291 0x0A, 0x00, 0x5C, 0x86, 0x4C, 0x00, 0x2F, 0x5E,
292 0x1A, 0x00, 0xBF, 0xD3, 0xD7, 0x00, 0x29, 0x17,
293 0x8D, 0x00, 0x50, 0xA7, 0xA4, 0x00, 0x59, 0x57,
294 0x7F, 0x00, 0xC6, 0xA3, 0xAC, 0x00, 0xFC, 0xFE,
295 0xFC, 0x00, 0x28, 0x12, 0x53, 0x00, 0x58, 0x7D,
296 0x72, 0x00, 0xC4, 0x3A, 0x34, 0x00, 0x3C, 0x3D,
297 0x69, 0x00, 0xC5, 0xB6, 0xB9, 0x00, 0x94, 0x92,
298 0x87, 0x00, 0x7E, 0x7A, 0xAA, 0x00, 0x88, 0x88,
299 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x81, 0x22,
300 0xD8, 0x88, 0x88, 0x88, 0xF6, 0xD8, 0x82, 0x22,
301 0xE8, 0x88, 0x88, 0x8D, 0x44, 0x98, 0x82, 0x22,
302 0xA8, 0x88, 0x88, 0x8F, 0x44, 0x48, 0x82, 0x22,
303 0x25, 0x76, 0x67, 0x55, 0x44, 0xF8, 0x88, 0x88,
304 0x3A, 0xC9, 0x9C, 0x53, 0x83, 0x88, 0x88, 0x88,
305 0x8D, 0x99, 0x99, 0x38, 0x88, 0x88, 0x88, 0x88,
306 0x88, 0x99, 0x9C, 0x88, 0x88, 0x88, 0x88, 0x88,
307 0x88, 0xF9, 0x9D, 0x88, 0x88, 0x88, 0x88, 0x88,
308 0x88, 0x8A, 0x58, 0x88, 0x88, 0x88, 0x88, 0x88,
309 0x88, 0x85, 0xD8, 0x88, 0x88, 0x88, 0x88, 0x88,
310 0x88, 0xEA, 0xAE, 0x88, 0x88, 0x88, 0x88, 0x88,
311 0x88, 0x00, 0x0B, 0x88, 0x88, 0x88, 0x88, 0x88,
312 0x88, 0x70, 0x0D, 0x88, 0x88, 0x88, 0x88, 0x88,
313 0x88, 0x87, 0xD8, 0x88, 0x88, 0x88, 0x88, 0x88,
314 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 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, 0x00, 0x00,
321 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
322 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
334 int minor,
int major,
int text,
int label,
int grid,
double xmin,
double xmax);
336void show_header(
Return* r,
const char *title,
const char *method,
const char *path,
int refresh);
350 pp = (
char *) pattern;
380 return tv.tv_sec*1.0 +
tv.tv_usec/1000000.0;
428 if (
fRPC.length() > 0) {
441 std::vector<RequestTrace*>
fBuf;
477 for (
unsigned i=0;
i<
fBuf.size();
i++) {
486 for (
unsigned i=0;
i<
fBuf.size();
i++) {
511#define WEB_BUFFER_SIZE (6*1024*1024)
560 for (
int i=0;
i<1000;
i++) {
572 assert(!
"Cannot happen!");
588void rread(
const char* filename,
int fh,
int len)
632 for (
size_t i = 0;
i < len;
i++) {
636 char* p = (
char *) (
str +
i + 7);
639 for (
k = 0; *p && *p !=
' ' && *p !=
'\n';
k++,
i++)
698#define PARAM_LENGTH 256
699#define TEXT_SIZE 50000
732 printf(
"Error: parameter value too big\n");
752 printf(
"Error: parameter array too small\n");
868 }
else if (*p ==
'+') {
908 }
else if (*p ==
'+') {
946 for (p=
ps; *p!=0; p++)
947 printf(
"0x%02x ", (*p)&0xFF);
965 const char* p = text;
971 sprintf(buf,
"%%%02X", (*p)&0xFF);
979 for (p=text; *p!=0; p++)
980 printf(
"0x%02x ", (*p)&0xFF);
998 std::vector<std::string>
paths;
1004 paths.push_back(buf);
1012 paths.push_back(buf);
1017 paths.push_back(
cwd +
"/resources/");
1021 char *m =
getenv(
"MIDASSYS");
1023 paths.push_back(std::string(m) +
"/resources/");
1037 if (
strlen(filename) < 1) {
1038 cm_msg(
MERROR,
"open_resource_file",
"Invalid resource file name \'%s\' is too short",
1044 cm_msg(
MERROR,
"open_resource_file",
"Invalid resource file name \'%s\' starting with \'%c\' which is not allowed",
1050 cm_msg(
MERROR,
"open_resource_file",
"Invalid resource file name \'%s\' containing \'..\' which is not allowed",
1059 for (
unsigned i=0;
i<
paths.size();
i++) {
1060 std::string path =
paths[
i];
1061 if (path.length() < 1)
1096 cm_msg(
MERROR,
"open_resource_file",
"File \'%s\' for resource \'%s\' is a directory",
xpath.c_str(), filename);
1100 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);
1129 cm_msg(
MERROR,
"open_resource_file",
"Cannot find resource file \'%s\', tried %s", filename, s.c_str());
1138 const char* p = filename;
1156 if (
type.length() > 0)
1159 cm_msg(
MERROR,
"get_content_type",
"Unknown HTTP Content-Type for resource file \'%s\', file extension \'%s\'", filename,
ext_upper.c_str());
1161 return "text/plain";
1172 r->
rsprintf(
"HTTP/1.1 200 Document follows\r\n");
1174 r->
rsprintf(
"Accept-Ranges: bytes\r\n");
1179 now += (
int) (3600 * 24);
1182 const char* format =
"%A, %d-%b-%y %H:%M:%S GMT";
1214 FILE *
fp =
fopen(path.c_str(),
"rb");
1219 r->
rsprintf(
"HTTP/1.1 404 Not Found\r\n");
1241 r->
rsprintf(
"HTTP/1.1 404 Not Found\r\n");
1245 r->
rsprintf(
"Error: resource file \"%s\" not found, see messages\n",
name.c_str());
1260 char *
str, buf[256];
1271 memset(&bind_addr, 0,
sizeof(bind_addr));
1272 bind_addr.sin_family =
AF_INET;
1273 bind_addr.sin_port =
htons((
short) 25);
1278 memcpy((
char *) &(bind_addr.sin_addr),
phe->h_addr,
phe->h_length);
1280 if (connect(s, (
const sockaddr*)&bind_addr,
sizeof(bind_addr)) < 0) {
1354 strftime(buf,
sizeof(buf),
"%a, %d %b %Y %H:%M:%S", &
tms);
1364 sprintf(
str,
"Content-Type: TEXT/PLAIN; charset=US-ASCII\r\n\r\n");
1370 const char* p = text;
1372 while (
strstr(p,
"\r\n.\r\n")) {
1420 r->
rsprintf(
"HTTP/1.1 302 Found\r\n");
1424 if (
strncmp(path,
"http:", 5) == 0)
1425 r->
rsprintf(
"Location: %s\r\n\r\n<html>redir</html>\r\n",
str);
1426 else if (
strncmp(path,
"https:", 6) == 0)
1427 r->
rsprintf(
"Location: %s\r\n\r\n<html>redir</html>\r\n",
str);
1429 r->
rsprintf(
"Location: %s\r\n\r\n<html>redir</html>\r\n",
str);
1438 r->
rsprintf(
"HTTP/1.1 307 Temporary Redirect\r\n");
1441 r->
rsprintf(
"Location: %s\r\n", path);
1443 r->
rsprintf(
"<html>redirect to %s</html>\r\n", path);
1466 const char* search_name =
sinfo->search_name;
1476 for (
i = 0; search_name[
i] ;
i++)
1487 r->
rsprintf(
"<tr><td class=\"ODBkey\"><a href=\"?cmd=odb&odb_path=/%s\">/%s</a></tr>\n",
path_encoded.c_str(), path.c_str());
1490 char* p =
const_cast<char *
>(path.data() + path.length() - 1);
1491 while (*p && *p !=
'/')
1498 size =
sizeof(
data);
1506 r->
rsprintf(
"<tr><td class=\"ODBkey\">");
1514 r->
rsprintf(
"<tr><td rowspan=%d class=\"ODBkey\">",
i);
1518 size =
sizeof(
data);
1549 r->
rsprintf(
"<script type=\"text/javascript\" src=\"midas.js\"></script>\n");
1550 r->
rsprintf(
"<script type=\"text/javascript\" src=\"mhttpd.js\"></script>\n");
1553 r->
rsprintf(
"<table class=\"mtable\" style=\"width: 95%%\">\n");
1555 r->
rsprintf(
" <td class=\"mtableheader\">MIDAS Help Page</td>\n");
1562 r->
rsprintf(
" <td style=\"text-align:right;\">Documentation:</td>\n");
1563 r->
rsprintf(
" <td style=\"text-align:left;\"><a href=\"https://midas.triumf.ca\">https://midas.triumf.ca</a></td>\n");
1566 r->
rsprintf(
" <td style=\"text-align:right;\">Discussion Forum:</td>\n");
1567 r->
rsprintf(
" <td style=\"text-align:left;\"><a href=\"https://midas.triumf.ca/forum/\">https://midas.triumf.ca/forum/</a></td>\n");
1570 r->
rsprintf(
" <td style=\"text-align:right;\">Code:</td>\n");
1571 r->
rsprintf(
" <td style=\"text-align:left;\"><a href=\"https://bitbucket.org/tmidas/midas/\">https://bitbucket.org/tmidas/midas/</a></td>\n");
1574 r->
rsprintf(
" <td style=\"text-align:right;\">Report a bug:</td>\n");
1575 r->
rsprintf(
" <td style=\"text-align:left;\"><a href=\"https://bitbucket.org/tmidas/midas/issues/\">https://bitbucket.org/tmidas/midas/issues/</a></td>\n");
1579 r->
rsprintf(
" <td style=\"text-align:right;\">Version:</td>\n");
1583 r->
rsprintf(
" <td style=\"text-align:right;\">Revision:</td>\n");
1585 std::string
url =
"https://bitbucket.org/tmidas/midas/commits/";
1591 std::string::size_type pos =
rev.find(
"-g");
1592 if (pos != std::string::npos) {
1593 std::string
hash =
rev.substr(pos+2);
1594 pos =
hash.find(
"-dirty");
1595 if (pos != std::string::npos) {
1598 pos =
hash.find(
" ");
1599 if (pos != std::string::npos) {
1603 r->
rsprintf(
" <td style=\"text-align:left;\"><a href=\"%s\">%s</a></td>\n",
url.c_str(),
rev.c_str());
1605 r->
rsprintf(
" <td style=\"text-align:left;\">%s</td>\n",
rev.c_str());
1610 r->
rsprintf(
" <td style=\"text-align:right;\">MIDASSYS:</td>\n");
1612 if (!s) s =
"(unset)";
1614 r->
rsprintf(
" <td style=\"text-align:left;\">%s</td>\n",
str);
1618 r->
rsprintf(
" <td style=\"text-align:right;\">mhttpd current directory:</td>\n");
1620 r->
rsprintf(
" <td style=\"text-align:left;\">%s</td>\n",
cwd.c_str());
1624 r->
rsprintf(
" <td style=\"text-align:right;\">Exptab file:</td>\n");
1629 r->
rsprintf(
" <td style=\"text-align:right;\">Experiment:</td>\n");
1634 r->
rsprintf(
" <td style=\"text-align:right;\">Experiment directory:</td>\n");
1642 if (
list.size() == 1) {
1644 r->
rsprintf(
" <td style=\"text-align:right;\">System logfile:</td>\n");
1647 r->
rsprintf(
" <td style=\"text-align:left;\">%s</td>\n", s.c_str());
1651 r->
rsprintf(
" <td style=\"text-align:right;\">Logfiles:</td>\n");
1652 r->
rsprintf(
" <td style=\"text-align:left;\">\n");
1653 for (
unsigned i=0 ;
i<
list.size() ;
i++) {
1666 r->
rsprintf(
" <td style=\"text-align:right;\">Image history:</td>\n");
1671 r->
rsprintf(
" <td style=\"text-align:right;\">Resource paths:</td>\n");
1672 r->
rsprintf(
" <td style=\"text-align:left;\">");
1692 r->
rsprintf(
" <td style=\"text-align:right;\">midas.css:</td>\n");
1694 r->
rsprintf(
" <td style=\"text-align:left;\">%s</td>\n", path.c_str());
1696 r->
rsprintf(
" <td style=\"text-align:left;\">NOT FOUND</td>\n");
1700 r->
rsprintf(
" <td style=\"text-align:right;\">midas.js:</td>\n");
1702 r->
rsprintf(
" <td style=\"text-align:left;\">%s</td>\n", path.c_str());
1704 r->
rsprintf(
" <td style=\"text-align:left;\">NOT FOUND</td>\n");
1708 r->
rsprintf(
" <td style=\"text-align:right;\">controls.js:</td>\n");
1710 r->
rsprintf(
" <td style=\"text-align:left;\">%s</td>\n", path.c_str());
1712 r->
rsprintf(
" <td style=\"text-align:left;\">NOT FOUND</td>\n");
1716 r->
rsprintf(
" <td style=\"text-align:right;\">mhttpd.js:</td>\n");
1718 r->
rsprintf(
" <td style=\"text-align:left;\">%s</td>\n", path.c_str());
1720 r->
rsprintf(
" <td style=\"text-align:left;\">NOT FOUND</td>\n");
1724 r->
rsprintf(
" <td style=\"text-align:right;\">obsolete.js:</td>\n");
1726 r->
rsprintf(
" <td style=\"text-align:left;\">%s</td>\n", path.c_str());
1728 r->
rsprintf(
" <td style=\"text-align:left;\">NOT FOUND</td>\n");
1732 r->
rsprintf(
" <td style=\"text-align:right;\">Obsolete mhttpd.css:</td>\n");
1734 r->
rsprintf(
" <td style=\"text-align:left;\">%s</td>\n", path.c_str());
1736 r->
rsprintf(
" <td style=\"text-align:left;\">NOT FOUND</td>\n");
1740 r->
rsprintf(
" <td style=\"text-align:right;\">JSON-RPC schema:</td>\n");
1741 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");
1745 r->
rsprintf(
" <td style=\"text-align:right;\">JavaScript examples:</td>\n");
1746 r->
rsprintf(
" <td style=\"text-align:left;\"><a href=\"?cmd=example\">example.html</a></td>\n");
1750 r->
rsprintf(
" <td style=\"text-align:right;\">Custom page example:</td>\n");
1751 r->
rsprintf(
" <td style=\"text-align:left;\"><a href=\"?cmd=custom_example\">custom_example.html</a></td>\n");
1755 r->
rsprintf(
" <td style=\"text-align:right;\">MPlot custom plot examples:</td>\n");
1756 r->
rsprintf(
" <td style=\"text-align:left;\"><a href=\"?cmd=plot_example\">plot_example.html</a></td>\n");
1764 r->
rsprintf(
"<table class=\"mtable\" style=\"width: 95%%\">\n");
1766 r->
rsprintf(
" <td class=\"mtableheader\">Contributions</td>\n");
1770 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");
1790 r->
rsprintf(
"HTTP/1.1 200 Document follows\r\n");
1792 r->
rsprintf(
"Cache-control: private, max-age=0, no-cache\r\n");
1793 r->
rsprintf(
"Expires: Fri, 01 Jan 1983 00:00:00 GMT\r\n");
1796 r->
rsprintf(
"<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\n");
1800 r->
rsprintf(
"<link rel=\"icon\" href=\"favicon.png\" type=\"image/png\" />\n");
1801 r->
rsprintf(
"<link rel=\"stylesheet\" href=\"mhttpd.css\" type=\"text/css\" />\n");
1802 r->
rsprintf(
"<link rel=\"stylesheet\" href=\"midas.css\" type=\"text/css\" />\n");
1806 r->
rsprintf(
"<meta http-equiv=\"Refresh\" content=\"%02d\">\n", refresh);
1808 r->
rsprintf(
"<title>%s</title></head>\n", title);
1815 (
"<body><form name=\"form1\" method=\"POST\" action=\"%s\" enctype=\"multipart/form-data\">\n\n",
1818 r->
rsprintf(
"<body><form name=\"form1\" method=\"GET\" action=\"%s\">\n\n",
str);
1831 r->
rsprintf(
"HTTP/1.1 200 Document follows\r\n");
1833 r->
rsprintf(
"Access-Control-Allow-Origin: *\r\n");
1834 r->
rsprintf(
"Cache-control: private, max-age=0, no-cache\r\n");
1835 r->
rsprintf(
"Expires: Fri, 01 Jan 1983 00:00:00 GMT\r\n");
1844 r->
rsprintf(
"HTTP/1.1 200 Document follows\r\n");
1849 r->
rsprintf(
"<link rel=\"stylesheet\" href=\"mhttpd.css\" type=\"text/css\" />\n");
1850 r->
rsprintf(
"<title>MIDAS error</title></head>\n");
1851 r->
rsprintf(
"<body><H1>%s</H1></body></html>\n", error);
1859 r->
rsprintf(
"HTTP/1.1 404 Not Found\r\n");
1861 r->
rsprintf(
"Content-Type: text/plain\r\n");
1864 r->
rsprintf(
"MIDAS error: %s\n", error);
1872 r->
rsprintf(
"window.addEventListener(\"load\", function(e) { mhttpd_init('%s', 1000); });\n",
cur_page);
1875 r->
rsprintf(
"<!-- header and side navigation will be filled in mhttpd_init -->\n");
1876 r->
rsprintf(
"<div id=\"mheader\"></div>\n");
1877 r->
rsprintf(
"<div id=\"msidenav\"></div>\n");
1878 r->
rsprintf(
"<div id=\"mmain\">\n");
1888 cm_msg(
MERROR,
"check_obsolete_odb",
"ODB \"%s\" is obsolete, please delete it.", odb_path);
1943 cm_msg(
MERROR,
"init_mhttpd_odb",
"ODB \"/Experiment/Base URL\" is obsolete, please delete it.");
1948 cm_msg(
MERROR,
"init_mhttpd_odb",
"ODB \"/Experiment/CSS File\" is obsolete, please delete it.");
1953 cm_msg(
MERROR,
"init_mhttpd_odb",
"ODB \"/Experiment/JS File\" is obsolete, please delete it.");
1958 cm_msg(
MERROR,
"init_mhttpd_odb",
"ODB \"/Experiment/Start-Stop Buttons\" is obsolete, please delete it.");
1962 odb->RB(
"Experiment/Pause-Resume Buttons", &
xdefault,
true);
1964#ifdef HAVE_MONGOOSE616
1973 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.");
1997 size =
sizeof(
BOOL);
2024 size_t len =
strlen(text);
2025 for (
size_t i = 0;
i < len;
i++) {
2053 size_t len =
strlen(text);
2054 for (
size_t i = 0;
i < len;
i++) {
2083 size_t len =
strlen(text);
2084 for (
size_t i = 0;
i < len;
i++) {
2108 size_t len =
strlen(text);
2109 for (
size_t i = 0;
i < len;
i++) {
2155 bout +=
"<table border=3 cellpadding=1 class=\"dialogTable\">\n";
2180 size =
sizeof(
data);
2195 bout +=
"</td><td>";
2199 bout +=
")</td></tr>\n";
2203 bout +=
"</td></tr>\n";
2210 size =
sizeof(
data);
2232 bout +=
")<br></td></tr>\n";
2239 bout +=
"<br></td></tr>\n";
2246 bout +=
"</table>\n";
2253 char path[256],
path1[256];
2268 for (
int i = 0;
i < 3;
i++) {
2276 while (
strchr(path,
'\\'))
2277 *
strchr(path,
'\\') =
'/';
2303 }
else if (
strncmp(path,
"/HS/", 4) == 0) {
2304 char* buf = (
char*)
M_MALLOC(100000);
2329 pp->unsetparam(
"scale");
2330 pp->unsetparam(
"offset");
2331 pp->unsetparam(
"width");
2332 pp->unsetparam(
"index");
2334 r->
rsprintf(
"HTTP/1.1 200 Document follows\r\n");
2339 r->
rsprintf(
"<link rel=\"icon\" href=\"favicon.png\" type=\"image/png\" />\n");
2340 r->
rsprintf(
"<link rel=\"stylesheet\" href=\"midas.css\" type=\"text/css\" />\n");
2341 r->
rsprintf(
"<link rel=\"stylesheet\" href=\"mhttpd.css\" type=\"text/css\" />\n");
2342 r->
rsprintf(
"<title>ELog Error</title></head>\n");
2343 r->
rsprintf(
"<i>Error: Attachment file <i>%s</i> not valid.</i><p>\n",
pp->getparam(
str));
2344 r->
rsprintf(
"Please go back and enter a proper filename (use the <b>Browse</b> button).\n");
2345 r->
rsprintf(
"<body></body></html>\n");
2356 mstrlcpy(tag,
pp->getparam(
"orig"),
sizeof(tag));
2360 pp->getparam(
"author"),
2361 pp->getparam(
"type"),
2362 pp->getparam(
"system"),
2363 pp->getparam(
"subject"),
2364 pp->getparam(
"text"),
2365 pp->getparam(
"orig"),
2366 *
pp->getparam(
"html") ?
"HTML" :
"plain",
2394 str +=
"/Elog/Email ";
2396 str +=
pp->getparam(
"type");
2398 str +=
pp->getparam(
"system");
2405 show_error(r,
"No SMTP host defined under /Elog/SMTP host");
2421 mail_text +=
"A new entry has been submitted by ";
2470 r->
rsprintf(
"HTTP/1.1 302 Found\r\n");
2479 r->
rsprintf(
"Location: ?cmd=Show+elog&tag=%s&%s\n\n<html>redir</html>\r\n", tag,
mail_param + 1);
2481 r->
rsprintf(
"Location: ?cmd=Show+elog&tag=%s\n\n<html>redir</html>\r\n", tag);
2515 r->
rsprintf(
"HTTP/1.1 200 Document follows\r\n");
2517 r->
rsprintf(
"Accept-Ranges: bytes\r\n");
2583 if (
pp->getparam(
"eq"))
2586 if (
pp->getparam(
"group") && *
pp->getparam(
"group"))
2622 r->
rsprintf(
"<script type=\"text/javascript\" src=\"midas.js\"></script>\n");
2623 r->
rsprintf(
"<script type=\"text/javascript\" src=\"mhttpd.js\"></script>\n");
2624 r->
rsprintf(
"<script type=\"text/javascript\" src=\"obsolete.js\"></script>\n");
2629 r->
rsprintf(
"<tr><td colspan=15>\n");
2632 r->
rsprintf(
"<input type=submit name=cmd value=Set>\n");
2637 r->
rsprintf(
"<table class=\"ODBtable\" style=\"max-width:700px;\">");
2641 r->
rsprintf(
"<tr><td class=\"subStatusTitle\" colspan=15><i>Equipment:</i> \n");
2697 r->
rsprintf(
"<tr><td colspan=15><i>Groups:</i> ");
2701 r->
rsprintf(
"<b>All</b> ");
2750 r->
rsprintf(
"<i>ODB:</i> ");
2771 if (
i == 0 ||
i > 15) {
2778 r->
rsprintf(
"<tr class=\"subStatusTitle\"><th colspan=%d>Names",
colspan);
2781 for (
int i = 0;;
i++) {
2805 for (
int i = 0;
i < num_values;
i++) {
2832 for (
int j = 0;;
j++) {
2845 size =
sizeof(
data);
2850 if (n_var ==
i_set) {
2864 r->
rsprintf(
"<input type=text size=10 maxlenth=80 name=value value=\"%s\">\n",
data_str.c_str());
2865 r->
rsprintf(
"<input type=submit size=20 name=cmd value=Set>\n");
2866 r->
rsprintf(
"<input type=hidden name=index value=%d>\n",
i_edit);
2871 r->
rsprintf(
"<a href=\"#\" onClick=\"ODBInlineEdit(this.parentNode,\'%s\', 0);return false;\" >%s</a>", odb_path,
data_str.c_str());
2882 r->
rsprintf(
"<tr><td colspan=15><i>Groups:</i> ");
2886 r->
rsprintf(
"<b>All</b> ");
2888 r->
rsprintf(
"<a href=\"?cmd=eqtable&eq=%s\">All</a> ",
eq_name);
2897 for (
int i = 0;;
i++) {
2915 r->
rsprintf(
"<i>ODB:</i> ");
2928 mstrlcpy(style,
"ODBtableEven",
sizeof(style));
2930 mstrlcpy(style,
"ODBtableOdd",
sizeof(style));
2942 r->
rsprintf(
"<tr class=\"subStatusTitle\"><th colspan=9>Names<th>%s</tr>\n",
varkey.name);
2958 r->
rsprintf(
"<tr class=\"%s\"><td colspan=9>%s<br></tr>\n", style,
key.
name);
2962 size =
sizeof(
data);
2975 (
"<tr class=\"%s\" ><td colspan=9>%s<td align=center>%s (%s)<br></tr>\n",
2978 r->
rsprintf(
"<tr class=\"%s\"><td colspan=9>%s<td align=center>%s<br></tr>\n",
2987 size =
sizeof(
data);
3018 if (
varkey.num_values > 1000)
3019 r->
rsprintf(
"<tr class=\"%s\"><td colspan=9>%s<td align=center><i>... %d values ...</i>",
3022 for (
j = 0;
j <
varkey.num_values;
j++) {
3025 mstrlcpy(style,
"ODBtableEven",
sizeof(style));
3027 mstrlcpy(style,
"ODBtableOdd",
sizeof(style));
3031 size =
sizeof(
name);
3041 r->
rsprintf(
"<tr class=\"%s\"><td colspan=9>%s", style,
name);
3043 size =
sizeof(
data);
3048 if (n_var ==
i_set) {
3062 r->
rsprintf(
"<td align=center><input type=text size=10 maxlenth=80 name=value value=\"%s\">\n",
data_str.c_str());
3063 r->
rsprintf(
"<input type=submit size=20 name=cmd value=Set></tr>\n");
3064 r->
rsprintf(
"<input type=hidden name=index value=%d>\n",
i_edit);
3065 r->
rsprintf(
"<input type=hidden name=cmd value=Set>\n");
3071 r->
rsprintf(
"<a href=\"#\" onClick=\"ODBInlineEdit(this.parentNode,\'%s\', 0);return false;\" >%s</a>", odb_path,
data_str.c_str());
3106 strcpy(
type,
"text");
3108 while (*p && *p !=
'<')
3116 while (*p && ((*p ==
' ') ||
iscntrl(*p)))
3134 while (*p && ((*p ==
' ') ||
iscntrl(*p)))
3144 while (*p && *p !=
'\"')
3150 while (*p && *p !=
' ' && *p !=
'>')
3163 while (*p && *p !=
'\"')
3169 while (*p && *p !=
' ' && *p !=
'>')
3190 while (*p && *p !=
' ' && *p !=
'>')
3202 while (*p && *p !=
'\"')
3208 while (*p && *p !=
' ' && *p !=
'>')
3219 while (*p && *p !=
'\"')
3225 while (*p && *p !=
' ' && *p !=
'>')
3235 while (*
pt && *
pt !=
'\"')
3241 while (*
pt && *
pt !=
' ' && *
pt !=
'>')
3259 while (*p && ((*p ==
' ') ||
iscntrl(*p)))
3266 }
while (*p !=
'>');
3271 while (*p && *p !=
'>')
3307 if (*p && *p ==
']') {
3319 size =
sizeof(
data);
3323 if (format &&
strlen(format)>0)
3330 if (
pp->isparam(
"cbi"))
3332 if (n_var ==
i_set) {
3357 options +=
"onClick=\"o=document.createElement('input');o.type='hidden';o.name='cbi';o.value='";
3359 options +=
"';document.form1.appendChild(o);";
3360 options +=
"document.form1.submit();\" ";
3372 if (n_var ==
i_set) {
3380 size =
sizeof(
data);
3386 r->
rsprintf(
"<input type=text size=10 maxlength=80 name=value value=\"%s\">\n",
data_str.c_str());
3387 r->
rsprintf(
"<input type=submit size=20 name=cmd value=Set>\n");
3388 r->
rsprintf(
"<input type=hidden name=index value=%d>\n", n_var);
3389 r->
rsprintf(
"<input type=hidden name=cmd value=Set>\n");
3397 r->
rsprintf(
"<a onClick=\"promptpwd('%s?cmd=Edit&index=%d&pnam=%s')\" href=\"#\">", path, n_var,
pwd);
3399 r->
rsprintf(
"<a href=\"%s?cmd=Edit&index=%d\" %s>", path, n_var,
tail);
3406 }
else if (
edit == 2) {
3434 "Src = STRING : [256] ",
3435 "Format = STRING : [32] %1.1f",
3436 "Font = STRING : [32] Medium",
3440 "FGColor = STRING : [8] 000000",
3441 "BGColor = STRING : [8] FFFFFF",
3474 "Src = STRING : [256] ",
3478 "Height = INT : 100",
3479 "Direction = INT : 0",
3481 "Logscale = BOOL : n",
3483 "Max = DOUBLE : 10",
3484 "FGColor = STRING : [8] 000000",
3485 "BGColor = STRING : [8] FFFFFF",
3486 "BDColor = STRING : [8] 808080",
3492 int x, y, width, height, direction,
axis;
3506 int i,
n, size, ivalue;
3513 if (src[
i] ==
'>' || src[
i] ==
'&')
3524 cm_msg(
MERROR,
"evaluate_src",
"Invalid Src key \"%s\" for Fill \"%s\"",
3530 size =
sizeof(
data);
3537 *fvalue = (
value[0] ==
'y');
3543 if (src[
i] ==
'>' && src[
i+1] ==
'>') {
3546 while (src[
i] ==
' ' ||
isdigit(src[
i]))
3548 ivalue = (
int)*fvalue;
3553 if (src[
i] ==
'&') {
3555 while (src[
i] ==
' ')
3557 if (src[
i] ==
'0' && src[
i+1] ==
'x')
3561 while (src[
i] ==
' ' ||
isxdigit(src[
i]) || src[
i] ==
'x')
3563 ivalue = (
int)*fvalue;
3579 if (filename[0] ==
'/')
3598 cm_msg(
MERROR,
"add_custom_path",
"ODB /Custom/Path has a forbidden value \"%s\", please change it",
custom_path.c_str());
3617 std::string filename;
3636 sprintf(
str,
"show_custom_file: Invalid custom page: \"/Custom/%s\" not found in ODB",
name);
3679 char str[256],
data[256], src[256];
3680 int i,
index,
length,
status, size, width, height,
bgcol,
fgcol,
bdcol, r,
g, b, x, y;
3682 double fvalue,
ratio;
3705 std::string filename;
3721 sprintf(
str,
"show_custom_gif: File \"%s\" is not a GIF image", filename.c_str());
3738 size =
sizeof(label);
3741 cm_msg(
MERROR,
"show_custom_gif",
"Cannot open data record for label \"%s\"",
3746 if (label.
src[0] == 0) {
3753 cm_msg(
MERROR,
"show_custom_gif",
"Invalid Src key \"%s\" for label \"%s\"",
3759 size =
sizeof(
data);
3802 height =
pfont->h + 2 + 2;
3804 if (label.
align == 0) {
3807 label.
y + height,
bgcol);
3811 }
else if (label.
align == 1) {
3814 label.
y + height,
bgcol);
3816 label.
y + height,
fgcol);
3821 label.
y + height,
bgcol);
3842 cm_msg(
MERROR,
"show_custom_gif",
"Cannot open data record for bar \"%s\"",
3847 if (
bar.src[0] == 0) {
3854 cm_msg(
MERROR,
"show_custom_gif",
"Invalid Src key \"%s\" for bar \"%s\"",
3860 size =
sizeof(
data);
3868 sscanf(
bar.fgcolor,
"%02x%02x%02x", &r, &
g, &b);
3873 sscanf(
bar.bgcolor,
"%02x%02x%02x", &r, &
g, &b);
3878 sscanf(
bar.bdcolor,
"%02x%02x%02x", &r, &
g, &b);
3897 if (
bar.direction == 0) {
3911 -5, -7, -8, 0,
bar.min,
bar.max,
bar.logscale);
3912 else if (
bar.axis == 2)
3914 bar.height, 3, 5, 7, 10, 0,
bar.min,
bar.max,
bar.logscale);
3929 haxis(
im,
gdFontSmall,
bdcol, 0,
bar.x,
bar.y,
bar.height, -3, -5, -7, -18,
3931 else if (
bar.axis == 2)
3933 5, 7, 8, 0,
bar.min,
bar.max);
3965 size =
sizeof(
data);
3968 cm_msg(
MERROR,
"show_custom_gif",
"No \"Limits\" entry for Fill \"%s\"",
3972 for (
i = 0;
i < size / (
int)
sizeof(
double);
i++)
3973 if (*((
double *)
data +
i) > fvalue)
3980 cm_msg(
MERROR,
"show_custom_gif",
"No \"Fillcolors\" entry for Fill \"%s\"",
3985 size =
sizeof(
data);
3986 strcpy(
data,
"FFFFFF");
4004 rr->rsprintf(
"HTTP/1.1 200 Document follows\r\n");
4007 rr->rsprintf(
"Content-Type: image/gif\r\n");
4008 rr->rsprintf(
"Content-Length: %d\r\n",
length);
4009 rr->rsprintf(
"Cache-control: private, max-age=0, no-cache\r\n");
4010 rr->rsprintf(
"Expires: Fri, 01-Jan-1983 00:00:00 GMT\r\n\r\n");
4022 { 9999,
"mhttpd_jrpc_rev0", {
4044 r->
rsprintf(
"<INVALID_ARGUMENTS>");
4092 size =
sizeof(client_name);
4109 r->
rsprintf(
"client %s", client_name);
4147 { 9998,
"mhttpd_jrpc_rev1", {
4171 r->
rsprintf(
"<INVALID_ARGUMENTS>");
4219 assert(buf !=
NULL);
4224 for (
int i=0; ;
i++) {
4237 size =
sizeof(client_name);
4330 const char *cmd = p->
getparam(
"rcmd");
4335 r->
rsprintf(
"<INVALID_ARGUMENTS>");
4348 assert(buf !=
NULL);
4357 r->
rsprintf(
"<RPC_CONNECT_ERROR>%d</RPC_CONNECT_ERROR>",
status);
4398 size =
sizeof(
data);
4409 if (format && format[0])
4421 r->
rsputs(
"<DB_OUT_OF_RANGE>");
4480 std::vector<std::string> odb;
4515 for (
int i=0 ; ;
i++) {
4525 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());
4533 ppath +=
"/Custom/Pwd/";
4558 const char* ptr = p->
getparam(
"value");
4559 for (
i=0 ; ptr !=
NULL ;
i++) {
4560 size =
sizeof(
data);
4570 size =
sizeof(
data);
4599 size =
sizeof(
data);
4636 r->
rsputs(
"<DB_NO_KEY>");
4660 r->
rsputs(
"<DB_NO_KEY>");
4680 const char* fmt =
NULL;
4685 }
else if (p->
isparam(
"format")) {
4749 r->
rsputs(
"<DB_NO_KEY>");
4766 for (
int i=0 ; ;
i++) {
4775 r->
rsputs(
"</data>\n<data>\n");
4788 r->
rsputs(
"<DB_NO_KEY/>\n");
4794 r->
rsputs(
"<DB_NO_KEY>\n");
4804 const char* s =
strstr(buf,
"-->");
4822 r->
rsputs(
"</data>\n</jcopy>\n");
4858 for (
unsigned i=0;
i<odb.size();
i++) {
4873 r->
rsputs(
"<DB_NO_KEY>\n");
4940 for (
unsigned i=0;
i<odb.size();
i++) {
5029 for (
unsigned i=0;
i<odb.size();
i++) {
5126 for (
unsigned i=0;
i<odb.size();
i++) {
5188 for (
unsigned i=0;
i<odb.size();
i++) {
5249 for (
unsigned i=0;
i<odb.size();
i++) {
5313 for (
unsigned i=0;
i<odb.size();
i++) {
5383 mstrlcpy(user,
"javascript_commands",
sizeof(user));
5395 r->
rsputs(
"Message successfully created\n");
5439 std::string path =
pp->getparam(
"page");
5442 show_error_404(r,
"show_custom_page: Invalid custom page: \"page\" parameter is empty");
5446 if (
strstr(path.c_str(),
"..")) {
5448 str +=
"Invalid custom page name \'";
5450 str +=
"\' contains \'..\'";
5455 if (
strstr(path.c_str(),
".gif")) {
5460 if (
strchr(path.c_str(),
'.')) {
5467 std::string
xpath = std::string(
"/Custom/") + path;
5470 xpath = std::string(
"/Custom/") + path +
"&";
5473 xpath = std::string(
"/Custom/") + path +
"!";
5551 if (
pwd[0] && n_var ==
atoi(
pp->getparam(
"index"))) {
5558 ppath +=
"/Custom/Pwd/";
5559 if (
pp->getparam(
"pnam") && *
pp->getparam(
"pnam")) {
5560 ppath +=
pp->getparam(
"pnam");
5575 }
while (p !=
NULL);
5581 if (
pp->getparam(
"pnam") && *
pp->getparam(
"pnam")) {
5583 ppath +=
"/Custom/Pwd/";
5584 ppath +=
pp->getparam(
"pnam");
5593 std::string
podb =
pp->getparam(
"odb");
5594 std::string::size_type pos =
podb.find(
'[');
5595 if (pos != std::string::npos) {
5606 size =
sizeof(
data);
5624 r->
rsprintf(
"HTTP/1.1 200 Document follows\r\n");
5645 }
while (p !=
NULL);
5656 std::string
str =
msprintf(
"Invalid custom page: Page \"%s\" not found in ODB", path.c_str());
5667 int c,
n, a, f,
d,
q, x, r,
ia, id, w;
5689 size =
sizeof(client_name);
5696 if (client_name[0]) {
5704 rr->rsprintf(
"HTTP/1.1 200 Document follows\r\n");
5706 rr->rsprintf(
"Content-Type: text/html; charset=%s\r\n\r\n",
HTTP_ENCODING);
5708 rr->rsprintf(
"<html><head>\n");
5709 rr->rsprintf(
"<link rel=\"icon\" href=\"favicon.png\" type=\"image/png\" />\n");
5710 rr->rsprintf(
"<link rel=\"stylesheet\" href=\"midas.css\" type=\"text/css\" />\n");
5711 rr->rsprintf(
"<link rel=\"stylesheet\" href=\"mhttpd.css\" type=\"text/css\" />\n");
5712 rr->rsprintf(
"<title>MIDAS CAMAC interface</title></head>\n");
5713 rr->rsprintf(
"<body><form method=\"GET\" action=\"CNAF\">\n\n");
5721 rr->rsprintf(
"<table border=3 cellpadding=1>\n");
5722 rr->rsprintf(
"<tr><th colspan=3>MIDAS experiment \"%s\"",
str);
5724 if (client_name[0] == 0)
5725 rr->rsprintf(
"<th colspan=3 class=\"redLight\">No CAMAC server running</tr>\n");
5726 else if (
hconn == 0)
5727 rr->rsprintf(
"<th colspan=3 class=\"redLight\">Cannot connect to %s</tr>\n", client_name);
5729 rr->rsprintf(
"<th colspan=3>CAMAC server: %s</tr>\n", client_name);
5733 a = f =
d =
q = x = 0;
5739 rr->rsprintf(
"<tr><td colspan=3>\n");
5740 rr->rsprintf(
"<input type=submit name=cmd value=Execute>\n");
5742 rr->rsprintf(
"<td colspan=3>\n");
5743 rr->rsprintf(
"<input type=submit name=cmd value=ODB>\n");
5744 rr->rsprintf(
"<input type=submit name=cmd value=Status>\n");
5745 rr->rsprintf(
"<input type=submit name=cmd value=Help>\n");
5746 rr->rsprintf(
"</tr>\n\n");
5749 rr->rsprintf(
"<tr><th>N");
5750 rr->rsprintf(
"<th>A");
5751 rr->rsprintf(
"<th>F");
5752 rr->rsprintf(
"<th colspan=3>Data");
5757 const char* cmd = p->
getparam(
"cmd");
5759 rpc_client_call(
hconn,
RPC_CNAF16,
CNAF_CRATE_CLEAR, 0, 0, 0, 0, 0, &
d, &size, &x,
5762 rr->rsprintf(
"<tr><td colspan=6 class=\"greenLight\">C cycle executed sucessfully</tr>\n");
5764 rpc_client_call(
hconn,
RPC_CNAF16,
CNAF_CRATE_ZINIT, 0, 0, 0, 0, 0, &
d, &size, &x,
5767 rr->rsprintf(
"<tr><td colspan=6 class=\"greenLight\">Z cycle executed sucessfully</tr>\n");
5769 rpc_client_call(
hconn,
RPC_CNAF16,
CNAF_INHIBIT_CLEAR, 0, 0, 0, 0, 0, &
d, &size, &x,
5773 (
"<tr><td colspan=6 class=\"greenLight\">Clear inhibit executed sucessfully</tr>\n");
5775 rpc_client_call(
hconn,
RPC_CNAF16,
CNAF_INHIBIT_SET, 0, 0, 0, 0, 0, &
d, &size, &x,
5779 (
"<tr><td colspan=6 class=\"greenLight\">Set inhibit executed sucessfully</tr>\n");
5804 for (
i = 0;
i < r;
i++) {
5810 rpc_client_call(
hconn,
RPC_CNAF24,
CNAF, 0,
c,
n, a, f, &
d, &size, &x,
5823 status =
rpc_client_call(
hconn,
RPC_CNAF24,
CNAF, 0,
c,
n, a, f, &
d, &size, &x, &
q);
5830 (
"<tr><td colspan=6 class=\"redLight\">Error executing function, code = %d</tr>",
5833 rr->rsprintf(
"<tr align=center><td>%d",
n);
5834 rr->rsprintf(
"<td>%d", a);
5835 rr->rsprintf(
"<td>%d", f);
5836 rr->rsprintf(
"<td colspan=3>%d / 0x%04X Q%d X%d",
d,
d,
q, x);
5849 (
"<tr align=center><td><input type=text size=3 name=N value=%d>\n",
5851 rr->rsprintf(
"<td><input type=text size=3 name=A value=%d>\n", a);
5852 rr->rsprintf(
"<td><input type=text size=3 name=F value=%d>\n", f);
5854 (
"<td colspan=3><input type=text size=8 name=D value=%d></tr>\n",
5858 rr->rsprintf(
"<tr><td colspan=2>Repeat");
5859 rr->rsprintf(
"<td><input type=text size=3 name=R value=%d>\n", r);
5862 (
"<td align=center colspan=3><input type=submit name=cmd value=\"C cycle\">\n");
5863 rr->rsprintf(
"<input type=submit name=cmd value=\"Z cycle\">\n");
5865 rr->rsprintf(
"<tr><td colspan=2>Repeat delay [ms]");
5866 rr->rsprintf(
"<td><input type=text size=3 name=W value=%d>\n", w);
5869 (
"<td align=center colspan=3><input type=submit name=cmd value=\"Set inhibit\">\n");
5870 rr->rsprintf(
"<input type=submit name=cmd value=\"Clear inhibit\">\n");
5872 rr->rsprintf(
"<tr><td colspan=2>Data increment");
5873 rr->rsprintf(
"<td><input type=text size=3 name=ID value=%d>\n",
id);
5876 (
"<td colspan=3 align=center>Branch <input type=text size=3 name=B value=0>\n");
5878 rr->rsprintf(
"<tr><td colspan=2>A increment");
5879 rr->rsprintf(
"<td><input type=text size=3 name=IA value=%d>\n",
ia);
5882 (
"<td colspan=3 align=center>Crate <input type=text size=3 name=C value=%d>\n",
5885 rr->rsprintf(
"</table></body>\r\n");
6005 for (
i = 0;
i < 8;
i++)
6006 if (*((
unsigned char *)
pdata) & (0x80 >>
i))
6070static int cmp_int(
const void *a,
const void *b)
6072 return *((
int *)a) > *((
int *)b);
6150 size =
sizeof(address);
6183 int i,
j,
n,
ind,
fi, fd,
status, size,
n_addr,
cur_node, adr,
show_hidden;
6206 sprintf(errorstr,
"No submaster defined under /MSCB/Submaster");
6231 std::vector<int>
addr;
6267 for (
i=0 ;
i<0x10000 ;
i++)
6269 for (
i=0 ;
i<1000 ;
i++)
6271 for (
i=0 ;
i<0x10000 ;
i+=100)
6273 for (
i=0 ;
i<0x10000 ;
i+= 0x100)
6275 for (
i=0xFF00 ;
i<0x10000 ;
i++)
6354 if (
value[1] ==
'x')
6377 r->
rsprintf(
"<script type=\"text/javascript\" src=\"midas.js\"></script>\n");
6378 r->
rsprintf(
"<script type=\"text/javascript\" src=\"mhttpd.js\"></script>\n");
6382 r->
rsprintf(
"<style type=\"text/css\">\r\n");
6383 r->
rsprintf(
"select { width:150px; background-color:#FFFFE0; font-size:12px; }\r\n");
6385 r->
rsprintf(
" background-color:#E0E0E0; text-align:center; font-weight:bold;\r\n");
6387 r->
rsprintf(
" vertical-align:top;\r\n");
6388 r->
rsprintf(
" font-size:16px;\r\n");
6389 r->
rsprintf(
" border-right:1px solid #808080;\r\n");
6392 r->
rsprintf(
" background-color:#E0E0E0; text-align:center; font-weight:bold;\r\n");
6394 r->
rsprintf(
" vertical-align:top;\r\n");
6395 r->
rsprintf(
" font-size:16px;\r\n");
6396 r->
rsprintf(
" border-right:1px solid #808080;\r\n");
6399 r->
rsprintf(
" background-color:#E0E0E0; text-align:center; font-weight:bold;\r\n");
6401 r->
rsprintf(
" vertical-align:top;\r\n");
6402 r->
rsprintf(
" font-size:10px;\r\n");
6406 r->
rsprintf(
" font-weight:bold;\r\n");
6407 r->
rsprintf(
" font-size:12px;\r\n");
6410 r->
rsprintf(
" background-color:#F0F0F0;\r\n");
6412 r->
rsprintf(
" font-size:12px;\r\n");
6413 r->
rsprintf(
" border:1px solid #808080;\r\n");
6414 r->
rsprintf(
" border-right:1px solid #FFFFFF;\r\n");
6415 r->
rsprintf(
" border-bottom:1px solid #FFFFFF;\r\n");
6419 r->
rsprintf(
" font-size:12px;\r\n");
6424 r->
rsprintf(
"<script type=\"text/javascript\">\r\n");
6425 r->
rsprintf(
"function mscb_edit(index, value)\r\n");
6427 r->
rsprintf(
" var new_value = prompt('Please enter new value', value);\r\n");
6428 r->
rsprintf(
" if (new_value != undefined) {\r\n");
6436 r->
rsprintf(
"<table class=\"mtable\">");
6437 r->
rsprintf(
"<tr><th class=\"mtableheader\" colspan=2>MSCB</th><tr>");
6441 r->
rsprintf(
"<tr><td colspan=2>\n");
6442 r->
rsprintf(
"<table width=100%%><tr>\n");
6443 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());
6445 r->
rsprintf(
"<tr><td colspan=\"2\" cellpadding=\"0\" cellspacing=\"0\">\r\n");
6449 r->
rsprintf(
"<h1>No MSCB Submasters defined in ODB</h1>\r\n");
6460 r->
rsprintf(
"<table width=\"100%%\" cellpadding=\"0\" cellspacing=\"0\">");
6463 r->
rsprintf(
"<tr><td class=\"subm\">\r\n");
6475 r->
rsprintf(
"<select name=\"subm\" id=\"subm\" size=%d ",
i);
6476 r->
rsprintf(
"onChange=\"window.location.search='?cmd=mscb&subm='+document.getElementById('subm').value;\">\r\n");
6486 size =
sizeof(comment);
6502 r->
rsprintf(
"<td class=\"node\">\r\n");
6505 r->
rsprintf(
"<script type=\"text/javascript\">\n");
6507 r->
rsprintf(
"function rescan()\n");
6509 r->
rsprintf(
" flag = confirm('Rescan can take up to one minute.');\n");
6510 r->
rsprintf(
" if (flag == true)\n");
6516 r->
rsprintf(
"<input type=button name=cmd value=\"Rescan\" onClick=\"rescan();\">");
6520 r->
rsprintf(
"No submaster found in ODB\r\n");
6555 r->
rsprintf(
"<select name=\"node\" id=\"node\" size=%d ",
i);
6556 r->
rsprintf(
"onChange=\"window.location.search='?cmd=mscb&subm=%s&node='+document.getElementById('node').value;\">\r\n",
cur_subm_name);
6578 size =
sizeof(comment);
6587 r->
rsprintf(
"<option selected>%s</option>\r\n",
str);
6595 r->
rsprintf(
"<td class=\"vars\">\r\n");
6612 r->
rsprintf(
"<tr><td colspan=3><b>Invalid password</b></td>");
6614 r->
rsprintf(
"<tr><td colspan=3><b>Submaster does not respond</b></td>");
6622 r->
rsprintf(
"<tr><td colspan=3><b>No response from node</b></td>");
6627 r->
rsprintf(
"<tr><td colspan=3><b>No response from node</b></td>");
6632 r->
rsprintf(
"<tr><td class=\"v1\">Node name<td colspan=2 class=\"v2\">%s</tr>\n",
tr16);
6633 r->
rsprintf(
"<tr><td class=\"v1\">GIT revision<td colspan=2 class=\"v2\">%d</tr>\n",
info.revision);
6635 if (
info.rtc[0] &&
info.rtc[0] != 0xFF) {
6636 for (
i=0 ;
i<6 ;
i++)
6638 r->
rsprintf(
"<tr><td class=\"v1\">Real Time Clock<td colspan=2 class=\"v2\">%02d-%02d-%02d %02d:%02d:%02d</td>\n",
6645 r->
rsprintf(
"<tr><td class=\"v1\">Uptime<td colspan=2 class=\"v2\">%dd %02dh %02dm %02ds</tr>\n",
6650 r->
rsprintf(
"<tr><td colspan=3><hr></td></tr>\r\n");
6653 for (
i=0 ;
i <
info.n_variables ;
i++) {
6658 if (
i <
info.n_variables) {
6661 r->
rsprintf(
"<tr><td colspan=3><input type=checkbox%s name=\"hidden\" value=\"1\"",
str);
6662 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);
6666 for (
fi=0 ;
fi <
info.n_variables ; ) {
6667 for (
i=
fi,size=0 ;
i <
info.n_variables && size < 100;
i++) {
6672 size =
sizeof(
dbuf);
6675 r->
rsprintf(
"<tr><td colspan=3><b>Error reading data from node</b></td>");
6685 r->
rsprintf(
"<tr><td class=\"v1\">%s</td>\r\n",
tr8);
6686 r->
rsprintf(
"<td class=\"v2\">\r\n");
6689 r->
rsprintf(
"<a href=\"#\" onClick=\"mscb_edit(%d,'%s')\">%s</a>",
6702 r->
rsprintf(
"</td></tr></table>\r\n");
6703 r->
rsprintf(
"</td></tr></table>\r\n");
6704 r->
rsprintf(
"</td></tr></table>\r\n");
6705 r->
rsprintf(
"</div></body></html>\r\n");
6714 r->
rsprintf(
"HTTP/1.1 200 Document follows\r\n");
6719 r->
rsprintf(
"<link rel=\"icon\" href=\"favicon.png\" type=\"image/png\" />\n");
6720 r->
rsprintf(
"<link rel=\"stylesheet\" href=\"midas.css\" type=\"text/css\" />\n");
6721 r->
rsprintf(
"<link rel=\"stylesheet\" href=\"mhttpd.css\" type=\"text/css\" />\n");
6722 r->
rsprintf(
"<title>Enter password</title></head><body>\n\n");
6724 r->
rsprintf(
"<form method=\"GET\" action=\".\">\n\n");
6727 r->
rsprintf(
"<table class=\"headerTable\"><tr><td></td><tr></table>\n");
6729 r->
rsprintf(
"<table class=\"dialogTable\">\n");
6731 r->
rsprintf(
"<tr><th class=\"redLight\">Wrong password!</tr>\n");
6733 r->
rsprintf(
"<tr><th>Please enter password</tr>\n");
6734 r->
rsprintf(
"<tr><td align=center><input type=password name=pwd></tr>\n");
6735 r->
rsprintf(
"<tr><td align=center><input type=submit value=Submit></tr>");
6761 r->
rsprintf(
"HTTP/1.1 200 Document follows\r\n");
6766 r->
rsprintf(
"<link rel=\"icon\" href=\"favicon.png\" type=\"image/png\" />\n");
6767 r->
rsprintf(
"<link rel=\"stylesheet\" href=\"midas.css\" type=\"text/css\" />\n");
6768 r->
rsprintf(
"<link rel=\"stylesheet\" href=\"mhttpd.css\" type=\"text/css\" />\n");
6769 r->
rsprintf(
"<title>Enter password</title></head><body>\n\n");
6771 r->
rsprintf(
"<form method=\"GET\" action=\".\">\n\n");
6775 r->
rsprintf(
"<input type=hidden name=redir value=\"%s\">\n",
redir);
6778 r->
rsprintf(
"<table class=\"headerTable\"><tr><td></td><tr></table>\n");
6780 r->
rsprintf(
"<table class=\"dialogTable\">\n");
6783 r->
rsprintf(
"<tr><th class=\"redLight\">Wrong password!</tr>\n");
6786 (
"<tr><th>Please enter password to obtain write access</tr>\n");
6787 r->
rsprintf(
"<tr><td align=center><input type=password name=wpwd></tr>\n");
6788 r->
rsprintf(
"<tr><td align=center><input type=submit value=Submit></tr>");
6829 r->
rsprintf(
"<script type=\"text/javascript\" src=\"midas.js\"></script>\n");
6830 r->
rsprintf(
"<script type=\"text/javascript\" src=\"mhttpd.js\"></script>\n");
6831 r->
rsprintf(
"<script type=\"text/javascript\" src=\"obsolete.js\"></script>\n");
6832 r->
rsprintf(
"<script type=\"text/javascript\" src=\"controls.js\"></script>\n");
6851 while (*p && *p !=
'/')
6876 r->
rsprintf(
"<table class=\"mtableheader\">\n");
6878 r->
rsprintf(
"<input type=button value=ELog onclick=\"self.location=\'?cmd=Alarms\';\">\n");
6879 r->
rsprintf(
"</td></tr></table>\n\n");
6885 r->
rsprintf(
"<table class=\"mtable\" style=\"border-spacing:0px;\">\n");
6886 r->
rsprintf(
"<tr><th colspan=%d class=\"mtableheader\">Online Database Browser</tr>\n",
colspan);
6890 r->
rsprintf(
"<input type=button value=Find onclick=\"self.location=\'?cmd=Find\';\">\n");
6891 r->
rsprintf(
"<input type=button value=Create onclick=\"dlgShow('dlgCreate')\">\n");
6892 r->
rsprintf(
"<input type=button value=Link onclick=\"dlgShow('dlgLink')\">\n");
6893 r->
rsprintf(
"<input type=button value=Delete onclick=\"dlgShow('dlgDelete')\">\n");
6894 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());
6895 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());
6896 r->
rsprintf(
"<input type=button value=\"Show ODB clients\" onclick=\"self.location=\'?cmd=odb_scl\';\">\n");
6902 std::string dd =
"";
6904 dd +=
"<!-- Demo dialog -->\n";
6905 dd +=
"<div id=\"dlgDelete\" class=\"dlgFrame\">\n";
6906 dd +=
"<div class=\"dlgTitlebar\">Delete ODB entry</div>\n";
6907 dd +=
"<div class=\"dlgPanel\">\n";
6908 dd +=
"<div id=odbpath>";
6910 dd += MJsonNode::Encode(
odbpath.c_str());
6913 dd +=
"<div><br></div>\n";
6915 dd +=
"<table class=\"dialogTable\">\n";
6916 dd +=
"<th colspan=2>Delete ODB entries:</th>\n";
6926 r->
rsprintf(
"<a href=\"?cmd=oldodb\">/</a> \n");
6935 while (*p && *p !=
'/')
6940 if (
pd.length() > 0)
6955 r->
rsprintf(
"<tr class=\"titleRow\">\n");
6956 r->
rsprintf(
"<th class=\"ODBkey\">Key</th>\n");
6957 r->
rsprintf(
"<th class=\"ODBvalue\">Value ");
6958 r->
rsprintf(
"<script type=\"text/javascript\">\n");
6959 r->
rsprintf(
"function expand()\n");
6961 r->
rsprintf(
" var n = document.getElementsByName('ext');\n");
6962 r->
rsprintf(
" for (i=0 ; i<n.length ; i++) {\n");
6963 r->
rsprintf(
" if (n[i].style.display == 'none')\n");
6964 r->
rsprintf(
" n[i].style.display = 'table-cell';\n");
6966 r->
rsprintf(
" n[i].style.display = 'none';\n");
6968 r->
rsprintf(
" if (document.getElementById('expp').expflag === true) {\n");
6969 r->
rsprintf(
" document.getElementById('expp').expflag = false;\n");
6970 r->
rsprintf(
" document.getElementById('expp').innerHTML = '⇥';\n");
6972 r->
rsprintf(
" document.getElementById('expp').expflag = true;\n");
6973 r->
rsprintf(
" document.getElementById('expp').innerHTML = '⇤';\n");
6977 r->
rsprintf(
"<div style=\"display:inline;float:right\"><a id=\"expp\"href=\"#\" onClick=\"expand();return false;\">⇥</div>");
6979 r->
rsprintf(
"<th class=\"ODBvalue\" name=\"ext\" style=\"display:none\">Type</th>\n");
6980 r->
rsprintf(
"<th class=\"ODBvalue\" name=\"ext\" style=\"display:none\">#Val</th>\n");
6981 r->
rsprintf(
"<th class=\"ODBvalue\" name=\"ext\" style=\"display:none\">Size</th>\n");
6982 r->
rsprintf(
"<th class=\"ODBvalue\" name=\"ext\" style=\"display:none\">Written</th>\n");
6983 r->
rsprintf(
"<th class=\"ODBvalue\" name=\"ext\" style=\"display:none\">Mode</th>\n");
6987 for (
int i = 0;;
i++) {
6998 mstrlcpy(style,
"ODBtableEven",
sizeof(style));
7000 mstrlcpy(style,
"ODBtableOdd",
sizeof(style));
7008 if (odb_path.length() > 0 && odb_path[odb_path.length() - 1] !=
'/')
7042 enc_ref +=
"?cmd=Set&odb_path=";
7048 enc_ref +=
"?cmd=Set&odb_path=";
7055 enc_ref +=
"?cmd=Set&odb_path=";
7061 r->
rsprintf(
"<tr><td class=\"yellowLight\">");
7082 size =
sizeof(
data);
7093 if (size ==
sizeof(
data)) {
7115 r->
rsprintf(
"<td class=\"ODBkey\">\n");
7118 r->
rsprintf(
"<td class=\"%s\">\n", style);
7122 r->
rsprintf(
"<a href=\"%s\" onClick=\"ODBInlineEdit(this.parentNode,\'%s\');return false;\" ",
enc_ref.c_str(), odb_path.c_str());
7123 r->
rsprintf(
"onFocus=\"ODBInlineEdit(this.parentNode,\'%s\');\">%s (%s)</a>\n", odb_path.c_str(),
data_str.c_str(),
hex_str.c_str());
7126 r->
rsprintf(
"<td class=\"ODBkey\">\n");
7131 r->
rsprintf(
"<a href=\"%s\" onClick=\"ODBInlineEdit(this.parentNode,\'%s\');return false;\" ",
enc_ref.c_str(), odb_path.c_str());
7132 r->
rsprintf(
"onFocus=\"ODBInlineEdit(this.parentNode,\'%s\');\">%s (%s)</a>\n", odb_path.c_str(),
data_str.c_str(),
hex_str.c_str());
7138 r->
rsprintf(
"<td class=\"ODBkey\">");
7141 r->
rsprintf(
"<td class=\"ODBkey\">%s<td class=\"%s\">",
keyname.c_str(), style);
7151 r->
rsprintf(
"<td class=\"ODBkey\">\n");
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());
7162 r->
rsprintf(
"<td class=\"ODBkey\">%s<td class=\"%s\">",
keyname.c_str(), style);
7166 r->
rsprintf(
"<a href=\"%s\" onClick=\"ODBInlineEdit(this.parentNode,\'%s\');return false;\" ",
enc_ref.c_str(), odb_path.c_str());
7167 r->
rsprintf(
"onFocus=\"ODBInlineEdit(this.parentNode,\'%s\');\">", odb_path.c_str());
7176 r->
rsprintf(
"<td class=\"ODBkey\" name=\"ext\" style=\"display:none\">");
7180 r->
rsprintf(
"<td class=\"ODBkey\" name=\"ext\" style=\"display:none\">");
7184 r->
rsprintf(
"<td class=\"ODBkey\" name=\"ext\" style=\"display:none\">");
7188 r->
rsprintf(
"<td class=\"ODBkey\" name=\"ext\" style=\"display:none\">");
7192 else if (
delta < 3600)
7194 else if (
delta < 86400)
7196 else if (
delta < 86400 * 99)
7202 r->
rsprintf(
"<td class=\"ODBkey\" name=\"ext\" style=\"display:none\">");
7218 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);
7228 mstrlcpy(style,
"ODBtableEven",
sizeof(style));
7230 mstrlcpy(style,
"ODBtableOdd",
sizeof(style));
7233 size =
sizeof(
data);
7245 if (size ==
sizeof(
data)) {
7257 enc_ref +=
"?cmd=Set&odb_path=";
7272 r->
rsprintf(
"<td class=\"%s\">[%d] ", style,
j);
7276 r->
rsprintf(
"<a href=\"%s\" onClick=\"ODBInlineEdit(this.parentNode,\'%s\');return false;\" ",
enc_ref.c_str(),
tmpstr.c_str());
7277 r->
rsprintf(
"onFocus=\"ODBInlineEdit(this.parentNode,\'%s\');\">",
tmpstr.c_str());
7286 r->
rsprintf(
"<td class=\"ODBkey\" name=\"ext\" style=\"display:none\" rowspan=%d>",
key.
num_values);
7290 r->
rsprintf(
"<td class=\"ODBkey\" name=\"ext\" style=\"display:none\" rowspan=%d>",
key.
num_values);
7294 r->
rsprintf(
"<td class=\"ODBkey\" name=\"ext\" style=\"display:none\" rowspan=%d>",
key.
num_values);
7298 r->
rsprintf(
"<td class=\"ODBkey\" name=\"ext\" style=\"display:none\" rowspan=%d>",
key.
num_values);
7302 else if (
delta < 3600)
7304 else if (
delta < 86400)
7306 else if (
delta < 86400 * 99)
7312 r->
rsprintf(
"<td class=\"ODBkey\" name=\"ext\" style=\"display:none\" rowspan=%d>",
key.
num_values);
7345 dd +=
"<tr><td style=\"text-align:left;\" align=left><input align=left type=checkbox id=delete";
7349 dd += MJsonNode::Encode(
name.c_str());
7353 dd +=
"</input></td></tr>\n";
7357 dd +=
"<input type=button value=Delete onClick='mhttpd_delete_page_handle_delete(event);'>\n";
7358 dd +=
"<input type=button value=Cancel onClick='mhttpd_delete_page_handle_cancel(event);'>\n";
7366 std::string cd =
"";
7368 cd +=
"<!-- Demo dialog -->\n";
7369 cd +=
"<div id=\"dlgCreate\" class=\"dlgFrame\">\n";
7370 cd +=
"<div class=\"dlgTitlebar\">Create ODB entry</div>\n";
7371 cd +=
"<div class=\"dlgPanel\">\n";
7373 cd +=
"<div id=odbpath>";
7375 cd += MJsonNode::Encode(
odbpath.c_str());
7378 cd +=
"<div><br></div>\n";
7380 cd +=
"<table class=\"dialogTable\">\n";
7381 cd +=
"<th colspan=2>Create ODB entry:</th>\n";
7385 cd +=
"<select type=text size=1 id=create_tid name=type>";
7386 cd +=
"<option value=7>Integer (32-bit)";
7387 cd +=
"<option value=9>Float (4 Bytes)";
7388 cd +=
"<option value=12>String";
7389 cd +=
"<option selected value=15>Subdirectory";
7390 cd +=
"<option value=1>Byte";
7391 cd +=
"<option value=2>Signed byte";
7392 cd +=
"<option value=3>Character (8-bit)";
7393 cd +=
"<option value=4>Word (16-bit)";
7394 cd +=
"<option value=5>Short integer (16-bit)";
7395 cd +=
"<option value=6>Double Word (32-bit)";
7396 cd +=
"<option value=8>Boolean";
7397 cd +=
"<option value=10>Double float (8 Bytes)";
7401 cd +=
"<tr><td>Name<td><input type=text size=31 maxlength=31 id=create_name name=value></tr>\n";
7402 cd +=
"<tr><td>Array size<td><input type=text size=31 maxlength=31 id=create_array_length name=index value=1></tr>\n";
7403 cd +=
"<tr><td>String length<td><input type=text size=31 maxlength=31 id=create_strlen name=strlen value=32></tr>\n";
7405 cd +=
"<input type=button value=Create onClick='mhttpd_create_page_handle_create(event);'>\n";
7406 cd +=
"<input type=button value=Cancel onClick='mhttpd_create_page_handle_cancel(event);'>\n";
7414 std::string
ld =
"";
7416 ld +=
"<!-- Demo dialog -->\n";
7417 ld +=
"<div id=\"dlgLink\" class=\"dlgFrame\">\n";
7418 ld +=
"<div class=\"dlgTitlebar\">Create a link to an ODB entry</div>\n";
7419 ld +=
"<div class=\"dlgPanel\">\n";
7421 ld +=
"<div id=link_odbpath>";
7423 ld += MJsonNode::Encode(
odbpath.c_str());
7426 ld +=
"<div><br></div>\n";
7428 ld +=
"<table class=\"dialogTable\">\n";
7429 ld +=
"<th colspan=2>Create a link to an ODB entry:</th>\n";
7430 ld +=
"<tr><td>Name<td><input type=text size=31 maxlength=31 id=link_name name=value></tr>\n";
7431 ld +=
"<tr><td>Link target<td><input type=text size=31 maxlength=256 id=link_target name=target></tr>\n";
7433 ld +=
"<input type=button value=Link onClick='mhttpd_link_page_handle_link(event);'>\n";
7434 ld +=
"<input type=button value=Cancel onClick='mhttpd_link_page_handle_cancel(event);'>\n";
7452 std::string odb_path =
pp->getparam(
"odb_path");
7459 if (!
pp->isparam(
"value") && !*
pp->getparam(
"text")) {
7462 r->
rsprintf(
"Error: cannot find key %s<P>\n", odb_path.c_str());
7472 r->
rsprintf(
"<table class=\"dialogTable\">");
7475 r->
rsprintf(
"<input type=hidden name=index value=\"%d\">\n",
index);
7480 r->
rsprintf(
"<input type=hidden name=group value=\"%s\">\n",
group);
7482 r->
rsprintf(
"<input type=hidden name=odb_path value=\"%s\">\n", odb_path.c_str());
7490 str1 = odb_path.c_str();
7492 r->
rsprintf(
"<tr><th colspan=2>Set new value - type = %s</tr>\n",
data_str1.c_str());
7496 size =
sizeof(
data);
7504 r->
rsprintf(
"<textarea rows=20 cols=80 name=\"text\">\n");
7509 if ((
int)
data_str.length() > size)
7514 r->
rsprintf(
"<input type=\"text\" size=%d maxlength=256 name=\"value\" value=\"", size);
7521 r->
rsprintf(
"<tr><td align=center colspan=2>");
7522 r->
rsprintf(
"<input type=submit name=cmd value=Set>");
7523 r->
rsprintf(
"<input type=submit name=cmd value=Cancel>");
7527 r->
rsprintf(
"<input type=hidden name=cmd value=Set>\n");
7538 r->
rsprintf(
"Error: cannot find key %s<P>\n", odb_path.c_str());
7545 if (
pp->getparam(
"text") && *
pp->getparam(
"text"))
7567 r->
rsprintf(
"<h2>Write access not allowed</h2>\n");
7583 if (
value[0] == 0) {
7591 r->
rsprintf(
"<table class=\"dialogTable\">");
7593 r->
rsprintf(
"<tr><th colspan=2>Find string in Online Database</tr>\n");
7594 r->
rsprintf(
"<tr><td>Enter substring (case insensitive)\n");
7596 r->
rsprintf(
"<td><input type=\"text\" size=\"20\" maxlength=\"80\" name=\"value\">\n");
7599 r->
rsprintf(
"<tr><td align=center colspan=2>");
7600 r->
rsprintf(
"<input type=submit name=cmd value=Find>");
7601 r->
rsprintf(
"<input type=submit name=cmd value=Cancel>");
7605 r->
rsprintf(
"<input type=hidden name=cmd value=Find>");
7613 r->
rsprintf(
"<table class=\"mtable\">\n");
7614 r->
rsprintf(
"<tr><th colspan=2 class=\"mtableheader\">");
7615 r->
rsprintf(
"Results of search for substring \"%s\"</tr>\n",
value);
7616 r->
rsprintf(
"<tr><th class=\"titlerow\">Key<th>Value</tr>\n");
7638#define LN10 2.302585094
7639#define LOG2 0.301029996
7640#define LOG5 0.698970005
7643 int x1,
int y1,
int width,
7644 int minor,
int major,
int text,
int label,
int grid,
double xmin,
double xmax)
7649 double base[] = { 1, 2, 5, 10, 20, 50, 100, 200, 500, 1000 };
7651 if (xmax <= xmin || width <= 0)
7655 dx = (xmax - xmin) / (
double) (width / 5);
7774 sprintf(result,
"%02d %s %02d %02d:%02d:%02d",
7777 else if (
base < 3600 * 24)
7778 sprintf(result,
"%02d %s %02d %02d:%02d",
7785 else if (
base < 3600 * 3)
7787 else if (
base < 3600 * 24)
7788 sprintf(result,
"%02d %s %02d %02d:%02d",
7796 int x1,
int y1,
int width,
int xr,
7797 int minor,
int major,
int text,
int label,
int grid,
double xmin,
double xmax)
7802 const int base[] = { 1, 5, 10, 60, 300, 600, 1800, 3600, 3600 * 6, 3600 * 12, 3600 * 24, 0 };
7807 if (xmax <= xmin || width <= 0)
7820 dx = (
int) ((xmax - xmin) / (
double) (width / 5) + 0.5);
7917 int x1,
int y1,
int width,
7925 const double base[] = { 1, 2, 5, 10, 20, 50, 100, 200, 500, 1000 };
7988 if (
x1 != 0 ||
y1 != 0)
8008 if (
x1 != 0 ||
y1 != 0) {
8036 if (
x1 != 0 ||
y1 != 0) {
8052 if (
x1 != 0 ||
y1 != 0) {
8060 if (
x1 != 0 ||
y1 != 0) {
8130 for (; *
str != 0;
str++) {
8146 sprintf(buf,
"%.0f", (
double)t);
8159 cm_msg(
MINFO,
"history_watch_callback",
"History configuration may have changed, will reconnect");
8226 cm_msg(
MERROR,
"get_history",
"Cannot configure history, hs_get_history() status %d",
status);
8244#define ALLOC(t,n) (t*)calloc(sizeof(t),(n))
8245#define DELETE(x) if (x) { free(x); (x)=NULL; }
8246#define DELETEA(x, n) if (x) { for (int i=0; i<(n); i++) { free((x)[i]); (x)[i]=NULL; }; DELETE(x); }
8247#define STRDUP(x) strdup(x)
8330#define READ_HISTORY_DATA 0x1
8331#define READ_HISTORY_RUNMARKER 0x2
8332#define READ_HISTORY_LAST_WRITTEN 0x4
8392 cm_msg(
MERROR,
"read_history",
"Cannot find \'/History/Display\' in ODB, status %d",
status);
8399 cm_msg(
MERROR,
"read_history",
"Cannot find \'%s\' in ODB, status %d", path,
status);
8405 cm_msg(
MERROR,
"read_history",
"Cannot find \'%s/Variables\' in ODB, status %d", path,
status);
8413 data->Allocate(
hp.vars.size()+2);
8415 data->tstart = tstart;
8417 data->scale = scale;
8419 for (
size_t i=0;
i<
hp.vars.size();
i++) {
8467 data->var_index[
data->nvars+0] = 0;
8468 data->var_index[
data->nvars+1] = 0;
8470 data->odb_index[
data->nvars+0] = -1;
8471 data->odb_index[
data->nvars+1] = -2;
8476 bool get_last_written =
false;
8490 printf(
"read_history: nvars %d, hs_read() status %d\n",
data->nvars,
status);
8491 for (
int i=0;
i<
data->nvars;
i++) {
8492 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]);
8497 cm_msg(
MERROR,
"read_history",
"Complete history failure, hs_read() status %d, see messages",
status);
8501 for (
int i=0;
i<
data->nvars;
i++) {
8503 get_last_written =
true;
8510 get_last_written =
true;
8512 if (get_last_written) {
8513 data->have_last_written =
true;
8521 data->last_written);
8524 data->have_last_written =
false;
8560 if (!
hsdata->have_last_written) {
8609 printf(
"get_hist_last_written: elapsed time %f ms\n", tend-tstart);
8615 int width,
int height,
8619 int labels,
const char *bgcolor,
const char *fgcolor,
const char *
gridcolor)
8663 std::vector<int> var_index; var_index.resize(
hp.vars.size());
8665 for (
size_t i=0;
i<
hp.vars.size();
i++) {
8667 const char *
vp =
strchr(
hp.vars[
i].tag_name.c_str(),
'[');
8694 sscanf(bgcolor,
"%02x%02x%02x", &r, &
g, &b);
8696 sscanf(fgcolor,
"%02x%02x%02x", &r, &
g, &b);
8735 sprintf(
str,
"History is not configured, see messages");
8759 if (
hp.vars.empty()) {
8774 for (
i = 0;
i < (
int)
hp.vars.size();
i++) {
8835 if (
hp.vars[
i].colour[0] ==
'#') {
8836 const char*
str =
hp.vars[
i].colour.c_str();
8963 while (p >
str && *p !=
' ')
8965 std::string key_name = p + 1;
9003 std::string key_name =
key.
name;
9007 path +=
"Settings/Names ";
9089 if (
hp.enable_factor) {
9099 if (
hp.enable_factor) {
9119 if (
hp.show_run_markers)
9125 sprintf(
str,
"Complete history failure, read_history() status %d, see messages",
status);
9154 for (
int j=0;
j<
hsdata->num_entries[
k];
j++) {
9171 if (
hp.enable_factor) {
9172 yy =
hp.vars[
i].factor * (
yy -
hp.vars[
i].voffset) +
hp.vars[
i].offset;
9196 assert(x[
i].size() == y[
i].size());
9225 if (
hp.zero_ylow &&
ymin > 0)
9286 aoffset =
vaxis(
im,
gdFontSmall,
fgcol,
gridcol, 0, 0, height, -3, -5, -7, -8, 0,
ymin,
ymax,
logaxis);
9297 taxis(
im,
gdFontSmall,
fgcol,
gridcol,
x1,
y1,
x2 -
x1, width, 3, 5, 9, 10, 0, (
double)
starttime, (
double)
endtime);
9299 vaxis(
im,
gdFontSmall,
fgcol,
gridcol,
x1,
y1,
y1 -
y2, -3, -5, -7, -8,
x2 -
x1,
ymin,
ymax,
logaxis);
9308 if ( (0) &&
hp.show_run_markers) {
9310 const char* event_names[] = {
9371 if (
dbuf[0][
j] == 1)
9373 else if (
dbuf[0][
j] == 2)
9375 else if (
dbuf[0][
j] == 3)
9398 if (num_entries[0]) {
9405 if (num_entries[1]) {
9414 if (
hp.show_run_markers) {
9420 if (
hsdata->odb_index[
k] == -1)
9423 if (
hsdata->odb_index[
k] == -2)
9439 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]);
9480 else if (
state == 2)
9482 else if (
state == 3)
9506 for (
i = 0;
i < (
int)
hp.vars.size();
i++) {
9621 for (
i = 0;
i < (
int)
hp.vars.size();
i++) {
9632 std::string
str =
hp.vars[
i].label.c_str();
9635 if (
hp.enable_factor) {
9636 str =
hp.vars[
i].tag_name;
9638 if (
hp.vars[
i].voffset > 0)
9640 else if (
hp.vars[
i].voffset < 0)
9643 if (
hp.vars[
i].factor != 1) {
9644 if (
hp.vars[
i].voffset == 0)
9651 if (
hp.vars[
i].offset > 0)
9653 else if (
hp.vars[
i].offset < 0)
9657 str =
hp.vars[
i].tag_name;
9669 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]);
9672 if (
hp.show_values) {
9676 }
else if (
hsdata->num_entries[
k] > 0) {
9678 }
else if (
hsdata->have_last_written) {
9679 if (
hsdata->last_written[
k]) {
9732 if (buffer ==
NULL) {
9733 rr->rsprintf(
"HTTP/1.1 200 Document follows\r\n");
9736 rr->rsprintf(
"Content-Type: image/gif\r\n");
9737 rr->rsprintf(
"Content-Length: %d\r\n",
length);
9738 rr->rsprintf(
"Cache-control: private, max-age=0, no-cache\r\n");
9739 rr->rsprintf(
"Expires: Fri, 01-Jan-1983 00:00:00 GMT\r\n\r\n");
9743 if (
length > *buffer_size) {
9744 printf(
"return buffer too small\n");
9813 for (
i = 0;
i < 12;
i++)
9823 if (
tms.tm_year < 90)
9832 for (
i = 0;
i < 12;
i++)
9842 if (
tms.tm_year < 90)
9851 redir +=
"?cmd=oldhistory&";
9891 r->
rsprintf(
"<tr><td colspan=2>\n");
9892 r->
rsprintf(
"<input type=hidden name=cmd value=OldHistory>\n");
9893 r->
rsprintf(
"<input type=submit name=hcmd value=Query>\n");
9894 r->
rsprintf(
"<input type=submit name=hcmd value=Cancel>\n");
9896 r->
rsprintf(
"<input type=hidden name=group value=\"%s\">\n", p->
getparam(
"group"));
9898 r->
rsprintf(
"<input type=hidden name=panel value=\"%s\">\n", p->
getparam(
"panel"));
9900 r->
rsprintf(
"<input type=hidden name=htime value=\"%s\">\n", p->
getparam(
"htime"));
9902 r->
rsprintf(
"<input type=hidden name=hscale value=\"%s\">\n", p->
getparam(
"hscale"));
9904 r->
rsprintf(
"<input type=hidden name=hindex value=\"%s\">\n", p->
getparam(
"hindex"));
9908 r->
rsprintf(
"<table class=\"dialogTable\">");
9912 tms.tm_year += 1900;
9914 r->
rsprintf(
"<tr><td nowrap>Start date:</td>");
9916 r->
rsprintf(
"<td>Month: <select name=\"m1\">\n");
9917 r->
rsprintf(
"<option value=\"\">\n");
9918 for (
i = 0;
i < 12;
i++)
9919 if (
i ==
tms.tm_mon)
9925 r->
rsprintf(
" Day: <select name=\"d1\">");
9926 r->
rsprintf(
"<option selected value=\"\">\n");
9927 for (
i = 0;
i < 31;
i++)
9928 if (
i + 1 ==
tms.tm_mday)
9929 r->
rsprintf(
"<option selected value=%d>%d\n",
i + 1,
i + 1);
9931 r->
rsprintf(
"<option value=%d>%d\n",
i + 1,
i + 1);
9938 r->
rsprintf(
" Hour: <input type=\"text\" size=5 maxlength=5 name=\"h1\" value=\"%d\">",
start_hour);
9940 r->
rsprintf(
" Year: <input type=\"text\" size=5 maxlength=5 name=\"y1\" value=\"%d\">",
tms.tm_year);
9943 r->
rsprintf(
"<tr><td nowrap>End date:</td>");
9946 tms.tm_year += 1900;
9948 r->
rsprintf(
"<td>Month: <select name=\"m2\">\n");
9949 r->
rsprintf(
"<option value=\"\">\n");
9950 for (
i = 0;
i < 12;
i++)
9951 if (
i ==
tms.tm_mon)
9957 r->
rsprintf(
" Day: <select name=\"d2\">");
9958 r->
rsprintf(
"<option selected value=\"\">\n");
9959 for (
i = 0;
i < 31;
i++)
9960 if (
i + 1 ==
tms.tm_mday)
9961 r->
rsprintf(
"<option selected value=%d>%d\n",
i + 1,
i + 1);
9963 r->
rsprintf(
"<option value=%d>%d\n",
i + 1,
i + 1);
9970 r->
rsprintf(
" Hour: <input type=\"text\" size=5 maxlength=5 name=\"h2\" value=\"%d\">",
end_hour);
9972 r->
rsprintf(
" Year: <input type=\"text\" size=5 maxlength=5 name=\"y2\" value=\"%d\">",
tms.tm_year);
9988 const char*sa = (
const char*)a;
9989 const char*
sb = (
const char*)b;
9998 printf(
"compare [%s] and [%s]\n", sa,
sb);
10001 if (sa[
i]==0 &&
sb[
i]==0)
10022 if (sa[
i]==
sb[
i]) {
10027 printf(
"index %d, char [%c] [%c]\n",
i, sa[
i],
sb[
i]);
10031 else if (
sb[
i] == 0)
10045 return cmp_names(a.c_str(), b.c_str()) < 0;
10059static int cmp_tags(
const void *a,
const void *b)
10061 const TAG*sa = (
const TAG*)a;
10098 str =
"bad_xdb_find_key";
10118 printf(
"hist plot: %d variables\n", (
int)
hp.vars.size());
10119 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);
10121 for (
size_t i=0;
i<
hp.vars.size();
i++) {
10122 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);
10128 const char*
const colour[] =
10130 "#00AAFF",
"#FF9000",
"#FF00A0",
"#00C030",
10131 "#A0C0D0",
"#D0A060",
"#C04010",
"#807060",
10132 "#F0C000",
"#2090A0",
"#D040D0",
"#90B000",
10133 "#B0B040",
"#B0B0FF",
"#FFA0A0",
"#A0FFA0",
10136 for (
int i=0; colour[
i];
i++) {
10139 for (
size_t j=0;
j<
hp.vars.size();
j++)
10140 if (
hp.vars[
j].colour == colour[
i]) {
10155 for (
size_t i=0;
i<
hp.vars.size();
i++)
10156 if (
hp.vars[
i].order > order)
10157 order =
hp.vars[
i].order;
10165 std::vector<size_t>
colons;
10173 if (
colons.size() == 0) {
10207 std::string path =
"History/Display/";
10212 MVOdb*
o = odb->Chdir(path.c_str());
10217 o->RS(
"Timescale", &
hp->timescale);
10218 o->RD(
"Minimum", &
hp->minimum);
10219 o->RD(
"Maximum", &
hp->maximum);
10220 o->RB(
"Zero ylow", &
hp->zero_ylow);
10221 o->RB(
"Log axis", &
hp->log_axis);
10222 o->RB(
"Zero ylow", &
hp->zero_ylow);
10223 o->RB(
"Show run markers", &
hp->show_run_markers);
10224 o->RB(
"Show values", &
hp->show_values);
10225 o->RB(
"Show fill", &
hp->show_fill);
10226 o->RB(
"Show factor", &
hp->show_factor);
10280 for (
size_t i=0;
i<
num;
i++) {
10295 if (
hp->enable_factor && v.
formula.empty()) {
10301 hp->vars.push_back(v);
10317 hp->show_run_markers = *p->
getparam(
"run_markers");
10318 hp->show_values = *p->
getparam(
"show_values");
10320 hp->show_factor = *p->
getparam(
"show_factor");
10374 hp->vars.push_back(v);
10379 if (
hp->vars[
index].order < 0)
10395 if (
par.length() < 1)
10398 std::string event_name, tag_name;
10401 if (tag_name ==
"")
10411 hp.vars.push_back(v);
10418 cm_msg(
MERROR,
"SaveHistPlotToOdb",
"Error: Cannot write history plot to ODB, group \"%s\", panel \"%s\", invalid group name",
group,
panel);
10423 cm_msg(
MERROR,
"SaveHistPlotToOdb",
"Error: Cannot write history plot to ODB, group \"%s\", panel \"%s\", invalid panel name",
group,
panel);
10427 std::string path =
"History/Display/";
10435 MVOdb*
o = odb->Chdir(path.c_str(),
true);
10437 o->WS(
"Timescale",
hp.timescale.c_str());
10438 o->WD(
"Minimum",
hp.minimum);
10439 o->WD(
"Maximum",
hp.maximum);
10440 o->WB(
"Zero ylow",
hp.zero_ylow);
10441 o->WB(
"Log axis",
hp.log_axis);
10442 o->WB(
"Show run markers",
hp.show_run_markers);
10443 o->WB(
"Show values",
hp.show_values);
10444 o->WB(
"Show fill",
hp.show_fill);
10445 o->WB(
"Show factor and offset",
hp.show_factor);
10457 for (
size_t i=0;
i<
hp.vars.size();
i++) {
10458 hist_vars.push_back(
hp.vars[
i].event_name +
":" +
hp.vars[
i].tag_name);
10468 if (
hp.vars.size() > 0) {
10478 o->Delete(
"Variables");
10479 o->Delete(
"Formula");
10480 o->Delete(
"Colour");
10481 o->Delete(
"Label");
10482 o->Delete(
"Show raw value");
10483 o->Delete(
"Factor");
10484 o->Delete(
"Offset");
10485 o->Delete(
"VOffset");
10497 for (
unsigned i=0;
i<
hp.vars.size();
i++) {
10498 if (
hp.vars[
i].order <= 0) {
10499 hp.vars.erase(
hp.vars.begin() +
i);
10513 for (
size_t i=1;
i<
hp.vars.size();
i++) {
10514 if (
hp.vars[
i-1].order >=
hp.vars[
i].order) {
10543 strcpy(
hcmd,
"Refresh");
10583 r->
rsprintf(
"<table class=\"mtable\">");
10585 r->
rsprintf(
"<tr><th colspan=11 class=\"subStatusTitle\">History Panel \"%s\" / \"%s\"</th></tr>\n",
hgroup,
hpanel);
10588 r->
rsprintf(
"<tr><td colspan=11>\n");
10590 r->
rsprintf(
"<input type=button value=Refresh ");
10591 r->
rsprintf(
"onclick=\"document.form1.hcmd.value='Refresh';document.form1.submit()\">\n");
10593 r->
rsprintf(
"<input type=button value=Save ");
10594 r->
rsprintf(
"onclick=\"document.form1.hcmd.value='Save';document.form1.submit()\">\n");
10597 r->
rsprintf(
"<input type=button value=Cancel ");
10598 std::string
url =
"?cmd=oldhistory&group=";
10602 url +=
"&hcmd=Cancel";
10607 r->
rsprintf(
"onclick=\"window.location.search='%s'\">\n",
url.c_str());
10610 r->
rsprintf(
"<input type=button value=\"Edit in ODB\"");
10611 std::string
url =
"?cmd=odb&odb_path=";
10612 url +=
"/History/Display/";
10616 r->
rsprintf(
"onclick=\"window.location.search='%s'\">\n",
url.c_str());
10619 r->
rsprintf(
"<input type=button value=\"Edit in new editor\"");
10620 std::string
url =
"?cmd=hs_edit";
10629 r->
rsprintf(
"onclick=\"window.location.search='%s'\">\n",
url.c_str());
10631 r->
rsprintf(
"<input type=button value=\"Clear history cache\"");
10632 r->
rsprintf(
"onclick=\"document.form1.hcmd.value='Clear history cache';document.form1.submit()\">\n");
10633 r->
rsprintf(
"<input type=button value=\"Delete panel\"");
10634 r->
rsprintf(
"onclick=\"window.location.search='?cmd=oldhistory&group=%s&panel=%s&hcmd=Delete%%20panel'\">\n",
hgroup,
hpanel);
10637 r->
rsprintf(
"<tr><td colspan=11>\n");
10641 r->
rsprintf(
"<input type=checkbox %s name=sort_vars value=1 onclick=\"this.form.submit();\">Sort variable names",
sort_vars?
"checked":
"");
10645 r->
rsprintf(
" <input type=checkbox %s name=old_vars value=1 onclick=\"this.form.submit();\">Show deleted and renamed variables",
old_vars?
"checked":
"");
10647 if (
hp.show_factor)
10648 r->
rsprintf(
" <input type=checkbox checked name=show_factor value=1 onclick=\"document.form1.hcmd.value='Refresh';document.form1.submit()\">");
10650 r->
rsprintf(
" <input type=checkbox name=show_factor value=1 onclick=\"document.form1.hcmd.value='Refresh';document.form1.submit()\">");
10651 r->
rsprintf(
"Show factor and offset\n");
10654 r->
rsprintf(
"<input type=hidden name=cmd value=Oldhistory>\n");
10655 r->
rsprintf(
"<input type=hidden name=hcmd value=Refresh>\n");
10656 r->
rsprintf(
"<input type=hidden name=panel value=\"%s\">\n",
hpanel);
10657 r->
rsprintf(
"<input type=hidden name=group value=\"%s\">\n",
hgroup);
10660 r->
rsprintf(
"<input type=hidden name=redir value=\"%s\">\n", p->
getparam(
"redir"));
10664 r->
rsprintf(
"<tr><td colspan=4 style='text-align:right'>Time scale (in units 'm', 'h', 'd'):</td>\n");
10665 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());
10667 r->
rsprintf(
"<tr><td colspan=4 style='text-align:right'>Minimum (set to '-inf' for autoscale):</td>\n");
10668 r->
rsprintf(
"<td colspan=3><input type=text size=12 name=minimum value=%f></td><td colspan=4></td></tr>\n",
hp.minimum);
10670 r->
rsprintf(
"<tr><td colspan=4 style='text-align:right'>Maximum (set to 'inf' for autoscale):</td>\n");
10671 r->
rsprintf(
"<td colspan=3><input type=text size=12 name=maximum value=%f></td><td colspan=4></td></tr>\n",
hp.maximum);
10673 r->
rsprintf(
"<tr><td colspan=11>");
10676 r->
rsprintf(
"<input type=checkbox checked name=zero_ylow value=1>");
10678 r->
rsprintf(
"<input type=checkbox name=zero_ylow value=1>");
10679 r->
rsprintf(
"Zero Y; axis\n");
10682 r->
rsprintf(
"<input type=checkbox checked name=log_axis value=1>");
10684 r->
rsprintf(
"<input type=checkbox name=log_axis value=1>");
10685 r->
rsprintf(
"Logarithmic Y axis\n");
10687 if (
hp.show_run_markers)
10688 r->
rsprintf(
" <input type=checkbox checked name=run_markers value=1>");
10690 r->
rsprintf(
" <input type=checkbox name=run_markers value=1>");
10691 r->
rsprintf(
"Show run markers\n");
10693 if (
hp.show_values)
10694 r->
rsprintf(
" <input type=checkbox checked name=show_values value=1>");
10696 r->
rsprintf(
" <input type=checkbox name=show_values value=1>");
10697 r->
rsprintf(
"Show values of variables\n");
10700 r->
rsprintf(
" <input type=checkbox checked name=show_fill value=1>");
10702 r->
rsprintf(
" <input type=checkbox name=show_fill value=1>");
10703 r->
rsprintf(
"Show graph fill\n");
10722 std::vector<std::string>
events;
10731 for (
unsigned i=0;
i<
events.size();
i++)
10740 r->
rsprintf(
"<tr><th colspan=8 class=\"subStatusTitle\">List of available history variables</th></tr>\n");
10741 r->
rsprintf(
"<tr><th colspan=1>Sel<th colspan=1>Equipment<th colspan=1>Event<th colspan=1>Variable</tr>\n");
10747 for (
unsigned e=0;
e<
events.size();
e++) {
10751 if (
eqname.length() < 1)
10777 r->
rsprintf(
"<td><input type=submit name=cmdx value=\"%s\"></td>\n",
qcmd.c_str());
10785 r->
rsprintf(
"<tr><input type=hidden name=\"%s\" value=%d></tr>\n",
qcmd.c_str(), 1);
10804 r->
rsprintf(
"<td><input type=submit name=cmdx value=\"%s\"></td>\n",
rcmd.c_str());
10809 r->
rsprintf(
"<tr><input type=hidden name=\"%s\" value=%d></tr>\n",
rcmd.c_str(), 1);
10813 std::vector<TAG> tags;
10820 std::sort(tags.begin(), tags.end(),
cmp_tags);
10822 for (
unsigned v=0; v<tags.size(); v++) {
10824 for (
unsigned j=0;
j<tags[v].n_data;
j++) {
10827 if (tags[v].n_data == 1)
10856 r->
rsprintf(
"<input type=hidden name=seln value=%d>\n",
i);
10857 r->
rsprintf(
"<input type=submit value=\"Add Selected\">\n");
10862 r->
rsprintf(
"<tr><td colspan=11 style='text-align:left'>New history: displayed_value = formula(history_value)</td></tr>\n");
10863 r->
rsprintf(
"<tr><td colspan=11 style='text-align:left'>Old history: displayed_value = offset + factor*(history_value - voffset)</td></tr>\n");
10864 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");
10865 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");
10866 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");
10867 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");
10870 r->
rsprintf(
"<th>Col<th>Event<th>Variable<th>Formula<th>Colour<th>Label<th>Raw<th>Order");
10871 if (
hp.show_factor) {
10872 r->
rsprintf(
"<th>Factor<th>Offset<th>VOffset");
10878 size_t nvars =
hp.vars.size();
10883 if (
index < nvars) {
10884 if (
hp.vars[
index].colour.empty())
10886 r->
rsprintf(
"<td style=\"background-color:%s\"> <td>\n",
hp.vars[
index].colour.c_str());
10893 r->
rsprintf(
"<select name=\"event%d\" size=1 onChange=\"document.form1.submit()\">\n", (
int)
index);
10898 r->
rsprintf(
"<option value=\"/empty\"><empty>\n");
10900 if (
index==nvars) {
10901 for (
unsigned e=0;
e<
events.size();
e++) {
10902 const char *p =
events[
e].c_str();
10903 r->
rsprintf(
"<option value=\"%s\">%s\n", p, p);
10906 r->
rsprintf(
"<option selected value=\"%s\">%s\n",
hp.vars[
index].event_name.c_str(),
hp.vars[
index].event_name.c_str());
10907 r->
rsprintf(
"<option>(%d events omitted)\n", (
int)
events.size());
10909 bool found =
false;
10910 for (
unsigned e=0;
e<
events.size();
e++) {
10911 const char *s =
"";
10912 const char *p =
events[
e].c_str();
10917 r->
rsprintf(
"<option %s value=\"%s\">%s\n", s, p, p);
10920 const char *p =
hp.vars[
index].event_name.c_str();
10921 r->
rsprintf(
"<option selected value=\"%s\">%s\n", p, p);
10930 if (
index < nvars) {
10936 std::vector<TAG> tags;
10954 std::sort(tags.begin(), tags.end(),
cmp_tags);
10957 printf(
"Event [%s] %d tags\n",
hp.vars[
index].event_name.c_str(), (
int)tags.size());
10959 for (
unsigned v=0; v<tags.size(); v++) {
10965 for (
unsigned v=0; v<tags.size(); v++)
10971 for (
unsigned v=0; v<tags.size(); v++) {
10973 for (
unsigned j=0;
j<tags[v].n_data;
j++) {
10976 if (tags[v].n_data == 1)
10998 if (
hp.vars[
index].tag_name.length() > 0)
10999 r->
rsprintf(
"<option selected value=\"%s\">%s\n",
hp.vars[
index].tag_name.c_str(),
hp.vars[
index].tag_name.c_str());
11002 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());
11003 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());
11005 if (
hp.vars[
index].show_raw_value)
11006 r->
rsprintf(
"<td><input type=checkbox checked name=\"raw%d\" value=1></td>", (
int)
index);
11008 r->
rsprintf(
"<td><input type=checkbox name=\"raw%d\" value=1></td>", (
int)
index);
11009 r->
rsprintf(
"<td><input type=text size=3 maxlength=32 name=\"ord%d\" value=\"%d\"></td>\n", (
int)
index,
hp.vars[
index].order);
11010 if (
hp.show_factor) {
11011 r->
rsprintf(
"<td><input type=text size=6 maxlength=32 name=\"factor%d\" value=\"%g\"></td>\n", (
int)
index,
hp.vars[
index].factor);
11012 r->
rsprintf(
"<td><input type=text size=6 maxlength=32 name=\"offset%d\" value=\"%g\"></td>\n", (
int)
index,
hp.vars[
index].offset);
11013 r->
rsprintf(
"<td><input type=text size=6 maxlength=32 name=\"voffset%d\" value=\"%g\"></td>\n", (
int)
index,
hp.vars[
index].voffset);
11015 r->
rsprintf(
"<input type=hidden name=\"factor%d\" value=\"%f\">\n", (
int)
index,
hp.vars[
index].factor);
11016 r->
rsprintf(
"<input type=hidden name=\"offset%d\" value=\"%f\">\n", (
int)
index,
hp.vars[
index].offset);
11017 r->
rsprintf(
"<input type=hidden name=\"voffset%d\" value=\"%f\">\n", (
int)
index,
hp.vars[
index].voffset);
11020 r->
rsprintf(
"<td colspan=2><input type=submit name=cmdx value=\"List all variables\"></td>\n");
11030 r->
rsprintf(
"</body></html>\r\n");
11065 std::string
ts =
"1h";
11111 for (
int i = 0;
i <
hsdata->nvars;
i++)
11117 for (
int i = 0;
i <
hsdata->nvars;
i++)
11118 if (
hsdata->odb_index[
i] >= 0)
11119 if (
hsdata->num_entries[
i] > 0)
11120 if ((t == 0) || (
hsdata->t[
i][0] > t))
11123 if (t == 0 &&
hsdata->nvars > 1) {
11124 show_error(r,
"No history available for choosen period");
11133 if (
hp.show_run_markers)
11134 for (
int i = 0;
i <
hsdata->nvars;
i++) {
11135 if (
hsdata->odb_index[
i] == -2) {
11139 }
else if (
hsdata->odb_index[
i] == -1) {
11147 r->
rsprintf(
"HTTP/1.1 200 Document follows\r\n");
11149 r->
rsprintf(
"Accept-Ranges: bytes\r\n");
11150 r->
rsprintf(
"Cache-control: private, max-age=0, no-cache\r\n");
11151 r->
rsprintf(
"Expires: Fri, 01 Jan 1983 00:00:00 GMT\r\n");
11152 r->
rsprintf(
"Content-Type: text/plain\r\n");
11153 r->
rsprintf(
"Content-disposition: attachment; filename=\"export.csv\"\r\n");
11158 r->
rsprintf(
"Time, Timestamp, Run, Run State, ");
11163 if (
hsdata->odb_index[
i] < 0)
11165 if (
hsdata->num_entries[
i] <= 0)
11189 for (
int i = 0;
i <
hsdata->nvars;
i++)
11195 for (
int i = 0 ;
i <
hsdata->nvars ;
i++)
11202 printf(
"step to time %d: ", (
int)t);
11203 for (
int i = 0;
i <
hsdata->nvars;
i++) {
11217 strcpy(fmt,
"%Y.%m.%d %H:%M:%S");
11230 for (
int i= 0 ;
i <
hsdata->nvars ;
i++)
11238 if (
hsdata->odb_index[
i] < 0)
11250 for (
int i = 0 ;
i <
hsdata->nvars ;
i++)
11296 redir +=
"?cmd=oldhistory&group=";
11298 redir +=
"&panel=";
11315 redir +=
"?cmd=oldhistory&group=";
11317 redir +=
"&panel=";
11336 r->
rsprintf(
"<table class=\"dialogTable\">");
11337 r->
rsprintf(
"<tr><th class=\"subStatusTitle\" colspan=2>New History Item</th><tr>");
11338 r->
rsprintf(
"<tr><td align=center colspan=2>\n");
11339 r->
rsprintf(
"Select group: ");
11340 r->
rsprintf(
"<select id=\"group\" name=\"group\">\n");
11346 for (
i = 0;;
i++) {
11359 if (!
hkey ||
i == 0)
11360 r->
rsprintf(
"<option>Default</option>\n");
11363 r->
rsprintf(
"Or enter new group name: ");
11364 r->
rsprintf(
"<input type=text size=15 maxlength=31 id=new_group name=new_group>\n");
11366 r->
rsprintf(
"<tr><td align=center colspan=2>\n");
11367 r->
rsprintf(
"<br>Panel name: ");
11368 r->
rsprintf(
"<input type=text size=15 maxlength=31 id=panel name=panel><br><br>\n");
11371 r->
rsprintf(
"<tr><td align=center colspan=2>");
11372 std::string
str =
"?cmd=oldhistory&hcmd=createnew";
11373 str +=
"&new_group='+document.getElementById('new_group').value+'";
11374 str +=
"&group='+document.getElementById('group').value+'";
11375 str +=
"&panel='+document.getElementById('panel').value+'";
11376 r->
rsprintf(
"<input type=button value=Submit onclick=\"window.location.search='%s'\">\n",
str.c_str());
11382 r->
rsprintf(
"</body></html>\r\n");
11389 path +=
"/History/Display/";
11403 while (
hpanel[0] ==
' ') {
11437 std::string bgcolor =
"FFFFFF";
11441 std::string fgcolor =
"000000";
11454 else if (p->
isparam(
"htime"))
11494 generate_hist_graph(odb, r,
hgroup,
hpanel,
fbuffer, &
fsize, width, height,
endtime, scale,
index,
labels, bgcolor.c_str(), fgcolor.c_str(),
gridcolor.c_str());
11499 if (dir.length() > 0 && dir[dir.length()-1] !=
DIR_SEPARATOR)
11506 tms.tm_year % 100,
tms.tm_mon + 1,
tms.tm_mday,
11591 height = (
int)(0.625 * width);
11596 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());
11610 time_t last_written = 0;
11613 endtime = last_written + scale/2;
11619 time_t last_written = 0;
11623 endtime = last_written + scale/2;
11666 r->
rsprintf(
"<script type=\"text/javascript\" src=\"midas.js\"></script>\n");
11667 r->
rsprintf(
"<script type=\"text/javascript\" src=\"mhttpd.js\"></script>\n");
11670 r->
rsprintf(
"<table class=\"mtable\">");
11671 r->
rsprintf(
"<tr><th class=\"mtableheader\" colspan=2>History</th></tr>");
11677 path +=
"/History/Display/";
11683 r->
rsprintf(
"<h1>Error: History panel \"%s\" in group \"%s\" does not exist</h1>\n",
hpanel,
hgroup);
11687 r->
rsprintf(
"</body></html>\r\n");
11694 r->
rsprintf(
"<input type=hidden name=hscale id=hscale value=%d>\n", scale);
11699 path +=
"/History/Display/";
11703 path +=
"/Timescale";
11717 r->
rsprintf(
"<input type=hidden name=hscale id=hscale value=%s>\n",
scalestr.c_str());
11725 r->
rsprintf(
"<input type=hidden name=hwidth id=hwidth value=%s>\n",
pwidth);
11727 r->
rsprintf(
"<input type=hidden name=hheight id=hheight value=%s>\n",
pheight);
11729 r->
rsprintf(
"<input type=hidden name=hindex id=hindex value=%s>\n",
pindex);
11735 r->
rsprintf(
"<tr><td colspan=2><input type=\"button\" name=\"New\" value=\"New\" ");
11736 r->
rsprintf(
"onClick=\"window.location.href='?cmd=oldhistory&hcmd=New'\"></td></tr>\n");
11739 r->
rsprintf(
"<tr><td colspan=2 style=\"text-align:left;\">\n");
11741 r->
rsprintf(
"<b>Please select panel:</b><br>\n");
11744 r->
rsprintf(
"<table class=\"historyTable\">");
11747 r->
rsprintf(
"<tr><td colspan=2 class=\"titleCell\">\n");
11751 r->
rsprintf(
"<a href=\"?cmd=oldhistory&group=All\">ALL</a>\n");
11759 strcpy(
str,
"System:Trigger per sec.");
11779 for (
i = 0;;
i++) {
11795 r->
rsprintf(
"<tr><td class=\"titleCell\"><a href=\"?cmd=oldhistory&group=%s\">%s</a></td>\n<td>",
enc_name,
key.
name);
11797 for (
j = 0;;
j++) {
11813 r->
rsprintf(
"<small><b>%s</b></small> ",
ikey.name);
11826 r->
rsprintf(
"<tr><td colspan=2>\n");
11830 r->
rsprintf(
"<select title=\"Select group\" id=\"fgroup\" onChange=\"window.location.search='?cmd=oldhistory&group='+document.getElementById('fgroup').value;\">\n");
11835 for (
i = 0;;
i++) {
11855 r->
rsprintf(
"<option selected value=\"%s\">%s\n",
"ALL",
"ALL");
11857 r->
rsprintf(
"<option value=\"%s\">%s\n",
"ALL",
"ALL");
11861 r->
rsprintf(
" Panel:\n");
11862 r->
rsprintf(
"<select title=\"Select panel\" id=\"fpanel\" ");
11863 r->
rsprintf(
"onChange=\"window.location.search='?cmd=oldhistory&group='+document.getElementById('fgroup').value+");
11864 r->
rsprintf(
"'&panel='+document.getElementById('fpanel').value;\">\n");
11868 for (
i = 0;;
i++) {
11887 r->
rsprintf(
"<option value=\"\">- all -\n");
11889 r->
rsprintf(
"<option selected value=\"\">- all -\n");
11895 r->
rsprintf(
"<input type=submit value=\"Go\">\n");
11898 r->
rsprintf(
" <input type=\"button\" name=\"New\" value=\"New\" ");
11899 r->
rsprintf(
"onClick=\"window.location.href='?cmd=oldhistory&hcmd=New&group=%s'\">\n",
hgroup);
11901 r->
rsprintf(
"<input type=\"button\" name=\"Cmd\" value=\"Reset\" onClick=\"window.location.href='?cmd=oldhistory&hcmd=Reset&group=%s&panel=%s'\">\n",
hgroup,
hpanel);
11903 r->
rsprintf(
"<input type=\"button\" name=\"Cmd\" value=\"Query\" onClick=\"window.location.href='?cmd=oldhistory&hcmd=Query&group=%s&panel=%s'\">\n",
hgroup,
hpanel);
11910 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);
11923 path +=
"/History/Display/";
11927 for (
i = 0 ;;
i++) {
11940 ref +=
"graph.gif?width=";
11942 ref +=
"&cmd=oldhistory&group=";
11948 ref2 +=
"?cmd=oldhistory&group=";
11963 r->
rsprintf(
"<tr><td><a href=\"%s\"><img src=\"%s\"></a>\n",
ref2.c_str(),
ref.c_str());
11965 r->
rsprintf(
"<td><a href=\"%s\"><img src=\"%s\"></a></tr>\n",
ref2.c_str(),
ref.c_str());
11979 path +=
"/History/Display/";
11983 path +=
"/Buttons";
11990 cm_msg(
MERROR,
"show_hist_page",
"Cannot create history panel with invalid ODB path \"%s\"", path.c_str());
11997 r->
rsprintf(
"function histDisp(p) {\n");
11999 r->
rsprintf(
" params += '&'+p;\n");
12000 r->
rsprintf(
" if (document.getElementById(\'hscale\') !== null)\n");
12001 r->
rsprintf(
" params += '&hscale='+document.getElementById(\'hscale\').value;\n");
12002 r->
rsprintf(
" if (document.getElementById(\'htime\') !== null)\n");
12003 r->
rsprintf(
" params += '&htime='+document.getElementById(\'htime\').value;\n");
12004 r->
rsprintf(
" if (document.getElementById(\'hwdith\') !== null)\n");
12005 r->
rsprintf(
" params += '&hwidth='+document.getElementById(\'hwidth\').value;\n");
12006 r->
rsprintf(
" if (document.getElementById(\'hindex\') !== null)\n");
12007 r->
rsprintf(
" params += '&hindex='+document.getElementById(\'hindex\').value;\n");
12008 r->
rsprintf(
" window.location.search = params;\n");
12016 size =
sizeof(
str);
12018 r->
rsprintf(
"<input type=\"button\" title=\"display last %s\" value=%s onclick=\"histDisp('scale=%s')\">\n",
str,
str,
str);
12021 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')\">");
12022 r->
rsprintf(
"<input type=\"button\" value=\"<<\" title=\"go back in time to last available data\" onclick=\"histDisp('shift=leftmax')\">");
12023 r->
rsprintf(
"<input type=\"button\" value=\"<\" title=\"go back in time\" onclick=\"histDisp('shift=left')\">");
12025 r->
rsprintf(
"<input type=\"button\" value=\" + \" title=\"zoom in\" onclick=\"histDisp('shift=zoomin')\">");
12026 r->
rsprintf(
"<input type=\"button\" value=\" - \" title=\"zoom out\" onclick=\"histDisp('shift=zoomout')\">");
12029 r->
rsprintf(
"<input type=\"button\" value=\">\" title=\"go forward in time\" onclick=\"histDisp('shift=right')\">");
12030 r->
rsprintf(
"<input type=\"button\" value=\">>\" title=\"go to currently updated fresh data\" onclick=\"histDisp('shift=rightmax')\">");
12034 r->
rsprintf(
"<input type=\"button\" value=\"Large\" title=\"large display\" onclick=\"histDisp('width=Large')\">\n");
12035 r->
rsprintf(
"<input type=\"button\" value=\"Small\" title=\"large display\" onclick=\"histDisp('width=Small')\">\n");
12036 r->
rsprintf(
"<input type=\"button\" value=\"Create Elog\" title=\"large display\" onclick=\"histDisp('hcmd=Create Elog')\">\n");
12037 r->
rsprintf(
"<input type=\"button\" value=\"Config\" title=\"large display\" onclick=\"histDisp('hcmd=Config')\">\n");
12038 r->
rsprintf(
"<input type=\"button\" value=\"Export\" title=\"large display\" onclick=\"histDisp('hcmd=Export')\">\n");
12050 std::string
wi =
"640";
12062 path +=
"/History/Display/";
12066 path +=
"/Variables";
12079 ref +=
"?cmd=oldhistory&group=";
12090 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());
12094 std::string
ref =
"?cmd=oldhistory&group=";
12113 r->
rsprintf(
" <area shape=rect coords=\"%d,%d,%d,%d\" href=\"%s\">\r\n", 0, 0, width, 20,
ref.c_str());
12124 ref +=
"graph.gif?cmd=oldhistory&group=";
12131 r->
rsprintf(
"<tr><td colspan=2><img src=\"%s\" usemap=\"#%s\"></tr>\n",
ref.c_str(),
hpanel);
12138 for (
i = 0,
k = 0;;
i++) {
12150 for (
j = 0;;
j++,
k++) {
12164 ref +=
"graph.gif?width=Small";
12165 ref +=
"&cmd=oldhistory&group=";
12171 ref2 +=
"?cmd=oldhistory&group=";
12186 r->
rsprintf(
"<tr><td><a href=\"%s\"><img src=\"%s\"></a>\n",
ref2.c_str(),
ref.c_str());
12188 r->
rsprintf(
"<td><a href=\"%s\"><img src=\"%s\"></a></tr>\n",
ref2.c_str(),
ref.c_str());
12195 r->
rsprintf(
"</body></html>\r\n");
12204 const unsigned char *
picon;
12205 char str[256], format[256];
12211 }
else if (
strstr(
icon,
"favicon.png") != 0) {
12217 r->
rsprintf(
"HTTP/1.1 200 Document follows\r\n");
12219 r->
rsprintf(
"Accept-Ranges: bytes\r\n");
12223 now += (
int) (3600 * 24);
12226 strcpy(format,
"%A, %d-%b-%y %H:%M:%S GMT");
12231 r->
rsprintf(
"Content-Type: image/x-icon\r\n");
12233 r->
rsprintf(
"Content-Type: image/png\r\n");
12287 const char* password = p->
getparam(
"pwd");
12289 const char* command = p->
getparam(
"cmd");
12312 if (!password[0] &&
hkey) {
12314 int size =
sizeof(
str);
12330 r->
rsprintf(
"HTTP/1.1 302 Found\r\n");
12344 r->
rsprintf(
"Set-Cookie: midas_pwd=%s; path=/; expires=%s\r\n",
12347 r->
rsprintf(
"Location: ./\n\n<html>redir</html>\r\n");
12356 r->
rsprintf(
"HTTP/1.1 302 Found\r\n");
12373 r->
rsprintf(
"Location: %s\n\n<html>redir</html>\r\n",
str);
12458 path +=
"/Script/";
12484 path +=
"/CustomScript/";
12485 path += p->
getparam(
"customscript");
12512 std::string filename =
custom[
"Status"];
12674 show_error(r,
"MSCB support not compiled into this version of mhttpd");
12692 if (
strncmp(command,
"Trigger", 7) == 0) {
12711 path +=
"/Equipment/";
12713 path +=
"/Common/Frontend name";
12720 path +=
"/Equipment/";
12722 path +=
"/Common/Event ID";
12729 str +=
"Frontend \"";
12731 str +=
"\" not running!";
12738 str +=
"Cannot connect to frontend \"";
12760 if (
strncmp(command,
"Next Subrun", 11) == 0) {
12847 if (
equal_ustring(command,
"Create ELog from this page")) {
12849 redir +=
"?cmd=New+elog";
12850 redir +=
"&odb_path=";
12876 r->
rsprintf(
"HTTP/1.1 302 Found\r\n");
12883 now += 3600 * 24 * 365;
12891 r->
rsprintf(
"Set-Cookie: midas_refr=%d; path=/; expires=%s\r\n", refresh,
str);
12892 r->
rsprintf(
"Location: ./\r\n\r\n<html>redir</html>\r\n");
12943 int size =
sizeof(
str);
12945 if (
strcmp(
c->cookie_wpwd.c_str(),
str) == 0)
12951 std::string odb_path;
12953 odb_path = p->
getparam(
"odb_path");
12984 if ((command[0]==0) &&
dec_path[0]) {
12986 std::string
new_url =
"./?cmd=odb";
12993 if ((command[0]==0) &&
dec_path[0]) {
12999 for (
const char* s =
dec_path; *s; s++) {
13042 std::string odb_path;
13047 odb_path +=
"/Custom/Images/";
13049 odb_path +=
"/Background";
13058 str +=
"Invalid custom gif name \'";
13060 str +=
"\' contains \'..\'";
13074 odb_path +=
"/Custom/";
13085 odb_path +=
"/Custom/";
13097 odb_path +=
"/Custom/";
13115 str +=
"Invalid custom page name \'";
13117 str +=
"\' contains \'..\'";
13137 str +=
"Invalid custom file name \'";
13139 str +=
"\' contains \'..\'";
13177 r->
rsprintf(
"HTTP/1.1 400 Bad Request\r\n");
13181 r->
rsprintf(
"Error: Invalid URL \"%s\" or query \"%s\" or command \"%s\"\n", p->
getparam(
"path"), p->
getparam(
"query"), command);
13188 int len =
strlen(query_string);
13189 char *buf = (
char *)
malloc(len+1);
13190 assert(buf !=
NULL);
13191 memcpy(buf, query_string, len+1);
13194 while (p !=
NULL) {
13219 param->initparam();
13224 mstrlcpy(path,
string + 1,
sizeof(path));
13230 param->setparam(
"path", path);
13232 assert(query_string !=
NULL);
13236 param->setparam(
"query", query_string);
13243 param->freeparam();
13262 mstrlcpy(path, header + 1,
sizeof(path));
13268 param->setparam(
"path", path);
13272 const char*
pinit = string;
13278 if (
strstr(
string, boundary))
13282 printf(
"decode_post: -->[%s]<--\n",
string);
13286 if (
strstr(
string,
"name=")) {
13288 if (*
pitem ==
'\"')
13304 if (
strstr(p,
"\r\n\r\n"))
13305 string =
strstr(p,
"\r\n\r\n") + 4;
13306 else if (
strstr(p,
"\r\r\n\r\r\n"))
13307 string =
strstr(p,
"\r\r\n\r\r\n") + 6;
13324 const char*
ptmp = string;
13325 const char* p =
NULL;
13327 while (*
ptmp !=
'-')
13348 char* buf = (
char*)
malloc(size+1);
13352 memcpy(buf,
string, size);
13362 const char* p =
pitem;
13363 if (
strstr(p,
"\r\n\r\n"))
13364 p =
strstr(p,
"\r\n\r\n") + 4;
13365 else if (
strstr(p,
"\r\r\n\r\r\n"))
13366 p =
strstr(p,
"\r\r\n\r\r\n") + 6;
13372 char*
pb = (
char*)(
strstr(p, boundary));
13377 while (*
ptmp ==
'-' || *
ptmp ==
'\n' || *
ptmp ==
'\r')
13388 while (*
string ==
'-' || *
string ==
'\n' || *
string ==
'\r')
13420 cm_msg(
MINFO,
"check_odb_records",
"ODB subtree /Runinfo corrected successfully");
13422 cm_msg(
MERROR,
"check_odb_records",
"Cannot correct ODB subtree /Runinfo, db_check_record() status %d",
status);
13426 cm_msg(
MERROR,
"check_odb_records",
"ODB subtree /Runinfo does not exist");
13429 cm_msg(
MINFO,
"check_odb_records",
"ODB subtree /Runinfo created successfully");
13431 cm_msg(
MERROR,
"check_odb_records",
"Cannot create ODB subtree /Runinfo, db_create_record() status %d",
status);
13435 cm_msg(
MERROR,
"check_odb_records",
"Cannot correct ODB subtree /Runinfo, db_check_record() status %d",
status);
13441 for (
i = 0 ;;
i++) {
13451 cm_msg(
MINFO,
"check_odb_records",
"ODB subtree /Equipment/%s/Common corrected successfully",
key.
name);
13453 cm_msg(
MERROR,
"check_odb_records",
"Cannot correct ODB subtree /Equipment/%s/Common, db_check_record() status %d",
key.
name,
status);
13456 cm_msg(
MERROR,
"check_odb_records",
"Cannot correct ODB subtree /Equipment/%s/Common, db_check_record() status %d",
key.
name,
status);
13476#ifdef HAVE_MONGOOSE6
13480#ifdef HAVE_MONGOOSE6
13481static const std::string
gOdbAllowedHosts =
"/Experiment/Security/mhttpd hosts/Allowed hosts";
13484#ifdef HAVE_MONGOOSE6
13488 cm_msg(
MINFO,
"load_allowed_hosts",
"Reloading mhttpd hosts access control list via hotlink callback");
13498 for (
int i=0; ;
i++) {
13507 if (s.length() < 1)
13525 cm_msg(
MERROR,
"load_allowed_hosts",
"Cannot resize the allowed hosts access control list, db_resize_string(%d) status %d",
new_size,
status);
13544 cm_msg(
MERROR,
"init_allowed_hosts",
"Cannot create the mhttpd hosts access control list, db_get_value_string() status %d",
status);
13551 cm_msg(
MERROR,
"init_allowed_hosts",
"Cannot find the mhttpd hosts access control list, db_find_key() status %d",
status);
13560 cm_msg(
MERROR,
"init_allowed_hosts",
"Cannot watch the mhttpd hosts access control list, db_watch() status %d",
status);
13601 printf(
"Rejecting connection from \'%s\'\n",
hname);
13619 memset(&bind_addr, 0,
sizeof(bind_addr));
13620 bind_addr.sin_family =
AF_INET;
13622 bind_addr.sin_port =
htons((
short) port);
13647 printf(
"mhttpd is listening on port %d\n", port);
13669 FILE*
fp =
fopen(path.c_str(),
"r");
13673 printf(
"file \"%s\": OK!\n", path.c_str());
13675 printf(
"file \"%s\": not found.\n", path.c_str());
13709#ifdef HAVE_MONGOOSE6
13713#ifdef HAVE_MONGOOSE616
13717extern void cs_md5(
char buf[33], ...);
13725#ifdef HAVE_MONGOOSE616
13729#ifdef HAVE_MONGOOSE6
13773 const char *nonce,
size_t nonce_len,
const char *nc,
13776 static const char colon[] =
":";
13777 static const size_t one = 1;
13781 cs_md5(
resp,
ha1,
ha1_len,
colon,
one, nonce,
nonce_len,
colon,
one, nc,
13806 "HTTP/1.1 401 Unauthorized\r\n"
13807 "WWW-Authenticate: Digest qop=\"auth\", "
13808 "realm=\"%s\", nonce=\"%lu\"\r\n"
13809 "Content-Length: 0\r\n\r\n",
13819 auth->passwd_filename = path;
13820 auth->passwords.clear();
13823 cm_msg(
MERROR,
"mongoose",
"mongoose web server cannot find password file \"%s\"", path.c_str());
13824 cm_msg(
MERROR,
"mongoose",
"please create password file: touch %s", path.c_str());
13847 if (
e.realm ==
auth->realm) {
13849 auth->passwords.push_back(
e);
13859#ifdef HAVE_MONGOOSE6
13862 assert(!
"this code is untested!");
13868 if (buf_size == 0) {
13870 buf = (
char*)
malloc(buf_size);
13871 assert(buf !=
NULL);
13881 if (size < buf_size) {
13882 std::string s = buf;
13887 buf_size = buf_size*2 + 16;
13888 buf = (
char*)
realloc(buf, buf_size);
13889 assert(buf !=
NULL);
13894#ifdef HAVE_MONGOOSE616
13902 assert(buf !=
NULL);
13903 std::string s = buf;
13931 if (user.length()<1)
return "";
13932 if (cnonce.length()<1)
return "";
13933 if (
response.length()<1)
return "";
13934 if (uri.length()<1)
return "";
13935 if (qop.length()<1)
return "";
13936 if (nc.length()<1)
return "";
13937 if (nonce.length()<1)
return "";
13959 for (
unsigned i=0;
i<
auth->passwords.size();
i++) {
13961 if (
e->username != user)
13963 if (
e->realm !=
auth->realm)
13972 nonce.c_str(), nonce.length(),
13973 nc.c_str(), nc.length(),
13974 cnonce.c_str(), cnonce.length(),
13975 qop.c_str(), qop.length(),
13980 return e->username;
13987#ifdef HAVE_MONGOOSE616
13998 std::string hostname;
14017 printf(
"%3d: %s \"%s\", ok %d, count_used %d, age created: %d, last_used %d",
14019 e->ipv4?
"IPv4":(
e->
ipv6?
"IPv6":
"????"),
14026 if (
e->gai_status) {
14027 printf(
", getnameinfo() status %d (%s)",
e->gai_status,
e->gai_strerror.c_str());
14049 printf(
"Rejecting connection from unknown address family %d (AF_xxx)\n", sa->
sa.sa_family);
14062 e->time_last_used =
now;
14069 e->time_last_used =
now;
14076 if (
e->time_last_used <
now - 24*60*60) {
14077 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);
14089 bool found =
false;
14100 e->time_created =
now;
14101 e->time_last_used =
now;
14116 if (
e->gai_status) {
14119 printf(
"Rejecting connection from \'%s\', getnameinfo() status %d (%s)\n",
hname,
e->gai_status,
e->gai_strerror.c_str());
14130 if (
e->hostname ==
"localhost.localdomain")
14132 else if (
e->hostname ==
"localhost")
14143 printf(
"Rejecting connection from \'%s\'\n",
hname);
14155 return std::string(s->
p, s->
len);
14197 printf(
"handle_event_mg: nc %p, ev %d, ev_data %p -> accept\n", nc,
ev,
ev_data);
14201 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);
14210 printf(
"handle_event_mg: nc %p, ev %d, ev_data %p -> send %d bytes\n", nc,
ev,
ev_data, *(
int*)
ev_data);
14214 printf(
"handle_event_mg: nc %p, ev %d, ev_data %p -> close\n", nc,
ev,
ev_data);
14218 printf(
"handle_event_mg: nc %p, ev %d, ev_data %p\n", nc,
ev,
ev_data);
14227 char cookie_pwd[256];
14228 char cookie_wpwd[256];
14229 char cookie_cpwd[256];
14232 cookie_wpwd[0] = 0;
14233 cookie_cpwd[0] = 0;
14236 if (s.length() > 0) {
14237 mstrlcpy(cookie_pwd, s.c_str(),
sizeof(cookie_pwd));
14238 cookie_pwd[
strcspn(cookie_pwd,
" ;\r\n")] = 0;
14243 mstrlcpy(cookie_wpwd, s.c_str(),
sizeof(cookie_pwd));
14244 cookie_wpwd[
strcspn(cookie_wpwd,
" ;\r\n")] = 0;
14249 mstrlcpy(cookie_cpwd, s.c_str(),
sizeof(cookie_pwd));
14250 cookie_cpwd[
strcspn(cookie_cpwd,
" ;\r\n")] = 0;
14256 if (s.length() > 0)
14257 c->refresh =
atoi(s.c_str());
14265 c->cookie_pwd = cookie_pwd;
14266 c->cookie_wpwd = cookie_wpwd;
14267 c->cookie_cpwd = cookie_cpwd;
14270#define RESPONSE_SENT 1
14271#define RESPONSE_QUEUED 2
14272#define RESPONSE_501 3
14282#ifdef HAVE_MONGOOSE6
14300 printf(
"handle_decode_get: return buffer length %d bytes, strlen %d\n",
rr->return_length, (
int)
strlen(
rr->return_buffer));
14304 if (
rr->return_length == -1) {
14306#ifdef HAVE_MONGOOSE6
14313 if (
rr->return_length == 0)
14314 rr->return_length =
strlen(
rr->return_buffer);
14318#ifdef HAVE_MONGOOSE6
14322 mg_send(nc,
rr->return_buffer,
rr->return_length);
14324 if (!
strstr(
rr->return_buffer,
"Content-Length")) {
14338#ifdef HAVE_MONGOOSE616
14365 return ncud->ncseqno;
14377 bool mjsonrpc =
false;
14381 std::string query_string;
14409 std::thread* fThread =
NULL;
14412 std::deque<MongooseWorkObject*>
fQueue;
14413 std::condition_variable
fNotify;
14438 if (
to->fNc == nc) {
14476 if (
to->fNc == nc) {
14490 assert(
to->fNc == nc);
14492 to->fQueue.push_back(w);
14493 to->fMutex.unlock();
14494 to->fNotify.notify_one();
14502 w->http_get =
true;
14505 w->query_string = query_string;
14516 w->http_post =
true;
14519 w->query_string = query_string;
14521 w->post_boundary = boundary;
14532 w->mjsonrpc =
true;
14559 decode_get(
rr,
NULL, &w->cookies, w->uri.c_str(), w->query_string.c_str(), w->t);
14562 printf(
"handle_decode_get: return buffer length %d bytes, strlen %d\n",
rr->return_length, (
int)
strlen(
rr->return_buffer));
14566 if (
rr->return_length == -1) {
14573 if (
rr->return_length == 0)
14574 rr->return_length =
strlen(
rr->return_buffer);
14582 if (!
strstr(
rr->return_buffer,
"Content-Length")) {
14600 const char*
post_data = w->post_body.c_str();
14619 printf(
"handle_decode_post: return buffer length %d bytes, strlen %d\n",
rr->return_length, (
int)
strlen(
rr->return_buffer));
14621 if (
rr->return_length == -1) {
14627 if (
rr->return_length == 0)
14628 rr->return_length =
strlen(
rr->return_buffer);
14633 if (!
strstr(
rr->return_buffer,
"Content-Length")) {
14650 w->t->fRPC = w->post_body;
14668 reply->GetArrayBuffer(&ptr, &size);
14671 headers +=
"HTTP/1.1 200 OK\n";
14672 if (w->origin.length() > 0)
14673 headers +=
"Access-Control-Allow-Origin: " + w->origin +
"\n";
14675 headers +=
"Access-Control-Allow-Origin: *\n";
14676 headers +=
"Access-Control-Allow-Credentials: true\n";
14678 headers +=
"Content-Type: application/octet-stream\n";
14701 headers +=
"HTTP/1.1 200 OK\n";
14702 if (w->origin.length() > 0)
14703 headers +=
"Access-Control-Allow-Origin: " + w->origin +
"\n";
14705 headers +=
"Access-Control-Allow-Origin: *\n";
14706 headers +=
"Access-Control-Allow-Credentials: true\n";
14708 headers +=
"Content-Type: application/json\n";
14712 printf(
"-----------------------\nSending headers: %s",
headers.c_str());
14714 printf(
"-----------------------\nSending reply (%d bytes): %s\n\n\n", (
int)
reply_string.size(), r.c_str());
14734 else if (w->http_post)
14736 else if (w->mjsonrpc)
14747 char boundary[256];
14750 if (
ct.length() > 0) {
14751 const char* s =
strstr(
ct.c_str(),
"boundary=");
14753 mstrlcpy(boundary, s+9,
sizeof(boundary));
14756#ifdef HAVE_MONGOOSE616
14770#ifdef HAVE_MONGOOSE6
14786 printf(
"handle_decode_post: return buffer length %d bytes, strlen %d\n",
rr->return_length, (
int)
strlen(
rr->return_buffer));
14788 if (
rr->return_length == -1) {
14789#ifdef HAVE_MONGOOSE6
14796 if (
rr->return_length == 0)
14797 rr->return_length =
strlen(
rr->return_buffer);
14799#ifdef HAVE_MONGOOSE6
14803 mg_send(nc,
rr->return_buffer,
rr->return_length);
14805 if (!
strstr(
rr->return_buffer,
"Content-Length")) {
14822 printf(
"handle_http_get: uri [%s], query [%s]\n", uri, query_string.c_str());
14824 if (query_string ==
"mjsonrpc_schema") {
14826 std::string
reply = s->Stringify();
14834 headers +=
"HTTP/1.1 200 OK\n";
14838 headers +=
"Access-Control-Allow-Origin: *\n";
14839 headers +=
"Access-Control-Allow-Credentials: true\n";
14841 headers +=
"Content-Type: application/json\n";
14858 if (query_string ==
"mjsonrpc_schema_text") {
14868 headers +=
"HTTP/1.1 200 OK\n";
14872 headers +=
"Access-Control-Allow-Origin: *\n";
14873 headers +=
"Access-Control-Allow-Credentials: true\n";
14875 headers +=
"Content-Type: text/plain\n";
14892#ifdef HAVE_MONGOOSE616
14906 printf(
"handle_http_post: uri [%s], query [%s], post data %d bytes\n", uri, query_string.c_str(), (
int)
post_data.length());
14910 if (query_string.substr(0, 8) ==
"mjsonrpc") {
14916 headers +=
"HTTP/1.1 415 Unsupported Media Type\n";
14936#ifdef HAVE_MONGOOSE616
14945#ifdef HAVE_MONGOOSE6
14956#ifdef HAVE_MONGOOSE6
14963 reply->GetArrayBuffer(&ptr, &size);
14966 headers +=
"HTTP/1.1 200 OK\n";
14970 headers +=
"Access-Control-Allow-Origin: *\n";
14971 headers +=
"Access-Control-Allow-Credentials: true\n";
14973 headers +=
"Content-Type: application/octet-stream\n";
14997 headers +=
"HTTP/1.1 200 OK\n";
15001 headers +=
"Access-Control-Allow-Origin: *\n";
15002 headers +=
"Access-Control-Allow-Credentials: true\n";
15004 headers +=
"Content-Type: application/json\n";
15065 headers +=
"HTTP/1.1 200 OK\n";
15070 headers +=
"Access-Control-Allow-Origin: *\n";
15071 headers +=
"Access-Control-Allow-Headers: Content-Type\n";
15072 headers +=
"Access-Control-Allow-Credentials: true\n";
15073 headers +=
"Access-Control-Max-Age: 120\n";
15074 headers +=
"Content-Length: 0\n";
15075 headers +=
"Content-Type: text/plain\n";
15092#ifdef HAVE_MONGOOSE616
15104 printf(
"handle_http_message: method [%s] uri [%s] proto [%s]\n", method.c_str(), uri.c_str(),
mgstr(&msg->
proto).c_str());
15110 t->
fQuery = query_string;
15114 if (method ==
"OPTIONS" && query_string ==
"mjsonrpc" &&
mg_get_http_header(msg,
"Access-Control-Request-Method") !=
NULL) {
15137 printf(
"handle_http_message: auth user: \"%s\"\n", username.c_str());
15139 if (username.length() == 0) {
15141 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());
15153#ifdef HAVE_MONGOOSE616
15155 std::string::size_type
p1 = uri.find(
"/", 1);
15156 if (
p1 == uri.length()-1) {
15157 std::string
response =
"404 Not Found (Proxy name is missing)";
15163 std::string::size_type
p2 = uri.find(
"/",
p1+1);
15164 if (
p2 == std::string::npos) {
15165 std::string
response =
"404 Not Found (Proxy URL should end with a slash)";
15171 std::string p = uri.substr(
p1+1,
p2-
p1-1);
15173 if (p.length() < 1) {
15174 std::string
response =
"404 Not Found (Double-slash or Proxy name is too short)";
15183 std::string
response =
"404 Not Found (Proxy not found in ODB)";
15189 std::string
response =
"404 Not Found (Proxy commented-out in ODB)";
15195 std::string
response =
"404 Not Found (Proxy address should not end with a slash)";
15201 std::string
response =
"404 Not Found (Proxy address does not start with http";
15225 if (method ==
"GET")
15227 else if (method ==
"POST")
15232 printf(
"handle_http_message: sending 501 Not Implemented error\n");
15234 std::string
response =
"501 Not Implemented";
15245#ifdef HAVE_MONGOOSE6
15252 printf(
"handle_http_event_mg: nc %p, ev %d, ev_data %p -> http request\n", nc,
ev,
ev_data);
15257 printf(
"handle_http_event_mg: nc %p, ev %d, ev_data %p\n", nc,
ev,
ev_data);
15269 printf(
"handle_http_redirect: nc %p, ev %d, ev_data %p -> http request\n", nc,
ev,
ev_data);
15271 mg_printf(nc,
"HTTP/1.1 302 Found\r\nLocation: https://%s%s\r\n\r\n",
15272 ((std::string*)(nc->
user_data))->c_str(),
15279 printf(
"handle_http_redirect: nc %p, ev %d, ev_data %p\n", nc,
ev,
ev_data);
15285#ifdef HAVE_MONGOOSE616
15292static std::atomic_int
s_rseqno{1};
15353 if (
res->send_501) {
15354 std::string
response =
"501 Not Implemented";
15365 if (
res->close_flag) {
15372 res->w->send_done =
true;
15387 res.send_501 =
false;
15444 res.close_flag =
false;
15445 res.send_501 =
true;
15480 printf(
"handle_http_message: sending 501 Not Implemented error\n");
15484 req.w->t->fCompleted =
true;
15500 std::unique_lock<std::mutex>
ulm(
to->fMutex, std::defer_lock);
15502 to->fIsRunning =
true;
15508 while (
to->fQueue.empty()) {
15510 to->fNotify.wait(
ulm);
15520 w =
to->fQueue.front();
15521 to->fQueue.pop_front();
15530 printf(
"handle_http_message: sending 501 Not Implemented error\n");
15536 if (!w->send_done) {
15542 w->t->fCompleted =
true;
15550 to->fIsRunning =
false;
15571 printf(
"ev_handler: connection %p, event %d\n", nc,
ev);
15593 printf(
"ev_handler: connection %p, MG_EV_RECV, %d bytes\n", nc, *(
int*)
ev_data);
15602 printf(
"ev_handler: connection %p, MG_EV_SEND, %d bytes\n", nc, *(
int*)
ev_data);
15607 printf(
"ev_handler: connection %p, MG_EV_HTTP_CHUNK\n", nc);
15618 printf(
"ev_handler: connection %p, MG_EV_HTTP_REQUEST \"%s\" \"%s\"\n", nc,
mgstr(&msg->
method).c_str(),
mgstr(&msg->
uri).c_str());
15644#define FLAG_HTTPS MG_F_USER_1
15645#define FLAG_PASSWORDS MG_F_USER_2
15646#define FLAG_HOSTLIST MG_F_USER_3
15673 cm_msg(
MERROR,
"mongoose_listen",
"https port \"%s\" requested, but mhttpd compiled without MG_ENABLE_SSL", address);
15680 cm_msg(
MERROR,
"mongoose_listen",
"Cannot mg_bind address \"%s\"", address);
15692 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");
15693 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");
15697 printf(
"Mongoose web server will use https certificate file \"%s\"\n",
cert_file.c_str());
15736 std::vector<std::string>
hostlist;
15752 odb->RSA(
"Host list", &
hostlist,
true, 10, 256);
15770 printf(
"mongoose_init: Error: Cannot initialize authorization object!\n");
15775 printf(
"Password protection is off\n");
15789 if (s.length() < 1)
15799 printf(
"Hostlist active, connections will be accepted only from: ");
15807 printf(
"Hostlist off, connections from anywhere will be accepted\n");
15870 cm_msg(
MERROR,
"mongoose_init",
"Failed to listen on a TCP port enabled in ODB /WebServer");
15884 printf(
"Mongoose web server shutting down\n");
15889 if (
s_mgr.active_connections) {
15903 to->fNotify.notify_one();
15907 for (
int i=0;
i<10;
i++) {
15912 if (
to->fIsRunning) {
15926 if (
to->fIsRunning) {
15927 cm_msg(
MERROR,
"mongoose",
"thread failed to shut down");
15930 to->fThread->join();
15931 delete to->fThread;
15955 printf(
"Mongoose web server shut down\n");
15960#ifdef HAVE_MONGOOSE6
16021 printf(
"Mongoose web server password portection is disabled: serving unencrypted http on port 80\n");
16033 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");
16037 printf(
"Mongoose web server will use SSL certificate file \"%s\"\n",
cert_file.c_str());
16044 printf(
"Error: Cannot initialize authorization object!\n");
16049 printf(
"Mongoose web server will not use password protection\n");
16074 cm_msg(
MERROR,
"mongoose",
"Cannot create mg_connection for set-uid-root privileged port");
16079#ifdef MG_ENABLE_THREADS
16086 printf(
"mongoose web server is listening on the set-uid-root privileged port\n");
16098#ifdef MG_ENABLE_THREADS
16107 std::string s = hostname +
":" + std::string(
str);
16110 printf(
"mongoose web server is redirecting HTTP port %d to https://%s\n",
http_port, s.c_str());
16116 printf(
"mongoose web server is listening on the HTTP port %d\n",
http_port);
16120#ifdef MG_ENABLE_SSL
16130#ifdef MG_ENABLE_THREADS
16137 printf(
"mongoose web server is listening on the HTTPS port %d\n",
https_port);
16139 cm_msg(
MERROR,
"mongoose",
"https port %d requested, but mhttpd compiled without MG_ENABLE_SSL",
https_port);
16145 cm_msg(
MERROR,
"mongoose",
"cannot start: no ports defined");
16161 printf(
"stop_mg done!\n");
16176#ifdef HAVE_MONGOOSE6
16187#ifdef HAVE_MONGOOSE6
16204 doc->D(
"get current value of mhttpd http_trace");
16205 doc->P(
NULL, 0,
"there are no input parameters");
16217 doc->D(
"set new value of mhttpd http_trace");
16239#ifdef HAVE_MONGOOSE6
16243#ifdef HAVE_MONGOOSE616
16247 const char *
myname =
"mhttpd";
16256#ifdef HAVE_MONGOOSE6
16268 printf(
"mhttpd is running in setuid-root mode.\n");
16272 printf(
"Cannot open listening socket on TCP port %d, aborting.\n",
port80);
16279 printf(
"Cannot give up root privelege, aborting.\n");
16284 printf(
"Cannot give up root privelege, aborting.\n");
16298#ifdef HAVE_MONGOOSE6
16303 for (
int i = 1;
i <
argc;
i++) {
16306 else if (
argv[
i][0] ==
'-' &&
argv[
i][1] ==
'v')
16308 else if (
argv[
i][0] ==
'-' &&
argv[
i][1] ==
'E')
16310 else if (
argv[
i][0] ==
'-' &&
argv[
i][1] ==
'H') {
16312#ifdef HAVE_MONGOOSE6
16326 }
else if (
strcmp(
argv[
i],
"--trace-mg-verbose") == 0) {
16328 }
else if (
strcmp(
argv[
i],
"--no-trace-mg-recv") == 0) {
16330 }
else if (
strcmp(
argv[
i],
"--no-trace-mg-send") == 0) {
16332 }
else if (
strcmp(
argv[
i],
"--verbose-mg") == 0) {
16334#ifdef HAVE_MONGOOSE616
16335 }
else if (
strcmp(
argv[
i],
"--no-multithread") == 0) {
16337 }
else if (
strcmp(
argv[
i],
"--no-passwords") == 0) {
16339 }
else if (
strcmp(
argv[
i],
"--no-hostlist") == 0) {
16342 }
else if (
argv[
i][0] ==
'-') {
16345 if (
argv[
i][1] ==
'h')
16347 else if (
argv[
i][1] ==
'e')
16349 else if (
argv[
i][1] ==
'a') {
16350#ifdef HAVE_MONGOOSE6
16355 }
else if (
argv[
i][1] ==
'p') {
16356 printf(
"Option \"-p port_number\" for the old web server is obsolete.\n");
16357 printf(
"mongoose web server is the new default, port number is set in ODB or with \"--http port_number\".\n");
16358 printf(
"To run the obsolete old web server, please use \"--oldserver\" switch.\n");
16362 printf(
"usage: %s [-h Hostname[:port]] [-e Experiment] [-v] [-D] [-a Hostname]\n\n",
argv[0]);
16363 printf(
" -a add hostname to the hostlist of hosts allowed to connect to mhttpd\n");
16364 printf(
" -e experiment to connect to\n");
16365 printf(
" -h connect to midas server (mserver) on given host\n");
16366 printf(
" -v display verbose HTTP communication\n");
16367 printf(
" -D become a daemon\n");
16368 printf(
" -E only display ELog system\n");
16369 printf(
" -H only display history plots\n");
16370#ifdef HAVE_MONGOOSE6
16371 printf(
" --http port - bind to specified HTTP port (default is ODB \"/Experiment/midas http port\")\n");
16372 printf(
" --https port - bind to specified HTTP port (default is ODB \"/Experiment/midas https port\")\n");
16374 printf(
" --verbose-mg - trace mongoose web requests\n");
16375 printf(
" --trace-mg - trace mongoose events\n");
16376 printf(
" --no-trace-mg-recv - do not trace mongoose recv events\n");
16377 printf(
" --no-trace-mg-send - dop not trace mongoose send events\n");
16378#ifdef HAVE_MONGOOSE616
16379 printf(
" --no-multithread - disable mongoose multithreading\n");
16380 printf(
" --no-passwords - disable password protection\n");
16381 printf(
" --no-hostlist - disable access control host list\n");
16389 printf(
"Becoming a daemon...\n");
16395 FILE *
f =
fopen(
"/var/run/mhttpd.pid",
"w");
16403 myname =
"mhttpd_history";
16439 printf(
"check_odb_records() failed, see messages and midas.log, bye!\n");
16444#ifdef HAVE_MONGOOSE6
16446 printf(
"init_allowed_hosts() failed, see messages and midas.log, bye!\n");
16453 printf(
"mhttpd allowed hosts list: ");
16461 printf(
"mhttpd allowed hosts list is empty\n");
16484#ifdef HAVE_MONGOOSE6
16488 printf(
"could not start the mongoose web server, see messages and midas.log, bye!\n");
16494#ifdef HAVE_MONGOOSE616
16514 MVOdb*
o = odb->Chdir(
"WebServer",
true);
16518 printf(
"Error: Could not start the mongoose web server, see messages and midas.log, bye!\n");
16526#ifdef HAVE_MONGOOSE6
16531#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 trace_mg_verbose
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)