Roxen.git / server / base_server / global_variables.pike

version» Context lines:

Roxen.git/server/base_server/global_variables.pike:1:   #include <module.h>   #include <roxen.h>   #include <config.h>   inherit "read_config";   inherit "module_support";   string real_version;   // The following three functions are used to hide variables when they   // are not used. This makes the user-interface clearer and quite a lot   // less clobbered. - int cache_disabled_p() { return !QUERY(cache); } - int syslog_disabled() { return QUERY(LogA)!="syslog"; } +  + private int cache_disabled_p() { return !QUERY(cache); } + private int syslog_disabled() { return QUERY(LogA)!="syslog"; }   private int ident_disabled_p() { return QUERY(default_ident); }    -  + // Get the current domain. This is not as easy as one could think. + string get_domain(int|void l) + { +  array f; +  string t, s; +  + // ConfigurationURL is set by the 'install' script. +  if(!(!l && sscanf(QUERY(ConfigurationURL), "http://%s:%*s", s))) +  { + #if constant(gethostbyname) && constant(gethostname) +  f = gethostbyname(gethostname()); // First try.. +  if(f) +  foreach(f, f) if (arrayp(f)) { +  foreach(f, t) if(search(t, ".") != -1 && !(int)t) +  if(!s || strlen(s) < strlen(t)) +  s=t; +  } + #endif +  if(!s) +  { +  // FIXME: NT support. +  +  t = Stdio.read_bytes("/etc/resolv.conf"); +  if(t) +  { +  if(!sscanf(t, "domain %s\n", s)) +  if(!sscanf(t, "search %s%*[ \t\n]", s)) +  s="nowhere"; +  } else { +  s="nowhere"; +  } +  s = "host."+s; +  } +  } +  sscanf(s, "%*s.%s", s); +  if(s && strlen(s)) +  { +  if(s[-1] == '.') s=s[..strlen(s)-2]; +  if(s[0] == '.') s=s[1..]; +  } else { +  s="unknown"; +  } +  return s; + } +  +  + // This is the most likely URL for a virtual server. Again, this + // should move into the actual 'configuration' object. It is not all + // that nice to have all this code lying around in here. +  + string get_my_url() + { +  string s; + #if constant(gethostname) +  s = (gethostname()/".")[0] + "." + query("Domain"); + #else +  s = "localhost"; + #endif +  s -= "\n"; +  return "http://" + s + "/"; + } +    string docurl;      void define_global_variables( int argc, array (string) argv )   {    int p;    -  +     globvar("set_cookie", 0, "Set unique user id cookies", TYPE_FLAG,    #"If set to Yes, all users of your server whose clients support   cookies will get a unique 'user-id-cookie', this can then be   used in the log and in scripts to track individual users.");       deflocaledoc( "svenska", "set_cookie",    "Sätt en unik cookie för alla användare",    #"Om du sätter den här variabeln till 'ja', så kommer   alla användare att få en unik kaka (cookie) med namnet 'RoxenUserID' satt. Den   här kakan kan användas i skript för att spåra individuella användare. Det är
Roxen.git/server/base_server/global_variables.pike:95:          globvar("logdirprefix", "../logs/", "Log directory prefix",    TYPE_DIR|VAR_MORE,    #"This is the default file path that will be prepended to the log    file path in all the default modules and the virtual server.");       deflocaledoc( "svenska", "logdirprefix", "Loggningsmappprefix",    "Alla nya loggar som skapas får det här prefixet.");    -  // Cache variables. The actual code recides in the file -  // 'disk_cache.pike' -  -  +     globvar("cache", 0, "Proxy disk cache: Enabled", TYPE_FLAG,    "If set to Yes, caching will be enabled.");    deflocaledoc( "svenska", "cache", "Proxydiskcache: På",    "Om ja, använd cache i alla proxymoduler som hanterar det.");       globvar("garb_min_garb", 1, "Proxy disk cache: Clean size", TYPE_INT,    "Minimum number of Megabytes removed when a garbage collect is done.",    0, cache_disabled_p);    deflocaledoc( "svenska", "garb_min_garb",    "Proxydiskcache: Minimal rensningsmängd",
Roxen.git/server/base_server/global_variables.pike:607:   #"Om servern inte svarar på några frågor under så här många    minuter så kommer roxen startas om automatiskt. Om du    har en väldigt långsam dator kan en minut vara för    kort tid för en del saker, t.ex. diagramritning kan ta    ett bra tag.");          globvar("locale", "standard", "Language", TYPE_STRING_LIST,    "Locale, used to localise all messages in roxen.\n"   #"Standard means using the default locale, which varies according to the - value of the 'LANG' environment variable.", sort(indices(Locale.Roxen) - -  ({ "Modules" }))); + value of the 'LANG' environment variable.", +  sort(indices(master()->resolv("Locale")["Roxen"]) +  - ({ "Modules" })));    deflocaledoc("svenska", "locale", "Språk",    "Den här variablen anger vilket språk roxen ska använda. "    "'standard' betyder att språket sätts automatiskt från "    "värdet av omgivningsvariabeln LANG.");       globvar("suicide_engage",    0,    "Automatic Restart: Enable",    TYPE_FLAG|VAR_MORE,   #"If set, Roxen will automatically restart after a configurable number of
Roxen.git/server/base_server/global_variables.pike:710:    }    }    else    perror("Unknown variable: "+c+"\n");    }    }    docurl=QUERY(docurl2);      }    +  + static mapping __vars = ([ ]); +  + // These two should be documented somewhere. They are to be used to + // set global, but non-persistent, variables in Roxen. By using + // these functions modules can "communicate" with one-another. This is + // not really possible otherwise. + mixed set_var(string var, mixed to) + { +  return __vars[var] = to; + } +  + mixed query_var(string var) + { +  return __vars[var]; + } +  +  + // return the URL of the configuration interface. This is not as easy + // as it sounds, unless the administrator has entered it somewhere. +  + public string config_url() + { +  if(strlen(QUERY(ConfigurationURL)-" ")) +  return QUERY(ConfigurationURL)-" "; +  +  array ports = QUERY(ConfigPorts), port, tmp; +  +  if(!sizeof(ports)) return "CONFIG"; +  +  int p; +  string prot; +  string host; +  +  foreach(ports, tmp) +  if(tmp[1][0..2]=="ssl") +  { +  port=tmp; +  break; +  } +  +  if(!port) +  foreach(ports, tmp) +  if(tmp[1]=="http") +  { +  port=tmp; +  break; +  } +  +  if(!port) port=ports[0]; +  +  if(port[2] == "ANY") + // host = quick_ip_to_host( port[2] ); + // else +  { + #if efun(gethostname) +  host = gethostname(); + #else +  host = "127.0.0.1"; + #endif +  } +  +  switch(port[1][..2]) { +  case "ssl": +  prot = "https"; +  break; +  case "ftp": +  prot = "ftp"; +  break; +  default: +  prot = port[1]; +  break; +  } +  p = port[0]; +  +  return (prot+"://"+host+":"+p+"/"); + }