-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathconsole.java
More file actions
1018 lines (884 loc) · 38.4 KB
/
console.java
File metadata and controls
1018 lines (884 loc) · 38.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
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
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package Jvakt;
/*
* 2025-04-17 V.62 Michael Ekdal Fixed misspelling of RecId in the showLine routine..
* 2025-04-01 V.61 Michael Ekdal Added recid.
* 2024-06-19 V.60 Michael Ekdal Improved error handling in consoleDM.
* 2023-11-25 V.59 Michael Ekdal Added cmdLogs to start the Logs pgm.
* 2023-11-07 V.58 Michael Ekdal Added "About" in the menu.
* 2023-10-04 V.57 Michael Ekdal Added triggering of the plugins from the console.
* 2023-05-26 V.56 Michael Ekdal Added menus in addition to the F keys
* 2023-01-09 V.55 Michael Ekdal Added CheckStatus warning.
* 2022-06-23 V.54 Michael Ekdal Added getVersion() to get at consistent version throughout all classes.
*/
import java.awt.*;
import java.awt.event.*;
import javax.swing.event.*;
import javax.swing.*;
import javax.swing.table.*;
import java.io.*;
import java.util.*;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.Timer;
import javax.swing.border.*;
// Extend of Jframe to get access to the swing metohods in Jframe.
// Jframe is the base in the windows management.
//implementing TableModelListener to use this class as listener to Jtables datamodell class via the method tableChanged.
//implementing WindowListener to use this class as lyssnare to Jframe with the method windowClosing
public class console extends JFrame implements TableModelListener, WindowListener {
// Creates variables
static final long serialVersionUID = 42L;
private JPanel topPanel;
private JTable table;
private JScrollPane scrollPane;
private JButton bu1;
private JMenuBar menuBar;
private JMenu menu, menuPgm, menuRow, menuAbout;
private JMenuItem menuItem;
private JTableHeader header;
private consoleDM wD;
private Boolean swAuto = true;
private Boolean swRed = true;
private Boolean swDBopen = true;
private Boolean swServer = true;
private Boolean swDormant = true;
private Boolean swCheckStatus = true;
private Boolean swPropFile = true;
private String jvhost = "127.0.0.1";
private String jvport = "1956";
private int port = 1956;
private String cmdHst = "javaw -cp Jvakt.jar Jvakt.consoleHst";
private String cmdSts = "javaw -cp Jvakt.jar Jvakt.consoleSts";
private String cmdLogs = "javaw -cp Jvakt.jar Jvakt.consoleLogs";
private String cmdStat = "javaw -cp Jvakt.jar Jvakt.StatisticsChartLauncher";
private int deselectCount = 0;
private int jvconnectCount = 0;
private int jvCheckStatusCount = 1000;
private String infotxt;
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws IOException {
console mainFrame = new console(); // Creates an object of the current class
mainFrame.pack(); // calling method pack which is inherited from Jframe
mainFrame.setVisible(true); // calling method setVisible so show all findows to the user
} // main is now in waiting mode waiting for all the other objects to end.
// this is the constructor which starts from the static main method.
// it creates all needed objects and connects them.
// it also calls methods inherited from Jframe to set certain values.
public console() throws IOException {
ImageIcon img = new ImageIcon("console.png");
setIconImage(img.getImage());
// get the parameters from the console.properties file
getProps();
port = Integer.parseInt(jvport);
// a function inherited from Jframe used to set a heading
setTitle("Jvakt console "+getVersion()+".62");
// setSize(5000, 5000);
// get the screen size as a java dimension
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
// get 2/5 of the height, and 2/3 of the width
int height = screenSize.height * 1 / 5;
int width = screenSize.width * 5 / 6;
// set the jframe height and width
setPreferredSize(new Dimension(width, height));
setLocation(20,20);
// function in Jframe to set colors
setBackground(Color.gray);
setUndecorated(false);
// creates a new Jpanel and saves the reference in topPanel
topPanel = new JPanel();
// tells topPanel which layout to use by create a BorderLayout object with no name.
topPanel.setLayout(new BorderLayout());
//topPanel.setLayout(new FlowLayout());
// gets Jpanels simple content handler and inserts topPanel in stead to handle the rest of the objects
getContentPane().add(topPanel);
//topPanel.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
// creates a data model to handle the data in the table
wD = new consoleDM();
// creates a Jtable and add the reference to wD via the Jtable contructor
table = new JTable(wD);
header = table.getTableHeader();
header.setBackground(Color.LIGHT_GRAY);
bu1 = new JButton();
//Create the menu.
menuBar = new JMenuBar();
//Build the first menu.
menu = new JMenu("File");
menuPgm = new JMenu("Programs");
menuRow = new JMenu("Rows");
menuAbout = new JMenu("About");
// menu.setMnemonic(KeyEvent.VK_A);
// menu.getAccessibleContext().setAccessibleDescription("The only menu in this program that has menu items");
menuBar.add(menu);
menuBar.add(menuPgm);
menuBar.add(menuRow);
menuBar.add(menuAbout);
//a group of JMenuItems
menuItem = new JMenuItem("History (F5)");
menuItem.addActionListener(strHst());
menuPgm.add(menuItem);
menuItem = new JMenuItem("Status (F6)");
menuItem.addActionListener(strSts());
menuPgm.add(menuItem);
menuItem = new JMenuItem("Statistics (F10)");
menuItem.addActionListener(strStat());
menuPgm.add(menuItem);
menuItem = new JMenuItem("Imported log files");
menuItem.addActionListener(strLogs());
menuPgm.add(menuItem);
menuItem = new JMenuItem("Delete selected row(s) (DEL)");
menuItem.addActionListener(delRow());
menuRow.add(menuItem);
menuItem = new JMenuItem("Send selected row(s) to plugin(s) (Ivanti and/or Syslog)");
menuItem.addActionListener(sendRowToPlugin());
menuRow.add(menuItem);
menuItem = new JMenuItem("Unselect row(s) (ESC)");
menuItem.addActionListener(clearSel());
menuRow.add(menuItem);
menuItem = new JMenuItem("Increase font (F3)");
menuItem.addActionListener(increaseH());
menuRow.add(menuItem);
menuItem = new JMenuItem("Decrease font (F4)");
menuItem.addActionListener(decreaseH());
menuRow.add(menuItem);
menuItem = new JMenuItem("Show selected row in separate window (F7)");
menuItem.addActionListener(showLine());
menuRow.add(menuItem);
menuItem = new JMenuItem("Toggle active/dormant status of Jvakt server. (F8)");
menuItem.addActionListener(toggleDormant());
menu.add(menuItem);
menuItem = new JMenuItem("Create info line in console (F9)");
menuItem.addActionListener(getInfo());
menuRow.add(menuItem);
menuItem = new JMenuItem("Help (F1)");
menuItem.addActionListener(showHelp());
menuAbout.add(menuItem);
menuItem = new JMenuItem("About");
menuItem.addActionListener(showAbout());
menuAbout.add(menuItem);
setJMenuBar(menuBar);
System.out.println("screenHeightWidth :" +screenSize.height+" " +screenSize.width);
if (screenSize.height > 1200) {
table.setRowHeight(table.getRowHeight()*2);
header.setFont(new javax.swing.plaf.FontUIResource("Dialog", Font.PLAIN, table.getRowHeight()));
bu1.setFont(new javax.swing.plaf.FontUIResource("Dialog", Font.PLAIN, table.getRowHeight()));
}
else
if (screenSize.height > 1080) {
table.setRowHeight(table.getRowHeight()*1,5);
header.setFont(new javax.swing.plaf.FontUIResource("Dialog", Font.PLAIN, table.getRowHeight()));
bu1.setFont(new javax.swing.plaf.FontUIResource("Dialog", Font.PLAIN, table.getRowHeight()));
}
swServer = true;
try {
SendMsg jm = new SendMsg(jvhost, port); // check if the Jvakt.Server is accessable
String oSts = jm.open();
// System.out.println("#1 "+oSts);
if (oSts.startsWith("failed")) swServer = false;
if (oSts.startsWith("DORMANT")) swDormant = true;
else swDormant = false;
jm.close();
}
catch (NullPointerException npe2 ) {
swServer = false;
System.out.println("-- Rpt Failed 1 --" + npe2);
}
swDBopen = wD.refreshData(); // check if the DB is available
setBu1Color();
bu1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
swAuto = !swAuto;
swDBopen = wD.refreshData();
setBu1Color();
}
});
// enables the table to accept multiple row selection
table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
// ask the table for the reference to the LIstSecectionModel object, the reference is saved in rowSM
ListSelectionModel rowSM = table.getSelectionModel();
//
// NB internal class start---
// Use the rowSM method to create a listener to the table to know which row is selected
rowSM.addListSelectionListener(new ListSelectionListener() {
// the internal class method which gets the selected row
public void valueChanged(ListSelectionEvent e) {
// Ignore extra messages.
if (e.getValueIsAdjusting()) return;
ListSelectionModel lsm = (ListSelectionModel) e.getSource();
if (lsm.isSelectionEmpty()) {
// System.out.println("No rows are selected.");
} else {
// int selectedRow = lsm.getMinSelectionIndex();
// System.out.println("Row " + selectedRow + " is now selected.");
deselectCount = 0;
}
return;
}
}
);
// NB internal class end---
//
// sets auto sorting in the table
// table.setAutoCreateRowSorter(true);
// tells the table data model object (wD) this object is listening; method tableChanged
table.getModel().addTableModelListener(this);
// consoleCR selects color on the rows
consoleCR cr=new consoleCR();
for (int i=0; i <= 8 ; i++ ) {
table.getColumn(table.getColumnName(i)).setCellRenderer(cr);
}
// creates new JScrollPane and adds the table via the constructor. To be able to scroll the tables.
scrollPane = new JScrollPane(table);
table.setAutoResizeMode(JTable. AUTO_RESIZE_SUBSEQUENT_COLUMNS);
TableColumn column = null;
column = table.getColumnModel().getColumn(0); // id
column.setPreferredWidth(400);
column.setMaxWidth(1100);
column = table.getColumnModel().getColumn(1); // prio
column.setPreferredWidth(30);
column.setMaxWidth(65);
column = table.getColumnModel().getColumn(2); // type
column.setPreferredWidth(30);
column.setMaxWidth(65);
column = table.getColumnModel().getColumn(3); // credate
column.setPreferredWidth(190);
column.setMaxWidth(895);
column = table.getColumnModel().getColumn(4); // condate
column.setPreferredWidth(190);
column.setMaxWidth(895);
column = table.getColumnModel().getColumn(5); // status
column.setPreferredWidth(50);
column.setMaxWidth(420);
column = table.getColumnModel().getColumn(6); // body
column.setPreferredWidth(1000);
column.setMaxWidth(2800);
column = table.getColumnModel().getColumn(7); // agent
column.setPreferredWidth(80);
column.setMaxWidth(950);
column = table.getColumnModel().getColumn(8); // recid
column.setPreferredWidth(50);
column.setMaxWidth(950);
addKeyBindings();
scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
// scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
// Creates two new JPanels to be used inside topPanel, also a JPanel
topPanel.add(scrollPane, BorderLayout.CENTER);
topPanel.add(bu1, BorderLayout.NORTH);
// tells the current object to use itself as a listener. (methods for WindowListener)
addWindowListener(this);
Timer timer = new Timer(2000, new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (deselectCount > 10 ) {
table.getSelectionModel().clearSelection(); // clear selected rows.
deselectCount = 0;
}
deselectCount++;
if (swAuto) {
jvconnectCount++;
if (jvconnectCount > 2 || !swServer) { // keep the number of connection checks down because of limitations in Win10
jvconnectCount = 0;
try {
swServer = true;
SendMsg jm = new SendMsg(jvhost, port); // check if the Jvakt.Server is started.
String oSts = jm.open();
if (oSts.startsWith("failed")) swServer = false;
if (oSts.startsWith("DORMANT")) swDormant = true;
else swDormant = false;
jm.close();
}
catch (NullPointerException npe2 ) {
swServer = false;
System.out.println("-- Rpt Failed 2 --" + npe2);
}
}
swDBopen = wD.refreshData();
jvCheckStatusCount++;
if (jvCheckStatusCount > 30) {
swCheckStatus = wD.isCheckStatusActive();
jvCheckStatusCount=0;
// System.out.println("isCheckStatusActive? "+ swCheckStatus);
}
setBu1Color();
if (swRed) scrollPane.setBorder(new LineBorder(Color.RED));
else scrollPane.setBorder(new LineBorder(Color.CYAN));
swRed = !swRed;
scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER);
scrollPane.validate();
scrollPane.repaint();
scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
revalidate();
repaint();
}
}
});
timer.start();
} // end constructor
// we implemented TableModelListener and added "this" so this method should be called at a change in the table
// this is only used for logging
public void tableChanged(TableModelEvent e) {
int row = e.getFirstRow();
int column = e.getColumn();
String ls ;
TableModel model = (TableModel)e.getSource();
// String columnName = model.getColumnName(column);
String data = (String)model.getValueAt(row, column);
ls = "Workout tableChanged " + row + " " + column + " " + data;
System.out.println(ls);
}
public void setBu1Color() {
String txt = "";
if (swAuto) {
bu1.setBackground(Color.GRAY);
txt = "Auto Update ON.";
}
else {
bu1.setBackground(Color.yellow);
txt = "Auto Update OFF.";
}
if (!swPropFile) {
txt = txt + " No console.properties file found. ";
}
if (!swDBopen) {
bu1.setBackground(Color.RED);
txt = txt + " No connection with DB. ";
}
if (!swServer) {
bu1.setBackground(Color.RED);
txt = txt + " No connection with JvaktServer. ";
}
else if (swDormant) {
bu1.setBackground(Color.ORANGE);
txt = txt + " System DORMANT.";
}
else txt = txt + " System ACTIVE.";
if (!swCheckStatus) {
bu1.setBackground(Color.RED);
txt = txt + " CheckStatus not active. ";
}
bu1.setText(txt);
}
private void addKeyBindings() {
table.getActionMap().put("delRow", delRow());
table.getActionMap().put("strHst", strHst());
table.getActionMap().put("strSts", strSts());
table.getActionMap().put("strStat", strStat());
table.getActionMap().put("clearSel", clearSel());
table.getActionMap().put("increaseH", increaseH());
table.getActionMap().put("decreaseH", decreaseH());
table.getActionMap().put("getInfo", getInfo());
table.getActionMap().put("showHelp", showHelp());
table.getActionMap().put("showLine", showLine());
table.getActionMap().put("toggleDormant", toggleDormant());
KeyStroke keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_BACK_SPACE, 0); // delete key in mac
table.getInputMap(JComponent.WHEN_FOCUSED).put(keyStroke, "delRow");
keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0); // delete key in win linux
table.getInputMap(JComponent.WHEN_FOCUSED).put(keyStroke, "delRow");
// Do not use VK_F2 beacuse JTable overides it sometimes
keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_F1, 0);
table.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(keyStroke, "showHelp");
keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_HELP, 0);
table.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(keyStroke, "showHelp");
keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_F3, 0);
table.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(keyStroke, "increaseH");
keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_F4, 0);
table.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(keyStroke, "decreaseH");
keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_F5, 0);
table.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(keyStroke, "strHst");
keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_F6, 0);
table.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(keyStroke, "strSts");
keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_F7, 0);
table.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(keyStroke, "showLine");
keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_F8, 0);
table.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(keyStroke, "toggleDormant");
// keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_F9, 0);
// table.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(keyStroke, "strHst");
keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_F9, 0);
table.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(keyStroke, "getInfo");
keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_F10, 0);
table.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(keyStroke, "strStat");
keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_F11, 0);
table.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(keyStroke, "strHst");
keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_F12, 0);
table.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(keyStroke, "delRow");
keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE , 0);
table.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(keyStroke, "clearSel");
}
private AbstractAction showHelp() {
AbstractAction save = new AbstractAction() {
static final long serialVersionUID = 43L;
@Override
public void actionPerformed(ActionEvent e) {
// JOptionPane.showMessageDialog(TestTableKeyBinding.this.table, "Action Triggered.");
// System.out.println("ShowHelp");
JOptionPane.showMessageDialog(getContentPane(),
"F1 : Help \nF3 : Increase font size \nF4 : Decrease font size \nF5 : History \nF6 : Status table \nF7 : Show row \nF8 : Toggle System active / dormant \nF9 : Enter info text \nF10 : Statistics \n\nDEL : delete rows \nESC : Unselect\n" +
"\nThis app shows the filtered reports/messages sent to the Jvakt server. OK messages of types 'R', 'T' and 'S' remains in the database." +
"\nThe upper bar acts a button to stop/start the automatic update. \nIt will also show the status of the server and database." +
"\n\nFields: " +
"\nId= The Id of the message. " +
"\nPrio= Prio 30 and higher is meant for office hours and messages will remain in the console. No mail or SMS." +
"\n Below 30 is important and might trigger SMS and/or mail depending on chkday/chktim " +
"\n Prio 10 or less is very important and will trigger SMS and/or mail 24/7. " +
"\ntype= 'S' means a check that rptday is updated 'today'. The check is made once a day at the time in the chkday and chktim fields. " +
"\n When read and acted upon, the row may be selected and removed with the DEL button." +
"\n If not manually deleted it will be automatically removed the next time the check sends an OK report. Usually the next day." +
"\ntype= 'R' means a check that rptdat is updated at least every 20 minute. The check starts from the time in chkday and chktim fields." +
"\n The message will disappear automatically when the issue is resolved. " +
"\ntype= 'T' means no tome-out checks are made." +
"\n When read and acted upon the line may be selected and removed with the DEL button." +
"\n It will be automatically removed the next time the check sends an OK report." +
"\n When or if this will happen is unknown." +
"\ntype= 'I' means impromptu messages. " +
"\n The 'I' type will not remain in the status table and can not be prepared in advance." +
"\n When read and acted upon the row must be selected and removed with the DEL button." +
"\nCreDate= The inital time the message arrived the the console."+
"\nConDate= The latest time the message was updated. "+
"\nStatus= ERR, INFO, OK or TOut."+
"\n TOut means the agent has stopped sending the expected status reports. This applied only to types 'S' and 'R'. "+
"\nbody= Contains the message text sent by the agent"+
"\nagent= Contains the host name and IP address where the agent is executed."+
"\nRecId= The id obtained when creating an Ivanti incident."
,"Jvakt Help",
JOptionPane.INFORMATION_MESSAGE);
}
};
return save;
}
private AbstractAction showAbout() {
AbstractAction save = new AbstractAction() {
static final long serialVersionUID = 43L;
@Override
public void actionPerformed(ActionEvent e) {
// JOptionPane.showMessageDialog(TestTableKeyBinding.this.table, "Action Triggered.");
// System.out.println("ShowHelp");
JOptionPane.showMessageDialog(getContentPane(),
"Version: "+getVersion()+
"\n\nJvakt is a simple reactive monitoring system/toolbox." +
"\n\nJvakt is distributed under the MIT License (i.e. It is free of charge to use)"+
"\nhttps://github.com/mEkdal/Jvakt/blob/master/LICENSE"+
"\n\nDownload Jvakt and read the wiki documentation at the Github site"+
"\nhttps://github.com/mEkdal/Jvakt/wiki" +
"\n\nby Michael Ekdal"
,"Jvakt About",
JOptionPane.INFORMATION_MESSAGE);
}
};
return save;
}
private AbstractAction getInfo() {
AbstractAction save = new AbstractAction() {
static final long serialVersionUID = 53L;
@Override
public void actionPerformed(ActionEvent e) {
table.getSelectionModel().clearSelection(); // clear selected rows.
infotxt = JOptionPane.showInputDialog(getContentPane(),
"Enter information text to be sent to the console\n"
,"Jvakt Info",
JOptionPane.QUESTION_MESSAGE);
if ((infotxt != null) && (infotxt.length() > 0)) {
System.out.println("*** infotxt: " + infotxt);
try {
Message jmsg = new Message();
SendMsg jm = new SendMsg(jvhost, port);
System.out.println(jm.open());
jmsg.setId("INFO-to-console");
jmsg.setType("I");
jmsg.setRptsts("INFO");
jmsg.setBody(infotxt);
jmsg.setAgent("GUI");
if (jm.sendMsg(jmsg)) System.out.println("-- Rpt Delivered 5 --");
else System.out.println("-- Rpt Failed 5 --");
jm.close();
}
catch (Exception e2) {
System.err.println(e2);
System.err.println(e2.getMessage());
}
}
}
};
return save;
}
private AbstractAction showLine() {
AbstractAction save = new AbstractAction() {
static final long serialVersionUID = 44L;
@Override
public void actionPerformed(ActionEvent e) {
// System.out.println("ShowLine");
table.editingCanceled(null);
table.editingStopped(null);
int[] selectedRow = table.getSelectedRows();
System.out.println("ShowLine: "+selectedRow.length);
try {
for (int i = 0; i < selectedRow.length; i++) {
// System.out.println("*** Row to show :" + selectedRow[i]);
Object ValueId = table.getValueAt(selectedRow[i],table.getColumnModel().getColumnIndex("Id"));
// System.out.println(ValueId);
String id = (String) ValueId;
if (id == null) continue;
// System.out.println("*** " + selectedRow[i]);
ValueId = table.getValueAt(selectedRow[i],table.getColumnModel().getColumnIndex("Prio"));
// System.out.println(ValueId);
int prio = (Integer) ValueId;
ValueId = table.getValueAt(selectedRow[i],table.getColumnModel().getColumnIndex("Type"));
// System.out.println(ValueId);
String type = (String) ValueId;
ValueId = table.getValueAt(selectedRow[i],table.getColumnModel().getColumnIndex("CreDate"));
// System.out.println(ValueId);
String credate = (String) ValueId;
ValueId = table.getValueAt(selectedRow[i],table.getColumnModel().getColumnIndex("ConDate"));
// System.out.println(ValueId);
String condate = (String) ValueId;
ValueId = table.getValueAt(selectedRow[i],table.getColumnModel().getColumnIndex("Status"));
// System.out.println(ValueId);
String status = (String) ValueId;
ValueId = table.getValueAt(selectedRow[i],table.getColumnModel().getColumnIndex("Body"));
// System.out.println(ValueId);
String body = (String) ValueId;
ValueId = table.getValueAt(selectedRow[i],table.getColumnModel().getColumnIndex("Agent"));
// System.out.println(ValueId);
String agent = (String) ValueId;
ValueId = table.getValueAt(selectedRow[i],table.getColumnModel().getColumnIndex("RecId"));
// System.out.println(ValueId);
String recid = (String) ValueId;
JOptionPane.showMessageDialog(getContentPane(),
"- ID (the id of the message. Together with prio it makes an unique id) -\n"+id+" \n\n" +
"- Prio (the priority, part of the unique id. Below 30 trigger email and SMS text) -\n"+prio +"\n\n" +
"- Type (R=repeated, S=scheduled, I=immediate/impromptu, T=permanent with no time-out checks) -\n"+type +"\n\n" +
"- CreDate (the date it appeared in the console) -\n"+credate +"\n\n" +
"- ConDate (the date it updated in the console) -\n"+condate +"\n\n" +
"- Status (OK, INFO, TOut or ERR) -\n"+status +"\n\n" +
"- Body (any text) -\n"+body +"\n\n" +
"- Agent (description of the reporting agent) -\n"+agent+ "\n\n" +
"- Recid (Ivanti id) -\n"+recid
,
"Jvakt Show line",
JOptionPane.INFORMATION_MESSAGE);
}
}
catch (Exception e2) {
System.err.println("#sl1 "+e2);
System.err.println(e2.getMessage());
}
table.getSelectionModel().clearSelection(); // clear selected rows.
}
};
return save;
}
private AbstractAction clearSel() {
AbstractAction save = new AbstractAction() {
static final long serialVersionUID = 45L;
@Override
public void actionPerformed(ActionEvent e) {
// JOptionPane.showMessageDialog(TestTableKeyBinding.this.table, "Action Triggered.");
table.getSelectionModel().clearSelection(); // clear selected rows.
}
};
return save;
}
private AbstractAction increaseH() {
AbstractAction save = new AbstractAction() {
static final long serialVersionUID = 52L;
@Override
public void actionPerformed(ActionEvent e) {
if (table.getRowHeight()<100) {
table.setRowHeight(table.getRowHeight()+1);
header.setFont(new javax.swing.plaf.FontUIResource("Dialog", Font.PLAIN, table.getRowHeight()));
bu1.setFont(new javax.swing.plaf.FontUIResource("Dialog", Font.PLAIN, table.getRowHeight()));
}
}
};
return save;
}
private AbstractAction decreaseH() {
AbstractAction save = new AbstractAction() {
static final long serialVersionUID = 46L;
@Override
public void actionPerformed(ActionEvent e) {
// System.out.println("getRowHeight :" + table.getRowHeight());
if (table.getRowHeight()>10) {
table.setRowHeight(table.getRowHeight()-1);
header.setFont(new javax.swing.plaf.FontUIResource("Dialog", Font.PLAIN, table.getRowHeight()));
bu1.setFont(new javax.swing.plaf.FontUIResource("Dialog", Font.PLAIN, table.getRowHeight()));
}
}
};
return save;
}
private AbstractAction delRow() {
AbstractAction save = new AbstractAction() {
static final long serialVersionUID = 47L;
@Override
public void actionPerformed(ActionEvent e) {
// JOptionPane.showMessageDialog(TestTableKeyBinding.this.table, "Action Triggered.");
table.editingCanceled(null);
table.editingStopped(null);
// int selectedRow = table.getSelectedRow();
int[] selectedRow = table.getSelectedRows();
// for (int i = 0; i < selectedRow.length; i++) {
// System.out.println("*** Row do delete :" + selectedRow[i]);
// }
// if (selectedRow != -1) {
// ((DefaultTableModel) table.getModel()).removeRow(selectedRow);
// }
try {
for (int i = 0; i < selectedRow.length; i++) {
// System.out.println("*** Row to delete :" + selectedRow[i]);
Message jmsg = new Message();
SendMsg jm = new SendMsg(jvhost, port);
System.out.println("Response opening connection to Jvakt server: "+ jm.open());
Object ValueId = table.getValueAt(selectedRow[i],table.getColumnModel().getColumnIndex("Id"));
// System.out.println(ValueId);
jmsg.setId(ValueId.toString());
jmsg.setRptsts("OK");
// jmsg.setBody("Delete of row from GUI");
ValueId = table.getValueAt(selectedRow[i],table.getColumnModel().getColumnIndex("Body"));
// System.out.println(ValueId);
jmsg.setBody(ValueId.toString());
// jmsg.setBody("Delete of row from GUI");
ValueId = table.getValueAt(selectedRow[i],table.getColumnModel().getColumnIndex("Prio"));
// System.out.println(ValueId);
jmsg.setPrio(Integer.parseInt(ValueId.toString()));
jmsg.setType("D");
jmsg.setAgent("GUI");
// jm.sendMsg(jmsg);
if (jm.sendMsg(jmsg)) System.out.println("-- Rpt Delivered 3 --");
else System.out.println("-- Rpt Failed 3 --");
jm.close();
}
}
catch (Exception e2) {
System.err.println(e2);
System.err.println(e2.getMessage());
}
table.getSelectionModel().clearSelection(); // clear selected rows.
}
};
return save;
}
private AbstractAction sendRowToPlugin() {
AbstractAction save = new AbstractAction() {
static final long serialVersionUID = 47L;
@Override
public void actionPerformed(ActionEvent e) {
Object[] options = { "OK", "Cancel" };
int n = JOptionPane.showOptionDialog(null, "Do you really want to send the rows to be handeled by the plugins?\n"+
"Check the status table for an existing RecId if you are unsure.", "Send / Cancel",
JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE,
null, options, options[0]);
if (n==1) {
System.out.println("-- Cancel sending rows ---");
} else {
try {
table.editingCanceled(null);
table.editingStopped(null);
int[] selectedRow = table.getSelectedRows();
try {
for (int i = 0; i < selectedRow.length; i++) {
// System.out.println("*** Row to delete :" + selectedRow[i]);
Object ValueId = table.getValueAt(selectedRow[i],table.getColumnModel().getColumnIndex("RecId"));
// if (ValueId!=null) {
// if (ValueId.toString()!=null) {
// JOptionPane.showMessageDialog(getContentPane(),
// "The RecId shows there already is a Ivanti incident: "+ValueId.toString()+"\n"
// ,
// "Jvakt Show line",
// JOptionPane.INFORMATION_MESSAGE);
// return;
// }
// }
SendMsg jm = new SendMsg(jvhost, port);
System.out.println("Response opening connection to Jvakt server: "+ jm.open());
Message jmsg = new Message();
ValueId = table.getValueAt(selectedRow[i],table.getColumnModel().getColumnIndex("Id"));
jmsg.setId(ValueId.toString());
// jmsg.setRptsts("OK");
ValueId = table.getValueAt(selectedRow[i],table.getColumnModel().getColumnIndex("Status"));
jmsg.setRptsts(ValueId.toString());
ValueId = table.getValueAt(selectedRow[i],table.getColumnModel().getColumnIndex("Body"));
jmsg.setBody(ValueId.toString());
ValueId = table.getValueAt(selectedRow[i],table.getColumnModel().getColumnIndex("Prio"));
jmsg.setPrio(Integer.parseInt(ValueId.toString()));
jmsg.setType("P");
jmsg.setAgent("GUI");
// jm.sendMsg(jmsg);
if (jm.sendMsg(jmsg)) {
System.out.println("-- Rpt Delivered 3p --");
// System.out.println(jmsg.getId()+" "+jmsg.getPrio()+" "+jmsg.getRptsts()+" "+jmsg.getType()+" "+" "+jmsg.getBody() );
}
else {
System.out.println("-- Rpt Failed 3p --");
}
jm.close();
}
}
catch (Exception e2) {
System.err.println(e2);
System.err.println(e2.getMessage());
}
table.getSelectionModel().clearSelection(); // clear selected rows.
}
catch (Exception e2) {
System.err.println(e2);
System.err.println(e2.getMessage());
}
}
}
};
return save;
}
private AbstractAction toggleDormant() {
AbstractAction save = new AbstractAction() {
static final long serialVersionUID = 48L;
@Override
public void actionPerformed(ActionEvent e) {
Object[] options = { "OK", "Cancel" };
int n = JOptionPane.showOptionDialog(null, "Do you want to toggle System active / dormant?", "Toggle active / dormant",
JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE,
null, options, options[0]);
if (n==1) {
System.out.println("-- Cancel Toggle dormant ---");
} else {
// System.out.println("-- OK to Toggle dormant ---");
try {
Message jmsg = new Message();
SendMsg jm = new SendMsg(jvhost, port);
System.out.println(jm.open());
jmsg.setId("Jvakt");
if (swDormant) jmsg.setType("Active");
else jmsg.setType("Dormant");
jmsg.setAgent("GUI");
if (jm.sendMsg(jmsg)) System.out.println("-- Rpt Delivered --");
else System.out.println("-- Rpt Failed 4 --");
jm.close();
}
catch (Exception e2) {
System.err.println(e2);
System.err.println(e2.getMessage());
}
}
}
};
return save;
}
//************
private AbstractAction strHst() {
AbstractAction save = new AbstractAction() {
static final long serialVersionUID = 49L;
@Override
public void actionPerformed(ActionEvent e) {
// System.out.println("-- Start consoleHst: " + cmdHst);
try {
Runtime.getRuntime().exec(cmdHst);
} catch (IOException e1) {
System.err.println(e1);
System.err.println(e1.getMessage());
}
}
};
return save;
}
// ************
private AbstractAction strStat() {
AbstractAction save = new AbstractAction() {
static final long serialVersionUID = 49L;
@Override
public void actionPerformed(ActionEvent e) {
// System.out.println("-- Start consoleHst: " + cmdHst);
try {
// Runtime.getRuntime().exec("java -cp \"/Users/septpadm/OneDrive - Perstorp Group/JavaSrc;/Users/septpadm/OneDrive - Perstorp Group/JavaSrc/postgresql-42.1.3.jar\" Jvakt.consoleHst");
Runtime.getRuntime().exec(cmdStat);
} catch (IOException e1) {
System.err.println(e1);
System.err.println(e1.getMessage());
}
}
};
return save;
}
//************
private AbstractAction strSts() {
AbstractAction save = new AbstractAction() {
static final long serialVersionUID = 50L;
@Override
public void actionPerformed(ActionEvent e) {
// System.out.println("-- Start consoleSts: " + cmdSts);
try {
// Runtime.getRuntime().exec("java -cp \"/Users/septpadm/OneDrive - Perstorp Group/JavaSrc;/Users/septpadm/OneDrive - Perstorp Group/JavaSrc/postgresql-42.1.3.jar\" Jvakt.consoleHst");
Runtime.getRuntime().exec(cmdSts);
} catch (IOException e1) {
System.err.println(e1);
System.err.println(e1.getMessage());
}
}
};
return save;
}
// ************
private AbstractAction strLogs() {
AbstractAction save = new AbstractAction() {
static final long serialVersionUID = 50L;
@Override
public void actionPerformed(ActionEvent e) {
System.out.println("-- Start consoleLogs: " + cmdLogs);
try {
// Runtime.getRuntime().exec("java -cp \"/Users/septpadm/OneDrive - Perstorp Group/JavaSrc;/Users/septpadm/OneDrive - Perstorp Group/JavaSrc/postgresql-42.1.3.jar\" Jvakt.consoleHst");
Runtime.getRuntime().exec(cmdLogs);
} catch (IOException e1) {
System.err.println(e1);
System.err.println(e1.getMessage());
}
}
};
return save;
}
// ************
// windows listeners
// we implemented WindowListener and added "this" so this method should be used at a normal ending of Jframe
public void windowClosing(WindowEvent e) {
//skriv userDB
wD.closeDB();
System.exit(0);
// ...and now all ends..!!!...
}
void getProps() {
Properties prop = new Properties();
InputStream input = null;
try {
input = new FileInputStream("console.properties");
prop.load(input);
// get the property value and print it out
jvport = prop.getProperty("jvport");
jvhost = prop.getProperty("jvhost");
cmdHst = prop.getProperty("cmdHst");
cmdSts = prop.getProperty("cmdSts");
cmdStat = prop.getProperty("cmdStat");
cmdLogs = prop.getProperty("cmdLogs");
input.close();
} catch (IOException ex) {
swPropFile = false;
System.out.println("The console.properties file was not found! Am using default values! ");
System.err.println(ex);
}
}
static String getVersion() {
String version = "0";
try {
Class<?> c1 = Class.forName("Jvakt.Version",false,ClassLoader.getSystemClassLoader());
Version ver = new Version();