<?php

/**
 * resources/templates/etc/appserver/appserver.xml.phtml
 *
 * PHP version 5
 *
 * @category   Server
 * @package    Appserver
 * @subpackage Meta
 * @author     Tim Wagner <tw@appserver.io>
 * @author     Bernhard Wick <bw@appserver.io>
 * @author     Johann Zelger <jz@appserver.io>
 * @copyright  2014 TechDivision GmbH <info@appserver.io>
 * @license    http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
 * @link       http://www.appserver.io
 */

use AppserverIo\Appserver\Meta\Composer\Script\Setup;
use AppserverIo\Appserver\Meta\Composer\Script\SetupKeys;

?>
<?php echo '<?xml version="1.0" encoding="UTF-8"?>' . PHP_EOL ?>
<appserver xmlns="http://www.appserver.io/appserver"  xmlns:xi="http://www.w3.org/2001/XInclude">

    <params>
        <param name="user" type="string"><?php echo Setup::getValue(SetupKeys::USER) ?></param>
        <param name="group" type="string"><?php echo Setup::getValue(SetupKeys::GROUP) ?></param>
        <param name="umask" type="string"><?php echo Setup::getValue(SetupKeys::UMASK) ?></param>
        <param name="allowApplicationConfiguration" type="boolean">true</param>
    </params>

    <!--
     ! Customize this to fit your needs ragarding log information. The logLevel attribute can be one
     ! of https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-3-logger-interface.md#5-psrlogloglevel.
     -->

    <loggers>
        <logger channelName="system" name="System" type="\AppserverIo\Logger\Logger">
            <handlers>
                <handler type="\AppserverIo\Logger\Handlers\CustomFileHandler">
                    <formatter type="\AppserverIo\Logger\Formatters\StandardFormatter"/>
                    <params>
                        <param name="logFile" type="string">php://stdout</param>
                        <param name="logLevel" type="string">info</param>
                    </params>
                </handler>
            </handlers>
        </logger>
        <logger channelName="access" name="Access" type="\AppserverIo\Logger\Logger">
            <handlers>
                <handler type="\AppserverIo\Logger\Handlers\CustomFileHandler">
                    <formatter type="\AppserverIo\Logger\Formatters\StandardFormatter">
                        <params>
                            <param name="format" type="string">%4$s</param>
                        </params>
                    </formatter>
                    <params>
                        <param name="logFile" type="string">php://stderr</param>
                        <param name="logLevel" type="string">info</param>
                    </params>
                </handler>
            </handlers>
        </logger>
    </loggers>

    <!--
     ! You might add optional configuration for implicitly configured components here.
     !
     ! http://appserver.io/get-started/documentation/configuration.html#optional-configuration
     -->

    <containers>

        <container
                name="system-container"
                type="AppserverIo\Appserver\Core\GenericContainer"
                factory="AppserverIo\Appserver\Core\GenericContainerFactory">

            <description>
                <![CDATA[Container for appserver.io internal functionality]]>
            </description>

            <deployment type="AppserverIo\Appserver\Core\GenericDeployment" />

            <host name="internal" appBase="internal" deployBase="var/deploy" tmpBase="var/tmp/internal" />

            <servers>

                <server
                    name="dns"
                    type="\AppserverIo\Server\Servers\MultiThreadedServer"
                    worker="\AppserverIo\DnsServer\Workers\UdpThreadWorker"
                    socket="\AppserverIo\Server\Sockets\StreamSocket"
                    streamContext="\AppserverIo\Server\Contexts\StreamContext"
                    serverContext="\AppserverIo\Server\Contexts\ServerContext"
                    requestContext="\AppserverIo\Server\Contexts\RequestContext"
                    loggerName="System">

                    <params>
                        <param name="admin" type="string"><?php echo Setup::getValue(SetupKeys::ADMIN_EMAIL) ?></param>
                        <param name="transport" type="string">udp</param>
                        <param name="address" type="string">127.0.0.1</param>
                        <param name="port" type="integer">9053</param>
                        <param name="flags" type="string">STREAM_SERVER_BIND</param>
                        <param name="workerNumber" type="integer">4</param>
                        <param name="workerAcceptMin" type="integer">3</param>
                        <param name="workerAcceptMax" type="integer">8</param>
                    </params>

                    <connectionHandlers>
                        <connectionHandler type="\AppserverIo\DnsServer\ConnectionHandlers\DnsConnectionHandler" />
                    </connectionHandlers>

                    <modules>
                        <module type="\AppserverIo\DnsServer\Modules\CoreModule" >
                            <params>
                                <param name="resolverFactory" type="string">\AppserverIo\Appserver\Core\Modules\StorageProvider\SystemConfigurationResolverFactory</param>
                                <param name="defaultTTL" type="integer">300</param>
                            </params>
                        </module>
                    </modules>

                </server>

            </servers>

        </container>

        <container
                name="combined-appserver"
                type="AppserverIo\SingleApp\Core\SimpleContainer"
                factory="AppserverIo\Appserver\Core\GenericContainerFactory">

            <description>
                <![CDATA[This is an example of a webserver container that handles http requests in common way]]>
            </description>

            <deployment type="AppserverIo\SingleApp\Core\SimpleDeployment" />

            <host name="localhost" appBase="webapps" deployBase="deploy" tmpBase="var/tmp/localhost" />

            <servers>

                <!--
                 | To distribute componenents like SLSBs across a network, you've to configure separate server for
                 | the Persistence-Container.
                 |
                 | http://appserver.io/get-started/documentation/configuration.html#persistence-container-(remote)
                 |-->

                <server
                        name="message-queue"
                        type="\AppserverIo\Server\Servers\MultiThreadedServer"
                        worker="\AppserverIo\Server\Workers\ThreadWorker"
                        socket="\AppserverIo\Server\Sockets\StreamSocket"
                        requestContext="\AppserverIo\Server\Contexts\RequestContext"
                        serverContext="\AppserverIo\Appserver\Server\Contexts\StandardServerContext"
                        streamContext="\AppserverIo\Server\Contexts\StreamContext"
                        loggerName="System">

                    <params>
                        <param name="admin" type="string"><?php echo Setup::getValue(SetupKeys::ADMIN_EMAIL) ?></param>
                        <param name="transport" type="string">tcp</param>
                        <param name="address" type="string"><?php echo Setup::getValue(SetupKeys::CONTAINER_MESSAGE_QUEUE_HOST) ?></param>
                        <param name="port" type="integer"><?php echo Setup::getValue(SetupKeys::CONTAINER_MESSAGE_QUEUE_PORT) ?></param>
                        <param name="workerNumber" type="integer"><?php echo Setup::getValue(SetupKeys::CONTAINER_MESSAGE_QUEUE_WORKER_NUMBER) ?></param>
                        <param name="workerAcceptMin" type="integer"><?php echo Setup::getValue(SetupKeys::CONTAINER_SERVER_WORKER_ACCEPT_MIN) ?></param>
                        <param name="workerAcceptMax" type="integer"><?php echo Setup::getValue(SetupKeys::CONTAINER_SERVER_WORKER_ACCEPT_MAX) ?></param>
                        <param name="documentRoot" type="string">webapps</param>
                        <param name="directoryIndex" type="string">index.mq</param>
                        <param name="keepAliveMax" type="integer">64</param>
                        <param name="keepAliveTimeout" type="integer">5</param>
                        <param name="errorsPageTemplatePath" type="string">resources/templates/www/error.phtml</param>
                    </params>

                    <environmentVariables>
                        <environmentVariable condition="" definition="LOGGER_ACCESS=Access" />
                    </environmentVariables>

                    <connectionHandlers>
                        <connectionHandler type="\AppserverIo\WebServer\ConnectionHandlers\HttpConnectionHandler" />
                    </connectionHandlers>

                    <accesses>
                        <!-- per default allow everything -->
                        <access type="allow">
                            <params>
                                <param name="X_REQUEST_URI" type="string">.*</param>
                            </params>
                        </access>
                    </accesses>

                    <modules>
                        <!-- REQUEST_POST hook -->
                        <module type="\AppserverIo\WebServer\Modules\AuthenticationModule"/>
                        <module type="\AppserverIo\WebServer\Modules\VirtualHostModule"/>
                        <module type="\AppserverIo\WebServer\Modules\EnvironmentVariableModule" />
                        <module type="\AppserverIo\WebServer\Modules\RewriteModule"/>
                        <module type="\AppserverIo\WebServer\Modules\DirectoryModule"/>
                        <module type="\AppserverIo\WebServer\Modules\AccessModule"/>
                        <module type="\AppserverIo\WebServer\Modules\CoreModule"/>
                        <module type="\AppserverIo\Appserver\MessageQueue\MessageQueueModule" />
                        <!-- RESPONSE_PRE hook -->
                        <module type="\AppserverIo\WebServer\Modules\DeflateModule"/>
                        <!-- RESPONSE_POST hook -->
                    </modules>

                    <fileHandlers>
                        <fileHandler name="message-queue" extension=".mq" />
                    </fileHandlers>

                </server>

                <server
                        name="http"
                        type="\AppserverIo\Server\Servers\MultiThreadedServer"
                        worker="\AppserverIo\Server\Workers\ThreadWorker"
                        socket="\AppserverIo\Server\Sockets\StreamSocket"
                        requestContext="\AppserverIo\Server\Contexts\RequestContext"
                        serverContext="\AppserverIo\Appserver\Server\Contexts\StandardServerContext"
                        streamContext="\AppserverIo\Server\Contexts\StreamContext"
                        loggerName="System">
                    <params>
                        <param name="admin" type="string"><?php echo Setup::getValue(SetupKeys::ADMIN_EMAIL) ?></param>
                        <param name="transport" type="string">tcp</param>
                        <param name="address" type="string"><?php echo Setup::getValue(SetupKeys::CONTAINER_HTTP_HOST) ?></param>
                        <param name="port" type="integer"><?php echo Setup::getValue(SetupKeys::CONTAINER_HTTP_PORT) ?></param>
                        <param name="workerNumber" type="integer"><?php echo Setup::getValue(SetupKeys::CONTAINER_HTTP_WORKER_NUMBER) ?></param>
                        <param name="workerAcceptMin" type="integer"><?php echo Setup::getValue(SetupKeys::CONTAINER_SERVER_WORKER_ACCEPT_MIN) ?></param>
                        <param name="workerAcceptMax" type="integer"><?php echo Setup::getValue(SetupKeys::CONTAINER_SERVER_WORKER_ACCEPT_MAX) ?></param>
                        <param name="documentRoot" type="string">webapps</param>
                        <param name="directoryIndex" type="string">index.dhtml index.do index.php index.html index.htm</param>
                        <param name="keepAliveMax" type="integer">64</param>
                        <param name="keepAliveTimeout" type="integer">5</param>
                        <param name="autoIndex" type="boolean">false</param>
                        <param name="errorsPageTemplatePath" type="string">resources/templates/www/error.phtml</param>
                        <param name="welcomePageTemplatePath" type="string">resources/templates/www/welcome.phtml</param>
                        <param name="autoIndexTemplatePath" type="string">resources/templates/www/auto_index.phtml</param>
                    </params>

                    <environmentVariables>
                        <environmentVariable condition="" definition="LOGGER_ACCESS=Access" />
                    </environmentVariables>

                    <connectionHandlers>
                        <connectionHandler type="\AppserverIo\WebServer\ConnectionHandlers\HttpConnectionHandler" />
                    </connectionHandlers>

                    <accesses>
                        <!-- per default allow everything -->
                        <access type="allow">
                            <params>
                                <param name="X_REQUEST_URI" type="string">.*</param>
                            </params>
                        </access>
                    </accesses>

                    <modules>
                        <!-- REQUEST_POST hook -->
                        <module type="\AppserverIo\WebServer\Modules\VirtualHostModule"/>
                        <module type="\AppserverIo\WebServer\Modules\AuthenticationModule"/>
                        <module type="\AppserverIo\WebServer\Modules\EnvironmentVariableModule" />
                        <module type="\AppserverIo\WebServer\Modules\RewriteModule"/>
                        <module type="\AppserverIo\WebServer\Modules\DirectoryModule"/>
                        <module type="\AppserverIo\WebServer\Modules\AccessModule"/>
                        <module type="\AppserverIo\WebServer\Modules\LocationModule"/>
                        <module type="\AppserverIo\WebServer\Modules\AutoIndexModule"/>
                        <!-- FileHandler Modules -->
                        <module type="\AppserverIo\WebServer\Modules\CoreModule"/>
                        <module type="\AppserverIo\WebServer\Modules\FcgiModule"/>
                        <module type="\AppserverIo\SingleApp\ServletEngine\SimpleServletEngine"/>
                        <module type="\AppserverIo\WebServer\Modules\ProxyModule"/>
                        <!-- RESPONSE_PRE hook -->
                        <module type="\AppserverIo\WebServer\Modules\HeaderModule"/>
                        <module type="\AppserverIo\WebServer\Modules\DeflateModule"/>
                        <!-- RESPONSE_POST hook -->
                    </modules>

                    <fileHandlers>
                        <fileHandler name="fastcgi" extension=".php">
                            <params>
                                <param name="host" type="string"><?php echo Setup::getValue(SetupKeys::PHP_FPM_HOST) ?></param>
                                <param name="port" type="integer"><?php echo Setup::getValue(SetupKeys::PHP_FPM_PORT) ?></param>
                            </params>
                        </fileHandler>
                        <fileHandler name="fastcgi" extension=".phtml">
                            <params>
                                <param name="host" type="string"><?php echo Setup::getValue(SetupKeys::PHP_FPM_HOST) ?></param>
                                <param name="port" type="integer"><?php echo Setup::getValue(SetupKeys::PHP_FPM_PORT) ?></param>
                            </params>
                        </fileHandler>
                        <fileHandler name="servlet" extension=".dhtml" />
                        <fileHandler name="servlet" extension=".do" />
                    </fileHandlers>

                </server>

                <server
                        name="https"
                        type="\AppserverIo\Server\Servers\MultiThreadedServer"
                        worker="\AppserverIo\Server\Workers\ThreadWorker"
                        socket="\AppserverIo\Server\Sockets\StreamSocket"
                        requestContext="\AppserverIo\Server\Contexts\RequestContext"
                        serverContext="\AppserverIo\Appserver\Server\Contexts\StandardServerContext"
                        streamContext="\AppserverIo\Server\Contexts\StreamContext"
                        loggerName="System">
                    <params>
                        <param name="admin" type="string"><?php echo Setup::getValue(SetupKeys::ADMIN_EMAIL) ?></param>
                        <param name="workerNumber" type="integer"><?php echo Setup::getValue(SetupKeys::CONTAINER_HTTPS_WORKER_NUMBER) ?></param>
                        <param name="workerAcceptMin" type="integer"><?php echo Setup::getValue(SetupKeys::CONTAINER_SERVER_WORKER_ACCEPT_MIN) ?></param>
                        <param name="workerAcceptMax" type="integer"><?php echo Setup::getValue(SetupKeys::CONTAINER_SERVER_WORKER_ACCEPT_MAX) ?></param>
                        <param name="transport" type="string">ssl</param>
                        <param name="address" type="string"><?php echo Setup::getValue(SetupKeys::CONTAINER_HTTPS_HOST) ?></param>
                        <param name="port" type="integer"><?php echo Setup::getValue(SetupKeys::CONTAINER_HTTPS_PORT) ?></param>
                        <param name="documentRoot" type="string">webapps</param>
                        <param name="directoryIndex" type="string">index.dhtml index.do index.php index.html index.htm</param>
                        <param name="keepAliveMax" type="integer">64</param>
                        <param name="keepAliveTimeout" type="integer">5</param>
                        <param name="autoIndex" type="boolean">false</param>
                        <param name="errorsPageTemplatePath" type="string">resources/templates/www/error.phtml</param>
                        <param name="welcomePageTemplatePath" type="string">resources/templates/www/welcome.phtml</param>
                        <param name="autoIndexTemplatePath" type="string">resources/templates/www/auto_index.phtml</param>
                        <param name="certPath" type="string">etc/appserver/server.pem</param>
                        <param name="privateKeyPath" type="string"></param>
                        <param name="dhParamPath" type="string"></param>
                        <param name="passphrase" type="string"></param>
                        <param name="cryptoMethod" type="string">STREAM_CRYPTO_METHOD_TLSv1_0_SERVER | STREAM_CRYPTO_METHOD_TLSv1_1_SERVER | STREAM_CRYPTO_METHOD_TLSv1_2_SERVER</param>
                        <param name="peerName" type="string"></param>
                        <param name="verifyPeer" type="boolean">false</param>
                        <param name="verifyPeerName" type="boolean">false</param>
                        <param name="allowSelfSigned" type="boolean">true</param>
                        <param name="disableCompression" type="boolean">true</param>
                        <param name="honorCipherOrder" type="boolean">true</param>
                        <param name="ecdhCurve" type="string">secp384r1</param>
                        <param name="singleEcdhUse" type="boolean">true</param>
                        <param name="singleDhUse" type="boolean">true</param>
                        <param name="ciphers" type="string">ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:ECDHE-RSA-RC4-SHA:ECDHE-ECDSA-RC4-SHA:AES128:AES256:RC4-SHA:HIGH:!aNULL:!eNULL:!EXPORT:!DES:!3DES:!MD5:!PSK</param>
                    </params>

                    <!-- By default, we want to send additional response headers to improve HTTPS security -->
                    <headers>
                        <header type="response" name="Strict-Transport-Security" value="max-age=31536000; includeSubDomains; preload" />
                    </headers>

                    <environmentVariables>
                        <environmentVariable condition="" definition="LOGGER_ACCESS=Access" />
                    </environmentVariables>

                    <connectionHandlers>
                        <connectionHandler type="\AppserverIo\WebServer\ConnectionHandlers\HttpConnectionHandler" />
                    </connectionHandlers>

                    <accesses>
                        <!-- per default allow everything -->
                        <access type="allow">
                            <params>
                                <param name="X_REQUEST_URI" type="string">.*</param>
                            </params>
                        </access>
                    </accesses>

                    <modules>
                        <!-- REQUEST_POST hook -->
                        <module type="\AppserverIo\WebServer\Modules\VirtualHostModule"/>
                        <module type="\AppserverIo\WebServer\Modules\AuthenticationModule"/>
                        <module type="\AppserverIo\WebServer\Modules\EnvironmentVariableModule" />
                        <module type="\AppserverIo\WebServer\Modules\RewriteModule"/>
                        <module type="\AppserverIo\WebServer\Modules\DirectoryModule"/>
                        <module type="\AppserverIo\WebServer\Modules\AccessModule"/>
                        <module type="\AppserverIo\WebServer\Modules\LocationModule"/>
                        <module type="\AppserverIo\WebServer\Modules\AutoIndexModule"/>
                        <!-- FileHandler Modules -->
                        <module type="\AppserverIo\WebServer\Modules\CoreModule"/>
                        <module type="\AppserverIo\WebServer\Modules\FcgiModule"/>
                        <module type="\AppserverIo\SingleApp\ServletEngine\SimpleServletEngine"/>
                        <module type="\AppserverIo\WebServer\Modules\ProxyModule"/>
                        <!-- RESPONSE_PRE hook -->
                        <module type="\AppserverIo\WebServer\Modules\HeaderModule"/>
                        <module type="\AppserverIo\WebServer\Modules\DeflateModule"/>
                        <!-- RESPONSE_POST hook -->
                    </modules>

                    <fileHandlers>
                        <fileHandler name="fastcgi" extension=".php">
                            <params>
                                <param name="host" type="string"><?php echo Setup::getValue(SetupKeys::PHP_FPM_HOST) ?></param>
                                <param name="port" type="integer"><?php echo Setup::getValue(SetupKeys::PHP_FPM_PORT) ?></param>
                            </params>
                        </fileHandler>
                        <fileHandler name="fastcgi" extension=".phtml">
                            <params>
                                <param name="host" type="string"><?php echo Setup::getValue(SetupKeys::PHP_FPM_HOST) ?></param>
                                <param name="port" type="integer"><?php echo Setup::getValue(SetupKeys::PHP_FPM_PORT) ?></param>
                            </params>
                        </fileHandler>
                        <fileHandler name="servlet" extension=".dhtml" />
                        <fileHandler name="servlet" extension=".do" />
                    </fileHandlers>

                </server>

            </servers>
        </container>

    </containers>

</appserver>
