{% extends "base.html" %}

    {% block content %}
    <details>
    <summary>Current RaSCSI Configuration</summary>
    <ul>
    <li>Displays the currently attached devices for each available SCSI ID.</li>
    <li>Save and load device configurations into <tt>{{cfg_dir}}</tt></li>
    <li>The <em>default</em> configuration will be loaded when the Web UI starts up, if available.</li>
    </ul>
    </details>

    <p>
    <form action="/config/load" method="post">
        <select name="name" required>
            {% for config in config_files %}
                <option value="{{config}}">{{config.replace(".json", '')}}</option>
            {% endfor %}
        </select>
        <input type="submit" name="load" value="Load" />
        <input type="submit" name="delete" value="Delete" />
    </form>
    </p>
    <p>
    <form action="/config/save" method="post">
        <input name="name" placeholder="default">
        <input type="submit" value="Save" />
    </form>
    <form action="/scsi/detach_all" method="post" onsubmit="return confirm('Detach all SCSI Devices?')">
        <input type="submit" value="Detach All" />
    </form>
    </p>

    <table cellpadding="3" border="black">
        <tbody>
        <tr>
            <td><b>ID</b></td>
	    {% if luns %}
            <td><b>LUN</b></td>
	    {% endif %}
            <td><b>Type</b></td>
            <td><b>Status</b></td>
            <td><b>File</b></td>
            <td><b>Product</b></td>
            <td><b>Actions</b></td>
        </tr>
        {% for device in devices %}
        <tr>
            {% if device["id"] not in reserved_scsi_ids %}
            <td style="text-align:center">{{device.id}}</td>
	    {% if luns %}
            <td style="text-align:center">{{device.un}}</td>
	    {% endif %}
            <td style="text-align:center">{{device.device_type}}</td>
            <td style="text-align:center">{{device.status}}</td>
            <td style="text-align:left">{{device.file}}</td>
	    {% if device.vendor == "RaSCSI" %}
            <td style="text-align:center">{{device.product}}</td>
	    {% else %}
            <td style="text-align:center">{{device.vendor}} {{device.product}}</td>
	    {% endif %}
            <td style="text-align:left">
                {% if device.device_type in removable_device_types and "No Media" not in device.status %}
                <form action="/scsi/eject" method="post" onsubmit="return confirm('Eject Disk?')">
                    <input type="hidden" name="scsi_id" value="{{device.id}}">
                    <input type="hidden" name="un" value="{{device.un}}">
                    <input type="submit" value="Eject" />
                </form>
                <form action="/scsi/info" method="post">
                    <input type="hidden" name="scsi_id" value="{{device.id}}">
                    <input type="hidden" name="un" value="{{device.un}}">
                    <input type="submit" value="Info" />
                </form>
                {% else %}
                <form action="/scsi/detach" method="post" onsubmit="return confirm('Detach Disk?')">
                    <input type="hidden" name="scsi_id" value="{{device.id}}">
                    <input type="hidden" name="un" value="{{device.un}}">
                    <input type="submit" value="Detach" />
                </form>
                <form action="/scsi/info" method="post">
                    <input type="hidden" name="scsi_id" value="{{device.id}}">
                    <input type="hidden" name="un" value="{{device.un}}">
                    <input type="submit" value="Info" />
                </form>
                {% endif %}
            </td>
            {% else %}
            <td class="inactive">{{device.id}}</td>
	    {% if luns %}
            <td class="inactive"></td>
	    {% endif %}
            <td class="inactive"></td>
            <td class="inactive">Reserved ID</td>
            <td class="inactive"></td>
            <td class="inactive"></td>
            <td class="inactive"></td>
            {% endif %}
        </tr>
        {% endfor %}
        </tbody>
    </table>

    <hr/>

    <details>
    <summary>Image File Management</summary>
    <ul>
    <li>Manage image files in the active RaSCSI image directory: <tt>{{base_dir}}</tt></li>
    <li>Select a valid SCSI ID and <a href="https://en.wikipedia.org/wiki/Logical_unit_number">LUN</a> to attach to. Unless you know what you're doing, always use LUN 0.</li>
    <li>If RaSCSI was unable to detect the device type associated with the image, you can choose the type from the dropdown.</li>
    <li>Types: SAHD = SASI HDD | SCHD = SCSI HDD | SCRM = Removable | SCMO = Magneto-Optical | SCCD = CD-ROM | SCBR = Host Bridge | SCDP = DaynaPORT</li>
    </ul>
    </details>

    <table cellpadding="3" border="black">
        <tbody>
        <tr>
            <td><b>File</b></td>
            <td><b>Size</b></td>
            <td><b>Actions</b></td>
        </tr>
        {% for file in files %}
        <tr>
            <td>{{file["name"]}}</td>
            <td style="text-align:center">
                <form action="/files/download" method="post">
                    <input type="hidden" name="image" value="{{file["name"]}}">
                    <input type="submit" value="{{file["size_mb"]}} MB &#8595;" />
                </form>
            </td>
	    <td>
                <form action="/scsi/attach" method="post">
                    <input type="hidden" name="file_name" value="{{file["name"]}}">
                    <input type="hidden" name="file_size" value="{{file["size"]}}">
                    <label for="id">ID</label>
                    <select name="scsi_id">
                        {% for id in scsi_ids %}
			<option name="id" value="{{id}}"{% if id == recommended_id %} selected{% endif %}>{{id}}</option>
                        {% endfor %}
                    </select>
		    <label for="un">LUN</label>
		    <input type="number" name="un" size="2" value="0" min="0" max="31" />
		    {% if file["detected_type"] != "UNDEFINED" %}
		    <input type="hidden" name="type" value="{{file["detected_type"]}}">
		    {{file["detected_type"]}}
	            {% else %}
		    <select name="type">
                        <option value="" selected>Type</option>
			{% for d in device_types %}
			<option value="{{d}}">{{d}}</option>
			{% endfor %}
                    </select>
		    {% endif %}
                    <input type="submit" value="Attach" />
                </form>
                <form action="/files/delete" method="post" onsubmit="return confirm('Delete file?')">
                    <input type="hidden" name="image" value="{{file["name"]}}">
                    <input type="submit" value="Delete" />
                </form>
		{% if file["prop"] %}
		<form action="/files/prop" method="post">
                    <input type="hidden" name="image" value="{{file["name"]}}">
		    <input type="submit" value="Properties">
		</form>
		{% endif %}
            </td>
        </tr>
        {% endfor %}
        </tbody>
    </table>

    <hr/>

    <details>
    <summary>Attach Ethernet Adapter</summary>
    <ul>
    <li>Emulates a SCSI DaynaPORT Ethernet Adapter. <a href="https://github.com/akuker/RASCSI/wiki/Dayna-Port-SCSI-Link#-macintosh-setup-instructions">Host drivers required.</a></li>
    <li>If you have a DHCP setup, ignore the Static IP fields.</li>
    <li>
        {% if bridge_configured %}
        Bridge is currently configured!
        {% else %}
        Bridge is automatically configured when a network adapter is attached.
        {% endif %}
    </li>
    </ul>
    </details>
    <table style="border: none">
        <tr style="border: none">
            <td style="border: none; vertical-align:top;">
                <form action="/daynaport/attach" method="post">
		    <label for="if">Interface:</label>
		    <select name = "if">
			{% for if in netinfo["ifs"] %}
			<option value="{{if}}">{{if}}</option>
			{% endfor %}
                    </select>
		    <label for="ip">Static IP (optional):</label>
		    <input type="text" name="ip" size="15" placeholder="10.10.20.1" minlength="7" maxlength="15" pattern="^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$" />
		    <input type="number" name="mask" size="2" placeholder="24" min="16" max="30" />
		    <label for="scsi_id">SCSI ID:</label>
                    <select name="scsi_id">
                        {% for id in scsi_ids %}
                        <option value="{{id}}"{% if id == recommended_id %} selected{% endif %}>{{id}}</option>
                        {% endfor %}
                    </select>
                    <input type="submit" value="Attach" />
                </form>
            </td>
        </tr>
    </table>

    <hr/>

    <details>
    <summary>Upload File</summary>
    <ul>
    <li>Uploads file to <tt>{{base_dir}}</tt>. The largest file size accepted is {{max_file_size}} MB. Zip files will be unzipped.</li>
    <li>For unrecognized file types, try renaming hard drive images to '.hds' and CD-ROM images to '.iso' before uploading.</li>
    <li>Recognized file types: {{valid_file_suffix}}</li>
    </ul>
    </details>

    <table style="border: none">
        <tr style="border: none">
            <td style="border: none; vertical-align:top;">
                <form method="POST" action="/files/upload" class="dropzone dz-clickable" id="dropper" enctype="multipart/form-data">
                </form>
            </td>
        </tr>
    </table>
    <script type="application/javascript">
    Dropzone.options.dropper = {
        paramName: 'file',
        acceptedFiles: '{{valid_file_suffix}}',
        chunking: true,
        forceChunking: true,
        url: '/files/upload',
        maxFilesize: {{max_file_size}}, // MB
        chunkSize: 1000000 // bytes
    }
    </script>

    <hr/>

    <details>
    <summary>Download File from Web</summary>
    <ul>
    <li>Given a URL, download that file to the <tt>{{base_dir}}</tt> directory.</li>
    </ul>
    </details>

    <table style="border: none">
        <tr style="border: none">
            <td style="border: none; vertical-align:top;">
                <form action="/files/download_image" method="post">
                    <label for="url">URL:</label>
                    <input type="url" placeholder="URL" name="url" />
                    <input type="submit" value="Download" />
                </form>
            </td>
        </tr>
    </table>

    <hr/>

    <details>
    <summary>Download File from Web and Create HFS CD (Macintosh)</summary>
    <ul>
    <li>Given a URL this will download a file, create a HFS iso, and mount it on the SCSI ID given.</li>
    <li>Requires a <a href="https://github.com/akuker/RASCSI/wiki/Drive-Setup#Mounting_CD_ISO_or_MO_images">compatible CD-ROM driver</a> installed on the target system.</li>
    </ul>
    </details>

    <table style="border: none">
            <tr style="border: none">
                <td style="border: none; vertical-align:top;">
                <label for="scsi_id">SCSI ID:</label>
                <form action="/files/download_to_iso" method="post">
                    <select name="scsi_id">
                        {% for id in scsi_ids %}
                        <option value="{{id}}"{% if id == recommended_id %} selected{% endif %}>{{id}}</option>
                        {% endfor %}
                    </select>
                    <label for="url">URL:</label>
                    <input type="url" placeholder="URL" name="url" />
                    <input type="submit" value="Download and Mount ISO" />
                </form>
            </td>
        </tr>
    </table>

    <hr/>

    <details>
    <summary>Create Empty Disk Image File</summary>
    <ul>
    <li>The Generic image type is recommended for most systems</li>
    <li>APPLE GENUINE and NEC GENUINE image types will make RaSCSI masquerade as a particular drive type that are recognized by Mac and PC98 systems, respectively.</li>
    <li>SASI images should only be used on early X68000 or UNIX workstation systems that use this pre-SCSI standard.</li>
    <li>Available disk space on the Pi: {{free_disk}} MB</li>
    </ul>
    </details>
    <table style="border: none">
            <tr style="border: none">
                <td style="border: none; vertical-align:top;">
                <form action="/files/create" method="post">
                    <label for="file_name">File Name:</label>
                    <input type="text" placeholder="File name" name="file_name"/>
                    <label for="type">Type:</label>
                    <select name="type">
                        <option value="hds">SCSI Hard Disk image (Generic) [.hds]</option>
                        <option value="hda">SCSI Hard Disk image (APPLE GENUINE - use with Mac) [.hda]</option>
                        <option value="hdn">SCSI Hard Disk image (NEC GENUINE - use with PC98) [.hdn]</option>
                        <option value="hdr">SCSI Removable Media Disk image (Generic) [.hdr]</option>
                        <option value="hdf">SASI Hard Disk image (use with X68000) [.hdf]</option>
                    </select>
                    <label for="size">Size(MB):</label>
                    <input type="number" placeholder="Size(MB)" name="size" min="1" />
                    <input type="submit" value="Create" />
                </form>
            </td>
        </tr>
    </table>

    <hr/>

    <details>
    <summary>Create Named Drive</summary>
    <ul>
    <li>Here you can create pairs of images and properties files from a list of real-life drives.</li>
    <li>This will make RaSCSI use certain vendor strings and block sizes that may improve compatibility with certain systems</li>
    </ul>
    </details>

    <p><a href="/drive/list">Create a named disk image that mimics real-life drives</a></p>

    <hr/>

    <details>
    <summary>Logging</summary>
    <ul>
    <li>Get a certain number of lines of service logs with the given scope.</li>
    </ul>
    </details>

    <table style="border: none">
        <tr style="border: none">
            <td style="border: none; vertical-align:top;">
                <form action="/logs/show" method="post">
                    <label for="lines">Log Lines:</label>
                    <input type="number" placeholder="200" name="lines" min="1"/>
                    <label for="scope">Scope:</label>
                    <select name="scope">
                        <option value="default">default</option>
                        <option value="rascsi">rascsi.service</option>
                        <option value="rascsi-web">rascsi-web.service</option>
                    </select>
                    <input type="submit" value="Show Logs" />
                </form>
            </td>
	</tr>
    </table>

    <hr/>

    <details>
    <summary>Server Log Level</summary>
    <ul>
    <li>Change the log level of the RaSCSI backend service.</li>
    <li>The dropdown will indicate the current log level.</li>
    </ul>
    </details>

    <table style="border: none">
        <tr style="border: none">
            <td style="border: none; vertical-align:top;">
		<form action="/logs/level" method="post">
		    <label for="level">Log Level:</label>
		    <select name="level">
			{% for level in log_levels %}
			<option value="{{level}}"{% if level == current_log_level %} selected{% endif %}>{{level}}</option>
			{% endfor %}
                    </select>
		    <input type="submit" value="Set Log Level" />
		</form>
            </td>
        </tr>
    </table>

    <hr/>

    <details>
    <summary>Raspberry Pi Operations</summary>
    <ul>
    <li>Issue reboot or shutdown commands to the Raspberr Pi.</li>
    <li>You can also restart the RaSCSI backend service here.</li>
    </ul>
    </details>

    <table style="border: none">
            <tr style="border: none">
                <td style="border: none; vertical-align:top;">
                <form action="/pi/reboot" method="post" onsubmit="return confirm('Reboot Pi?')">
                    <input type="submit" value="Reboot Raspberry Pi" />
                </form>
            </td>
            <td style="border: none; vertical-align:top;">
                <form action="/pi/shutdown" method="post" onsubmit="return confirm('Shutdown Pi?')">
                    <input type="submit" value="Shut Down Raspberry Pi" />
                </form>
            </td>

            <td style="border: none; vertical-align:top;">
                <form action="/rascsi/restart" method="post" onsubmit="return confirm('Restart RaSCSI?')">
                    <input type="submit" value="Restart RaSCSI Service" />
                </form>
            </td>
        </tr>
    </table>

{% endblock %}
