a0c4952002-03-27Johan Schön /*
80cd682003-11-17Anders Johansson  * $Id: debug_summary.pike,v 1.9 2003/11/17 16:01:26 anders Exp $
a0c4952002-03-27Johan Schön  */ #include <stat.h> #include <roxen.h> //<locale-token project="admin_tasks">LOCALE</locale-token> #define LOCALE(X,Y) _DEF_LOCALE("admin_tasks",X,Y) constant action = "debug_info";
6fbcab2002-07-01Anders Johansson LocaleString name= LOCALE(163,"Debug Summary"); LocaleString doc = LOCALE(164,
a0c4952002-03-27Johan Schön  "Shows a text file containing a configuration summary, suitable " "for support purposes."); int creation_date = time(); int no_reload() { return creation_date > file_stat( __FILE__ )[ST_MTIME]; } string get_cvs_versions(string dir) { string res=""; foreach(sort(get_dir(dir)), string fn) { if(file_stat(dir+"/"+fn)->isdir && fn!="CVS") res+=get_cvs_versions(dir+"/"+fn); else res+=replace(dir+"/"+fn, ({"//", "\\\\"}), ({"/", "\\"}))+"\n"; } return res; } string indent(string text, int level) { array a=text/"\n"; for(int i=0; i<sizeof(a); i++) if(sizeof(a[i])) a[i]=" "*level+a[i]; return a*"\n"; }
dc22982002-03-27Johan Schön string describe_var_low(mixed value)
a0c4952002-03-27Johan Schön { if(arrayp(value))
dc22982002-03-27Johan Schön  return "{"+map(value, describe_var_low)*", "+"}";
a0c4952002-03-27Johan Schön  else return sprintf("%O", value); }
dc22982002-03-27Johan Schön string describe_var(mixed var) { if(var->type=="Password" || var->type=="VerifiedPassword") return "***** (censored)"; else return describe_var_low(var->query()); }
a0c4952002-03-27Johan Schön string make_headline(string title) { return sprintf("%s:\n%s\n", title, "-"*(sizeof(title)+1)); } string make_environment_summary() { string res = make_headline("Environment");
c79ed72003-01-27Martin Stjernholm  res+=sprintf(" %-30s %s\n", "Roxen version:", roxen_version()); res+=sprintf(" %-30s %s\n", "Pike version:", version());
a0c4952002-03-27Johan Schön  res+=sprintf(" %-30s %s", "Time:", ctime(time())); res+=sprintf(" %-30s %s\n", "Host:", gethostname()); #ifdef __NT__ res+=sprintf(" %-30s %s\n", "Platform:", "NT"); #else res+=sprintf(" %-30s %s %s %s\n", "Platform:", uname()->sysname||"", uname()->release||"", uname()->machine); #endif res += "\n"; res += make_headline("Local environment variables");
850bbd2002-05-15Anders Johansson #ifdef __NT__ res += indent(Stdio.read_file("../local/environment.ini")||"", 1); #else res += indent(Stdio.read_file("../local/environment")||"", 1); #endif
a0c4952002-03-27Johan Schön  res += "\n"; res += make_headline("System environment variables"); foreach(sort(indices(getenv())), string envvar) res+=sprintf(" %-30s %s\n", envvar+":", getenv(envvar)); return res; } string make_variables_summary(mapping vars) { string res=""; foreach(sort(indices(vars)), string varname) res+=sprintf("%s%-30s %s\n", vars[varname]->is_defaulted()?" ":" *", varname+":",
dc22982002-03-27Johan Schön  describe_var(vars[varname]));
a0c4952002-03-27Johan Schön  return res; } string make_extra_module_info(RoxenModule module) { if(module->debug_summary && functionp(module->debug_summary)) { string res="\n"+make_headline("Extra info"); mixed err=catch(res += indent(module->debug_summary(), 1)); if(err) res+=describe_backtrace(err); return res; } return ""; } string make_configuration_summary(string configuration) { mixed c=roxen->find_configuration(configuration); mapping vars = c->getvars(); string res = make_headline("Globals"); res += make_variables_summary(c->getvars())+"\n\n"; foreach(values(c->modules), mixed modulecopies) foreach(values(modulecopies->copies), RoxenModule module) res += sprintf("%s%s%s\n\n", make_headline(module->module_identifier()), make_variables_summary(module->getvars()), indent(make_extra_module_info(module),1)); return res; }
d4a2d72003-08-26Anders Johansson string make_global_summary() { string res = make_headline("Global Variables"); res += make_variables_summary(roxen->getvars()); return res + "\n"; }
2dd48d2002-04-17Anders Johansson string make_summary()
a0c4952002-03-27Johan Schön {
2dd48d2002-04-17Anders Johansson  string res = make_environment_summary()+"\n";
a0c4952002-03-27Johan Schön  // res +=make_headline("CVS file versions"); // res +=indent(get_cvs_versions(getcwd()), 1);
d4a2d72003-08-26Anders Johansson  res += make_global_summary();
a0c4952002-03-27Johan Schön  foreach(roxen->list_all_configurations(), string configuration) { res+=make_headline("Configuration: "+configuration)+"\n"; res+=indent(make_configuration_summary(configuration),1); }
2dd48d2002-04-17Anders Johansson  return res;
6693132002-04-22Anders Johansson }
2dd48d2002-04-17Anders Johansson  mixed parse( RequestID id ) { string res;
6693132002-04-22Anders Johansson  string debuglog = roxen_path("$LOGDIR/debug/default.1");
2dd48d2002-04-17Anders Johansson 
6693132002-04-22Anders Johansson  if (id->variables->download && id->variables->download == "summary") {
2dd48d2002-04-17Anders Johansson  res = make_headline("Debug summary")+"\n"; res += make_summary(); mapping ret = Roxen.http_string_answer(res, "application/octet-stream"); ret["extra_heads"] = ([]); Roxen.add_http_header(ret["extra_heads"], "Content-Disposition", "attachment; filename=debug-summary.txt"); return ret; }
6693132002-04-22Anders Johansson  else if (id->variables->download && id->variables->download == "debuglog") { string res = "---"; object st = file_stat(debuglog); if (st && st->isreg) res = Stdio.read_file(debuglog); mapping ret = Roxen.http_string_answer(res, "application/octet-stream"); ret["extra_heads"] = ([]); Roxen.add_http_header(ret["extra_heads"], "Content-Disposition", "attachment; filename="+((debuglog/"/")[-1])); return ret; }
2dd48d2002-04-17Anders Johansson 
80cd682003-11-17Anders Johansson  res = "<font size='+1'><b>Debug summary</b></font>\n<p />";
6693132002-04-22Anders Johansson  res += "<link-gbutton href='debug_summary.pike?download=summary'>Download" "</link-gbutton>"; if (file_stat(debuglog)) res += "<link-gbutton href='debug_summary.pike?download=debuglog'>" "Download debug log"
2dd48d2002-04-17Anders Johansson  "</link-gbutton>";
a0c4952002-03-27Johan Schön 
80cd682003-11-17Anders Johansson  res += "<pre>"+Roxen.html_encode_string(make_summary())+"</pre>" "<br /><br />" "<cf-ok/>";
2dd48d2002-04-17Anders Johansson  return res;
a0c4952002-03-27Johan Schön }