summaryrefslogtreecommitdiff
path: root/localwebsite
diff options
context:
space:
mode:
authorEvgeny Sorokin <me@ch1p.io>2024-01-18 04:14:38 +0300
committerEvgeny Sorokin <me@ch1p.io>2024-01-18 04:14:38 +0300
commitd237e81873a9e043f579e7f6a979f00510ddce08 (patch)
treef17ed95a80e1c594b585a829888da1c74f59798b /localwebsite
parenta9a241ad19449c29b68cd4a5b539bcbec816e341 (diff)
lws: sms page rewrite
Diffstat (limited to 'localwebsite')
-rw-r--r--localwebsite/handlers/ModemHandler.php79
-rw-r--r--localwebsite/templates-web/sms_page.twig62
2 files changed, 0 insertions, 141 deletions
diff --git a/localwebsite/handlers/ModemHandler.php b/localwebsite/handlers/ModemHandler.php
index 8179620..94ad75b 100644
--- a/localwebsite/handlers/ModemHandler.php
+++ b/localwebsite/handlers/ModemHandler.php
@@ -95,85 +95,6 @@ class ModemHandler extends RequestHandler
$this->tpl->render_page('routing_dhcp_page.twig');
}
- public function GET_sms() {
- global $config;
-
- list($selected, $is_outbox, $error, $sent) = $this->input('modem, b:outbox, error, b:sent');
- if (!$selected)
- $selected = array_key_first($config['modems']);
-
- $cfg = $config['modems'][$selected];
- $e3372 = new E3372($cfg['ip'], $cfg['legacy_token_auth']);
- $messages = $e3372->getSMSList(1, 20, $is_outbox);
-
- $this->tpl->set([
- 'modems_list' => array_keys($config['modems']),
- 'modems' => $config['modems'],
- 'selected_modem' => $selected,
- 'messages' => $messages,
- 'is_outbox' => $is_outbox,
- 'error' => $error,
- 'is_sent' => $sent
- ]);
-
- $direction = $is_outbox ? 'исходящие' : 'входящие';
- $this->tpl->set_title('SMS-сообщения ('.$direction.', '.$selected.')');
- $this->tpl->render_page('sms_page.twig');
- }
-
- public function POST_sms() {
- global $config;
-
- list($selected, $is_outbox, $phone, $text) = $this->input('modem, b:outbox, phone, text');
- if (!$selected)
- $selected = array_key_first($config['modems']);
-
- $return_url = '/sms/?modem='.$selected;
- if ($is_outbox)
- $return_url .= '&outbox=1';
-
- $go_back = function(?string $error = null) use ($return_url) {
- if (!is_null($error))
- $return_url .= '&error='.urlencode($error);
- else
- $return_url .= '&sent=1';
- redirect($return_url);
- };
-
- $phone = preg_replace('/\s+/', '', $phone);
-
- // при отправке смс на короткие номера не надо использовать libphonenumber и вот это вот всё
- if (strlen($phone) > 4) {
- $country = null;
- if (!startsWith($phone, '+'))
- $country = 'RU';
-
- $phoneUtil = PhoneNumberUtil::getInstance();
- try {
- $number = $phoneUtil->parse($phone, $country);
- } catch (NumberParseException $e) {
- debugError(__METHOD__.': failed to parse number '.$phone.': '.$e->getMessage());
- $go_back('Неверный номер ('.$e->getMessage().')');
- return;
- }
-
- if (!$phoneUtil->isValidNumber($number)) {
- $go_back('Неверный номер');
- return;
- }
-
- $phone = $phoneUtil->format($number, PhoneNumberFormat::E164);
- }
-
- $cfg = $config['modems'][$selected];
- $e3372 = new E3372($cfg['ip'], $cfg['legacy_token_auth']);
-
- $result = $e3372->sendSMS($phone, $text);
- debugLog($result);
-
- $go_back();
- }
-
protected static function getCurrentUpstream() {
global $config;
diff --git a/localwebsite/templates-web/sms_page.twig b/localwebsite/templates-web/sms_page.twig
deleted file mode 100644
index 112fa64..0000000
--- a/localwebsite/templates-web/sms_page.twig
+++ /dev/null
@@ -1,62 +0,0 @@
-{% include 'bc.twig' with {
- history: [
- {text: "SMS-сообщения" }
- ]
-} %}
-
-<nav>
- <div class="nav nav-tabs" id="nav-tab">
- {% for modem in modems_list %}
- {% if selected_modem != modem %}<a href="/sms/?modem={{ modem }}" class="text-decoration-none">{% endif %}
- <button class="nav-link{% if modem == selected_modem %} active{% endif %}" type="button">{{ modems[modem].short_label }}</button>
- {% if selected_modem != modem %}</a>{% endif %}
- {% endfor %}
- </div>
-</nav>
-
-<h6 class="text-primary mt-4">Отправить SMS</h6>
-
-{% if is_sent %}
- <div class="alert alert-success" role="alert">
- Сообщение отправлено.
- </div>
-{% elseif error %}
- <div class="alert alert-danger" role="alert">
- {{ error }}
- </div>
-{% endif %}
-
-<div>
- <form method="post" action="/sms/">
- <input type="hidden" name="modem" value="{{ selected_modem }}">
- <div class="form-floating mb-3">
- <input type="text" name="phone" class="form-control" id="inputPhone" placeholder="+7911xxxyyzz">
- <label for="inputPhone">Телефон</label>
- </div>
- <div class="form-floating">
- <textarea class="form-control" id="inputTA" name="text" placeholder="Hello world" style="height: 100px"></textarea>
- <label for="inputTA">Текст сообщения</label>
- </div>
- <div class="mt-3">
- <button type="submit" class="btn btn-primary">Отправить</button>
- </div>
- </form>
-</div>
-
-<h6 class="text-primary mt-4">
- Последние
- {% if not is_outbox %}
- <b>входящие</b> <span class="text-black-50">|</span> <a href="/sms/?modem={{ selected_modem }}&amp;outbox=1">исходящие</a>
- {% else %}
- <a href="/sms/?modem={{ selected_modem }}">входящие</a> <span class="text-black-50">|</span> <b>исходящие</b>
- {% endif %}
-</h6>
-
-{% for m in messages %}
- <div class="mt-3">
- <b>{{ m.phone }}</b> <span class="text-secondary">({{ m.date }})</span><br/>
- {{ m.content }}
- </div>
-{% else %}
- <span class="text-secondary">Сообщений нет.</span>
-{% endfor %} \ No newline at end of file