All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.aoindustries.aoserv.client.HttpdSite Maven / Gradle / Ivy

There is a newer version: 1.92.0
Show newest version
/*
 * aoserv-client - Java client for the AOServ platform.
 * Copyright (C) 2001-2009, 2016  AO Industries, Inc.
 *     [email protected]
 *     7262 Bull Pen Cir
 *     Mobile, AL 36695
 *
 * This file is part of aoserv-client.
 *
 * aoserv-client is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * aoserv-client is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with aoserv-client.  If not, see .
 */
package com.aoindustries.aoserv.client;

import com.aoindustries.io.CompressedDataInputStream;
import com.aoindustries.io.CompressedDataOutputStream;
import com.aoindustries.util.BufferManager;
import java.io.IOException;
import java.io.OutputStream;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Collections;
import java.util.List;

/**
 * An HttpdSite is one unique set of web content and resides in
 * its own directory under /www.  Each HttpdSite
 * has a unique name per server, and may be served simultaneously on any
 * number of HttpdBinds through any number of
 * HttpdServers.
 * 

* An HttpdSite only stores the information that is common to * all site types. The site will always reference one, and only one, other * type of entry, indicating the type of site and providing the rest of the * information about the site. * * @see HttpdSiteBind * @see HttpdBind * @see HttpdServer * @see HttpdStaticSite * @see HttpdTomcatSite * * @author AO Industries, Inc. */ final public class HttpdSite extends CachedObjectIntegerKey implements Disablable, Removable { static final int COLUMN_PKEY = 0, COLUMN_AO_SERVER = 1, COLUMN_PACKAGE = 4 ; static final String COLUMN_SITE_NAME_name = "site_name"; static final String COLUMN_AO_SERVER_name = "ao_server"; public static final int MAX_SITE_NAME_LENGTH = 255; // Same as maximum name of a directory /** * @deprecated The directory for websites is now operating-system specific. * * @see OperatingSystemVersion#getHttpdSitesDirectory() * @see OperatingSystemVersion#getHttpdSitesDirectory(int) */ @Deprecated public static final String WWW_DIRECTORY = "/www"; /** * The site name used when an account is disabled. */ public static final String DISABLED = "disabled"; int ao_server; String site_name; private boolean list_first; String packageName; String linuxAccount; String linuxGroup; private String serverAdmin, contentSrc ; int disable_log; private boolean isManual; private String awstatsSkipFiles; private int phpVersion; private boolean enableCgi; public int addHttpdSiteAuthenticatedLocation( String path, boolean isRegularExpression, String authName, String authGroupFile, String authUserFile, String require ) throws IOException, SQLException { return table.connector.getHttpdSiteAuthenticatedLocationTable().addHttpdSiteAuthenticatedLocation( this, path, isRegularExpression, authName, authGroupFile, authUserFile, require ); } @Override public boolean canDisable() throws IOException, SQLException { if(disable_log!=-1) return false; for(HttpdSiteBind hsb : getHttpdSiteBinds()) if(hsb.disable_log==-1) return false; return true; } @Override public boolean canEnable() throws SQLException, IOException { DisableLog dl=getDisableLog(); if(dl==null) return false; else return dl.canEnable() && getPackage().disable_log==-1 && getLinuxServerAccount().disable_log==-1 ; } @Override public List getCannotRemoveReasons() { return Collections.emptyList(); } @Override public void disable(DisableLog dl) throws IOException, SQLException { table.connector.requestUpdateIL(true, AOServProtocol.CommandID.DISABLE, SchemaTable.TableID.HTTPD_SITES, dl.pkey, pkey); } @Override public void enable() throws IOException, SQLException { table.connector.requestUpdateIL(true, AOServProtocol.CommandID.ENABLE, SchemaTable.TableID.HTTPD_SITES, pkey); } /** * Gets the directory where this site is installed. */ public String getInstallDirectory() throws SQLException, IOException { return getAOServer().getServer().getOperatingSystemVersion().getHttpdSitesDirectory()+'/'+site_name; } @Override Object getColumnImpl(int i) { switch(i) { case COLUMN_PKEY: return pkey; case COLUMN_AO_SERVER: return ao_server; case 2: return site_name; case 3: return list_first; case COLUMN_PACKAGE: return packageName; case 5: return linuxAccount; case 6: return linuxGroup; case 7: return serverAdmin; case 8: return contentSrc; case 9: return disable_log==-1?null:disable_log; case 10: return isManual; case 11: return awstatsSkipFiles; case 12: return phpVersion==-1 ? null : phpVersion; case 13: return enableCgi; default: throw new IllegalArgumentException("Invalid index: "+i); } } public String getContentSrc() { return contentSrc; } @Override public boolean isDisabled() { return disable_log!=-1; } @Override public DisableLog getDisableLog() throws SQLException, IOException { if(disable_log == -1) return null; DisableLog obj = table.connector.getDisableLogs().get(disable_log); if(obj == null) throw new SQLException("Unable to find DisableLog: "+disable_log); return obj; } public List getHttpdSiteAuthenticatedLocations() throws IOException, SQLException { return table.connector.getHttpdSiteAuthenticatedLocationTable().getHttpdSiteAuthenticatedLocations(this); } public List getHttpdSiteBinds() throws IOException, SQLException { return table.connector.getHttpdSiteBinds().getHttpdSiteBinds(this); } public List getHttpdSiteBinds(HttpdServer server) throws SQLException, IOException { return table.connector.getHttpdSiteBinds().getHttpdSiteBinds(this, server); } public HttpdStaticSite getHttpdStaticSite() throws IOException, SQLException { return table.connector.getHttpdStaticSites().get(pkey); } public HttpdTomcatSite getHttpdTomcatSite() throws IOException, SQLException { return table.connector.getHttpdTomcatSites().get(pkey); } public LinuxServerAccount getLinuxServerAccount() throws SQLException, IOException { // May be filtered LinuxAccount obj = table.connector.getLinuxAccounts().get(linuxAccount); if(obj == null) return null; LinuxServerAccount lsa = obj.getLinuxServerAccount(getAOServer()); if(lsa == null) throw new SQLException("Unable to find LinuxServerAccount: "+linuxAccount+" on "+ao_server); return lsa; } public LinuxServerGroup getLinuxServerGroup() throws SQLException, IOException { LinuxGroup obj = table.connector.getLinuxGroups().get(linuxGroup); if(obj == null) throw new SQLException("Unable to find LinuxGroup: "+linuxGroup); LinuxServerGroup lsg = obj.getLinuxServerGroup(getAOServer()); if(lsg == null) throw new SQLException("Unable to find LinuxServerGroup: "+linuxGroup+" on "+ao_server); return lsg; } public Package getPackage() throws SQLException, IOException { Package obj = table.connector.getPackages().get(packageName); if(obj == null) throw new SQLException("Unable to find Package: "+packageName); return obj; } public HttpdSiteURL getPrimaryHttpdSiteURL() throws SQLException, IOException { List binds=getHttpdSiteBinds(); if(binds.isEmpty()) return null; // Find the first one that binds to the default HTTP port, if one exists NetPort httpPort=table.connector.getProtocols().get(Protocol.HTTP).getPort(table.connector); int index = -1; for(int c=0;c/www * directory. The site name must be 255 characters or less, and comprised of * only a-z, 0-9, . or -. The first * character must be a-z or 0-9. */ public static boolean isValidSiteName(String name) { // These are the other files/directories that may exist under /www. To avoid // potential conflicts, these may not be used as site names. if( "lost+found".equals(name) || ".backup".equals(name) || "aquota.user".equals(name) ) return false; int len = name.length(); if (len == 0 || len > MAX_SITE_NAME_LENGTH) return false; // The first character must be [a-z] or [0-9] char ch = name.charAt(0); if ( (ch < 'a' || ch > 'z') && (ch<'0' || ch>'9') ) return false; // The rest may have additional characters for (int c = 1; c < len; c++) { ch = name.charAt(c); if( (ch < 'a' || ch > 'z') && (ch < '0' || ch > '9') && ch != '.' && ch != '-' ) return false; } return true; } public boolean listFirst() { return list_first; } @Override public void read(CompressedDataInputStream in) throws IOException { pkey = in.readCompressedInt(); ao_server = in.readCompressedInt(); site_name = in.readUTF(); list_first = in.readBoolean(); packageName = in.readUTF().intern(); linuxAccount = in.readUTF().intern(); linuxGroup = in.readUTF().intern(); serverAdmin = in.readUTF(); contentSrc = in.readNullUTF(); disable_log = in.readCompressedInt(); isManual = in.readBoolean(); awstatsSkipFiles = in.readNullUTF(); phpVersion = in.readCompressedInt(); enableCgi = in.readBoolean(); } @Override public void remove() throws IOException, SQLException { table.connector.requestUpdateIL(true, AOServProtocol.CommandID.REMOVE, SchemaTable.TableID.HTTPD_SITES, pkey); } public void setIsManual(boolean isManual) throws IOException, SQLException { table.connector.requestUpdateIL(true, AOServProtocol.CommandID.SET_HTTPD_SITE_IS_MANUAL, pkey, isManual); } public void setServerAdmin(String address) throws IOException, SQLException { table.connector.requestUpdateIL(true, AOServProtocol.CommandID.SET_HTTPD_SITE_SERVER_ADMIN, pkey, address); } @Override String toStringImpl() throws SQLException, IOException { return site_name+" on "+getAOServer().getHostname(); } @Override public void write(CompressedDataOutputStream out, AOServProtocol.Version version) throws IOException { out.writeCompressedInt(pkey); out.writeCompressedInt(ao_server); out.writeUTF(site_name); out.writeBoolean(list_first); out.writeUTF(packageName); out.writeUTF(linuxAccount); out.writeUTF(linuxGroup); out.writeUTF(serverAdmin); out.writeNullUTF(contentSrc); if(version.compareTo(AOServProtocol.Version.VERSION_1_30)<=0) { out.writeShort(0); out.writeShort(7); out.writeShort(0); out.writeShort(7); out.writeShort(0); out.writeShort(7); out.writeShort(0); out.writeShort(7); } out.writeCompressedInt(disable_log); out.writeBoolean(isManual); if(version.compareTo(AOServProtocol.Version.VERSION_1_0_A_129) >= 0) { out.writeNullUTF(awstatsSkipFiles); } if(version.compareTo(AOServProtocol.Version.VERSION_1_78) >= 0) { out.writeCompressedInt(phpVersion); } if(version.compareTo(AOServProtocol.Version.VERSION_1_79) >= 0) { out.writeBoolean(enableCgi); } } public void getAWStatsFile(final String path, final String queryString, final OutputStream out) throws IOException, SQLException { table.connector.requestUpdate( false, new AOServConnector.UpdateRequest() { @Override public void writeRequest(CompressedDataOutputStream masterOut) throws IOException { masterOut.writeCompressedInt(AOServProtocol.CommandID.GET_AWSTATS_FILE.ordinal()); masterOut.writeCompressedInt(pkey); masterOut.writeUTF(path); masterOut.writeUTF(queryString==null ? "" : queryString); } @Override public void readResponse(CompressedDataInputStream in) throws IOException, SQLException { byte[] buff=BufferManager.getBytes(); try { int code; while((code=in.readByte())==AOServProtocol.NEXT) { int len=in.readShort(); in.readFully(buff, 0, len); out.write(buff, 0, len); } AOServProtocol.checkResult(code, in); } finally { BufferManager.release(buff, false); } } @Override public void afterRelease() { } } ); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy