<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
        <link rel="stylesheet" href="bs5-jf.css">
        <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
        <script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
        <script src="https://stackpath.bootstrapcdn.com/bootstrap/5.0.0-alpha1/js/bootstrap.min.js" integrity="sha384-oesi62hOLfzrys4LxRF63OJCXdXDipiYWBnvTl9Y9/TRlw5xlKIEHpNyvvDShgf/" crossorigin="anonymous"></script>
        <style>
            .card-body {
                width: 100%;
                height: 100%;
                padding: 10%;
            }
            .slider {
                width: 100%;
                height: 100%;
                display: flex;
                overflow-x: hidden;
                -webkit-overflow-scrolling: none;
                scroll-snap-type: x mandatory;
            }
            .slider > div {
                scroll-snap-align: start;
            }
            .slide {
                width: 100%;
                flex-shrink: 0;
                height: 100%;
                margin: 10%;
            }
        </style>
        <title>Setup - Jellyfin Accounts</title>
    </head>
    <body>
        <div class="pageContainer">
            <div class="container">
                <div class="row">
                    <div class="col-sm"></div>
                    <div id="setupCarousel" class="col-md-auto slider">
                        <div class="slide card text-center" id="page-1">
                            <div class="card-body">
                                <h5 class="card-title">Welcome!</h5>
                                <p class="card-text">
                                You'll need to do a few things to start using jfa-go. Click below to get started, or quit and edit the config file manually.
                                </p>
                                <a class="btn btn-primary nextButton" href="#page-2">Get Started</a>
                            </div>
                            <div class="card-footer">
                                <small>Note: Make sure you are accessing this page through HTTPS, or on a private network.</small>
                            </div>
                        </div>
                        <div class="slide card" id="page-2">
                            <div class="card-body">
                                <h5 class="card-title">Login</h5>
                                <p class="card-text">
                                To access the admin page, you'll need to login. Choose how below.
                                <ul>
                                    <li><b>Authorize through Jellyfin: </b>Checks credentials with Jellyfin, allowing you to share login details and grant multiple users access.</li>
                                    <li><b>Username & Password: </b>Set your own username and password manually.</li>
                                </ul>
                                <div class="form-check" id="jfAuthFormGroup">
                                    <input class="form-check-input" type="radio" name="auth" id="jfAuthRadio" value="jfAuth" checked>
                                    <label class="form-check-label" for="jfAuthRadio">
                                        Authorize through Jellyfin
                                    </label>
                                </div>
                                <div id="adminOnlyArea">
                                    <div class="form-check" style="margin-left: 1rem;">
                                        <input type="checkbox" class="form-check-input" id="jfAuthAdminOnly" checked>
                                        <label for="jfAuthAdminOnly" class="form-check-label">Allow admin users only</label>
                                    </div>
                                </div>
                                <div class="form-check">
                                    <input class="form-check-input" type="radio" name="auth" id="manualAuthRadio" value="manualAuth">
                                    <label class="form-check-label" for="manualAuthRadio">
                                        Manual username &amp; password
                                    </label>
                                </div>
                                <div id="manualAuthArea">
                                    <div class="form-group">
                                        <label for="manualAuthUsername">Username</label>
                                        <input type="text" class="form-control" id="manualAuthUsername" placeholder="Username">
                                    </div>
                                    <div class="form-group">
                                        <label for="manualAuthPassword">Password</label>
                                        <input type="password" class="form-control" id="manualAuthPassword" placeholder="Password">
                                    </div>
                                    <div class="form-group">
                                        <label for="manualAuthEmail">Email (Optional)</label>
                                        <input type="email" class="form-control" id="manualAuthEmail" placeholder="example@example.com">
                                        <small class="form-text text-muted">Your email address is only required if you want to recieve activity notifications.</small>
                                    </div>
                                </div>
                                </p>
                                <div class="btn-group float-right" role="group" aria-label="Back/Next buttons">
                                    <a class="btn btn-secondary backButton" href="#page-1">Back</a>
                                    <a class="btn btn-primary nextButton" href="#page-3">Next</a>
                                </div>
                            </div>
                        </div>
                        <div class="slide card" id="page-3">
                            <div class="card-body">
                                <h5 class="card-title">Jellyfin</h5>
                                <p class="card-text">
                                jfa-go needs admin access so that it can create users, as this is currently not permitted via API tokens. 
                                You should create a separate account for it, checking 'Allow this user to manage the server'. You can disable everything else. Once done, enter the credentials here.
                                <div class="form-group">
                                    <label for="jfHost">Host (For internal use)</label>
                                    <input type="url" class="form-control" id="jfHost" placeholder="http://jellyf.in:443" required>
                                </div>
                                <div class="form-group">
                                    <label for="jfPublicHost">Public Host (For access by users)</label>
                                    <input type="url" class="form-control" id="jfPublicHost" placeholder="Leave blank to use the above address.">
                                </div>
                                <div class="form-group">
                                    <label for="jfUser">Username</label>
                                    <input type="text" class="form-control" id="jfUser" placeholder="Username" required>
                                </div>
                                <div class="form-group">
                                    <label for="jfPassword">Password</label>
                                    <input type="password" class="form-control" id="jfPassword" placeholder="Password" required>
                                </div>
                                <div style="margin-top: 1rem;">
                                    <button class="btn btn-secondary" id="jfTestButton">Test</button>
                                    <div class="btn-group float-right" role="group" aria-label="Back/Next buttons">
                                        <a class="btn btn-secondary backButton" href="#page-2">Back</a>
                                        <a class="btn btn-primary nextButton disabled" id="jfNextButton" aria-disabled="true" href="#page-4">Next</a>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="slide card" id="page-4">
                            <div class="card-body">
                                <h5 class="card-title">Email</h5>
                                <p class="card-text">jfa-go is capable of sending a PIN code when a user tries to reset their password on Jellyfin. One can also choose to send an invite code directly to an email address. This can be done through SMTP or through <a href="https://www.mailgun.com/">Mailgun's</a> API. 
                                <div class="form-group">
                                    <div class="form-check" id="emailDisabled">
                                        <input class="form-check-input" type="radio" name="email" id="emailDisabledRadio" value="emailDisabled">
                                        <label class="form-check-label" for="emailDisabledRadio">
                                            Disabled
                                        </label>
                                    </div>
                                    <div class="form-check" id="emailSMTP">
                                        <input class="form-check-input" type="radio" name="email" id="emailSMTPRadio" value="emailSMTP" checked>
                                        <label class="form-check-label" for="emailSMTPRadio">
                                            SMTP
                                        </label>
                                    </div>
                                    <div class="form-check">
                                        <input class="form-check-input" type="radio" name="email" id="emailMailgunRadio" value="emailMailgun">
                                        <label class="form-check-label" for="emailMailgunRadio">
                                            Mailgun API
                                        </label>
                                    </div>
                                </div>
                                <div id="emailSMTPArea">
                                    <div class="form-group form-check form-switch">
                                        <input type="checkbox" class="form-check-input" id="emailSSL_TLS" checked>
                                        <label for="emailSSL_TLS" class="form-check-label" id="emailSSL_TLSLabel">Use SSL/TLS</label>
                                        <small class="form-text text-muted">Note: SSL/TLS usually uses port 465, whereas STARTTLS usually uses 587.</small>
                                    </div>
                                    <div class="form-group form-row">
                                        <div class="col">
                                           <input type="text" class="form-control" id="emailSMTPServer" placeholder="SMTP Server Address">
                                        </div>
                                        <div class="col">
                                           <input type="number" class="form-control" id="emailSMTPPort" placeholder="Port">
                                        </div>
                                    </div>
                                    <div class="form-group form-row">
                                        <div class="col">
                                           <input type="email" class="form-control" id="emailSMTPAddress" placeholder="jellyfin@jellyf.in">
                                        </div>
                                        <div class="col">
                                           <input type="password" class="form-control" id="emailSMTPPassword" placeholder="Password">
                                        </div>
                                    </div>
                                </div>
                                <div id="emailMailgunArea">
                                    <div class="form-group">
                                       <input type="url" class="form-control" id="emailMailgunURL" placeholder="API URL">
                                    </div>
                                    <div class="form-group">
                                       <input type="password" class="form-control" id="emailMailgunKey" placeholder="API Key">
                                    </div>
                                    <div class="form-group">
                                       <input type="email" class="form-control" id="emailMailgunAddress" placeholder="jellyfin@jellyf.in">
                                    </div>
                                </div>
                                <div id="emailCommonArea">
                                    <h5 class="card-title">Notifications</h5>
                                    <p class="card-text">Enabling notifications will allow you to choose (per-invite) to recieve emails when an invite expires, or when a new user is created. If you chose to use Manual auth instead of Jellyfin auth previously, make sure you provided an email address.</p>
                                    <div class="form-check">
                                        <input type="checkbox" class="form-check-input" id="notificationsEnabled">
                                        <label for="notificationsEnabled" class="form-check-label">Enabled</label>
    
                                    </div>
                                </div>
                                </p>
                                <div class="btn-group float-right" role="group" aria-label="Back/Next buttons">
                                    <a class="btn btn-secondary backButton" href="#page-3">Back</a>
                                    <a class="btn btn-primary nextButton" id="emailNextButton" href="#page-5">Next</a>
                                </div>
                            </div>
                        </div>
                        <div class="slide card" id="page-5">
                            <div class="card-body">
                                <h5 class="card-title">Email</h5>
                                <p class="card-text">Just a few more things to get your emails looking great.
                                <div class="form-group">
                                    <label for="emailSender">Sender: The name shown when a user receives an email.</label>
                                    <input type="text" class="form-control" id="emailSender" value="Jellyfin">
                                </div>
                                <div class="form-group">
                                    <label for="emailDateFormat">Date Format: Follows <a target="_blank" href="https://strftime.org/">strftime</a> format.</label>
                                    <input type="text" class="form-control" id="emailDateFormat" value="%d/%m/%y">
                                </div>
                                <div class="form-group form-check">
                                    <input class="form-check-input" type="radio" name="time" id="email24hTimeRadio" value="email24hTime" checked>
                                    <label class="form-check-label" for="email24hTimeRadio">24h time</label>
                                </div>
                                <div class="form-group form-check">
                                    <input class="form-check-input" type="radio" name="time" id="email12hTimeRadio" value="email12hTime">
                                    <label class="form-check-label" for="email12hTimeRadio">12h time</label>
                                </div>
                                <div class="form-group">
                                    <label for="emailMessage">Message: Short message displayed at the bottom of emails.</label>
                                    <input type="text" class="form-control" id="emailMessage" value="Need help? Contact me.">
                                </div>
                                </p>
                                <div class="btn-group float-right" role="group" aria-label="Back/Next buttons">
                                    <a class="btn btn-secondary backButton" href="#page-4">Back</a>
                                    <a class="btn btn-primary nextButton" href="#page-6">Next</a>
                                </div>
                            </div>
                        </div>
                        <div class="slide card" id="page-6">
                            <div class="card-body">
                                <h5 class="card-title">Password Resets</h5>
                                <p class="card-text">
                                When a user tries to reset their password in jellyfin, it informs them that a file has been created, named "passwordreset*.json" where * is a number. jfa-go will then read this file, and send the PIN to the user's email. Try it now, and put the folder that it informs you it put the file in below. Also, if enter a custom email subject if you don't like the default one.
                                </p>
                                <div class="form-group form-check">
                                    <input type="checkbox" class="form-check-input" id="pwrEnabled" value="enabled">
                                    <label class="form-check-label" for="pwrEnabled">Enabled</label>
                                </div>
                                <div id="pwrArea">
                                    <div class="form-group">
                                        <label for="pwrJfPath">Path to Jellyfin</label>
                                        <input type="text" class="form-control" id="pwrJfPath" placeholder="Folder">
                                    </div>
                                    <div class="form-group">
                                        <label for="pwrSubject">Email Subject</label>
                                        <input type="text" class="form-control" id="pwrSubject" value="Password Reset - Jellyfin">
                                    </div>
                                </div>
                                <div class="btn-group float-right" role="group" aria-label="Back/Next buttons">
                                    <a class="btn btn-secondary backButton" href="#page-5">Back</a>
                                    <a class="btn btn-primary nextButton" href="#page-7">Next</a>
                                </div>
                            </div>
                        </div>
                        <div class="slide card" id="page-7">
                            <div class="card-body">
                                <h5 class="card-title">Invite Emails</h5>
                                <p class="card-text">
                                Allows you to send an invite code directly to a specified email address.
                                Since you'll most likely being running this behind a reverse proxy, the program has no way of knowing the address it will be accessed from. This is needed for sending emails with links. Write your URL Base with the protocol and append '/invite', e.g: 
                                <ul>
                                    <li>On the local network, you might use <a href="#">http://localhost:8056/invite</a></li>
                                    <li>Exposed to the internet, you might use <a href="#">https://accounts.jellyf.in/invite</a></li>
                                </ul>
                                </p>
                                <div class="form-group form-check">
                                    <input type="checkbox" class="form-check-input" id="invEnabled" value="enabled" checked>
                                    <label class="form-check-label" for="invEnabled">Enabled</label>
                                </div>
                                <div id="invArea">
                                    <div class="form-group">
                                        <label for="invURLBase">URL Base</label>
                                        <input type="url" class="form-control" id="invURLBase" placeholder="https://accounts.jellyf.in/invite">
                                    </div>
                                    <div class="form-group">
                                        <label for="invSubject">Subject</label>
                                        <input type="text" class="form-control" id="invSubject" value="Invite - Jellyfin">
                                    </div>
                                </div>
                                <div class="btn-group float-right" role="group" aria-label="Back/Next buttons">
                                    <a class="btn btn-secondary backButton" href="#page-6">Back</a>
                                    <a class="btn btn-primary nextButton" href="#page-8">Next</a>
                                </div>
                            </div>
                        </div>
                        <div class="slide card" id="page-8">
                            <div class="card-body">
                                <h5 class="card-title">Password Validation</h5>
                                <p class="card-text">
                                Enabling this will display a set of password requirements on the create account page, such as minimum length, uppercase characters, special characters, etc.
                                </p>
                                <div class="form-group form-check">
                                    <input type="checkbox" class="form-check-input" id="valEnabled" value="enabled">
                                    <label class="form-check-label" for="valEnabled">Enabled</label>
                                </div>
                                <div id="valArea">
                                    <div class="form-group">
                                        <label for="valLength">Minimum Length</label>
                                        <input type="number" class="form-control" id="valLength" value="8">
                                    </div>
                                    <div class="form-group">
                                        <label for="valUpper">Minimum number of uppercase characters</label>
                                        <input type="number" class="form-control" id="valUpper" value="1">
                                    </div>
                                    <div class="form-group">
                                        <label for="valLower">Minimum number of lowercase characters</label>
                                        <input type="number" class="form-control" id="valLower" value="0">
                                    </div>
                                    <div class="form-group">
                                        <label for="valNumber">Minimum number of numbers</label>
                                        <input type="number" class="form-control" id="valNumber" value="0">
                                    </div>
                                    <div class="form-group">
                                        <label for="valSpecial">Minimum number of special characters</label>
                                        <input type="number" class="form-control" id="valSpecial" value="0">
                                    </div>
                                </div>
                                <div class="btn-group float-right" role="group" aria-label="Back/Next buttons">
                                    <a class="btn btn-secondary backButton" id="valBackButton" href="#page-7">Back</a>
                                    <a class="btn btn-primary nextButton" href="#page-9">Next</a>
                                </div>
                            </div>
                        </div>
                        <div class="slide card" id="page-9">
                            <div class="card-body">
                                <h5 class="card-title">Help Messages</h5>
                                <p class="card-text">
                                Just a few little messages that will display in various places. Leave these alone if you want.
                                </p>
                                <div class="form-group">
                                    <label for="msgContact">Contact message: Displays at bottom of all pages (except admin).</label>
                                    <input id="msgContact" type="text" class="form-control" value="Need help? Contact me.">
                                </div>
                                <div class="form-group">
                                    <label for="msgHelp">Help message: Displays when a user is creating an account.</label>
                                    <input id="msgHelp" type="text" class="form-control" value="Enter your details to create an account.">
                                </div>
                                <div class="form-group">
                                    <label for="msgSuccess">Success message: Displays when a user successfully creates an account, just above a button taking the user to Jellyfin.</label>
                                    <input id="msgSuccess" type="text" class="form-control" value="Your account has been created. Click below to continue to Jellyfin.">
                                </div>
                                <div class="btn-group float-right" role="group" aria-label="Back/Next buttons">
                                    <a class="btn btn-secondary backButton" href="#page-8">Back</a>
                                    <a class="btn btn-primary nextButton" href="#page-10">Next</a>
                                </div>
                            </div>
                        </div>
                        <div class="slide card" id="page-10">
                            <div class="card-body text-center">
                                <h5 class="card-title">Finished!</h5>
                                <p class="card-text">
                                Press the button below to submit your settings. The program will restart. Once it's done, refresh this page.
                                </p>
                                <button id="submitButton" class="btn btn-primary">Submit</button>
                            </div>
                        </div>
                    </div>
                    <div class="col-sm"></div>
                </div>
            </div>
        </div>
        <script src="setup.js"></script>
    </body>
</html>                            
