<?php
/**
 * @copyright 2021 Double Bastion LLC <www.doublebastion.com>
 *
 * @author Double Bastion LLC
 *
 * @license GNU AGPL version 3 or any later version
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
 * License as published by the Free Software Foundation; either
 * version 3 of the License, or any later version.
 *
 * This program 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 AFFERO GENERAL PUBLIC LICENSE for more details.
 *
 * You should have received a copy of the GNU Affero General Public
 * License along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

declare(strict_types=1);

script('pax_fax', 'settings');
style('pax_fax', 'style');

?>

<div id="pax_fax_adm">
	<div class="section">
           <h2><?php p($l->t('Pax Fax'));?></h2>
	   <p id="settings-dscr"><?php p($l->t('Enter either your Phaxio credentials or your Sinch credentials in the fields from below:')); ?></p><br>

           <div class="stp_followupsection">

                <form id="phaxio_credentials" action="#" >

                   <p><label for="api_key" class="setlabeltext"><b><?php p($l->t('Phaxio API Key'));?></b> (Log in to your Phaxio account, click 'API Keys' on the left
                          panel, then, under 'Live Keys' you will find the 'API Key'. Enter the 'API Key' in the field from below.):</label></p>
                   <input type="password" class="pax_fax_box" id="api_key" name="api_key" autocomplete="false"
                          placeholder="E.g.: d6f172ce92e4f2 ..." /><br>

                   <p><label for="api_secret" class="setlabeltext"><b><?php p($l->t('Phaxio API Secret'));?></b> (While logged in to your Phaxio account, click 'API Keys' on the left
                          panel, then, under 'Live Keys' you will find the 'API Secret'. Enter the 'API Secret' in the field from below.):</label></p>
                   <input type="password" class="pax_fax_box" id="api_secret" name="api_secret" autocomplete="false"
                          placeholder="E.g.: 8af589b8ad9579 ..." /><br>

                   <p><label for="webhook_token" class="setlabeltext"><b><?php p($l->t('Phaxio Webhook Token'));?></b> (While logged in to your Phaxio account, click 'Webhooks' on the
                          left panel, then copy the token found under 'Webhook Token' and enter it in the field from below.):</label></p>
                   <input type="password" class="pax_fax_box" id="webhook_token" name="webhook_token" autocomplete="false"
                          placeholder="E.g.: b6d90b72ab6cce450025abd46f4d697" /><br>

                   <p><label for="receive_url" class="setlabeltext"><b>Phaxio callback URL for incoming faxes</b> (This URL must have the form:
                          <b>https://<font style="color:#a11a1a;">username</font>:<font
                          style="color:#a11a1a;">6VTGs-c36j4-qK2wm-RgJcl-9pjUD</font>@<font style="color:#a11a1a;">cloud.example.com</font>/apps/pax_fax/api/recfaxphaxio</b> if 
                          Nextcloud is served on a subdomain, or <b>https://<font style="color:#a11a1a;">username</font>:<font
                          style="color:#a11a1a;">6VTGs-c36j4-qK2wm-RgJcl-9pjUD</font>@<font style="color:#a11a1a;">example.com/nextcloud</font>/apps/pax_fax/api/recfaxphaxio</b> 
                          if Nextcloud is served on a subdirectory, where <b><font style="color:#a11a1a;">username</font></b> is the Nextcloud user who has a Phaxio phone number 
                          in his Phaxio account (Callback URLs can only be configured one per Phaxio phone number. If <b><font style="color:#a11a1a;">username</font></b> 
                          contains an <b>@</b> , replace <b>@</b> with <b>&amp;commat;</b> otherwise the URL won't function), 
                          <b><font style="color:#a11a1a;">6VTGs-c36j4-qK2wm-RgJcl-9pjUD</font></b> is the 'application password' created for this purpose as explained below, and 
                          <b><font style="color:#a11a1a;">cloud.example.com</font></b> is your Nextcloud domain. To create the Nextcloud 'application password' click on the user 
                          picture in the upper right corner, then click 'Personal settings', then, on the left panel, under 'Personal' click 'Security', then under 'Devices & sessions', 
                          in the 'App name' field enter Pax_Fax, then click the 'Create new app password' button. The password will be displayed only when created. Copy the password, 
                          click the 'Done' button, enter the password in the constructed callback URL between ':' and '@' as shown above, copy the entire callback URL to a safe 
                          location, then enter the callback URL in the field from below. The next step is to enter the callback URL that you have just created in your Phaxio account: 
                          log in to Phaxio, click 'Phone Numbers' on the left panel, click the settings wheel on the row of the phone number for which you want to set up the callback 
                          URL, enter the URL in the 'Callback URL' field, then click 'Save'. Also, click on 'Webhooks' on the left panel, then scroll down to 'Webhook Version' and 
                          choose 'Version 2.1.0', then click the 'Update' button. Don't forget to also click the 'Save' button at the bottom of this page to save all the settings to 
                          the database.):</label></p>
                   <input type="password" class="pax_fax_boxspec" id="receive_url" name="receive_url" autocomplete="false"
                          placeholder="E.g.:  https://username:6VTGs-c36j4-qK2wm-RgJcl-9pjUD@cloud.example.com/apps/pax_fax/api/recfaxphaxio" /><br><br><br>

                   <p><label for="sinch_project_id" class="setlabeltext"><b><?php p($l->t('Sinch Project ID'));?></b> (While logged in to your Sinch account, click the 'Project' 
                          drop-down menu located at the left end of the upper bar, then click 'View all projects'. On the 'Projects' page you will see a list with all the available 
                          projects and their respective Project IDs. Copy the ID of the project that you use for faxing (usually this is the default 'First project') and paste it in 
                          the field from below.):</label></p>
                   <input type="password" class="pax_fax_box" id="sinch_project_id" name="sinch_project_id" autocomplete="false"
                          placeholder="E.g.: d5d91b72ab6cce450024abd46f4d6d9" /><br>

                   <p><label for="sinch_key_id" class="setlabeltext"><b><?php p($l->t('Sinch Key ID'));?></b> (While logged in to your Sinch account, select the name of the project
                          you use for faxing from the 'Project' drop-down menu on the upper bar (usually this is the default 'First project'), then click 'Settings' on the left panel,
                          then click 'Access Keys'. On the 'Access Keys' page you will see a list with all the access keys for the selected project. If you haven't created any access
                          keys for the project, create a key by clicking the 'Create access key' button. On the 'Create Access Key' popup window, in the 'Name' field enter a display 
                          name for your key and click 'Create'. The access key will be created and the Key ID and Key Secret window will be displayed. Copy the Key ID and Key Secret
                          to a safe location, then enter the Key ID in the field from below. The Key Secret can be viewed only when the key is created. If you lose it, simply 
                          generate a new key. Each project has its own set of access keys.):</label></p>
                   <input type="password" class="pax_fax_box" id="sinch_key_id" name="sinch_key_id" autocomplete="false"
                          placeholder="E.g.: c0d50b72ab6ced450025abd46f6d5c4" /><br>

                   <p><label for="sinch_key_secret" class="setlabeltext"><b><?php p($l->t('Sinch Key Secret'));?></b> (Copy the Key Secret created as described above, in the field from
                          below.):</label></p>
                   <input type="password" class="pax_fax_box" id="sinch_key_secret" name="sinch_key_secret" autocomplete="false"
                          placeholder="E.g.: e4d50b72ab6cdf450025abd46f4d6c2" /><br>

                   <p><label for="sinch_service_id" class="setlabeltext"><b><?php p($l->t('Sinch service ID'));?></b> (While logged in to your Sinch account click 'Fax' on the left 
                          panel, then click 'Services'. On the 'Services' page you will see a list with your fax services. If you haven't created any service manually, you will see 
                          only the 'Default Service' created automatically. If you want to associate different callback URLs (for incoming faxes) with different numbers, you will 
                          want to create multiple services and assign a different callback URL and a different set of numbers to each service. You can create a new service by clicking 
                          'Add New Service' on the 'Services' page. If you don't need multiple services, just use the 'Default Service'. On the 'Services' page, below the name of each 
                          fax service you will see its ID. Copy the ID of the service you want to use, in the field from below.):</label></p>
                   <input type="password" class="pax_fax_box" id="sinch_service_id" name="sinch_service_id" autocomplete="false"
                          placeholder="E.g.: e6d50b72ab6cbe450025abd46f4d74d" /><br>

                   <p><label for="sinch_callback_url" class="setlabeltext"><b><?php p($l->t('Sinch callback URL for incoming faxes'));?></b> (The callback URL for incoming faxes must 
                          have the form: <b>https://<font style="color:#a11a1a;">username</font>:<font style="color:#a11a1a;">6VTGs-c36j4-qK2wm-RgJcl-9pjUD</font>@<font style="color:#a11a1a;">cloud.example.com</font>/apps/pax_fax/api/recfaxsinch</b> if Nextcloud is served on a subdomain, or <b>https://<font 
                          style="color:#a11a1a;">username</font>:<font style="color:#a11a1a;">6VTGs-c36j4-qK2wm-RgJcl-9pjUD</font>@<font style="color:#a11a1a;">example.com/nextcloud</font>/apps/pax_fax/api/recfaxsinch</b> if Nextcloud is served on a subdirectory, where <b><font style="color:#a11a1a;">username</font>
                          </b> is the Nextcloud user who has a Sinch phone number in his Sinch account (If <b><font style="color:#a11a1a;">username</font></b> contains an <b>@</b> , 
                          replace <b>@</b> with <b>&amp;commat;</b> otherwise the URL won't function), <b><font style="color:#a11a1a;">6VTGs-c36j4-qK2wm-RgJcl-9pjUD</font></b> is the 
                          'application password' created for this purpose as explained below, and <b><font style="color:#a11a1a;">cloud.example.com</font></b> is your Nextcloud domain. 
                          To create the Nextcloud 'application password' click on the user picture in the upper right corner, then click 'Personal settings', then, on the left panel, 
                          under 'Personal' click 'Security', then under 'Devices & sessions', in the 'App name' field enter Pax_Fax, then click the 'Create new app password' button. 
                          The password will be displayed only when created. Copy the password, click the 'Done' button, enter the password in the constructed callback URL between ':' 
                          and '@' as shown above, copy the entire callback URL to a safe location, then enter the callback URL in the field from below. Next, while logged in to your 
                          Sinch account click 'Fax' on the left panel, then click 'Services'. On the 'Services' page click the name of the service you want to use, then, on the 
                          'Incoming' tab, in the 'Incoming webhook url' field enter the callback URL for incoming faxes that you have just created, under 'Webhook content type' select
                          'multipart/form-data' and click 'Save'.):</label></p>
                   <input type="password" class="pax_fax_box" id="sinch_callback_url" name="sinch_callback_url" autocomplete="false"
                          placeholder="E.g.:  https://username:5CHGv-c36j9-kV2wm-RgJcl-7pjVE@cloud.example.com/apps/pax_fax/api/recfaxsinch" /><br><br>

                   <p><label for="get_notification" class="setlabeltext"><b><?php p($l->t('I want to see a notification in Nextcloud when a new fax is received:'));?></b></label></p>
                   <input type="checkbox" class="pax_fax_checkbox" id="get_notification" name="get_notification" autocomplete="false" /><br>

                   <p><label for="notification_email" class="setlabeltext"><b><?php p($l->t('I want to receive a notification to the email address from below, when a new fax is received'));?></b>
                          (To enable email notifications for every received fax, the "sendmail" utility  ("/usr/sbin/sendmail" on Debian Linux), has to be present on the server. "sendmail" 
                          is a binary that gets installed when Postfix is installed. Also, the web server user (www-data) has to be allowed to send emails from command line (by 
                          specifying "authorized_submit_users = www-data" in "/etc/postfix/main.cf" for Postfix on a Debian based Linux distribution).):
                      </label></p>
                   <input type="text" class="pax_fax_box" id="notification_email" name="notification_email" autocomplete="false"
                          placeholder="E.g.: john.doe@example.com" /><br>

                   <input type="hidden" id="user_id" name="user_id" />

                   <input id="save_fax_settings" type="submit" value="<?php p($l->t('Save')) ?>" />

                   <span id="paxfax_save_msg"></span>

               </form>
           </div>
        </div>
</div>