Debian Codegraph @

lib/plugins/sms/Email2SmsProvider.inc

raw
1 <?php
2
3 namespace LAM\PLUGINS\SMS;
4
5 /*
6
7 This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
8 Copyright (C) 2025 - 2026 Roland Gruber
9
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23
24 */
25
26 use LAMException;
27
28 /**
29 * Email2SMS provider.
30 *
31 * @author Roland Gruber
32 */
33
34 /**
35 * Email2SMS provider.
36 *
37 * @package LAM\PLUGINS\SMS
38 */
39 class Email2SmsProvider implements SmsProvider {
40
41 /**
42 * @inheritDoc
43 */
44 public function getLabel(): string {
45 return 'EMail2SMS';
46 }
47
48 /**
49 * @inheritDoc
50 */
51 public function getId(): string {
52 return 'email2sms';
53 }
54
55 /**
56 * @inheritDoc
57 */
58 public function sendSms(string $message, string $number, ?string $apiKey = '', ?string $apiToken = '',
59 ?string $accountId = '', ?string $region = '', ?string $from = '', ?string $subject = ''): void {
60 if (str_starts_with($number, '+')) {
61 $number = '00' . substr($number, 1);
62 }
63 $to = str_replace('$number', $number, $accountId);
64 $success = sendEMail($to, $subject ?? '', $message, $from, false);
65 if ($success) {
66 logNewMessage(LOG_DEBUG, 'Email2Sms sent to ' . $to);
67 }
68 else {
69 logNewMessage(LOG_ERR, 'Unable to send SMS via Email2SMS for ' . $to);
70 throw new LAMException(null, '');
71 }
72 }
73
74 /**
75 * @inheritDoc
76 */
77 public function usesApiToken(): bool {
78 return false;
79 }
80
81 /**
82 * @inheritDoc
83 */
84 public function usesApiKey(): bool {
85 return false;
86 }
87
88 /**
89 * @inheritDoc
90 */
91 public function usesAccountId(): bool {
92 return true;
93 }
94
95 /**
96 * @inheritDoc
97 */
98 public function usesFrom(): bool {
99 return true;
100 }
101
102 /**
103 * @inheritDoc
104 */
105 public function usesRegion(): bool {
106 return false;
107 }
108
109 /**
110 * @inheritDoc
111 */
112 public function usesSubject(): bool {
113 return true;
114 }
115
116 }