java.lang.Object
com.aoindustries.aoserv.daemon.httpd.HttpdSiteManager
Direct Known Subclasses:
HttpdStaticSiteManager, HttpdTomcatSiteManager

public abstract class HttpdSiteManager extends Object
Manages Site configurations.
Author:
AO Industries, Inc.
  • Field Details

    • httpdSite

      protected final Site httpdSite
  • Constructor Details

    • HttpdSiteManager

      protected HttpdSiteManager(Site httpdSite)
  • Method Details

    • getInstance

      public static HttpdSiteManager getInstance(Site site) throws IOException, SQLException
      Gets the specific manager for one type of web site.
      Throws:
      IOException
      SQLException
    • stopAndDisableDaemons

      public static void stopAndDisableDaemons(PosixFile siteDirectory) throws IOException, SQLException
      Stops all daemons that may be running in the provided directory. The exact type of site is not known. This is called during site clean-up to shutdown processes that should no longer be running. It is assumed that all types of sites will use the "daemon" directory with symbolic links that accept "start" and "stop" parameters.
      Throws:
      IOException
      SQLException
      See Also:
      • doRebuild(java.util.List<java.io.File>, java.util.Set<com.aoindustries.aoserv.client.web.Site>, java.util.Set<com.aoindustries.aoserv.client.web.tomcat.SharedTomcat>, java.util.Set<com.aoindustries.aoserv.daemon.posix.linux.PackageManager.PackageName>, java.util.Set<com.aoapps.io.posix.PosixFile>)
    • startHttpdSite

      public static String startHttpdSite(int sitePkey) throws IOException, SQLException
      Starts the site if it is not running. Restarts it if it is running.
      Returns:
      null if successful or a user-readable reason if not successful
      Throws:
      IOException
      SQLException
    • stopHttpdSite

      public static String stopHttpdSite(int sitePkey) throws IOException, SQLException
      Stops the site if it is running. Will return a message if already stopped.
      Returns:
      null if successful or a user-readable reason if not success.
      Throws:
      IOException
      SQLException
    • getAutoWarningXmlOld

      public String getAutoWarningXmlOld() throws IOException, SQLException
      Gets the auto-mode warning for this website for use in XML files. This may be used on any config files that a user would be tempted to change directly.
      Throws:
      IOException
      SQLException
    • getAutoWarningXml

      public String getAutoWarningXml() throws IOException, SQLException
      Gets the auto-mode warning for this website for use in XML files. This may be used on any config files that a user would be tempted to change directly.
      Throws:
      IOException
      SQLException
    • getRequiredPackages

      protected Set<PackageManager.PackageName> getRequiredPackages() throws IOException, SQLException
      Gets any packages that must be installed for this site.

      By default, no specific packages are required.

      Throws:
      IOException
      SQLException
    • buildSiteDirectory

      protected abstract void buildSiteDirectory(PosixFile siteDirectory, String optSlash, Set<Site> sitesNeedingRestarted, Set<SharedTomcat> sharedTomcatsNeedingRestarted, Set<PosixFile> restorecon) throws IOException, SQLException
      (Re)builds the site directory, from scratch if it doesn't exist. Creates, recreates, or removes resources as necessary. Also performs an automatic upgrade of resources if appropriate for the site. Also reconfigures any config files within the directory if appropriate for the site type and settings. If this site or other sites needs to be restarted due to changes in the files, add to sitesNeedingRestarted. If any shared Tomcat needs to be restarted due to changes in the files, add to sharedTomcatsNeedingRestarted. Any files under siteDirectory that need to be updated to enable/disable this site should be changed. Actual process start/stop will be performed later in stopStartAndRestart.
      1. If siteDirectory doesn't exist, create it as root with mode 0700
      2. If siteDirectory owned by root, do full pass (this implies manual=false regardless of setting)
      3. Otherwise, make necessary config changes or upgrades while adhering to the manual flag
      Throws:
      IOException
      SQLException
    • enableAnonymousFtp

      public boolean enableAnonymousFtp()
      Determines if should have anonymous FTP area.
    • configureFtpDirectory

      public void configureFtpDirectory(PosixFile ftpDirectory, Set<PosixFile> restorecon) throws IOException, SQLException
      Configures the anonymous FTP directory associated with this site. If the site is disabled, will make owner root, group root, mode 0700. Will reset ownership and permissions as needed. This will only be called when enableAnonymousFtp returns true. Manual mode has no impact on the ownership and permissions set.
      Throws:
      IOException
      SQLException
      See Also:
    • enableCgi

      protected boolean enableCgi()
      Determines if CGI should be enabled.
      See Also:
    • enablePhp

      protected boolean enablePhp() throws IOException, SQLException
      Determines if PHP should be enabled.

      If this is enabled and CGI is disabled, then the HttpdServer for the site must use mod_php.

      Throws:
      IOException
      SQLException
      See Also:
    • createCgiPhpScript

      protected void createCgiPhpScript(PosixFile siteDirectory, PosixFile cgibinDirectory, Set<PosixFile> restorecon) throws IOException, SQLException
      Creates or updates the CGI php script, CGI must be enabled and PHP enabled. If CGI is disabled or PHP is disabled, removes any php script. Any existing file will be overwritten, even when in manual mode.
      Throws:
      IOException
      SQLException
    • createTestIndex

      protected void createTestIndex(PosixFile indexFile) throws IOException, SQLException
      Creates the test index.html file if it is missing.

      TODO: Generate proper disabled page automatically. Or, better, put into logic of static site rebuild.

      Throws:
      IOException
      SQLException
    • getApacheUid

      public int getApacheUid() throws IOException, SQLException
      Gets the user ID that apache for this site runs as. If this site runs as multiple UIDs on multiple Apache instances, will return the "apache" user. If the site has no binds, returns UID for "apache". If the site is named Site.DISABLED, always returns UID for "apache".
      Throws:
      IOException
      SQLException
    • getRejectedLocations

      public Map<String,List<HttpdSiteManager.Location>> getRejectedLocations() throws IOException, SQLException
      Gets an unmodifiable map of URL patterns that should be rejected.
      Throws:
      IOException
      SQLException
    • getPermanentRewriteRules

      public List<HttpdSiteManager.PermanentRewriteRule> getPermanentRewriteRules()
      Gets the set of permanent rewrite rules. By default, no rules.
    • blockAllTraceAndTrackRequests

      public boolean blockAllTraceAndTrackRequests()
      By default, sites will block all TRACE and TRACK requests.

      Seriously consider security ramifications before enabling TRACK and TRACE.

      See Also:
    • getJkSettings

      Gets the JkMount and JkUnmounts for this site.

      This default implementation returns an empty set.

      Returns:
      An empty set if no Jk enabled.
      Throws:
      IOException
      SQLException
    • getWebapps

      Gets all the webapps for this site. The key is the webapp path and the value is the settings for that path. If any webapp enables CGI, then this site overall must allow CGI.
      Throws:
      IOException
      SQLException