public Boolean check(http_request req, DataAccessLayer d) { Boolean retval = false; switch (_match) { case "!-d": retval = !d.DirectoryExists (cgi.get_var(_subject_t,req)); break; case "!-f": retval = !d.FileExists (cgi.get_var (_subject_t, req)); break; default: #if DEBUG Console.Error.WriteLine ("RewriteCond " + _match + " is Regex?"); #endif Regex reg = new Regex (_match); if (_match.StartsWith ("!")) { string _tempmatch = _match.TrimStart ("!".ToCharArray ()); reg = new Regex (_tempmatch); retval = !reg.IsMatch (cgi.get_var (_subject_t, req)); } else { retval = reg.IsMatch (cgi.get_var (_subject_t, req)); } break; } return retval; }
public void apply(http_request req,string virtual_path){ if (_status.Contains ("E=")) return; Regex reg = new Regex (_match); if (reg.IsMatch (req.script_name)) { if (_status.Contains ("L")) req.script_name = "/" + Path.Combine (virtual_path, _dest); else { req.Header.Target = "/" + Path.Combine (virtual_path, _dest); req.Uri = new meticulus.text.URI.HttpUri (req.Header.Target); } } }
public void rewrite(http_request req, DataAccessLayer d, string virtual_path) { Boolean check = false; if (_conds.Count > 0) { for (int i = 0; i < _conds.Count; i ++) { if (i == 0) check = _conds [i].check (req, d); else if (_conds [i - 1].or) check = (check || _conds [i].check (req, d)); else check = (check & _conds [i].check (req, d)); } if (check) { foreach (RewriteRule rr in _rules) rr.apply (req, virtual_path); } } else { foreach (RewriteRule rr in _rules) rr.apply (req, virtual_path); } }
private Boolean extension_check(http_request req, DataAccessLayer d) { return d.FileExists(req.script_name) && new List<String>(_extentions).Contains(Path.GetExtension(req.script_name)); }
private void inpath_php(http_request req, DataAccessLayer d) { if(!d.DirectoryExists(req.script_name) && !d.FileExists(req.script_name)) { Boolean done = false; foreach(String ext in _extentions) { if(req.script_name.Contains(ext +"/")) { int index = req.script_name.IndexOf(ext +"/") + ext.Length; req.script_name = req.script_name.Substring(0,index); done = true; break; } } if(!done) { String[] folders = req.script_name.Split("/".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); String path = req.script_name; for(int i = folders.Length -1; i > -1; i --) { if(!d.DirectoryExists(path) & !d.FileExists(path)) { path = path.TrimEnd("/".ToCharArray()); int index = path.LastIndexOf(folders[i]); path = path.Remove(index); } else { break; } } req.script_name = path; } } }
private Boolean index_check(http_request req, DataAccessLayer d,http_response res) { Boolean retval = false; if (d.DirectoryExists (req.script_name)) { foreach (string index_file in _indexes) { String possible_index = Path.Combine (req.script_name, index_file); if (d.FileExists (possible_index)) { if(_redirectdirtoindex) { res.Header.Statuscode = "302"; res.Header.Statusmessage = "Found"; res.Header.SetValue ("Location", req.script_name + index_file); res.Header.ContentLength = 0; res.Respond(req.Connection,req.Connection.GetStream()); retval = true; } else { req.script_name = possible_index; retval = false; } break; } } } return retval; }
public void apply_directives(http_request req, DataAccessLayer d, string virtual_path) { foreach (Rewrite rw in _rws) { rw.rewrite (req, d, virtual_path); } }