6775fc2000-02-02Per Hedbor /*
0917d32013-03-04Anders Johansson  * $Id$
6775fc2000-02-02Per Hedbor  */ inherit "wizard";
e156142000-03-24Johan Sundström inherit "../logutil";
bebbad2000-08-16Andreas Lange #include <roxen.h>
49f4892008-11-06Martin Stjernholm #include <request_trace.h>
bebbad2000-08-16Andreas Lange //<locale-token project="admin_tasks">LOCALE</locale-token> #define LOCALE(X,Y) _STR_LOCALE("admin_tasks",X,Y)
bfbc232000-09-19Andreas Lange constant action = "debug_info";
6775fc2000-02-02Per Hedbor 
bebbad2000-08-16Andreas Lange string name= LOCALE(27, "Resolve path..."); string doc = LOCALE(28, "Check which modules handles the path you enter in " "the form");
6775fc2000-02-02Per Hedbor 
e156142000-03-24Johan Sundström string link(string to, string name)
2ae7752000-07-20Johan Sundström { return sprintf("<a href=\"%s\">%s</a>", to, name);
b8b1072000-03-24Per Hedbor }
e156142000-03-24Johan Sundström 
bebbad2000-08-16Andreas Lange string link_configuration(Configuration c, void|string cf_locale)
b8b1072000-03-24Per Hedbor {
bebbad2000-08-16Andreas Lange  return link(@get_conf_url_to_virtual_server(c, cf_locale));
b8b1072000-03-24Per Hedbor }
e156142000-03-24Johan Sundström 
3adfe92000-06-29Martin Stjernholm string module_name(function|RoxenModule|RXML.Tag m)
6775fc2000-02-02Per Hedbor {
6572562000-08-14Martin Stjernholm  m = Roxen.get_owning_module (m); if(!m) return "";
6775fc2000-02-02Per Hedbor  string name;
e15a7c2011-08-01Henrik Grubbström (Grubba)  catch (name = Roxen.html_encode_string(Roxen.get_modfullname (m)));
bebbad2000-08-16Andreas Lange  if (!name) return "<font color='red'>Unavailable</font>";
6775fc2000-02-02Per Hedbor 
e156142000-03-24Johan Sundström  Configuration c; if(functionp(m->my_configuration) && (c = m->my_configuration())) { foreach(indices(c->modules), string mn) { int w; mapping mod = c->modules[mn]; if(mod->enabled == m) { name = sprintf("<a href=\"%s\">%s</a> (%s)", @get_conf_url_to_module(c->name+"/"+mn), roxen->filename(m)); break; } else if(mod->copies && !zero_type(search(mod->copies, m))) { name = sprintf("<a href=\"%s\">%s</a> (%s)", @get_conf_url_to_module(c->name+"/"+mn+"#"+search(mod->copies, m)), roxen->filename(m)); break; } } }
6775fc2000-02-02Per Hedbor 
bebbad2000-08-16Andreas Lange  return "<font color='darkgreen'>"+name+"</font>";
6775fc2000-02-02Per Hedbor } string resolv;
2ae7752000-07-20Johan Sundström int level, prev_level;
49f4892008-11-06Martin Stjernholm mapping et = ([]);
2ae7752000-07-20Johan Sundström string anchor(string title) { while(level < prev_level) m_delete(et, (string)prev_level--); prev_level = level; et[(string)level]++;
fbefc52001-04-17Per Hedbor  array(string) anchor = level > 0 ? allocate(level) : ({});
2ae7752000-07-20Johan Sundström  for(int i=0; i<level; ) anchor[i] = (string)et[(string)++i]; return sprintf("<a name=\"%s\" href=\"#%s\">%s</a>", anchor*".", anchor*".", title); }
49f4892008-11-06Martin Stjernholm RequestID nid;
6775fc2000-02-02Per Hedbor 
49f4892008-11-06Martin Stjernholm mapping rtimes = ([]); mapping vtimes = ([]);
6775fc2000-02-02Per Hedbor 
49f4892008-11-06Martin Stjernholm void trace_enter_ol(string type, function|object module, void|int timestamp)
6775fc2000-02-02Per Hedbor { level++;
ccfa302011-07-12Jonas Wallden  resolv += (/*((prev_level >= level ? "<br />\n" : "")*/ "" + anchor("") + "<li class='timing open'>" +
2107942011-07-12Jonas Wallden  "<span class='toggle' onmousedown='return toggle_vis(event, this.parentNode);'></span>" +
ccfa302011-07-12Jonas Wallden  Roxen.html_encode_string(type) + " " + module_name(module) + "<div class='inner'>" "<ol class='timing'>");
49f4892008-11-06Martin Stjernholm 
6775fc2000-02-02Per Hedbor #if efun(gethrvtime)
49f4892008-11-06Martin Stjernholm  // timestamp is cputime. #if efun (gethrtime) rtimes[level] = gethrtime();
6775fc2000-02-02Per Hedbor #endif
49f4892008-11-06Martin Stjernholm  vtimes[level] = (timestamp || gethrvtime()) - nid->misc->trace_overhead; #elif efun (gethrtime) // timestamp is realtime. rtimes[level] = (timestamp || gethrtime()) - nid->misc->trace_overhead;
6775fc2000-02-02Per Hedbor #endif }
ead2b92002-09-03Martin Stjernholm #if efun(gethrtime) || efun(gethrvtime)
49f4892008-11-06Martin Stjernholm #define HAVE_TRACE_TIME string format_time (int hrrstart, int hrvstart, int timestamp) { int hrnow, hrvnow; #if efun (gethrvtime) // timestamp is cputime. #if efun (gethrtime) hrnow = gethrtime();
ead2b92002-09-03Martin Stjernholm #endif
49f4892008-11-06Martin Stjernholm  hrvnow = (timestamp || gethrvtime()) - nid->misc->trace_overhead;
ead2b92002-09-03Martin Stjernholm #else
49f4892008-11-06Martin Stjernholm  // timestamp is realtime. hrnow = (timestamp || gethrtime()) - nid->misc->trace_overhead;
ead2b92002-09-03Martin Stjernholm #endif
49f4892008-11-06Martin Stjernholm  return ({ hrvnow && ("CPU time: " + Roxen.format_hrtime (hrvnow - hrvstart)), hrnow && ("Real time: " + Roxen.format_hrtime (hrnow - hrrstart)) }) * ", ";
ead2b92002-09-03Martin Stjernholm }
49f4892008-11-06Martin Stjernholm #endif
ead2b92002-09-03Martin Stjernholm 
49f4892008-11-06Martin Stjernholm void trace_leave_ol(string desc, void|int timestamp)
6775fc2000-02-02Per Hedbor {
b4642f2008-09-03Jonas Wallden  string html_desc = Roxen.html_encode_string(desc || ""); if (has_value(html_desc, "\n")) html_desc = "<pre>" + html_desc + "</pre>\n"; else if (html_desc != "") html_desc += "<br />\n"; resolv +=
ccfa302011-07-12Jonas Wallden  "</ol>\n" + html_desc +
49f4892008-11-06Martin Stjernholm #ifdef HAVE_TRACE_TIME
ccfa302011-07-12Jonas Wallden  "<i class='timing'>" + format_time (rtimes[level], vtimes[level], timestamp) + "</i>"
49f4892008-11-06Martin Stjernholm #endif
ccfa302011-07-12Jonas Wallden  "</div></li>";
6775fc2000-02-02Per Hedbor  level--; }
950b062013-07-16Henrik Grubbström (Grubba) string resolv_describe_backtrace(mixed err) { catch { return describe_backtrace(err); }; catch { return sprintf("Thrown value: %O\n", err); }; return sprintf("Unformatable %t value.\n", err); } mapping|int resolv_get_file(object c, object nid) { mixed err = catch { return c->get_file(nid); }; if (!level) { trace_enter_ol("", this_object()); } trace_leave_ol(sprintf("Uncaught exception thrown:\n\n%s\n", resolv_describe_backtrace(err))); while(level) { trace_leave_ol(""); } return ([]); }
6775fc2000-02-02Per Hedbor void resolv_handle_request(object c, object nid) { int again; mixed file; function funp; do { again=0; foreach(c->first_modules(), funp) { nid->misc->trace_enter("First module", funp); if(file = funp( nid )) { nid->misc->trace_leave("Returns data"); break; } if(nid->conf != c) { c = nid->conf; nid->misc->trace_leave("Request transfered to the virtual server "+c->query_name()); again=1; break; }
b8b1072000-03-24Per Hedbor  nid->misc->trace_leave("");
6775fc2000-02-02Per Hedbor  } } while(again);
b8b1072000-03-24Per Hedbor 
950b062013-07-16Henrik Grubbström (Grubba)  if(!resolv_get_file(c, nid))
6775fc2000-02-02Per Hedbor  { foreach(c->last_modules(), funp) { nid->misc->trace_enter("Last try module", funp); if(file = funp(nid)) { if (file == 1) { nid->misc->trace_enter("Returned recurse", 0); resolv_handle_request(c, nid); nid->misc->trace_leave("Recurse done"); nid->misc->trace_leave("Last try done"); return; } nid->misc->trace_leave("Returns data"); break; } else nid->misc->trace_leave(""); } } }
bebbad2000-08-16Andreas Lange string parse( RequestID id )
6775fc2000-02-02Per Hedbor {
bebbad2000-08-16Andreas Lange  string res = ""; //"<nobr>Allow Cache <input type=checkbox></nobr>\n";
80cd682003-11-17Anders Johansson  res += "<input type='hidden' name='action' value='resolv.pike' />\n" "<font size='+1'><b>"+ name + "</b></font><p />\n"
bebbad2000-08-16Andreas Lange  "<table cellpadding='0' cellspacing='10' border='0'>\n"
5aacdd2008-10-15Jonas Wallden  "<tr><th align='left'>" +LOCALE(29, "URL")+ ": </th><td>"
bebbad2000-08-16Andreas Lange  "<input name='path' value='&form.path;' size='60' /></td></tr>\n"
82c0202009-03-17Jonas Wallden  "<tr><th align='left'>" + LOCALE(296, "HTTP auth") + ": </th>"
14fadc2008-09-28Martin Stjernholm  "<td>" +LOCALE(206, "User")+ ": "
bebbad2000-08-16Andreas Lange  "<input name='user' value='&form.user;' size='12' />" "&nbsp;&nbsp;&nbsp;" +LOCALE(30,"Password")+ ": " "<input name='password' value='&form.password;' type='password' "
4d9b822008-03-11 Erik Dahl  "size='12' /></td></tr>\n"
82c0202009-03-17Jonas Wallden  "<tr><td align='left' valign='top'>" + LOCALE(297, "Form variables") + ":</td><td align='left'>"
4d9b822008-03-11 Erik Dahl  "<input type='text' size='60' name='form_vars' value='&form.form_vars;' />"
b4642f2008-09-03Jonas Wallden  "<br/>Example: <tt>id=234&amp;page=3&amp;hidden=1</tt></td>\n"
4d9b822008-03-11 Erik Dahl  "</tr><tr><td align='left' valign='top'>" + LOCALE(325, "HTTP Cookies") + ": </td><td align='left'>" "<textarea cols='58' row='4' name='cookies'>&form.cookies;</textarea><br />"
b4642f2008-09-03Jonas Wallden  "Cookies are separated by a new line for each cookie you want to set. " "Example:"
4d9b822008-03-11 Erik Dahl  "<pre>UniqueUID=eIkT67lksoOe23q\nSessionID=123123:sadfi:114lj</pre></td>" "</tr></table>\n"
e1fff72016-01-15Henrik Grubbström (Grubba)  "<table border='0'><tr><td><cf-ok/></td><td><cf-cancel href='?class=&form.class;&amp;&usr.set-wiz-id;'/></td></tr></table>\n";
6775fc2000-02-02Per Hedbor 
ccfa302011-07-12Jonas Wallden  res += #"<script language='javascript'>
2107942011-07-12Jonas Wallden  function toggle_vis(evt, li_elem) { var items = [ li_elem ]; if (evt.shiftKey) { // Include all sibling <li> elements items = [ ]; var candidates = li_elem.parentNode.children; for (var i = 0; i < candidates.length; i++) if (candidates[i].nodeType == 1 && candidates[i].tagName.toLowerCase() == 'li') items.push(candidates[i]); } var is_open = li_elem.className.match('open'); var from_cls = is_open ? 'open' : 'closed'; var to_cls = is_open ? 'closed' : 'open'; for (var j = 0; j < items.length; j++) { items[j].className = items[j].className.replace(from_cls, to_cls); } if (evt.preventDefault) { evt.preventDefault(); evt.stopPropagation(); } else { evt.cancelBubble = true; evt.returnValue = false; }
ccfa302011-07-12Jonas Wallden  return false; } </script>";
49f4892008-11-06Martin Stjernholm  nid = roxen.InternalRequestID();
70ddf32003-06-16Martin Stjernholm  nid->client = id->client; nid->client_var = id->client_var + ([]); nid->supports = id->supports;
4d9b822008-03-11 Erik Dahl  string raw_vars = id->variables->form_vars; if( raw_vars && sizeof(raw_vars) ) { if( !nid->variables ) nid->variables = ([]); foreach( raw_vars /"&", string val_pair ) { string idx, val; if( sscanf(val_pair, "%s=%s", idx, val) == 2 ) { if(nid->variables[idx]) { if(arrayp(nid->variables[idx])) nid->variables[idx] += ({ val }); else nid->variables[idx] = ({ nid->variables[idx], val }); } else { nid->variables[idx] = val; } } } } string raw_cookies = id->variables->cookies; if( raw_cookies && sizeof(raw_cookies) ) { mapping(string:string) faked_cookies = ([]); foreach(raw_cookies / "\n", string raw_cookie) { string c_idx, c_val; if( sscanf( raw_cookie, "%s=%s", c_idx, c_val) == 2) { faked_cookies += ([ c_idx : c_val ]); } } if( sizeof(faked_cookies) ) { if( nid->cookies && sizeof(indices(nid->cookies)) ) { foreach(nid->cookies; string c_idx; string c_val ) faked_cookies[c_idx] = c_val; nid->cookies = faked_cookies; } else nid->cookies = faked_cookies; } }
6775fc2000-02-02Per Hedbor  if( id->variables->path ) {
78c7382004-06-10Anders Johansson  string err_msg; if (mixed err = catch( nid->set_url (id->variables->path) )) { err_msg = LOCALE(188, "Unable to parse URL.");
49f4892008-11-06Martin Stjernholm  report_debug("Unable to parse URL: " + describe_backtrace(err));
bebbad2000-08-16Andreas Lange  }
78c7382004-06-10Anders Johansson  else if(!nid->conf) { err_msg = LOCALE(31, "There is no configuration available that matches " "this URL."); } if (err_msg) return "<p><font color='red'>" + err_msg + "</font></p>" + res;
7452982000-03-27Per Hedbor 
e3e47e2003-10-22Henrik Grubbström (Grubba)  string canonic_url = nid->url_base() + nid->raw_url[1..];
6775fc2000-02-02Per Hedbor  if(!(int)id->variables->cache) nid->pragma = (<"no-cache">); else nid->pragma = (<>);
ead2b92002-09-03Martin Stjernholm  resolv =
54e3de2011-10-27Jonas Wallden  "<hr />\n" +
3f40442004-02-03Anders Johansson  LOCALE(179, "Canonic URL: ") +
e3e47e2003-10-22Henrik Grubbström (Grubba)  Roxen.html_encode_string(canonic_url) + "<br />\n" +
ead2b92002-09-03Martin Stjernholm  LOCALE(32, "Resolving")+" " +
e3e47e2003-10-22Henrik Grubbström (Grubba)  link(canonic_url, Roxen.html_encode_string (nid->not_query)) +
ead2b92002-09-03Martin Stjernholm  " "+LOCALE(33, "in")+" " + link_configuration(nid->conf, id->misc->cf_locale) + "<br />\n"
ccfa302011-07-12Jonas Wallden  "<ol class='timing'>";
6775fc2000-02-02Per Hedbor  nid->misc->trace_enter = trace_enter_ol; nid->misc->trace_leave = trace_leave_ol; if (id->variables->user && id->variables->user!="") { nid->rawauth
b8b1072000-03-24Per Hedbor  = "Basic "+MIME.encode_base64(id->variables->user+":"+
c2a6502012-11-08Jonas Wallden  id->variables->password, 1);
6775fc2000-02-02Per Hedbor  nid->realauth=id->variables->user+":"+id->variables->password;
2fc5172000-03-26Martin Stjernholm  }
6775fc2000-02-02Per Hedbor 
49f4892008-11-06Martin Stjernholm  int hrrstart, hrvstart;
ead2b92002-09-03Martin Stjernholm #if efun(gethrtime)
49f4892008-11-06Martin Stjernholm  hrrstart = gethrtime();
ead2b92002-09-03Martin Stjernholm #endif #if efun(gethrvtime) hrvstart = gethrvtime(); #endif
49f4892008-11-06Martin Stjernholm 
ead2b92002-09-03Martin Stjernholm  resolv_handle_request(nid->conf, nid);
49f4892008-11-06Martin Stjernholm  int endtime = HRTIME(); string trace_timetype; #if efun (gethrvtime) trace_timetype = "CPU time"; #elif efun (gethrtime) trace_timetype = "Real time"; #endif
6775fc2000-02-02Per Hedbor  while(level>0)
49f4892008-11-06Martin Stjernholm  trace_leave_ol ("Trace nesting inconsistency!", endtime); res += resolv + "</ol>\n"; if (trace_timetype) { res += format_time (hrrstart, hrvstart, endtime); if (int oh = nid->misc->trace_overhead) { res += ", trace overhead (" + trace_timetype + "): " + Roxen.format_hrtime (oh) + "<br />\n" "Note: The trace overhead has been mostly canceled out from the " + trace_timetype + " values above."; } }
6775fc2000-02-02Per Hedbor  }
49f4892008-11-06Martin Stjernholm  destruct (nid);
6775fc2000-02-02Per Hedbor  return res; }