/*---------------------------------------------------------------------------*/ static void *stop_cpus_and_ipl(int *ipltype) { int i; char iplcmd[256]; int cpustates; CPU_BITMAP mask; sysblk.diag8cmd |= DIAG8CMD_RUNNING; panel_command("stopall"); sysblk.diag8cmd &= ~DIAG8CMD_RUNNING; WRMSG(HHC01900, "I"); sprintf(iplcmd, "%s %03X", ipltype, sysblk.ipldev); do { OBTAIN_INTLOCK(NULL); cpustates = CPUSTATE_STOPPED; mask = sysblk.started_mask; for(i = 0; mask; i++) { if(mask & 1) { WRMSG(HHC01901, "I", PTYPSTR(i), i); if(IS_CPU_ONLINE(i) && sysblk.regs[i]->cpustate != CPUSTATE_STOPPED) cpustates = sysblk.regs[i]->cpustate; } mask >>= 1; } RELEASE_INTLOCK(NULL); if(cpustates != CPUSTATE_STOPPED) { WRMSG(HHC01902, "I"); SLEEP(1); } } while(cpustates != CPUSTATE_STOPPED); sysblk.diag8cmd |= DIAG8CMD_RUNNING; panel_command(iplcmd); sysblk.diag8cmd &= ~DIAG8CMD_RUNNING; return NULL; }
/*---------------------------------------------------------------------------*/ static void hao_message(char *buf) { char work[HAO_WKLEN]; regmatch_t rm; int i; /* copy and strip spaces */ hao_cpstrp(work, buf); /* strip the herc prefix */ while(!strncmp(work, "herc", 4)) hao_cpstrp(work, &work[4]); /* Ignore the message if we should (e.g. if one of our own!) */ if (hao_ignoremsg( work )) return; /* serialize */ obtain_lock(&ao_lock); /* check all defined rules */ for(i = 0; i < HAO_MAXRULE; i++) { if(ao_tgt[i] && ao_cmd[i]) /* complete rule defined in this slot? */ { /* does this rule match our message? */ if(!regexec(&ao_preg[i], work, 1, &rm, 0)) { /* issue command for this rule */ WRMSG(HHC00081, "I", i, ao_cmd[i]); panel_command(ao_cmd[i]); } } } release_lock(&ao_lock); }
void cgibin_syslog(WEBBLK *webblk) { int num_bytes; int logbuf_idx; char *logbuf_ptr; char *command; char *value; int autorefresh = 0; int refresh_interval = 5; int msgcount = 22; if ((command = cgi_variable(webblk,"command"))) { panel_command(command); // Wait a bit before proceeding in case // the command issues a lot of messages usleep(50000); } if((value = cgi_variable(webblk,"msgcount"))) msgcount = atoi(value); else if((value = cgi_cookie(webblk,"msgcount"))) msgcount = atoi(value); if ((value = cgi_variable(webblk,"refresh_interval"))) refresh_interval = atoi(value); if (cgi_variable(webblk,"autorefresh")) autorefresh = 1; else if (cgi_variable(webblk,"norefresh")) autorefresh = 0; else if (cgi_variable(webblk,"refresh")) autorefresh = 1; html_header(webblk); hprintf(webblk->sock,"<script language=\"JavaScript\">\n" "<!--\n" "document.cookie = \"msgcount=%d\";\n" "//-->\n" "</script>\n", msgcount); hprintf(webblk->sock, "<H2>Hercules System Log</H2>\n"); hprintf(webblk->sock, "<PRE>\n"); // Get the index to our desired starting message... logbuf_idx = msgcount ? log_line( msgcount ) : -1; // Now read the logfile starting at that index. The return // value is the total #of bytes of messages data there is. if ( (num_bytes = log_read( &logbuf_ptr, &logbuf_idx, LOG_NOBLOCK )) > 0 ) { // Copy the message data to a work buffer for processing. // This is to allow for the possibility, however remote, // that the logfile buffer actually wraps around and over- // lays the message data we were going to display (which // could happen if there's a sudden flood of messages) int sav_bytes = num_bytes; char *wrk_bufptr = malloc( num_bytes ); if ( wrk_bufptr ) strncpy( wrk_bufptr, logbuf_ptr, num_bytes ); else wrk_bufptr = logbuf_ptr; // We need to convert certain characters that might // possibly be erroneously interpretted as HTML code #define AMP_LT "<" // (HTML code for '<') #define AMP_GT ">" // (HTML code for '>') #define AMP_AMP "&" // (HTML code for '&') while ( num_bytes-- ) { switch ( *wrk_bufptr ) { case '<': hwrite( webblk->sock, AMP_LT , sizeof(AMP_LT) ); break; case '>': hwrite( webblk->sock, AMP_GT , sizeof(AMP_GT) ); break; case '&': hwrite( webblk->sock, AMP_AMP , sizeof(AMP_AMP)); break; default: hwrite( webblk->sock, wrk_bufptr , 1 ); break; } wrk_bufptr++; } // (free our work buffer if it's really ours) if ( ( wrk_bufptr -= sav_bytes ) != logbuf_ptr ) free( wrk_bufptr ); } hprintf(webblk->sock, "</PRE>\n"); hprintf(webblk->sock, "<FORM method=post>Command:\n"); hprintf(webblk->sock, "<INPUT type=text name=command size=80>\n"); hprintf(webblk->sock, "<INPUT type=submit name=send value=\"Send\">\n"); hprintf(webblk->sock, "<INPUT type=hidden name=%srefresh value=1>\n",autorefresh ? "auto" : "no"); hprintf(webblk->sock, "<INPUT type=hidden name=refresh_interval value=%d>\n",refresh_interval); hprintf(webblk->sock, "<INPUT type=hidden name=msgcount value=%d>\n",msgcount); hprintf(webblk->sock, "</FORM>\n<BR>\n"); hprintf(webblk->sock, "<A name=bottom>\n"); hprintf(webblk->sock, "<FORM method=post>\n"); if(!autorefresh) { hprintf(webblk->sock, "<INPUT type=submit value=\"Auto Refresh\" name=autorefresh>\n"); hprintf(webblk->sock, "Refresh Interval: "); hprintf(webblk->sock, "<INPUT type=text name=\"refresh_interval\" size=2 value=%d>\n", refresh_interval); } else { hprintf(webblk->sock, "<INPUT type=submit name=norefresh value=\"Stop Refreshing\">\n"); hprintf(webblk->sock, "<INPUT type=hidden name=refresh_interval value=%d>\n",refresh_interval); hprintf(webblk->sock, " Refresh Interval: %2d \n", refresh_interval); } hprintf(webblk->sock, "<INPUT type=hidden name=msgcount value=%d>\n",msgcount); hprintf(webblk->sock, "</FORM>\n"); hprintf(webblk->sock, "<FORM method=post>\n"); hprintf(webblk->sock, "Only show last "); hprintf(webblk->sock, "<INPUT type=text name=msgcount size=3 value=%d>",msgcount); hprintf(webblk->sock, " lines (zero for all loglines)\n"); hprintf(webblk->sock, "<INPUT type=hidden name=%srefresh value=1>\n",autorefresh ? "auto" : "no"); hprintf(webblk->sock, "<INPUT type=hidden name=refresh_interval value=%d>\n",refresh_interval); hprintf(webblk->sock, "</FORM>\n"); if (autorefresh) { /* JavaScript to cause automatic page refresh */ hprintf(webblk->sock, "<script language=\"JavaScript\">\n"); hprintf(webblk->sock, "<!--\nsetTimeout('window.location.replace(\"%s" "?refresh_interval=%d" "&refresh=1" "&msgcount=%d" "\")', %d)\n", cgi_baseurl(webblk), refresh_interval, msgcount, refresh_interval*1000); hprintf(webblk->sock, "//-->\n</script>\n"); } html_footer(webblk); }
/*---------------------------------------------------------------------------*/ DLL_EXPORT void hao_message(char *buf) { char work[HAO_WKLEN]; char cmd[HAO_WKLEN]; regmatch_t rm[HAO_MAXCAPT+1]; int i, j, k, numcapt; size_t n; char *p; /* copy and strip spaces */ hao_cpstrp(work, buf); /* strip the herc prefix */ while(!strncmp(work, "herc", 4)) hao_cpstrp(work, &work[4]); /* don't react on own messages */ if(!strncmp(work, "HHCAO", 5)) return; /* don't react on own commands */ if(!strncasecmp(work, "hao", 3)) return; /* also from the .rc file */ if(!strncasecmp(work, "> hao", 5)) return; /* serialize */ obtain_lock(&ao_lock); /* check all defined rules */ for(i = 0; i < HAO_MAXRULE; i++) { if(ao_tgt[i] && ao_cmd[i]) /* complete rule defined in this slot? */ { /* does this rule match our message? */ if (regexec(&ao_preg[i], work, HAO_MAXCAPT+1, rm, 0) == 0) { /* count the capturing group matches */ for (j = 0; j <= HAO_MAXCAPT && rm[j].rm_so >= 0; j++); numcapt = j - 1; /* copy the command and process replacement patterns */ for (n=0, p=ao_cmd[i]; *p && n < sizeof(cmd)-1; ) { /* replace $$ by $ */ if (*p == '$' && p[1] == '$') { cmd[n++] = '$'; p += 2; continue; } /* replace $` by characters to the left of the match */ if (*p == '$' && p[1] == '`') { n += hao_subst(work, 0, rm[0].rm_so, cmd, n, sizeof(cmd)); p += 2; continue; } /* replace $' by characters to the right of the match */ if (*p == '$' && p[1] == '\'') { n += hao_subst(work, rm[0].rm_eo, strlen(work), cmd, n, sizeof(cmd)); p += 2; continue; } /* replace $1..$99 by the corresponding capturing group */ if (*p == '$' && isdigit(p[1])) { if (isdigit(p[2])) { j = (p[1]-'0') * 10 + (p[2]-'0'); k = 3; } else { j = p[1]-'0'; k = 2; } if (j > 0 && j <= numcapt) { n += hao_subst(work, rm[j].rm_so, rm[j].rm_eo, cmd, n, sizeof(cmd)); p += k; continue; } } /* otherwise copy one character */ cmd[n++] = *p++; } cmd[n] = '\0'; /* issue command for this rule */ logmsg(HHCAO003I, cmd); panel_command(cmd); } } } release_lock(&ao_lock); }