Skip to content

Commit

Permalink
Added TLS setting for monitoring mails.
Browse files Browse the repository at this point in the history
  • Loading branch information
j-dimension committed Oct 4, 2019
1 parent 5d80108 commit d3e7fae
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -641,10 +641,12 @@
<Group type="103" groupAlignment="0" attributes="0">
<Component id="txtRecipient" max="32767" attributes="0"/>
<Component id="txtUser" max="32767" attributes="0"/>
<Component id="txtPassword" alignment="0" pref="430" max="32767" attributes="0"/>
<Component id="txtPassword" alignment="0" max="32767" attributes="0"/>
<Group type="102" alignment="0" attributes="0">
<Component id="txtSmtp" max="32767" attributes="0"/>
<Component id="txtSmtp" min="-2" pref="289" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="chkEmailStartTls" min="-2" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="2" max="-2" attributes="0"/>
<Component id="chkSsl" min="-2" max="-2" attributes="0"/>
</Group>
<Component id="txtSenderName" alignment="0" max="32767" attributes="0"/>
Expand All @@ -664,6 +666,7 @@
<Component id="jLabel6" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="txtSmtp" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="chkSsl" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="chkEmailStartTls" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
Expand Down Expand Up @@ -736,6 +739,11 @@
<Property name="text" type="java.lang.String" value="Absendername:"/>
</Properties>
</Component>
<Component class="javax.swing.JCheckBox" name="chkEmailStartTls">
<Properties>
<Property name="text" type="java.lang.String" value="StartTLS"/>
</Properties>
</Component>
</SubComponents>
</Container>
</SubComponents>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,7 @@ public ServerMonitoringDialog(java.awt.Frame parent, boolean modal) {
this.txtSenderName.setEnabled(false);
this.txtRecipient.setEnabled(false);
this.chkSsl.setEnabled(false);
this.chkEmailStartTls.setEnabled(false);
}
} catch (Exception ex) {
log.error(ex);
Expand Down Expand Up @@ -782,6 +783,12 @@ public ServerMonitoringDialog(java.awt.Frame parent, boolean modal) {
this.chkSsl.setSelected(true);
else
this.chkSsl.setSelected(false);

String startTls=set.getSetting(set.SERVERCONF_MONITOR_SMTPSTARTTLS, "false");
if("true".equalsIgnoreCase(startTls))
this.chkEmailStartTls.setSelected(true);
else
this.chkEmailStartTls.setSelected(false);
}

try {
Expand Down Expand Up @@ -898,6 +905,7 @@ private void initComponents() {
chkSsl = new javax.swing.JCheckBox();
txtSenderName = new javax.swing.JTextField();
jLabel20 = new javax.swing.JLabel();
chkEmailStartTls = new javax.swing.JCheckBox();

setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
setTitle("Servermonitoring");
Expand Down Expand Up @@ -1150,6 +1158,8 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {

jLabel20.setText("Absendername:");

chkEmailStartTls.setText("StartTLS");

javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
jPanel4.setLayout(jPanel4Layout);
jPanel4Layout.setHorizontalGroup(
Expand All @@ -1171,10 +1181,12 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
.addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(txtRecipient)
.addComponent(txtUser)
.addComponent(txtPassword, javax.swing.GroupLayout.DEFAULT_SIZE, 430, Short.MAX_VALUE)
.addComponent(txtPassword)
.addGroup(jPanel4Layout.createSequentialGroup()
.addComponent(txtSmtp)
.addComponent(txtSmtp, javax.swing.GroupLayout.PREFERRED_SIZE, 289, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(chkEmailStartTls)
.addGap(2, 2, 2)
.addComponent(chkSsl))
.addComponent(txtSenderName))))
.addContainerGap())
Expand All @@ -1187,7 +1199,8 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
.addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel6)
.addComponent(txtSmtp, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(chkSsl))
.addComponent(chkSsl)
.addComponent(chkEmailStartTls))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel7)
Expand Down Expand Up @@ -1309,6 +1322,11 @@ private void cmdSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST
ssl="true";
set.setSetting(set.SERVERCONF_MONITOR_SMTPSSL, ssl);

String startTls="false";
if(this.chkEmailStartTls.isSelected())
startTls="true";
set.setSetting(set.SERVERCONF_MONITOR_SMTPSTARTTLS, startTls);

this.setVisible(false);
this.dispose();
}//GEN-LAST:event_cmdSaveActionPerformed
Expand Down Expand Up @@ -1369,6 +1387,7 @@ public void windowClosing(java.awt.event.WindowEvent e) {
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.ButtonGroup backupMode;
private javax.swing.JCheckBox chkEmailStartTls;
private javax.swing.JCheckBox chkMonitorCpu;
private javax.swing.JCheckBox chkMonitorDisk;
private javax.swing.JCheckBox chkMonitorJava;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -749,6 +749,7 @@ public class ServerSettings {
public static final String SERVERCONF_MONITOR_SMTPSENDERNAME="jlawyer.server.monitor.smtpsendername";
public static final String SERVERCONF_MONITOR_SMTPTO="jlawyer.server.monitor.smtpto";
public static final String SERVERCONF_MONITOR_SMTPSSL="jlawyer.server.monitor.smtpssl";
public static final String SERVERCONF_MONITOR_SMTPSTARTTLS="jlawyer.server.monitor.smtpstarttls";

public static final String SERVERCONF_MONITOR_ENABLED_CPU="jlawyer.server.monitor.enabled.cpu";
public static final String SERVERCONF_MONITOR_ENABLED_RAM="jlawyer.server.monitor.enabled.ram";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1248,6 +1248,7 @@ public void statusMail(String subject, String body) {
ServerSettingsBean smtpPwdS = this.settingsFacade.find("jlawyer.server.monitor.smtppwd");
ServerSettingsBean smtpToS = this.settingsFacade.find("jlawyer.server.monitor.smtpto");
ServerSettingsBean smtpSslS = this.settingsFacade.find("jlawyer.server.monitor.smtpssl");
ServerSettingsBean smtpStartTlsS = this.settingsFacade.find("jlawyer.server.monitor.smtpstarttls");

if (smtpHostS == null || smtpUserS == null || smtpPwdS == null || smtpToS == null) {
log.error("incomplete configuration for sending status mails");
Expand All @@ -1271,6 +1272,14 @@ public void statusMail(String subject, String body) {
if (smtpSsl == null) {
smtpSsl = "false";
}

String smtpStartTls = "false";
if (smtpStartTlsS != null) {
smtpStartTls = smtpStartTlsS.getSettingValue();
}
if (smtpStartTls == null) {
smtpStartTls = "false";
}

Properties props = new Properties();
// props.put("mail.smtp.host", smtpHost);
Expand All @@ -1282,7 +1291,11 @@ public void statusMail(String subject, String body) {
if ("true".equalsIgnoreCase(smtpSsl)) {
props.put("mail.smtp.ssl.enable", "true");
}


if ("true".equalsIgnoreCase(smtpStartTls)) {
props.put("mail.smtp.starttls.enable", "true");
}

props.put("mail.smtp.host", smtpHost);
props.put("mail.smtp.user", smtpUser);
props.put("mail.smtp.auth", true);
Expand Down

0 comments on commit d3e7fae

Please sign in to comment.