Exemplo n.º 1
0
		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;
		}
Exemplo n.º 2
0
		string[] find_htaccess_files(http_request req, DataAccessLayer d) {
			List<String> paths = new List<string> ();
			string[] folders = req.script_name.Split (new string[] { "/" }, StringSplitOptions.RemoveEmptyEntries);
			String path = "";

			foreach (string folder in folders) {
				path = Path.Combine (path, folder);
				if(d.FileExists(Path.Combine(path,".htaccess")))
				   paths.Add(Path.Combine(path,".htaccess"));
			}
			return paths.ToArray ();
		}
Exemplo n.º 3
0
		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);
			}

		}
Exemplo n.º 4
0
		void InitSettings ()
		{
			String rp = "/var/www";
			if(Environment.OSVersion.Platform == PlatformID.Win32NT)
				rp = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),"www");

			_dataLayer = new FileDataAccessLayer(rp);

			Setting root_path = new Setting(
				typeof(String),
				"Document Root",
				rp,
				"The root directory for the webserver",
				"General");

			root_path.OnSettingChanged += delegate(object sender, EventArgs e) {
				String path = (String)((Setting)sender).Value;
				if(!Directory.Exists(path))
					Directory.CreateDirectory(path);
				_dataLayer = new FileDataAccessLayer(path);
			};
			_settings.Add(root_path);
		}
Exemplo n.º 5
0
		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));
		}
Exemplo n.º 6
0
		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;
				}
			}
		}
Exemplo n.º 7
0
		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;
		}
Exemplo n.º 8
0
		public void apply_directives(http_request req, DataAccessLayer d, string virtual_path) {
			foreach (Rewrite rw in _rws) {
				rw.rewrite (req, d, virtual_path);
			}
		}