f41b982009-05-07Martin Stjernholm // Associates a name with an SQL-database. Copyright © 1997 - 2009, Roxen IS.
4cf67b2000-04-06Mattias Wingstedt  #include <module.h> inherit "module";
0917d32013-03-04Anders Johansson constant cvs_version = "$Id$";
4cf67b2000-04-06Mattias Wingstedt constant module_type = MODULE_ZERO;
a0eaa12001-07-01Martin Nilsson constant module_name = "DEPRECATED: SQL databases"; constant module_doc =
c08c162001-01-02Per Hedbor "Use the DBs tab in the configuration interface instead. This module is"
a0eaa12001-07-01Martin Nilsson " only kept for compatibility with old configurations.";
4cf67b2000-04-06Mattias Wingstedt  void create() {
a0eaa12001-07-01Martin Nilsson  defvar("table", "", "Database URL table",
99e48d2000-11-21Per Hedbor  TYPE_TEXT_FIELD|VAR_INITIAL,
a0eaa12001-07-01Martin Nilsson  "The table with database URLs in the format:" "<pre>name\tURL</pre>" "The database URL is specified as " "<tt>driver://user name:password@host:port/database</tt>.\n");
4cf67b2000-04-06Mattias Wingstedt } mapping(string:string) parse_table(string tab) { mapping(string:string) res = ([]); tab = replace(tab||"", "\r", "\n"); foreach(tab/"\n", string line) { string line2 = replace(line, "\t", " "); array(string) arr = (line2/" ") - ({ "" }); if ((sizeof(arr) >= 2) && (arr[0][0] != '#')) { string name = arr[0]; string infix = arr[1]; string suffix = ((line/name)[1..])*name; suffix = infix + ((suffix/infix)[1..])*infix; res[name] = suffix; } } return(res); } void start(int level, Configuration conf) { conf->sql_urls = parse_table(QUERY(table)); } string status() { mapping sql_urls = parse_table(QUERY(table)); string res = ""; if (sizeof(sql_urls)) {
99e48d2000-11-21Per Hedbor  res += "<table border=\"0\">\n";
4cf67b2000-04-06Mattias Wingstedt  foreach(sort(indices(sql_urls)), string s) {
850c282001-01-10Per Hedbor  Sql.Sql o;
4cf67b2000-04-06Mattias Wingstedt 
1615402000-06-11Martin Stjernholm  mixed err = catch {
850c282001-01-10Per Hedbor  o = Sql.Sql(sql_urls[s]);
4cf67b2000-04-06Mattias Wingstedt  }; if (o) {
a0eaa12001-07-01Martin Nilsson  res += sprintf("<tr><td>Connection OK</td>"
99e48d2000-11-21Per Hedbor  "<td><tt>%s</tt></td>"
a0eaa12001-07-01Martin Nilsson  "<td>%s server on %s"
99e48d2000-11-21Per Hedbor  "</td></tr>\n", Roxen.html_encode_string (s),
86d4482000-10-18Martin Stjernholm  Roxen.html_encode_string (o->server_info()), Roxen.html_encode_string (o->host_info()));
1615402000-06-11Martin Stjernholm  } else if (err) {
a0eaa12001-07-01Martin Nilsson  res += sprintf("<tr><td><font color='&usr.warncolor;'>" "Connection failed</font>: %s</td>"
99e48d2000-11-21Per Hedbor  "<td><tt>%s</tt></td><td>&nbsp;</td></tr>\n", Roxen.html_encode_string (describe_error (err)), Roxen.html_encode_string (s));
4cf67b2000-04-06Mattias Wingstedt  }
1615402000-06-11Martin Stjernholm  else
a0eaa12001-07-01Martin Nilsson  res += sprintf("<tr><td><font color='&usr.warncolor;'>" "Connection failed</font>: " "Unknown reason</td>"
99e48d2000-11-21Per Hedbor  "<td><tt>%s</tt></td><td>&nbsp;</td></tr>\n", Roxen.html_encode_string (s));
4cf67b2000-04-06Mattias Wingstedt  } res += "</table>\n"; } else {
a0eaa12001-07-01Martin Nilsson  res += "No associations defined.<br />\n";
4cf67b2000-04-06Mattias Wingstedt  } return(res); }