<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height" />

    <title> Cloudron Setup </title>

    <!-- Theme CSS -->
    <link href="theme.css" rel="stylesheet">

    <!-- Custom Fonts -->
    <link href="3rdparty/css/font-awesome.min.css" rel="stylesheet" rel="stylesheet" type="text/css">

    <!-- jQuery-->
    <script src="3rdparty/js/jquery.min.js"></script>

    <!-- Bootstrap Core JavaScript -->
    <script src="3rdparty/js/bootstrap.min.js"></script>

    <!-- Angularjs scripts -->
    <script src="3rdparty/js/angular.min.js"></script>
    <script src="3rdparty/js/angular-loader.min.js"></script>
    <script src="3rdparty/js/angular-md5.min.js"></script>
    <script src="3rdparty/js/angular-ui-notification.min.js"></script>
    <script src="3rdparty/js/autofill-event.js"></script>

    <!-- Angular directives for tldjs -->
    <script src="3rdparty/js/tld.js"></script>

    <!-- Setup Application -->
    <script src="js/setupdns.js"></script>

</head>

<body class="setup" ng-app="Application" ng-controller="SetupDNSController">

    <div class="main-container ng-cloak text-center" ng-show="state === 'waitingForDnsSetup' || state === 'waitingForBox'">
        <div class="row">
            <div class="col-md-6 col-md-offset-3">
                <i class="fa fa-circle-o-notch fa-spin fa-5x"></i><br/>
                <h3>Waiting for domain and certificate setup</h3>
            </div>
        </div>
    </div>

    <div class="main-container ng-cloak" ng-show="state === 'initialized'">
        <div class="row">
            <div class="col-md-6 col-md-offset-3">
                <div class="card" style="max-width: none; padding: 20px;">
                    <form name="dnsCredentialsForm" role="form" novalidate ng-submit="setDnsCredentials()" autocomplete="off">
                        <div class="row">
                            <div class="col-md-10 col-md-offset-1 text-center">
                                <h1>Cloudron Setup</h1>
                                <h3>Provide a domain for your Cloudron</h3>
                                <p>Apps will be installed on subdomains of this domain.</p>
                                <div class="form-group" style="margin-bottom: 0;" ng-class="{ 'has-error': dnsCredentialsForm.domain.$dirty && dnsCredentialsForm.domain.$invalid }">
                                    <input type="text" class="form-control" ng-model="dnsCredentials.domain" name="domain" placeholder="example.com" required autofocus ng-disabled="dnsCredentials.busy">
                                </div>
                                <p ng-show="isSubdomain" class="text-bold">Installing on a subdomain requires an enterprise subscription. <a href="mailto:support@cloudron.io">Contact us</a></p>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-md-10 col-md-offset-1 text-center">
                                <h3>Choose how this domain is managed</h3>
                                <p class="has-error text-center" ng-show="dnsCredentials.error">{{ dnsCredentials.error }}</p>

                                <div class="form-group">
                                    <select class="form-control" ng-model="dnsCredentials.provider" ng-options="a.value as a.name for a in dnsProvider" ng-disabled="dnsCredentials.busy"></select>
                                </div>

                                <!-- Route53 -->
                                <div class="form-group" ng-class="{ 'has-error': dnsCredentialsForm.accessKeyId.$dirty && dnsCredentialsForm.accessKeyId.$invalid }" ng-show="dnsCredentials.provider === 'route53'">
                                    <input type="text" class="form-control" ng-model="dnsCredentials.accessKeyId" name="accessKeyId" placeholder="Access Key Id" ng-minlength="16" ng-maxlength="32" ng-required="dnsCredentials.provider === 'route53'" ng-disabled="dnsCredentials.busy">
                                </div>
                                <div class="form-group" ng-class="{ 'has-error': dnsCredentialsForm.secretAccessKey.$dirty && dnsCredentialsForm.secretAccessKey.$invalid }" ng-show="dnsCredentials.provider === 'route53'">
                                    <input type="text" class="form-control" ng-model="dnsCredentials.secretAccessKey" name="secretAccessKey" placeholder="Secret Access Key" ng-required="dnsCredentials.provider === 'route53'" ng-disabled="dnsCredentials.busy">
                                    <br/>
                                    <span ng-show="isDomain || explicitZone"><b>{{ explicitZone ? explicitZone : (dnsCredentials.domain | zoneName) }}</b> must be hosted on <a href="https://aws.amazon.com/route53/?nc2=h_m1" target="_blank">AWS Route53</a>.</span>
                                </div>

                                <!-- Google Cloud DNS -->
                                <div class="form-group" ng-class="{ 'has-error': false }" ng-show="dnsCredentials.provider === 'gcdns'">
                                    <div class="input-group">
                                        <input type="file" id="gcdnsKeyFileInput" style="display:none"/>
                                        <input type="text" class="form-control" placeholder="Service Account Key" ng-model="dnsCredentials.gcdnsKey.keyFileName" id="gcdnsKeyInput" name="cert" onclick="getElementById('gcdnsKeyFileInput').click();" style="cursor: pointer;" ng-required="dnsCredentials.provider === 'gcdns'" ng-disabled="dnsCredentials.busy">
                                        <span class="input-group-addon">
                                          <i class="fa fa-upload" onclick="getElementById('gcdnsKeyFileInput').click();"></i>
                                        </span>
                                    </div>
                                    <br/>
                                    <span ng-show="isDomain || explicitZone"><b>{{ explicitZone ? explicitZone : (dnsCredentials.domain | zoneName) }}</b> must be hosted on <a href="https://console.cloud.google.com/net-services/dns/zones" target="_blank">Google Cloud DNS</a>.</span>
                                </div>

                                <!-- DigitalOcean -->
                                <div class="form-group" ng-class="{ 'has-error': dnsCredentialsForm.digitalOceanToken.$dirty && dnsCredentialsForm.digitalOceanToken.$invalid }" ng-show="dnsCredentials.provider === 'digitalocean'">
                                    <input type="text" class="form-control" ng-model="dnsCredentials.digitalOceanToken" name="digitalOceanToken" placeholder="API Token" ng-required="dnsCredentials.provider === 'digitalocean'" ng-disabled="dnsCredentials.busy">
                                    <br/>
                                    <span ng-show="isDomain || explicitZone"><b>{{ explicitZone ? explicitZone : (dnsCredentials.domain | zoneName) }}</b> must be hosted on <a href="https://www.digitalocean.com/community/tutorials/how-to-set-up-a-host-name-with-digitalocean#step-two%E2%80%94change-your-domain-server" target="_blank">DigitalOcean</a>.</span>
                                </div>

                                <!-- Cloudflare -->
                                <div class="form-group" ng-class="{ 'has-error': dnsCredentialsForm.cloudflareToken.$dirty && dnsCredentialsForm.cloudflareToken.$invalid }" ng-show="dnsCredentials.provider === 'cloudflare'">
                                    <input type="text" class="form-control" ng-model="dnsCredentials.cloudflareToken" name="cloudflareToken" placeholder="API Key" ng-required="dnsCredentials.provider === 'cloudflare'" ng-disabled="dnsCredentials.busy">
                                </div>
                                <div class="form-group" ng-class="{ 'has-error': dnsCredentialsForm.cloudflareEmail.$dirty && dnsCredentialsForm.cloudflareEmail.$invalid }" ng-show="dnsCredentials.provider === 'cloudflare'">
                                    <input type="email" class="form-control" ng-model="dnsCredentials.cloudflareEmail" name="cloudflareEmail" placeholder="Cloudflare Account Email" ng-required="dnsCredentials.provider === 'cloudflare'" ng-disabled="dnsCredentials.busy">
                                    <br/>
                                    <span ng-show="isDomain || explicitZone"><b>{{ explicitZone ? explicitZone : (dnsCredentials.domain | zoneName) }}</b> must be hosted on <a href="https://www.cloudflare.com" target="_blank">Cloudflare</a>.</span>
                                </div>

                                <!-- Wildcard -->
                                <p ng-show="dnsCredentials.provider === 'wildcard'">
                                    <span>Setup A records for <b>*.{{ dnsCredentials.domain || 'example.com' }}</b> and <b>{{ dnsCredentials.domain || 'example.com' }}</b> to this server's IP.</span>
                                </p>

                                <!-- Manual -->
                                <p ng-show="dnsCredentials.provider === 'manual'">
                                    <span>
                                        Setup an A record for <b>my.{{ dnsCredentials.domain || 'example.com' }}</b> to this server's IP.<br/>
                                        All DNS records have to be setup manually <i>before</i> each app installation.
                                    </span>
                                </p>
                            </div>
                        </div>
                        <div class="row" ng-show="provider === 'ami'">
                            <div class="col-md-10 col-md-offset-1 text-center">
                                <br/>
                                <h3>Owner verification</h3>
                                <p>Provide the EC2 instance id to verify you have access to this server.</p>
                                <div class="form-group" ng-class="{ 'has-error': dnsCredentialsForm.instanceId.$dirty && (dnsCredentialsForm.instanceId.$invalid || error) }">
                                    <input type="text" class="form-control" ng-model="instanceId" id="inputInstanceId" name="instanceId" placeholder="AWS EC2 instance id" ng-maxlength="20" ng-minlength="10" ng-required="provider === 'ami'" autocomplete="off">
                                </div>
                                <p>&nbsp;<span ng-show="error" class="text-danger">{{ error }}</span></p>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-md-12 text-center">
                                <button type="submit" class="btn btn-primary" ng-disabled="dnsCredentialsForm.$invalid || (isSubdomain && !isEnterprise)"/><i class="fa fa-circle-o-notch fa-spin" ng-show="dnsCredentials.busy"></i> Next</button>
                            </div>
                        </div>
                        <br/>
                        <div class="row">
                            <div class="col-md-12 text-center">
                                <small>You can setup a new Cloudron or restore from a backup in the next step</small>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>

    <footer class="text-center">
        <span class="text-muted">&copy;2018 <a href="https://cloudron.io" target="_blank">Cloudron</a></span>
        <span class="text-muted"><a href="https://twitter.com/cloudron_io" target="_blank">Twitter <i class="fa fa-twitter"></i></a></span>
        <span class="text-muted"><a href="https://chat.cloudron.io" target="_blank">Chat <i class="fa fa-comments"></i></a></span>
    </footer>

</body>
</html>
