Fossil SCM

First cut at the /logsummary page. Provides a count of the various error log message types. Need to gather more examples in order to figure out how to deduce more types. Access by admins only.

drh 2025-03-09 23:04 trunk
Commit 55d476abf5ab6cb1a98f5bda43506849c64b79b3031e19dcefae56bc70698af9
--- src/security_audit.c
+++ src/security_audit.c
@@ -1019,5 +1019,92 @@
10191019
}
10201020
fclose(in);
10211021
@ </pre>
10221022
style_finish_page();
10231023
}
1024
+
1025
+/*
1026
+** WEBPAGE: logsummary
1027
+**
1028
+** Scan the error log and count the various kinds of entries.
1029
+*/
1030
+void logsummary_page(void){
1031
+ i64 szFile;
1032
+ char *zLog;
1033
+ FILE *in;
1034
+ int prevWasTime = 0;
1035
+ int nHack = 0;
1036
+ int nPanic = 0;
1037
+ int nOther = 0;
1038
+ int nTotal = 0;
1039
+ char z[10000];
1040
+
1041
+ login_check_credentials();
1042
+ if( !g.perm.Admin ){
1043
+ login_needed(0);
1044
+ return;
1045
+ }
1046
+ style_header("Server Hack Log");
1047
+ style_submenu_element("Log-Menu", "%R/setup-logmenu");
1048
+
1049
+ if( g.zErrlog==0 || fossil_strcmp(g.zErrlog,"-")==0 ){
1050
+ no_error_log_available();
1051
+ style_finish_page();
1052
+ return;
1053
+ }
1054
+ in = fossil_fopen(g.zErrlog, "rb");
1055
+ if( in==0 ){
1056
+ @ <p class='generalError'>Unable to open that file for reading!</p>
1057
+ style_finish_page();
1058
+ return;
1059
+ }
1060
+ szFile = file_size(g.zErrlog, ExtFILE);
1061
+ zLog = file_canonical_name_dup(g.zErrlog);
1062
+ @ Summary of messages contained within the %lld(szFile)-byte
1063
+ @ <a href="%R/errorlog?all">error log</a> found at
1064
+ @ "%h(zLog)".
1065
+ fossil_free(zLog);
1066
+ @ <hr>
1067
+ while( fgets(z, sizeof(z), in) ){
1068
+ if( prevWasTime
1069
+ && (strncmp(z,"possible hack attempt - 418 ", 27)==0)
1070
+ ){
1071
+ nHack++;
1072
+ prevWasTime = 0;
1073
+ continue;
1074
+ }
1075
+ if( prevWasTime
1076
+ && (strncmp(z,"panic: ", 7)==0 || strstr(z," assertion fault ")!=0)
1077
+ ){
1078
+ nPanic++;
1079
+ prevWasTime = 0;
1080
+ continue;
1081
+ }
1082
+ if( prevWasTime ) nOther++;
1083
+ if( strncmp(z, "--------", 8)==0 ){
1084
+ nTotal++;
1085
+ prevWasTime = 1;
1086
+ continue;
1087
+ }
1088
+ prevWasTime = 0;
1089
+ }
1090
+ fclose(in);
1091
+ @ <p><table border="a" cellspacing="0" cellpadding="5">
1092
+ @ <tr><td align="right">%d(nPanic)</td>
1093
+ if( nPanic>0 ){
1094
+ @ <td><a href="./paniclog">Panics</a></td>
1095
+ } else {
1096
+ @ <td>Panics</td>
1097
+ }
1098
+ @ <tr><td align="right">%d(nHack)</td>
1099
+ if( nHack>0 ){
1100
+ @ <td><a href="./hacklog">Hack Attempts</a></td>
1101
+ }else{
1102
+ @ <td>Hack Attempts</td>
1103
+ }
1104
+ @ <tr><td align="right">%d(nOther)</td>
1105
+ @ <td>Other</td>
1106
+ @ <tr><td align="right">%d(nTotal)</td>
1107
+ @ <td>Total Messages</td>
1108
+ @ </table>
1109
+ style_finish_page();
1110
+}
10241111
--- src/security_audit.c
+++ src/security_audit.c
@@ -1019,5 +1019,92 @@
1019 }
1020 fclose(in);
1021 @ </pre>
1022 style_finish_page();
1023 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1024
--- src/security_audit.c
+++ src/security_audit.c
@@ -1019,5 +1019,92 @@
1019 }
1020 fclose(in);
1021 @ </pre>
1022 style_finish_page();
1023 }
1024
1025 /*
1026 ** WEBPAGE: logsummary
1027 **
1028 ** Scan the error log and count the various kinds of entries.
1029 */
1030 void logsummary_page(void){
1031 i64 szFile;
1032 char *zLog;
1033 FILE *in;
1034 int prevWasTime = 0;
1035 int nHack = 0;
1036 int nPanic = 0;
1037 int nOther = 0;
1038 int nTotal = 0;
1039 char z[10000];
1040
1041 login_check_credentials();
1042 if( !g.perm.Admin ){
1043 login_needed(0);
1044 return;
1045 }
1046 style_header("Server Hack Log");
1047 style_submenu_element("Log-Menu", "%R/setup-logmenu");
1048
1049 if( g.zErrlog==0 || fossil_strcmp(g.zErrlog,"-")==0 ){
1050 no_error_log_available();
1051 style_finish_page();
1052 return;
1053 }
1054 in = fossil_fopen(g.zErrlog, "rb");
1055 if( in==0 ){
1056 @ <p class='generalError'>Unable to open that file for reading!</p>
1057 style_finish_page();
1058 return;
1059 }
1060 szFile = file_size(g.zErrlog, ExtFILE);
1061 zLog = file_canonical_name_dup(g.zErrlog);
1062 @ Summary of messages contained within the %lld(szFile)-byte
1063 @ <a href="%R/errorlog?all">error log</a> found at
1064 @ "%h(zLog)".
1065 fossil_free(zLog);
1066 @ <hr>
1067 while( fgets(z, sizeof(z), in) ){
1068 if( prevWasTime
1069 && (strncmp(z,"possible hack attempt - 418 ", 27)==0)
1070 ){
1071 nHack++;
1072 prevWasTime = 0;
1073 continue;
1074 }
1075 if( prevWasTime
1076 && (strncmp(z,"panic: ", 7)==0 || strstr(z," assertion fault ")!=0)
1077 ){
1078 nPanic++;
1079 prevWasTime = 0;
1080 continue;
1081 }
1082 if( prevWasTime ) nOther++;
1083 if( strncmp(z, "--------", 8)==0 ){
1084 nTotal++;
1085 prevWasTime = 1;
1086 continue;
1087 }
1088 prevWasTime = 0;
1089 }
1090 fclose(in);
1091 @ <p><table border="a" cellspacing="0" cellpadding="5">
1092 @ <tr><td align="right">%d(nPanic)</td>
1093 if( nPanic>0 ){
1094 @ <td><a href="./paniclog">Panics</a></td>
1095 } else {
1096 @ <td>Panics</td>
1097 }
1098 @ <tr><td align="right">%d(nHack)</td>
1099 if( nHack>0 ){
1100 @ <td><a href="./hacklog">Hack Attempts</a></td>
1101 }else{
1102 @ <td>Hack Attempts</td>
1103 }
1104 @ <tr><td align="right">%d(nOther)</td>
1105 @ <td>Other</td>
1106 @ <tr><td align="right">%d(nTotal)</td>
1107 @ <td>Total Messages</td>
1108 @ </table>
1109 style_finish_page();
1110 }
1111
--- src/setup.c
+++ src/setup.c
@@ -270,10 +270,13 @@
270270
@ &mdash;&mdash;
271271
@ <i>The remaining links are subsets of the Error Log</i>
272272
@ &mdash;&mdash;
273273
@ </td>
274274
275
+ setup_menu_entry("Error Summary", bErrLog ? "logsummary" : 0,
276
+ "Counts of the various message types seen in the Error Log.\n"
277
+ );
275278
setup_menu_entry("Panic Log", bErrLog ? "paniclog" : 0,
276279
"Only the most important messages in the Error Log:\n"
277280
"assertion faults, segmentation faults, and similar malfunctions.\n"
278281
);
279282
setup_menu_entry("Hack Log", bErrLog ? "hacklog" : 0,
280283
--- src/setup.c
+++ src/setup.c
@@ -270,10 +270,13 @@
270 @ &mdash;&mdash;
271 @ <i>The remaining links are subsets of the Error Log</i>
272 @ &mdash;&mdash;
273 @ </td>
274
 
 
 
275 setup_menu_entry("Panic Log", bErrLog ? "paniclog" : 0,
276 "Only the most important messages in the Error Log:\n"
277 "assertion faults, segmentation faults, and similar malfunctions.\n"
278 );
279 setup_menu_entry("Hack Log", bErrLog ? "hacklog" : 0,
280
--- src/setup.c
+++ src/setup.c
@@ -270,10 +270,13 @@
270 @ &mdash;&mdash;
271 @ <i>The remaining links are subsets of the Error Log</i>
272 @ &mdash;&mdash;
273 @ </td>
274
275 setup_menu_entry("Error Summary", bErrLog ? "logsummary" : 0,
276 "Counts of the various message types seen in the Error Log.\n"
277 );
278 setup_menu_entry("Panic Log", bErrLog ? "paniclog" : 0,
279 "Only the most important messages in the Error Log:\n"
280 "assertion faults, segmentation faults, and similar malfunctions.\n"
281 );
282 setup_menu_entry("Hack Log", bErrLog ? "hacklog" : 0,
283

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button