dd2f1d1999-11-17Per Hedbor #include <config.h>
cf2dec2000-07-11Martin Nilsson 
dd2f1d1999-11-17Per Hedbor int __lt; string describe_time(int t) { int full; if(localtime(__lt)->yday != localtime(t)->yday) { __lt = t; full=1; } if(full)
b9a7022000-07-15Andreas Lange  return capitalize(roxen->language(roxen.locale->get(),"date")(t));
dd2f1d1999-11-17Per Hedbor  else return sprintf("%02d:%02d",localtime(t)->hour,localtime(t)->min); }
8ba1822002-06-15Martin Nilsson string units(string unit, int num)
3e3bab2001-01-19Per Hedbor {
715d3c2000-07-11Martin Nilsson  if(num==1) return "one "+unit; return num+" "+unit+"s"; }
dd2f1d1999-11-17Per Hedbor string describe_interval(int i) {
715d3c2000-07-11Martin Nilsson  switch(i) { case 0..50:
8ba1822002-06-15Martin Nilsson  return units("second", i);
715d3c2000-07-11Martin Nilsson  case 51..3560:
8ba1822002-06-15Martin Nilsson  return units("minute", ((i+20)/60));
715d3c2000-07-11Martin Nilsson  default:
8ba1822002-06-15Martin Nilsson  return units("hour", ((i+300)/3600));
dd2f1d1999-11-17Per Hedbor  } } string describe_times(array (int) times) { __lt=0; if(sizeof(times) < 6)
8ba1822002-06-15Martin Nilsson  return String.implode_nicely(map(times, describe_time));
dd2f1d1999-11-17Per Hedbor  int d, every=1; int ot = times[0]; foreach(times[1..], int t) if(d) { if(abs(t-ot-d)>(d/4)) { every=0; break; } ot=t; } else d = t-ot; if(every && (times[-1]+d) >= time(1)-10)
8ba1822002-06-15Martin Nilsson  return ("every " +describe_interval(d)+" since "+
dd2f1d1999-11-17Per Hedbor  describe_time(times[0])); return String.implode_nicely(map(times[..4], describe_time)+({"..."})+
8ba1822002-06-15Martin Nilsson  map(times[sizeof(times)-3..], describe_time));
dd2f1d1999-11-17Per Hedbor } string fix_err(string s) { sscanf(reverse(s), "%*[ \t\n]%s", s); s=reverse(s); if(s=="") return s; if(!(<'.','!','?'>)[s[-1]]) s+=".";
715d3c2000-07-11Martin Nilsson  return Roxen.html_encode_string(capitalize(s));
dd2f1d1999-11-17Per Hedbor } int last_time;
c60cae2000-02-02Johan Sundström string describe_error(string err, array (int) times, string lang, int|void no_links)
dd2f1d1999-11-17Per Hedbor { int code, nt;
c60cae2000-02-02Johan Sundström  string links = "", reference, server;
8ba1822002-06-15Martin Nilsson  array(string) codetext = ({ "Notice", "Warning", "Error" });
c60cae2000-02-02Johan Sundström 
dd2f1d1999-11-17Per Hedbor  if(sizeof(times)==1 && times[0]/60==last_time) nt=1; last_time=times[0]/60;
c60cae2000-02-02Johan Sundström  sscanf(err, "%d,%[^,],%s", code, reference, err); switch(no_links) { Configuration conf; RoxenModule module; case 2: sscanf(reference, "%[^/]", server); if(conf = roxen->find_configuration( server )) links += sprintf("<a href=\"%s\">%s</a> : ", @get_conf_url_to_virtual_server( conf, lang )); case 1: // find_configuration(configinterface)->query_name() == realname
715d3c2000-07-11Martin Nilsson  if(module = Roxen.get_module( reference ))
c60cae2000-02-02Johan Sundström  links += sprintf("<a href=\"%s\">%s</a> : ", @get_conf_url_to_module( module, lang )); }
2bf3362000-02-16Martin Nilsson  return "<table><tr><td valign=\"top\"><img src=&usr.err-"+code+"; \n" "alt=\"" + codetext[code-1] + "\" />" "</td><td>" + links + (nt?"":describe_times(times)+"<br />") + replace(fix_err(err), "\n", "<br />\n") + "</table>";
c60cae2000-02-02Johan Sundström } // Returns ({ URL to module config page, human-readable (full) module name })
3e3bab2001-01-19Per Hedbor array(string) get_conf_url_to_module(string|RoxenModule m, string|void lang) { // module is either a RoxenModule object or a string as returned by
c60cae2000-02-02Johan Sundström  // get_modname(some RoxenModule), eg "ConfigInterface/piketag#0"
715d3c2000-07-11Martin Nilsson  RoxenModule module = stringp(m) ? Roxen.get_module(m) : m;
c60cae2000-02-02Johan Sundström  Configuration conf = module->my_configuration(); string url_modname = replace(conf->otomod[module], "#", "!"), url_confname = conf->name;
9d477e2001-05-16Per Hedbor  return ({ sprintf("/sites/site.html/%s/-!-/%s/?section=Information", Roxen.http_encode_string(url_confname), Roxen.http_encode_string(url_modname)),
715d3c2000-07-11Martin Nilsson  Roxen.get_modfullname(module) });
c60cae2000-02-02Johan Sundström } // Returns ({ URL to virtual server config page, virtual server name })
3e3bab2001-01-19Per Hedbor array(string) get_conf_url_to_virtual_server(string|Configuration conf,
51bfad2000-04-04Johan Sundström  string|void lang)
3e3bab2001-01-19Per Hedbor { // conf is either a conf object or the configuration's real name, // eg "ConfigInterface"
c60cae2000-02-02Johan Sundström  string url_confname; if(stringp(conf)) conf = roxen->find_configuration(url_confname = conf); else url_confname = conf->name;
9d477e2001-05-16Per Hedbor  return ({ sprintf("/sites/site.html/%s/", Roxen.http_encode_string(url_confname)), conf->query_name() });
dd2f1d1999-11-17Per Hedbor }
9d477e2001-05-16Per Hedbor