<?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('sms_relentless', 'settings');
style('sms_relentless', 'style');

?>

<div id="sms_relentless_adm">
        <div class="section">
           <h2><?php p($l->t('SMS Relentless'));?></h2>
           <p id="settings-dscr"><h3><?php p($l->t('Enter your credentials and options in the fields from below. As SMS/MMS service provider you can use Telnyx or Plivo or Twilio 
              or Flowroute or all of them.')); ?></h3></p><br>
           <div class="sms_followupsection">

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

                   <div class="providerSettings">
                   <p class="providerName">Telnyx Settings</p>
                   <p><label for="telapi_key" class="setlabeltext"><b>Telnyx API Secret Key</b> (Log in to Telnyx, then, on the 'Home' page, in the 'API Keys' section from the upper right
                          corner, click on 'Manage Keys'. If you already have an API key, just copy it by clicking the 'Copy to clipboard' icon. Otherwise, to create an API key, click the
                          'Create API Key' button, on the pop up message click 'Create', then enter it in the field from below.):</label></p>
                   <input type="password" class="smsr_textbox" id="telapi_key" name="telapi_key" autocomplete="false"
                          placeholder="<?php p($l->t('e.g. d6f172ce92e4f2 ...')); ?>" /><br>

                   <p><label for="tel_pub_key" class="setlabeltext"><b>Telnyx Account Public Key</b> (While logged in to Telnyx, on the 'Home' page, in the 'API Keys' section from the 
                          upper right corner, click on 'Manage Keys', then click on 'Public Key' on the upper bar, then copy the key from the 'Key' field and enter it in the field from 
                          below.):</label></p>
                   <input type="password" class="smsr_textbox" id="tel_pub_key" name="tel_pub_key" autocomplete="false"
                          placeholder="<?php p($l->t('e.g. KLCnMsTSp8utW3RRHx0FiXxbf5BxK2Y5q8mMTCn0jgv=')); ?>" /><br>

                   <p><label for="messaging_profile_id" class="setlabeltext"><b>Messaging Profile ID</b> (While logged in to Telnyx, click on 'Messaging', then on 'Programmable Messaging' 
                       on the left panel, click on the name of the messaging profile that you want to use, then under 'Profile ID' you will find the messaging profile ID. Copy it and 
                       enter it in the field from below.):
                   </label></p>
                   <input type="password" class="smsr_textbox" id="messaging_profile_id" name="messaging_profile_id" autocomplete="false"
                          placeholder="<?php p($l->t('e.g. 9d4f47b6-26c9-d25c-c2f5 ...')); ?>" /><br>

                   <p><label for="telapi_url_rec" class="setlabeltext"><b>Telnyx webhook URL for incoming SMS/MMS</b> (You have to first generate and then copy this URL into your Telnyx
                       account, so that Telnyx knows where to deliver the SMS/MMS messages received by your Telnyx phone number(s). First generate the URL by pressing the button from
                       below, copy it, then, in your Telnyx account click on 'Messaging' then on 'Programmable Messaging' on the left panel, click on the name of the messaging profile 
                       that you associated with your phone number(s), then, under 'Inbound Settings', enter the webhook URL generated here in the field 'Send a webhook to this URL' and 
                       click the 'Save' button. Don't forget to also click the 'Save' button at the bottom of this page after entering all the credentials, to save all the settings to 
                       the database.)</label></p>
                   <input type="button" id="generate_tel_rcpt" value="<?php p($l->t('Generate new webhook URL for incoming SMS/MMS')) ?>" />
                   <input type="text" class="smsr_textboxspec" id="telapi_url_rec" name="telapi_url_rec" autocomplete="false" />
                   <span id="copyToClipboardtel" class="icon icon-clippy" title="Copy to clipboard"></span><br><br>

                   <p><label for="telapi_url" class="setlabeltext"><b>Telnyx webhook URL for delivery receipts</b> (This URL will be included by SMS Relentless in message sending 
                       requests, so that Telnyx knows where to send the delivery receipts. Just generate it by pressing the button from below.
                       You don't have to enter this URL into your Telnyx account. Don't forget to click the 'Save' button at the bottom of this page after entering all the credentials, 
                       to save all the settings to the database.)</label></p>
                   <input type="button" id="generate_tel_delrcpt" value="<?php p($l->t('Generate new webhook URL for delivery receipts')) ?>" />
                   <input type="text" id="telapi_url" name="telapi_url" autocomplete="false" /><br><br>

                   <p><label for="tel_sender_name" class="setlabeltext"><b>Telnyx alphanumeric Sender ID</b> (If you intend to use an alphanumeric Sender ID, enter an alphanumeric 
                          sequence of up to 11 characters in the range of a-z, A-Z, 0-9 and space. In certain countries there are regulations that accept only shorter alphanumeric 
                          Sender IDs, such as up to 6 characters. You cannot send SMS/MMS messages with alphanumeric Sender IDs to USA or Canada. There are even 
                          <a href="https://support.plivo.com/hc/en-us/articles/360041448032" style="color:#1b60ba" target="_blank" rel="noreferrer noopener">countries</a> that require
                          preregistration of alphanumeric Sender IDs. Before sending SMS/MMS messages to a country, it's recommended to read the
                          <a href="https://support.twilio.com/hc/en-us/articles/223133767-International-support-for-Alphanumeric-Sender-ID" style="color:#1b60ba" target="_blank"
                          rel="noreferrer noopener">country specific features and restrictions.</a> Some carriers won't accept messages with an alphanumeric Sender ID): </label></p>
                   <input type="text" class="smsr_textbox" id="tel_sender_name" name="tel_sender_name" autocomplete="false"
                          placeholder="<?php p($l->t('e.g. Smart Inc')); ?>" />
                   </div><br><br><br>

                   <div class="providerSettings">
                   <p class="providerName">Plivo Settings</p>
                   <p><label for="nexapi_key" class="setlabeltext"><b>Plivo Auth ID</b> (Log in to Plivo. On the first page, which is the Overview page, under Account, copy the 'Auth ID'
                          and enter it in the field from below.):</label></p>
                   <input type="password" class="smsr_textbox" id="nexapi_key" name="nexapi_key" autocomplete="false"
                          placeholder="<?php p($l->t('e.g. r5g974cb92e4t1 ...')); ?>" /><br>

                   <p><label for="nexapi_secret" class="setlabeltext"><b>Plivo Auth Token</b> (While logged in to Plivo, on the Overview page, under Account, copy the 'Auth Token' and
                          enter it in the field from below.):</label></p>
                   <input type="password" class="smsr_textbox" id="nexapi_secret" name="nexapi_secret" autocomplete="false"
                          placeholder="<?php p($l->t('e.g. k6f489d8awn4p9 ...')); ?>" /><br>

                   <p><label for="nexapi_url_rec" class="setlabeltext"><b>Plivo webhook URL for incoming SMS/MMS</b> (You have to first generate and then copy this URL into your Plivo
                       account, so that Plivo knows where to deliver the SMS/MMS messages received by your Plivo phone number(s). First generate the URL by pressing the button from
                       below, copy it, then, in your Plivo account click on 'Messaging' on the left vertical bar, click on 'Applications', then, under 'Application name' click on
                       'Inbound SMS Messages', next, under 'Message', enter the webhook URL generated here in the field 'Message URL' and select 'POST' next to it, then click the
                       'Update Application' button. Don't forget to also click the 'Save' button at the bottom of this page after entering all the credentials, to save all the settings 
                       to the database.)</label></p>
                   <input type="button" id="generate_nex_rcpt" value="<?php p($l->t('Generate new webhook URL for incoming SMS/MMS')) ?>" />
                   <input type="text" class="smsr_textboxspec" id="nexapi_url_rec" name="nexapi_url_rec" autocomplete="false" />
                   <span id="copyToClipboardnex" class="icon icon-clippy" title="Copy to clipboard"></span><br><br>

                   <p><label for="nexapi_url" class="setlabeltext"><b>Plivo webhook URL for delivery receipts</b> (This URL will be included by SMS Relentless in message sending 
                       requests, so that Plivo knows where to send the delivery receipts. Just generate it by pressing the button from below.
                       You don't have to enter this URL into your Plivo account. Don't forget to click the 'Save' button at the bottom of this page after entering all the credentials, 
                       to save all the settings to the database.)</label></p>
                   <input type="button" id="generate_nex_delrcpt" value="<?php p($l->t('Generate new webhook URL for delivery receipts')) ?>" />
                   <input type="text" id="nexapi_url" name="nexapi_url" autocomplete="false" /><br><br>

                   <p><label for="nex_sender_name" class="setlabeltext"><b>Plivo alphanumeric Sender ID:</b> (If you intend to use an alphanumeric Sender ID, enter an alphanumeric 
                          sequence of up to 11 characters in the range of a-z, A-Z, 0-9 and space. In certain countries there are regulations that accept only shorter alphanumeric 
                          Sender IDs, such as up to 6 characters. You cannot send SMS/MMS messages with alphanumeric Sender IDs to USA or Canada. There are even 
                          <a href="https://support.plivo.com/hc/en-us/articles/360041448032" style="color:#1b60ba" target="_blank" rel="noreferrer noopener">countries</a> that require
                          preregistration of alphanumeric Sender IDs. Before sending SMS/MMS messages to a country, it's recommended to read the
                          <a href="https://support.twilio.com/hc/en-us/articles/223133767-International-support-for-Alphanumeric-Sender-ID" style="color:#1b60ba" target="_blank"
                          rel="noreferrer noopener">country specific features and restrictions.</a> Some carriers won't accept messages with an alphanumeric Sender ID): </label></p>
                   <input type="text" class="smsr_textbox" id="nex_sender_name" name="nex_sender_name" autocomplete="false"
                          placeholder="<?php p($l->t('e.g. Global Inc')); ?>" />
                   </div><br><br><br>

                   <div class="providerSettings">
                   <p class="providerName">Twilio Settings</p>
                   <p><label for="twilapi_key" class="setlabeltext"><b>Twilio Account SID</b> (Log in to Twilio. On the first page, under Account Info, copy the 'Account SID'
                          and enter it in the field from below.):</label></p>
                   <input type="password" class="smsr_textbox" id="twilapi_key" name="twilapi_key" autocomplete="false"
                          placeholder="<?php p($l->t('e.g. r5g974cb92e4t1 ...')); ?>" /><br>

                   <p><label for="twilapi_secret" class="setlabeltext"><b>Twilio Auth Token</b> (While logged in to Twilio, on the first page, under Account Info, copy the 'Auth Token'
                          and enter it in the field from below.):</label></p>
                   <input type="password" class="smsr_textbox" id="twilapi_secret" name="twilapi_secret" autocomplete="false"
                          placeholder="<?php p($l->t('e.g. k6f489d8awn4p9 ...')); ?>" /><br>

                   <p><label for="twilapi_url_rec" class="setlabeltext"><b>Twilio webhook URL for incoming SMS/MMS</b> (You have to first generate and then copy this URL into your Twilio
                       account, so that Twilio knows where to deliver the SMS/MMS messages received by your Twilio phone number(s). First generate the URL by pressing the button from
                       below, copy it, then, in your Twilio account click on 'Phone Numbers' on the left panel > 'Manage' > 'Active numbers', click on the phone number you want to use 
                       for SMS/MMS, scroll down to the 'Messaging' section, then under 'A MESSAGE COMES IN' select 'Webhook', then paste in the webhook URL that you have just generated 
                       and select 'HTTP POST' as the request type. Enter the same data under 'PRIMARY HANDLER FAILS', then click the 'Save' button. If you have multiple SMS/MMS enabled 
                       phone numbers, do the same for each number. Don't forget to also click the 'Save' button at the bottom of this page after entering all the credentials, to save 
                       all the settings to the database.)</label></p>
                   <input type="button" id="generate_twil_rcpt" value="<?php p($l->t('Generate new webhook URL for incoming SMS/MMS')) ?>" />
                   <input type="text" class="smsr_textboxspec" id="twilapi_url_rec" name="twilapi_url_rec" autocomplete="false" />
                   <span id="copyToClipboardtwil" class="icon icon-clippy" title="Copy to clipboard"></span><br><br>

                   <p><label for="twilapi_url" class="setlabeltext"><b>Twilio webhook URL for delivery receipts</b> (This URL will be included by SMS Relentless in message sending 
                       requests, so that Twilio knows where to send the delivery receipts. Just generate it by pressing the button from below.
                       You don't have to enter this URL into your Twilio account. Don't forget to click the 'Save' button at the bottom of this page after entering all the credentials, 
                       to save all the settings to the database.)</label></p>
                   <input type="button" id="generate_twil_delrcpt" value="<?php p($l->t('Generate new webhook URL for delivery receipts')) ?>" />
                   <input type="text" id="twilapi_url" name="twilapi_url" autocomplete="false" /><br><br>

                   <p><label for="twil_sender_name" class="setlabeltext"><b>Twilio alphanumeric Sender ID:</b> (If you intend to use an alphanumeric Sender ID, enter an alphanumeric 
                          sequence of up to 11 characters in the range of a-z, A-Z, 0-9 and space. In certain countries there are regulations that accept only shorter alphanumeric 
                          Sender IDs, such as up to 6 characters. You cannot send SMS/MMS messages with alphanumeric Sender IDs to USA or Canada. There are even 
                          <a href="https://support.plivo.com/hc/en-us/articles/360041448032" style="color:#1b60ba" target="_blank" rel="noreferrer noopener">countries</a> that require
                          preregistration of alphanumeric Sender IDs. Before sending SMS/MMS messages to a country, it's recommended to read the
                          <a href="https://support.twilio.com/hc/en-us/articles/223133767-International-support-for-Alphanumeric-Sender-ID" style="color:#1b60ba" target="_blank"
                          rel="noreferrer noopener">country specific features and restrictions.</a> Some carriers won't accept messages with an alphanumeric Sender ID): </label></p>
                   <input type="text" class="smsr_textbox" id="twil_sender_name" name="twil_sender_name" autocomplete="false"
                          placeholder="<?php p($l->t('e.g. Global Inc')); ?>" />
                   </div><br><br><br>

                   <div class="providerSettings">
                   <p class="providerName">Flowroute Settings</p>
                   <p><label for="flowapi_key" class="setlabeltext"><b>Flowroute Access Key</b> (Log in to Flowroute. On the left panel, click on 'Preferences', then on the 'API Control'
                          tab. Scroll down to the 'API Keys' section. If you already have a pair of keys listed in that section, just copy the Access Key to the field from below. If you
                          haven't created any keys yet, to create a key pair, under 'Add new API Key', in the 'Name' field, enter a name for the new key pair. In the 'Description' field 
                          enter a short description, then click 'Add new'. A new pair of keys will be created and you will be prompted to copy the Secret Key. After you copy the Secret 
                          Key to a safe location, copy the Access Key that has just been created to the field from below.):</label></p>
                   <input type="password" class="smsr_textbox" id="flowapi_key" name="flowapi_key" autocomplete="false"
                          placeholder="<?php p($l->t('e.g. r5g974cb92e4t1 ...')); ?>" /><br>

                   <p><label for="flowapi_secret" class="setlabeltext"><b>Flowroute Secret Key</b> (Enter the Secret Key created earlier and copied to a safe place, in the field from 
                          below.):</label></p>
                   <input type="password" class="smsr_textbox" id="flowapi_secret" name="flowapi_secret" autocomplete="false"
                          placeholder="<?php p($l->t('e.g. k6f489d8awn4p9 ...')); ?>" /><br>

                   <p><label for="flowapi_url_rec" class="setlabeltext"><b>Flowroute webhook URL for incoming SMS/MMS</b> (You have to first generate and then copy this URL into your 
                          Flowroute account, so that Flowroute knows where to deliver the SMS/MMS messages received by your Flowroute phone number(s). First generate the URL by pressing 
                          the button from below, copy it, then, in your Flowroute account click on 'Preferences' on the left panel, then click on the 'API Control tab', turn on the 'SMS' 
                          switch and in the field that shows up enter the URL that you have just generated. Click 'Save URL'. If you have an MMS enabled phone number, turn on the 'MMS' 
                          switch, enter the same URL in the URL field and save it. Also, under 'SMS Webhook Version' choose 'v2.1'. Don't forget to also click the 'Save' button at the 
                          bottom of this page after entering all the credentials, to save all the settings to the database.)</label></p>
                   <input type="button" id="generate_flow_rcpt" value="<?php p($l->t('Generate new webhook URL for incoming SMS/MMS')) ?>" />
                   <input type="text" class="smsr_textboxspec" id="flowapi_url_rec" name="flowapi_url_rec" autocomplete="false" />
                   <span id="copyToClipboardflow" class="icon icon-clippy" title="Copy to clipboard"></span><br><br>

                   <p><label for="flowapi_url" class="setlabeltext"><b>Flowroute webhook URL for delivery receipts</b> (This URL is needed by Flowroute to know where to send the 
                          delivery receipts. Just generate it by pressing the button from below. You don't have to enter this URL into your Flowroute account. Don't forget to click 
                          the 'Save' button at the bottom of this page after entering all the credentials, to save all the settings to the database.)</label></p>
                   <input type="button" id="generate_flow_delrcpt" value="<?php p($l->t('Generate new webhook URL for delivery receipts')) ?>" />
                   <input type="text" id="flowapi_url" name="flowapi_url" autocomplete="false" /><br><br>
                          Flowroute only supports sending/receiving SMS/MMS messages within USA and Canada and it doesn't support Alphanumeric Sender IDs.

                   </div><br><br><br>

                   <p><label for="messagesperpage" class="setlabeltext"><b>Number of messages per page</b> (Enter the number of messages to be displayed on one page of the
                          received and sent messages tables. If you don't enter anything in this field, the default of 100 messages per page will be used.):</label></p>
                   <input type="number" class="smsr_textbox" id="messagesperpage" name="messagesperpage" autocomplete="false" placeholder="<?php p($l->t('e.g. 100')); ?>"/><br>

                   <p><label for="get_notify" class="setlabeltext"><b>I want to see a notification in Nextcloud when a new SMS/MMS is received:</b></label></p>
                   <input type="checkbox" class="sms_rel_checkbox" id="get_notify" name="get_notify" autocomplete="false" /><br>

                   <p class="setlabeltext">To enable email notifications for every received SMS/MMS, the "sendmail" utility ("/usr/sbin/sendmail" on Debian Linux),
                      has to be present on the server. "sendmail" is a binary which gets installed when Postfix is installed. Also the 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).</p><br>

                   <p><label for="notification_email" class="setlabeltext"><b>I want to receive a notification to the email address from below, when a new SMS/MMS is
                      received:</b></label></p>
                   <input type="text" class="smsr_textbox" id="notification_email" name="notification_email" autocomplete="false"
                          placeholder="<?php p($l->t('e.g. john.doe@example.com')); ?>" /><br>

                   <p><label for="includesmsinemail" class="setlabeltext"><b>Include the SMS/MMS message in the email notification itself:</b></label></p>
                   <input type="checkbox" class="sms_rel_checkbox" id="includesmsinemail" name="includesmsinemail" autocomplete="false" /><br>

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

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

                   <span id="smsr_save_msg"></span>

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