public Override override(String key) { for (Override o : overrides) if (o.name().equalsIgnoreCase(key)) return o; return null; }
public boolean overrideNone() { for (Override o : overrides) if (o.allowed()) return false; return true; }
/** * Processes the provided {@link ApacheSection} (i.e., .htaccess) for instructions and options * * @param handler The {@link HttpHandler} * @return Will return false if the current request should halt, i.e., the request was already * handled by the directives */ public boolean handleDirectives(ApacheSection apache, HttpHandler handler) throws ApacheDirectiveException { boolean def = true; for (ApacheDirective kv : apache.directives()) { String key = kv.getKey(); String[] args = kv.getArguments(); HttpRequestWrapper request = handler.getRequest(); // HttpResponseWrapper response = handler.getResponse(); WebInterpreter fi = handler.getInterpreter(); Site site = handler.getSite(); switch (key) { /** Section Types */ case "IfDefine": kv.isSection(); kv.hasArguments(1, "<Startup Argument>"); if (AppLoader.options().has(args[0]) || AppLoader.options().hasArgument(args[0])) if (!handleDirectives((ApacheSection) kv, handler)) def = false; break; case "IfModule": // TODO Implement detection of common Apache modules the server can // currently imitate, e.g., Rewrite kv.isSection(); kv.hasArguments(1, "<plugin>"); if (PluginManager.instance().getPluginByNameWithoutException(args[0]) != null || PluginManager.instance().getPluginByClassnameWithoutException(args[0]) != null) if (!handleDirectives((ApacheSection) kv, handler)) def = false; break; case "IfVersion": kv.isSection(); kv.hasArguments(2, "<operator> <version>"); if (StringFunc.compareVersions(Versioning.getVersionNumber(), args[1], args[0])) if (!handleDirectives((ApacheSection) kv, handler)) def = false; break; case "Directory": kv.isSection(); kv.hasArguments(1, "<directory>"); if (fi.hasFile()) { String rel = fi.getFilePath() .substring( site.getSubdomain(request.getSubdomain()) .directory() .getAbsolutePath() .length()); if (rel.startsWith("/")) rel = rel.substring(1); if (args[0].startsWith("/") && (fi.getFilePath().startsWith(args[0]) || ("/" + rel).startsWith(args[0])) || rel.startsWith(args[0])) if (!handleDirectives((ApacheSection) kv, handler)) def = false; } break; /** Individual Key/Values */ case "ErrorDocument": ErrorDocument doc = ErrorDocument.parseArgs(args); errorDocuments.put(doc.getHttpCode(), doc); break; case "AllowOverride": for (String a : args) if (a.equalsIgnoreCase("All")) for (Override o : overrides) o.allow(); else if (a.equalsIgnoreCase("None")) for (Override o : overrides) o.deny(); else { Override o = override(a.contains("=") ? a.substring(0, a.indexOf("=")) : a); if (o == null) throw new ApacheDirectiveException( "The 'AllowOverride' directive does not reconize the option '" + a + "'", kv); if ((o == overrides.overrideNonfatal || o == overrides.overrideOptions) && a.contains("=")) o.setParams(a.substring(a.indexOf("=") + 1)); o.allow(); } break; case "Location": kv.isSection(); kv.hasArguments(1, "<url>"); if (request.getUri().startsWith(args[0])) if (!handleDirectives((ApacheSection) kv, handler)) def = false; break; case "LocationMatch": kv.isSection(); kv.hasArguments(1, "<url regex>"); if (request.getUri().matches(args[0])) if (!handleDirectives((ApacheSection) kv, handler)) def = false; break; case "Options": if (overrides.overrideOptions.allowed()) for (String a : args) { if ((a.startsWith("+") || a.startsWith("-") ? a.substring(1) : a) .equalsIgnoreCase("All")) { for (Option o : options) if (o != options.optionMultiViews) if (a.startsWith("-")) o.disable(); else o.enable(); } else { Option o = option(a.startsWith("+") || a.startsWith("-") ? a.substring(1) : a); if (o == null) throw new ApacheDirectiveException( "The 'Options' directive does not reconize the option '" + a + "'", kv); if (a.startsWith("-")) o.disable(); else o.enable(); } } else throw new ApacheDirectiveException( "The directive 'Option' has been forbidden here", kv); break; case "VirtualHost": throw new ApacheDirectiveException( "You can not define a new site using the VirtualHost directive here, site configs are located within the webroot."); case "Proxy": case "ProxyMatch": case "ProxyPass": throw new ApacheDirectiveException( "The module mod_proxy is exclusive to the Apache Web Server. We currently have no implementation, nor interest, to support said directives."); default: throw new ApacheDirectiveException( "Currently the Apache directive '" + key + "' is not implemented", kv); } // ErrorDocument 403 http://www.yahoo.com/ // Order deny,allow // Deny from all // Allow from 208.113.134.190 } return def; }