system_advanced_notifications.php 17.1 KB
Newer Older
Ad Schellevis's avatar
Ad Schellevis committed
1
<?php
2

Ad Schellevis's avatar
Ad Schellevis committed
3
/*
4 5
    Copyright (C) 2014-2015 Deciso B.V.
    Copyright (C) 2009 Scott Ullrich <sullrich@gmail.com>
6

7 8
    Redistribution and use in source and binary forms, with or without
    modification, are permitted provided that the following conditions are met:
9

10 11
    1. Redistributions of source code must retain the above copyright notice,
       this list of conditions and the following disclaimer.
12

13 14 15
    2. Redistributions in binary form must reproduce the above copyright
       notice, this list of conditions and the following disclaimer in the
       documentation and/or other materials provided with the distribution.
16

17 18 19 20 21 22 23 24 25 26
    THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
    INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
    AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
    AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
    OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
    CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
    POSSIBILITY OF SUCH DAMAGE.
Ad Schellevis's avatar
Ad Schellevis committed
27 28
*/

29
require_once("guiconfig.inc");
30
require_once("system.inc");
Ad Schellevis's avatar
Ad Schellevis committed
31

32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
if ($_SERVER['REQUEST_METHOD'] === 'GET') {
    // Growl
    $pconfig['disable_growl'] = isset($config['notifications']['growl']['disable']);
    $pconfig['password'] = !empty($config['notifications']['growl']['password']) ? $config['notifications']['growl']['password'] : null ;
    $pconfig['ipaddress'] = !empty($config['notifications']['growl']['ipaddress']) ? $config['notifications']['growl']['ipaddress'] : null;
    $pconfig['notification_name'] = !empty($config['notifications']['growl']['notification_name']) ? $config['notifications']['growl']['notification_name'] : "{$g['product_name']} growl alert";
    $pconfig['name'] = !empty($config['notifications']['growl']['name']) ? $config['notifications']['growl']['name'] : 'PHP-Growl';
    // SMTP
    $pconfig['disable_smtp'] = isset($config['notifications']['smtp']['disable']);
    $pconfig['smtpipaddress'] = !empty($config['notifications']['smtp']['ipaddress']) ? $config['notifications']['smtp']['ipaddress'] : null;
    $pconfig['smtpport'] = !empty($config['notifications']['smtp']['port']) ? $config['notifications']['smtp']['port'] : null;
    $pconfig['smtpssl'] = isset($config['notifications']['smtp']['ssl']);
    $pconfig['smtptls'] = isset($config['notifications']['smtp']['tls']);
    $pconfig['smtpnotifyemailaddress'] = !empty($config['notifications']['smtp']['notifyemailaddress']) ? $config['notifications']['smtp']['notifyemailaddress'] : null;
    $pconfig['smtpusername'] =!empty($config['notifications']['smtp']['username']) ? $config['notifications']['smtp']['username'] : null;
    $pconfig['smtppassword'] = !empty($config['notifications']['smtp']['password']) ? $config['notifications']['smtp']['password'] : null;
    $pconfig['smtpfromaddress'] = !empty($config['notifications']['smtp']['fromaddress']) ? $config['notifications']['smtp']['fromaddress'] : null;
    // System Sounds
    $pconfig['disablebeep'] = isset($config['system']['disablebeep']);
} elseif ($_SERVER['REQUEST_METHOD'] === 'POST') {
52 53
    $pconfig = $_POST;

54
    if (!empty($pconfig['Submit']) && $pconfig['Submit'] == gettext("Save")) {
55
        // Growl
56 57 58 59
        $config['notifications']['growl']['ipaddress'] = $pconfig['ipaddress'];
        $config['notifications']['growl']['password'] = $pconfig['password'];
        $config['notifications']['growl']['name'] = $pconfig['name'];
        $config['notifications']['growl']['notification_name'] = $pconfig['notification_name'];
60

61
        if (!empty($pconfig['disable_growl'])) {
62
            $config['notifications']['growl']['disable'] = true;
63
        } elseif (isset($config['notifications']['growl']['disable'])) {
64 65 66 67
            unset($config['notifications']['growl']['disable']);
        }

        // SMTP
68 69 70
        $config['notifications']['smtp']['ipaddress'] = $pconfig['smtpipaddress'];
        $config['notifications']['smtp']['port'] = $pconfig['smtpport'];
        if (!empty($pconfig['smtpssl'])) {
71
            $config['notifications']['smtp']['ssl'] = true;
72
        } elseif (isset($config['notifications']['smtp']['ssl'])) {
73 74
            unset($config['notifications']['smtp']['ssl']);
        }
75
        if (!empty($pconfig['smtptls'])) {
76
            $config['notifications']['smtp']['tls'] = true;
77
        } elseif (isset($config['notifications']['smtp']['tls'])) {
78 79
            unset($config['notifications']['smtp']['tls']);
        }
80 81 82 83
        $config['notifications']['smtp']['notifyemailaddress'] = $pconfig['smtpnotifyemailaddress'];
        $config['notifications']['smtp']['username'] = $pconfig['smtpusername'];
        $config['notifications']['smtp']['password'] = $pconfig['smtppassword'];
        $config['notifications']['smtp']['fromaddress'] = $pconfig['smtpfromaddress'];
84

85
        if (!empty($pconfig['disable_smtp'])) {
86
            $config['notifications']['smtp']['disable'] = true;
87
        } elseif (isset($config['notifications']['smtp']['disable'])) {
88 89 90 91
            unset($config['notifications']['smtp']['disable']);
        }

        // System Sounds
92
        if (!empty($pconfig['disablebeep'])) {
93
            $config['system']['disablebeep'] = true;
94
        } elseif (isset($config['system']['disablebeep'])) {
95 96 97 98
            unset($config['system']['disablebeep']);
        }

        write_config();
99
        header(url_safe('Location: /system_advanced_notifications.php'));
100 101
        return;

102
    } elseif (isset($pconfig['test_growl']) && $pconfig['test_growl'] == gettext("Test Growl")) {
103
        // Send test message via growl
104 105
        if (!empty($config['notifications']['growl']['ipaddress']) &&
            !empty($config['notifications']['growl']['password'])) {
106 107
            @unlink('/var/db/growlnotices_lastmsg.txt');
            register_via_growl();
Fabian Franz's avatar
Fabian Franz committed
108
            notify_via_growl(sprintf(gettext("This is a test message from %s. It is safe to ignore this message."), $g['product_name']), true);
109
        }
110
    } elseif (!empty($pconfig['test_smtp']) && $pconfig['test_smtp'] == gettext("Test SMTP")) {
111 112
        // Send test message via smtp
        @unlink('/var/db/notices_lastmsg.txt');
Fabian Franz's avatar
Fabian Franz committed
113
        notify_via_smtp(sprintf(gettext("This is a test message from %s. It is safe to ignore this message."), $g['product_name']), true);
114
    }
Ad Schellevis's avatar
Ad Schellevis committed
115 116
}

117
legacy_html_escape_form_data($pconfig);
118

Ad Schellevis's avatar
Ad Schellevis committed
119
include("head.inc");
120

Ad Schellevis's avatar
Ad Schellevis committed
121 122 123 124
?>

<script type="text/javascript">
//<![CDATA[
125 126 127 128 129 130 131 132 133 134 135 136 137
  $(document).ready(function() {
    if ($('#smtpssl').is(':checked')) {
      $('#smtptls').prop('disabled', true);
    } else if  ($('#smtptls').is(':checked')) {
      $('#smtpssl').prop('disabled', true);
    }
    $('#smtpssl').change( function() {
      $('#smtptls').prop('disabled', this.checked);
    });
    $('#smtptls').change( function() {
      $('#smtpssl').prop('disabled', this.checked);
    });
  });
Ad Schellevis's avatar
Ad Schellevis committed
138 139
//]]>
</script>
140

141 142 143 144 145
<body>
<?php include("fbegin.inc"); ?>
<section class="page-content-main">
  <div class="container-fluid">
    <div class="row">
146
      <form method="post">
147 148 149 150 151 152 153 154
<?php
      if (isset($savemsg)) {
          print_info_box($savemsg);
      }
?>
      </form>
        <section class="col-xs-12">
          <div class="content-box tab-content table-responsive">
155
            <form method="post" name="iform">
156
            <table class="table table-striped opnsense_standard_table_form">
157 158 159 160
              <tr>
                <td width="22%"><strong><?=gettext("Growl");?></strong></td>
                <td  width="78%" align="right">
                  <small><?=gettext("full help"); ?> </small>
Ad Schellevis's avatar
Ad Schellevis committed
161
                  <i class="fa fa-toggle-off text-danger"  style="cursor: pointer;" id="show_all_help_page" type="button"></i>
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209
                </td>
              </tr>
              <tr>
                <td><a id="help_for_disable_growl" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("Disable Growl Notifications"); ?></td>
                <td>
                  <input type='checkbox' name='disable_growl' value="yes" <?=!empty($pconfig['disable_growl']) ? "checked=\"checked\"" : "";?>/>
                  <div class="hidden" for="help_for_disable_growl">
                    <?=gettext("Check this option to disable growl notifications but preserve the settings below."); ?>
                  </div>
                </td>
              </tr>
              <tr>
                <td><a id="help_for_name" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("Registration Name"); ?></td>
                <td>
                  <input name="name" type="text" value="<?=$pconfig['name']; ?>"/>
                  <div class="hidden" for="help_for_name">
                    <?=gettext("Enter the name to register with the Growl server (default: PHP-Growl)."); ?>
                  </div>
                </td>
              </tr>
              <tr>
                <td><a id="help_for_notification_name" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("Notification Name"); ?></td>
                <td>
                  <input name='notification_name' type='text' value='<?=$pconfig['notification_name']; ?>' /><br />
                  <div class="hidden" for="help_for_notification_name">
                    <?=sprintf(gettext("Enter a name for the Growl notifications (default: %s growl alert)."), $g['product_name']); ?>
                  </div>
                </td>
              </tr>
              <tr>
                <td><a id="help_for_ipaddress" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("IP Address"); ?></td>
                <td>
                  <input name="ipaddress" type="text" value="<?=$pconfig['ipaddress']; ?>" /><br />
                  <div class="hidden" for="help_for_ipaddress">
                    <?=gettext("This is the IP address that you would like to send growl notifications to."); ?>
                  </div>
                </td>
              </tr>
              <tr>
                <td><a id="help_for_password" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("Password"); ?></td>
                <td>
                  <input name="password" type="password" value="<?=$pconfig['password']; ?>"/><br />
                  <div class="hidden" for="help_for_password">
                    <?=gettext("Enter the password of the remote growl notification device."); ?>
                  </div>
                </td>
              </tr>
              <tr>
210
                <th colspan="2"><?=gettext("SMTP Email"); ?></th>
211 212 213 214 215 216 217 218 219 220 221
              </tr>
              <tr>
                <td><a id="help_for_disable_smtp" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("Disable SMTP Notifications"); ?></td>
                <td>
                  <input type="checkbox" name="disable_smtp" value="yes" <?=!empty($pconfig['disable_smtp']) ? "checked=\"checked\"" : "";?>/>
                  <div class="hidden" for="help_for_disable_smtp">
                    <?=gettext("Check this option to disable SMTP notifications but preserve the settings below. Some other mechanisms, such as packages, may need these settings in place to function."); ?>
                  </div>
                </td>
              </tr>
              <tr>
222
                <td><a id="help_for_smtpipaddress" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("Email server"); ?></td>
223 224 225
                <td>
                  <input name="smtpipaddress" type="text" value="<?=$pconfig['smtpipaddress']; ?>" />
                  <div class="hidden" for="help_for_smtpipaddress">
226
                    <?=gettext("This is the FQDN or IP address of the SMTP Email server to which notifications will be sent."); ?>
227 228 229 230
                  </div>
                </td>
              </tr>
              <tr>
231
                <td><a id="help_for_smtpport" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("SMTP Port of Email server"); ?></td>
232 233 234
                <td>
                  <input name="smtpport" type="text" value="<?=$pconfig['smtpport']; ?>" />
                  <div class="hidden" for="help_for_smtpport">
235
                    <?=gettext("This is the port of the SMTP Email server, typically 25, 587 (submission) or 465 (smtps)"); ?>
236 237 238 239 240 241 242 243 244 245 246 247 248
                  </div>
                </td>
              </tr>
              <tr>
                <td><i class="fa fa-info-circle text-muted"></i> <?=gettext("Secure SMTP Connection"); ?></td>
                <td>
                  <input type="checkbox" id="smtpssl" name="smtpssl" <?=!empty($pconfig['smtpssl']) ? "checked=\"checked\"" : "";?> />
                  <strong><?=gettext('Enable SMTP over SSL/TLS');?></strong><br />
                  <input type="checkbox" id="smtptls" name="smtptls" <?=!empty($pconfig['smtptls']) ? "checked=\"checked\"" : "";?> />
                  <strong><?=gettext('Enable STARTTLS');?></strong><br />
                </td>
              </tr>
              <tr>
249
                <td><a id="help_for_smtpfromaddress" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("Sender address"); ?></td>
250 251 252
                <td>
                  <input name="smtpfromaddress" type="text" value="<?=$pconfig['smtpfromaddress']; ?>" />
                  <div class="hidden" for="help_for_smtpfromaddress">
253
                    <?=gettext("This is the email address that will appear as the email notification sender."); ?>
254 255 256 257
                  </div>
                </td>
              </tr>
              <tr>
258
                <td><a id="help_for_smtpnotifyemailaddress" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("Recipient address"); ?></td>
259 260 261
                <td>
                  <input name="smtpnotifyemailaddress" type="text" value="<?=$pconfig['smtpnotifyemailaddress'];?>" />
                  <div class="hidden" for="help_for_smtpnotifyemailaddress">
262
                    <?=gettext("Enter the email address that you would like email notifications sent to."); ?>
263 264 265 266
                  </div>
                </td>
              </tr>
              <tr>
267
                <td><a id="help_for_smtpusername" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("Email auth username"); ?></td>
268 269 270 271
                <td>
                  <input name="smtpusername" type="text" value="<?=$pconfig['smtpusername']; ?>" />
                  <div class="hidden" for="help_for_smtpusername">
                    <small><?=gettext("(optional)");?></small><br/>
272
                    <?=gettext("Enter the email address username for SMTP authentication."); ?>
273 274 275 276
                  </div>
                </td>
              </tr>
              <tr>
277
                <td><a id="help_for_smtppassword" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("Email auth password"); ?></td>
278 279 280 281
                <td>
                  <input name='smtppassword' type='password' value='<?=$pconfig['smtppassword']; ?>' /><br />
                  <div class="hidden" for="help_for_smtppassword">
                    <small><?=gettext("(optional)");?></small><br/>
282
                    <?=gettext("Enter the email address password for SMTP authentication."); ?>
283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328
                  </div>
                </td>
              </tr>
              <tr>
                <td colspan="2">&nbsp;</td>
              </tr>
              <!-- System Sounds -->
              <tr>
                <th colspan="2"><?=gettext("System Sounds"); ?></th>
              </tr>
              <tr>
                <td><a id="help_for_disablebeep" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("Startup/Shutdown Sound"); ?></td>
                <td>
                  <input name="disablebeep" type="checkbox" id="disablebeep" value="yes" <?=!empty($pconfig['disablebeep']) ? "checked=\"checked\"" : "";?>/>
                  <strong><?=gettext("Disable the startup/shutdown beep"); ?></strong>
                  <br />
                  <div class="hidden" for="help_for_disablebeep">
                    <span class="vexpl"><?=gettext("When this is checked, startup and shutdown sounds will no longer play."); ?></span>
                  </div>
                </td>
              </tr>
              <tr>
                <td colspan="2">&nbsp;</td>
              </tr>
              <tr>
                <td></td>
                <td>
                  <input type="submit" id="Submit" name="Submit" class="btn btn-primary" value="<?=gettext("Save"); ?>" />
                </td>
              </tr>
              <tr>
                <td></td>
                <td>
                  <input type="submit" id="test_growl" name="test_growl" value="<?=gettext("Test Growl"); ?>" class="btn btn-primary" />
                  <input type="submit" id="test_smtp" name="test_smtp" value="<?=gettext("Test SMTP"); ?>" class="btn btn-primary" />
                  <br />
                  <small><?= gettext("NOTE: A test notification will be sent even if the service is marked as disabled.") ?></small>
                </td>
              </tr>
            </table>
          </form>
        </div>
      </section>
    </div>
  </div>
</section>
329
<?php include("foot.inc");