1 2 23 24 27 32 package net.fenyo.gnetwatch.GUI; 33 34 import java.io.*; 35 import java.util.*; 36 import java.net.*; 37 38 import javax.swing.*; 39 40 import net.fenyo.gnetwatch.*; 41 import net.fenyo.gnetwatch.actions.*; 42 import net.fenyo.gnetwatch.activities.*; 43 import net.fenyo.gnetwatch.targets.*; 44 import net.fenyo.gnetwatch.data.*; 45 46 import org.apache.commons.logging.Log; 47 import org.apache.commons.logging.LogFactory; 48 49 import org.apache.commons.configuration.*; 50 import org.apache.commons.configuration.tree.xpath.*; 51 52 import org.eclipse.swt.*; 53 import org.eclipse.swt.widgets.*; 54 import org.eclipse.swt.layout.*; 55 import org.eclipse.swt.custom.*; 56 import org.eclipse.swt.events.*; 57 import org.eclipse.swt.graphics.*; 58 import org.eclipse.swt.browser.*; 59 import org.snmp4j.security.SecurityLevel; 60 import org.snmp4j.util.TableEvent; 61 62 67 68 public class GUI implements Runnable { 69 private static Log log = LogFactory.getLog(GUI.class); 70 71 private Config config; 72 private Background background; 73 private Main main; 74 private SNMPManager snmp_manager; 75 private Views views; 76 77 private AwtGUI awtGUI = null; 78 79 private Display display = null; 81 82 private Shell shell = null; 84 private GridLayout layout = null; 85 86 private Menu menu_bar = null, menu_file = null; 88 private MenuItem menu_item_file = null; 89 private MenuItem menu_item_exit = null; 90 91 private ToolBar toolbar = null; 93 private GridData toolbar_grid_data = null; 94 95 private SashForm vertical_sash = null; 97 private GridData vertical_sash_grid_data = null; 98 99 private Composite horizontal_composite = null; 101 private GridLayout horizontal_composite_layout = null; 102 103 private Browser text_console = null; 105 private StringBuffer text_console_content = new StringBuffer (); 106 107 private Composite groups_composite = null; 109 private RowLayout groups_composite_layout = null; 110 private GridData groups_composite_grid_data = null; 111 private Group group_target_subnet = null, group_target_range = null, group_target_host = null, group_target_group = null, group_target_host6 = null; 112 private GridLayout group_target_subnet_layout = null, group_target_range_layout = null, group_target_host_layout = null, group_target_group_layout = null, group_target_host6_layout = null; 114 private Text target_subnet_address = null, target_subnet_mask = null; 116 private Text target_range_begin = null, target_range_end = null; 117 private Button target_subnet_push = null, target_range_push = null; 118 private Text target_host_value = null; 119 private Text target_group_value = null; 120 private Text target_host6_value = null; 121 private Button target_host_push = null, target_group_push = null, target_host6_push = null; 122 private TargetGroup user_defined = null; 123 private final int bglevel = 100; 124 125 private SashForm horizontal_sash = null; 127 private GridData horizontal_sash_grid_data = null; 128 129 private Tree tree = null; 131 private TreeColumn tree_column1 = null, tree_column2 = null, tree_column3 = null; 132 133 private StyledText status = null; 135 private GridData status_grid_data = null; 136 137 private ProgressBar progress_bar = null; 139 private GridData progress_bar_grid_data = null; 140 private CTabFolder tab_folder = null; 141 142 private Thread thread = null; 144 private final boolean GUI_created[] = { false }; 145 146 private Image image_folder = null, image_oscillo = null, image_exec = null, 148 image_watch = null, image_host = null, image_host6 = null, 149 image_host_snmp = null, image_host6_snmp = null, 150 image_interface = null, image_queue = null, image_network = null, 151 image_multirow = null; 152 153 private VisualElement visual_root = null; 155 private VisualElement visual_queues = null; 156 private VisualElement visual_transient = null; 157 private TargetGroup visual_thishost = null; 158 private TargetGroup visual_transient_all = null; 160 private TargetGroup visual_transient_networks = null; 161 163 private Label label1 = null, label2 = null, label3 = null, 164 label4 = null, label5 = null, label6 = null, 165 label7 = null; 166 167 private MenuItem menu_item_add_host = null, menu_item_add_host6 = null, menu_item_add_range = null, 168 menu_item_add_network = null, menu_item_add_group = null; 169 170 private ToolItem item_add_host = null, item_add_network = null, 171 item_discover_start = null, item_discover_stop = null; 172 173 private MenuItem menu_item_credentials = null, menu_item_ip_options = null, menu_item_http_options = null; 174 175 private MenuItem menu_item_add_ping = null, menu_item_add_flood = null, menu_item_add_http = null, 176 menu_item_explore_snmp = null, menu_item_remove_action = null, 177 menu_item_remove_action_ping = null, menu_item_remove_action_flood = null, 178 menu_item_remove_action_explore = null, menu_item_remove_view = null, 179 menu_item_remove_view_ping = null, menu_item_remove_view_flood = null, 180 menu_item_remove_view_explore = null; 181 182 VisualElement previous_selection = null; 183 184 public Object sync_tree = new Object (); 186 187 private final Map<Target, Target> target_map = new HashMap<Target, Target>(); 188 189 private CTabItem tab_item1, tab_item2; 190 191 private int text_console_do_not_go_on_top = 0; 192 193 198 public Config getConfig() { 199 return config; 200 } 201 202 207 public Shell getShell() { 208 return shell; 209 } 210 211 216 public Color getBackgroundColor() { 217 return new Color(display, (int) Math.min((int) shell.getBackground().getRed() * 1.05, 255), 218 (int) Math.min((int) shell.getBackground().getGreen() * 1.05, 255), 219 (int) Math.min((int) shell.getBackground().getBlue() * 1.05, 255)); 220 } 221 222 227 public SNMPManager getSNMPManager() { 228 return snmp_manager; 229 } 230 231 236 public boolean [] getGUICreated() { 237 return GUI_created; 238 } 239 240 245 public VisualElement getVisualTransient() { 246 return visual_transient; 247 } 248 249 254 public TargetGroup getVisualThisHost() { 255 return visual_thishost; 256 } 257 258 263 public TargetGroup getVisualTransientAll() { 264 return visual_transient_all; 265 } 266 267 272 public TargetGroup getVisualTransientNetworks() { 273 return visual_transient_networks; 274 } 275 276 281 public AwtGUI getAwtGUI() { 283 return awtGUI; 284 } 285 286 291 public void dropTargetInstance(final VisualElement target) { 293 target_map.remove(target); 294 } 295 296 303 public Target getCanonicalInstance(final Target target) { 305 final Target canonic_instance = target_map.get(target); 306 if (canonic_instance == null) { 307 target_map.put(target, target); 308 return target; 309 } else return canonic_instance; 310 } 311 312 317 public boolean containsCanonicalInstance(final Target target) { 319 return target_map.get(target) != null; 320 } 321 322 327 public void asyncExecIfNeeded(final Runnable r) { 329 if (thread == null || Thread.currentThread().equals(thread)) r.run(); 331 else display.asyncExec(r); 332 } 333 334 339 public CTabFolder getTabFolder() { 341 return tab_folder; 342 } 343 344 349 public Image getImageFolder() { 351 return image_folder; 352 } 353 354 359 public Image getImageExec() { 361 return image_exec; 362 } 363 364 369 public Image getImageOscillo() { 371 return image_oscillo; 372 } 373 374 379 public Image getImageMultiRow() { 381 return image_multirow; 382 } 383 384 389 public Image getImageWatch() { 391 return image_watch; 392 } 393 394 399 public Image getImageHost() { 401 return image_host; 402 } 403 404 409 public Image getImageHost6() { 411 return image_host6; 412 } 413 414 419 public Image getImageInterface() { 421 return image_interface; 422 } 423 424 429 public Image getImageQueue() { 431 return image_queue; 432 } 433 434 439 public Image getImageNetwork() { 441 return image_network; 442 } 443 444 449 public Image getImageHostSNMP() { 451 return image_host_snmp; 452 } 453 454 459 public Image getImageHost6SNMP() { 461 return image_host6_snmp; 462 } 463 464 470 public void setStatus(final String str) { 471 asyncExecIfNeeded(new Runnable () { 472 public void run() { 473 status.setText(" " + str); 474 } 475 }); 476 } 477 478 483 public void setProgress(final int position) { 484 asyncExecIfNeeded(new Runnable () { 485 public void run() { 486 progress_bar.setSelection(position); 487 } 488 }); 489 } 490 491 496 public String htmlFace(final String html) { 497 return "<FONT FACE='Verdana' size='-2'>" + html + "</FONT>"; 498 } 499 500 506 public void appendConsole(final String str) { 507 asyncExecIfNeeded(new Runnable () { 508 public void run() { 509 text_console_content.append(str); 510 text_console.setText("<html><body bgcolor='#" + 511 String.format("%2x%2x%2x", 512 getBackgroundColor().getRed(), 513 getBackgroundColor().getGreen(), 514 getBackgroundColor().getBlue()) + 515 "'>" + 516 htmlFace(text_console_content.toString()) + 517 "</body></html>"); 518 } 519 }); 520 } 521 522 527 private boolean isSelectionTransient() { 529 if (tree.getSelectionCount() == 1) { 530 TreeItem current_item = tree.getSelection()[0]; 531 while (current_item != null && 532 visual_transient.isThisOurTreeItem(current_item) == false ) 534 current_item = current_item.getParentItem(); 535 if (visual_transient.isThisOurTreeItem(current_item)) return true; 536 } 537 return false; 538 } 539 540 554 555 560 private void expandAll(final TreeItem item) { 562 synchronized (sync_tree) { 563 item.setExpanded(true); 564 for (final TreeItem it : item.getItems()) expandAll(it); 565 } 566 } 567 568 573 private void mergeAll(final TreeItem item) { 575 synchronized (sync_tree) { 576 item.setExpanded(false); 577 for (final TreeItem it : item.getItems()) mergeAll(it); 578 } 579 } 580 581 587 private void addActionAll(final TreeItem item, Class clazz) { 589 synchronized (sync_tree) { 590 for (final VisualElement elt : VisualElement.getSubElements(item, Target.class)) { 591 final Target target = (Target) elt; 592 593 boolean already_has_action = false; 594 for (final VisualElement child : target.getChildren()) 595 if (clazz.isInstance(child)) { 596 already_has_action = true; 597 break; 598 } 599 600 if (already_has_action == false) { 601 net.fenyo.gnetwatch.actions.Action action; 602 try { 603 action = (net.fenyo.gnetwatch.actions.Action) clazz.newInstance(); 604 } catch (final IllegalAccessException ex) { 605 log.error("Exception", ex); 606 return; 607 } catch (final InstantiationException ex) { 608 log.error("Exception", ex); 609 return; 610 } 611 action.setTarget(target); 612 action.setBackground(background); 613 if (target.canManageThisChild(action)) 614 try { 615 background.addActionQueue(action); 616 action.setParent(this, target); 617 } catch (final GeneralException ex) { 618 log.error("Exception", ex); 619 } 620 } 621 } 622 } 623 } 624 625 630 private void addPingAll(final TreeItem item) { 632 addActionAll(item, ActionPing.class); 633 } 634 635 640 private void addFloodAll(final TreeItem item) { 642 addActionAll(item, ActionFlood.class); 643 } 644 645 650 private void addHTTPAll(final TreeItem item) { 652 addActionAll(item, ActionHTTP.class); 653 } 654 655 660 private void exploreSNMP(final TreeItem item) { 662 addActionAll(item, ActionSNMP.class); 663 } 664 665 670 private void exploreNmap(final TreeItem item) { 672 addActionAll(item, ActionNmap.class); 673 } 674 675 680 private void getSysdescr(final TreeItem item) { 682 synchronized (sync_tree) { 683 for (final VisualElement elt : VisualElement.getSubElements(item, TargetIPv4.class)) { 684 final TargetIPv4 target = (TargetIPv4) elt; 685 appendConsole("description[" + target.getAddress() + "]=\"" + target.getSNMPQuerier().getSysDescr() + "\"<BR/>"); 686 687 if (target.getSNMPQuerier().isSNMPCapable()) target.setImageHostSNMP(); 688 if (target.getSNMPQuerier().getLastSysdescr() != null) target.setType(target.getSNMPQuerier().getLastSysdescr()); 689 } 690 } 691 } 692 693 698 private void removeVisualElements(final TreeItem item) { 699 synchronized (sync_tree) { 700 final VisualElement visual_element = (VisualElement) item.getData(VisualElement.class.toString()); 701 if (item.getParentItem() == null) return; 702 final VisualElement visual_parent = (VisualElement) item.getParentItem().getData(VisualElement.class.toString()); 703 704 visual_element.removeVisualElements(visual_parent); 705 } 706 } 707 708 713 private void removeActionOrView(final TreeItem item, final Class clazz) { 714 synchronized (sync_tree) { 715 for (final VisualElement action : VisualElement.getSubElements(item, clazz)) 716 if (action.getParents().size() == 1) 717 action.removeVisualElements(action.getParents().get(0)); 718 } 719 } 720 721 726 private void removeActions(final TreeItem item) { 727 removeActionOrView(item, net.fenyo.gnetwatch.actions.Action.class); 728 } 729 730 735 private void removeActionsPing(final TreeItem item) { 736 removeActionOrView(item, ActionPing.class); 737 } 738 739 744 private void removeActionsFlood(final TreeItem item) { 745 removeActionOrView(item, ActionFlood.class); 746 } 747 748 753 private void removeActionsExplore(final TreeItem item) { 754 removeActionOrView(item, ActionSNMP.class); 755 } 756 757 762 private void removeViews(final TreeItem item) { 763 removeActionOrView(item, DataView.class); 764 } 765 766 771 private void removeViewsPing(final TreeItem item) { 772 removeActionOrView(item, ReachableView.class); 773 } 774 775 780 private void removeViewsFlood(final TreeItem item) { 781 removeActionOrView(item, FloodView.class); 782 } 783 784 789 private void removeViewsExplore(final TreeItem item) { 790 removeActionOrView(item, BytesReceivedView.class); 791 removeActionOrView(item, BytesSentView.class); 792 } 793 794 799 private boolean addTargetAtCurrentPosition(final Target target) { 803 synchronized (sync_tree) { 804 if (tree.getSelectionCount() == 1 && 805 ( isSelectionTransient())) { 806 final VisualElement parent = (VisualElement) tree.getSelection()[0].getData(VisualElement.class.toString()); 807 if (parent != null) return target.addTarget(this, parent); 808 } 809 } 811 return false; 812 } 813 814 819 private void exitApplication() { 821 shell.close(); 822 } 823 824 private void appendNetworkInterfaces() { 825 try { 826 String str = "<HR/><B>Local network interfaces</B>"; 827 str += "<TABLE BORDER='0' BGCOLOR='black' cellspacing='1' cellpadding='1'>"; 828 for (final Enumeration nifs = NetworkInterface.getNetworkInterfaces(); nifs.hasMoreElements(); ) { 829 final NetworkInterface nif = (NetworkInterface) nifs.nextElement(); 830 str += "<TR><TD bgcolor='lightyellow' align='right'><B>" + htmlFace("interface name") + "</B></TD><TD bgcolor='lightyellow'><B>" + htmlFace(nif.getName())+ "</B></TD></TR>"; 831 str += "<TR><TD bgcolor='lightyellow' align='right'>" + htmlFace("display name") + "</TD><TD bgcolor='lightyellow'>" + htmlFace(nif.getDisplayName())+ "</TD></TR>"; 832 for (final Enumeration addrs = nif.getInetAddresses(); addrs.hasMoreElements(); ) { 833 final InetAddress addr = (InetAddress) addrs.nextElement(); 834 if (Inet4Address.class.isInstance(addr)) 835 str += "<TR><TD bgcolor='lightyellow' align='right'>" + htmlFace("IPv4 address") + "</TD><TD bgcolor='lightyellow'>" + htmlFace(addr.getHostAddress()) + "</TD></TR>"; 836 if (Inet6Address.class.isInstance(addr)) 837 str += "<TR><TD bgcolor='lightyellow' align='right'>" + htmlFace("IPv6 address") + "</TD><TD bgcolor='lightyellow'>" + htmlFace(addr.getHostAddress()) + "</TD></TR>"; 838 } 839 } 840 str += "</TABLE>"; 841 appendConsole(str); 842 } catch (final SocketException ex) { 843 log.error("Exception", ex); 844 } 845 } 846 847 853 private void createGUI() throws UnknownHostException, SocketException, AlgorithmException { 854 final GUI gui = this; 855 856 synchronized (sync_tree) { 857 858 display = new Display(); 859 shell = new Shell(display); 860 shell.setText(getConfig().getString("version")); 861 862 layout = new GridLayout(); 864 layout.numColumns = 1; 865 layout.marginHeight = 2; 866 layout.marginWidth = 2; 867 layout.verticalSpacing = 1; 868 shell.setLayout(layout); 869 871 menu_bar = new Menu(shell, SWT.BAR); 873 shell.setMenuBar(menu_bar); 874 875 menu_file = new Menu(shell, SWT.DROP_DOWN); 877 menu_item_file = new MenuItem(menu_bar, SWT.CASCADE); 878 menu_item_file.setText(getConfig().getString("menu_file")); 879 menu_item_file.setMenu(menu_file); 880 881 menu_item_exit = new MenuItem(menu_file, SWT.PUSH); 883 menu_item_exit.setText(getConfig().getString("menu_exit")); 884 menu_item_exit.addListener(SWT.Selection, new Listener() { 885 public void handleEvent(final Event e) { 886 gui.exitApplication(); 887 } 888 }); 889 menu_item_exit.setImage(new Image(display, "pictures/exit.png")); 890 891 final Menu menu_discover = new Menu(shell, SWT.DROP_DOWN); 893 final MenuItem menu_item_discover = new MenuItem(menu_bar, SWT.CASCADE); 894 menu_item_discover.setText(getConfig().getString("menu_discover")); 895 menu_item_discover.setMenu(menu_discover); 896 897 final MenuItem menu_item_discover_start = new MenuItem(menu_discover, SWT.PUSH); 899 final MenuItem menu_item_discover_stop = new MenuItem(menu_discover, SWT.PUSH); 900 menu_item_discover_start.setText(getConfig().getString("menu_start")); 901 menu_item_discover_start.setImage(new Image(display, "pictures/exec.png")); 902 menu_item_discover_stop.setText(getConfig().getString("menu_stop")); 903 menu_item_discover_stop.setImage(new Image(display, "pictures/fileclose.png")); 904 menu_item_discover_stop.setEnabled(false); 905 menu_item_discover_start.addListener(SWT.Selection, new Listener() { 906 public void handleEvent(final Event e) { 907 menu_item_discover_start.setEnabled(false); 908 item_discover_start.setEnabled(false); 909 main.startDiscover(); 910 menu_item_discover_stop.setEnabled(true); 911 item_discover_stop.setEnabled(true); 912 } 913 }); 914 menu_item_discover_stop.addListener(SWT.Selection, new Listener() { 915 public void handleEvent(final Event e) { 916 menu_item_discover_start.setEnabled(true); 917 item_discover_start.setEnabled(true); 918 main.stopDiscover(); 919 menu_item_discover_stop.setEnabled(false); 920 item_discover_stop.setEnabled(false); 921 } 922 }); 923 924 final Menu menu_tree = new Menu(shell, SWT.DROP_DOWN); 926 final MenuItem menu_item_tree = new MenuItem(menu_bar, SWT.CASCADE); 927 menu_item_tree.setText(getConfig().getString("menu_tree")); 928 menu_item_tree.setMenu(menu_tree); 929 930 931 final MenuItem menu_item_expand = new MenuItem(menu_tree, SWT.PUSH); 933 menu_item_expand.setText(getConfig().getString("expand")); 934 menu_item_expand.addListener(SWT.Selection, new Listener() { 935 public void handleEvent(final Event e) { 936 if (tree.getSelectionCount() == 1) tree.getSelection()[0].setExpanded(true); 937 } 938 }); 939 940 final MenuItem menu_item_merge = new MenuItem(menu_tree, SWT.PUSH); 942 menu_item_merge.setText(getConfig().getString("collapse")); 943 menu_item_merge.addListener(SWT.Selection, new Listener() { 944 public void handleEvent(final Event e) { 945 if (tree.getSelectionCount() == 1) tree.getSelection()[0].setExpanded(false); 946 } 947 }); 948 949 new MenuItem(menu_tree, SWT.SEPARATOR); 950 951 final MenuItem menu_item_expand_all = new MenuItem(menu_tree, SWT.PUSH); 953 menu_item_expand_all.setText(getConfig().getString("menu_expand_all")); 954 menu_item_expand_all.setImage(new Image(display, "pictures/show_table_column.png")); 955 menu_item_expand_all.addListener(SWT.Selection, new Listener() { 956 public void handleEvent(final Event e) { 957 if (tree.getSelectionCount() == 1) expandAll(tree.getSelection()[0]); 958 } 959 }); 960 961 final MenuItem menu_item_merge_all = new MenuItem(menu_tree, SWT.PUSH); 963 menu_item_merge_all.setText(getConfig().getString("menu_collapse_all")); 964 menu_item_merge_all.setImage(new Image(display, "pictures/hide_table_column.png")); 965 menu_item_merge_all.addListener(SWT.Selection, new Listener() { 966 public void handleEvent(final Event e) { 967 if (tree.getSelectionCount() == 1) mergeAll(tree.getSelection()[0]); 968 } 969 }); 970 971 final Menu menu_target = new Menu(shell, SWT.DROP_DOWN); 973 final MenuItem menu_item_target = new MenuItem(menu_bar, SWT.CASCADE); 974 menu_item_target.setText(getConfig().getString("menu_target")); 975 menu_item_target.setMenu(menu_target); 976 977 menu_item_credentials = new MenuItem(menu_target, SWT.PUSH); 979 menu_item_credentials.setText(getConfig().getString("menu_set_credentials")); 980 menu_item_credentials.addListener(SWT.Selection, new Listener() { 981 public void handleEvent(final Event e) { 982 final SNMPQuerier querier; 983 984 synchronized (sync_tree) { 985 if (tree.getSelectionCount() == 1 && 986 ( isSelectionTransient())) { 987 final VisualElement target = (VisualElement) tree.getSelection()[0].getData(VisualElement.class.toString()); 988 989 if (target != null && (TargetIPv4.class.isInstance(target) || TargetIPv6.class.isInstance(target))) { 990 if (TargetIPv4.class.isInstance(target)) querier = ((TargetIPv4) target).getSNMPQuerier(); 991 else querier = ((TargetIPv6) target).getSNMPQuerier(); 992 } else return; 993 } else return; 994 } 995 996 final int version = querier.getVersion(); 997 final int sec = querier.getSec(); 998 final int port_src = querier.getRetries(); 999 final int timeout = querier.getTimeout(); 1000 final int port = querier.getPort(); 1001 final String community = querier.getCommunity(); 1002 final String username = querier.getUsername(); 1003 final String password_auth = querier.getPasswordAuth(); 1004 final String password_priv = querier.getPasswordPriv(); 1005 final int pdu_max_size = querier.getPDUMaxSize(); 1006 1007 final DialogCredentials dialog = new DialogCredentials(gui, shell); 1008 dialog.setVersion(version); 1009 dialog.setSec(sec); 1010 dialog.setRetries(port_src); 1011 dialog.setTimeout(timeout); 1012 dialog.setPort(port); 1013 dialog.setCommunity(community); 1014 dialog.setUsername(username); 1015 dialog.setPasswordAuth(password_auth); 1016 dialog.setPasswordPriv(password_priv); 1017 dialog.setPDUMaxSize(pdu_max_size); 1018 1019 dialog.open(); 1020 1021 synchronized (sync_tree) { 1022 if (dialog.getVersion() != version) querier.setVersion(dialog.getVersion()); 1023 if (dialog.getSec() != sec) querier.setSec(dialog.getSec()); 1024 if (dialog.getRetries() != port_src) querier.setRetries(dialog.getRetries()); 1025 if (dialog.getTimeout() != timeout) querier.setTimeout(dialog.getTimeout()); 1026 if (dialog.getPort() != port) querier.setPort(dialog.getPort()); 1027 if (dialog.getCommunity() != community) querier.setCommunity(dialog.getCommunity()); 1028 if (dialog.getUsername() != username) querier.setUsername(dialog.getUsername()); 1029 if (dialog.getPasswordAuth() != password_auth) querier.setPasswordAuth(dialog.getPasswordAuth()); 1030 if (dialog.getPasswordPriv() != password_priv) querier.setPasswordPriv(dialog.getPasswordPriv()); 1031 if (dialog.getPDUMaxSize() != pdu_max_size) querier.setPDUMaxSize(dialog.getPDUMaxSize()); 1032 querier.update(); 1033 } 1034 } 1035 }); 1036 1037 menu_item_ip_options = new MenuItem(menu_target, SWT.PUSH); 1039 menu_item_ip_options.setText(getConfig().getString("menu_set_ip_options")); 1040 menu_item_ip_options.addListener(SWT.Selection, new Listener() { 1041 public void handleEvent(final Event e) { 1042 final IPQuerier querier; 1043 1044 synchronized (sync_tree) { 1045 if (tree.getSelectionCount() == 1 && 1046 ( isSelectionTransient())) { 1047 final VisualElement target = (VisualElement) tree.getSelection()[0].getData(VisualElement.class.toString()); 1048 1049 if (target != null && (TargetIPv4.class.isInstance(target) || TargetIPv6.class.isInstance(target))) { 1050 if (TargetIPv4.class.isInstance(target)) querier = ((TargetIPv4) target).getIPQuerier(); 1051 else querier = ((TargetIPv6) target).getIPQuerier(); 1052 } else return; 1053 } else return; 1054 } 1055 1056 final int tos = querier.getTOS(); 1057 final int port_src = querier.getPortSrc(); 1058 final int port_dst = querier.getPortDst(); 1059 final int pdu_max_size = querier.getPDUMaxSize(); 1060 1061 final DialogIPOptions dialog = new DialogIPOptions(gui, shell); 1062 1063 dialog.setTOS(tos); 1064 dialog.setPortSrc(port_src); 1065 dialog.setPortDst(port_dst); 1066 dialog.setPDUMaxSize(pdu_max_size); 1067 1068 dialog.open(); 1069 1070 synchronized (sync_tree) { 1071 if (dialog.getTOS() != tos) querier.setTOS(dialog.getTOS()); 1072 if (dialog.getPortSrc() != port_src) querier.setPortSrc(dialog.getPortSrc()); 1073 if (dialog.getPortDst() != port_dst) querier.setPortDst(dialog.getPortDst()); 1074 if (dialog.getPDUMaxSize() != pdu_max_size) querier.setPDUMaxSize(dialog.getPDUMaxSize()); 1075 1076 querier.update(); 1077 } 1078 } 1079 }); 1080 1081 menu_item_http_options = new MenuItem(menu_target, SWT.PUSH); 1083 menu_item_http_options.setText(getConfig().getString("menu_set_http_options")); 1084 menu_item_http_options.addListener(SWT.Selection, new Listener() { 1085 public void handleEvent(final Event e) { 1086 final IPQuerier querier; 1087 1088 synchronized (sync_tree) { 1089 if (tree.getSelectionCount() == 1 && 1090 ( isSelectionTransient())) { 1091 final VisualElement target = (VisualElement) tree.getSelection()[0].getData(VisualElement.class.toString()); 1092 1093 if (target != null && (TargetIPv4.class.isInstance(target) || TargetIPv6.class.isInstance(target))) { 1094 if (TargetIPv4.class.isInstance(target)) querier = ((TargetIPv4) target).getIPQuerier(); 1095 else querier = ((TargetIPv6) target).getIPQuerier(); 1096 } else return; 1097 } else return; 1098 } 1099 1100 final int nparallel = querier.getNParallel(); 1101 final String proxy_host = querier.getProxyHost(); 1102 final int proxy_port = querier.getProxyPort(); 1103 final String URL = querier.getURL(); 1104 final boolean use_proxy = querier.getUseProxy(); 1106 1107 final DialogHTTPOptions dialog = new DialogHTTPOptions(gui, shell); 1108 1109 dialog.setNParallel(nparallel); 1110 dialog.setProxyHost(proxy_host); 1111 dialog.setProxyPort(proxy_port); 1112 dialog.setURL(URL); 1113 dialog.setUseProxy(use_proxy); 1115 1116 dialog.open(); 1117 1118 synchronized (sync_tree) { 1119 if (dialog.getNParallel() != nparallel) querier.setNParallel(dialog.getNParallel()); 1120 if (dialog.getProxyHost() != proxy_host) querier.setProxyHost(dialog.getProxyHost()); 1121 if (dialog.getProxyPort() != proxy_port) querier.setProxyPort(dialog.getProxyPort()); 1122 if (dialog.getURL() != URL) querier.setURL(dialog.getURL()); 1123 if (dialog.getUseProxy() != use_proxy) querier.setUseProxy(dialog.getUseProxy()); 1125 1126 querier.update(); 1127 } 1128 } 1129 }); 1130 1131 new MenuItem(menu_target, SWT.SEPARATOR); 1132 1133 menu_item_add_host = new MenuItem(menu_target, SWT.PUSH); 1135 menu_item_add_host.setText(getConfig().getString("menu_add_ipv4")); 1136 menu_item_add_host.setImage(new Image(display, "pictures/network_local.png")); 1137 menu_item_add_host.addListener(SWT.Selection, new Listener() { 1138 public void handleEvent(final Event e) { 1139 target_host_push.notifyListeners(SWT.Selection, e); 1140 } 1141 }); 1142 1143 menu_item_add_host6 = new MenuItem(menu_target, SWT.PUSH); 1145 menu_item_add_host6.setText(getConfig().getString("menu_add_ipv6")); 1146 menu_item_add_host6.addListener(SWT.Selection, new Listener() { 1147 public void handleEvent(final Event e) { 1148 target_host6_push.notifyListeners(SWT.Selection, e); 1149 } 1150 }); 1151 1152 menu_item_add_range = new MenuItem(menu_target, SWT.PUSH); 1154 menu_item_add_range.setText(getConfig().getString("menu_add_range")); 1155 menu_item_add_range.addListener(SWT.Selection, new Listener() { 1156 public void handleEvent(final Event e) { 1157 target_range_push.notifyListeners(SWT.Selection, e); 1158 } 1159 }); 1160 1161 menu_item_add_network = new MenuItem(menu_target, SWT.PUSH); 1163 menu_item_add_network.setText(getConfig().getString("menu_add_network")); 1164 menu_item_add_network.setImage(new Image(display, "pictures/network.png")); 1165 menu_item_add_network.addListener(SWT.Selection, new Listener() { 1166 public void handleEvent(final Event e) { 1167 target_subnet_push.notifyListeners(SWT.Selection, e); 1168 } 1169 }); 1170 1171 menu_item_add_group = new MenuItem(menu_target, SWT.PUSH); 1173 menu_item_add_group.setText(getConfig().getString("menu_add_group")); 1174 menu_item_add_group.addListener(SWT.Selection, new Listener() { 1175 public void handleEvent(final Event e) { 1176 target_group_push.notifyListeners(SWT.Selection, e); 1177 } 1178 }); 1179 1180 new MenuItem(menu_target, SWT.SEPARATOR); 1181 1182 final MenuItem menu_item_remove_target = new MenuItem(menu_target, SWT.PUSH); 1184 menu_item_remove_target.setText(getConfig().getString("menu_remove_element")); 1185 menu_item_remove_target.setImage(new Image(display, "pictures/nomailappt.png")); 1186 menu_item_remove_target.addListener(SWT.Selection, new Listener() { 1187 public void handleEvent(final Event e) { 1188 if (tree.getSelectionCount() == 1) removeVisualElements(tree.getSelection()[0]); 1189 } 1190 }); 1191 1192 final Menu menu_action = new Menu(shell, SWT.DROP_DOWN); 1194 final MenuItem menu_item_action = new MenuItem(menu_bar, SWT.CASCADE); 1195 menu_item_action.setText(getConfig().getString("menu_action")); 1196 menu_item_action.setMenu(menu_action); 1197 1198 1213 1214 menu_item_add_ping = new MenuItem(menu_action, SWT.PUSH); 1216 menu_item_add_ping.setText(getConfig().getString("menu_ping_target")); 1217 menu_item_add_ping.setImage(new Image(display, "pictures/yahoo_idle-af.png")); 1218 menu_item_add_ping.addSelectionListener(new SelectionListener() { 1219 public void widgetDefaultSelected(SelectionEvent e) { 1220 widgetSelected(e); 1221 } 1222 1223 public void widgetSelected(SelectionEvent e) { 1224 if (tree.getSelectionCount() == 1) addPingAll(tree.getSelection()[0]); 1225 } 1226 }); 1227 1228 menu_item_add_flood = new MenuItem(menu_action, SWT.PUSH); 1230 menu_item_add_flood.setText(getConfig().getString("menu_flood_target")); 1231 menu_item_add_flood.addSelectionListener(new SelectionListener() { 1232 public void widgetDefaultSelected(SelectionEvent e) { 1233 widgetSelected(e); 1234 } 1235 1236 public void widgetSelected(SelectionEvent e) { 1237 if (tree.getSelectionCount() == 1) addFloodAll(tree.getSelection()[0]); 1238 } 1239 }); 1240 1241 menu_item_add_http = new MenuItem(menu_action, SWT.PUSH); 1243 menu_item_add_http.setText(getConfig().getString("menu_http_target")); 1244 menu_item_add_http.addSelectionListener(new SelectionListener() { 1245 public void widgetDefaultSelected(SelectionEvent e) { 1246 widgetSelected(e); 1247 } 1248 1249 public void widgetSelected(SelectionEvent e) { 1250 if (tree.getSelectionCount() == 1) addHTTPAll(tree.getSelection()[0]); 1251 } 1252 }); 1253 1254 menu_item_explore_snmp = new MenuItem(menu_action, SWT.PUSH); 1256 menu_item_explore_snmp.setText(getConfig().getString("menu_explore_via_snmp")); 1257 menu_item_explore_snmp.addSelectionListener(new SelectionListener() { 1258 public void widgetDefaultSelected(SelectionEvent e) { 1259 widgetSelected(e); 1260 } 1261 1262 public void widgetSelected(SelectionEvent e) { 1263 if (tree.getSelectionCount() == 1) exploreSNMP(tree.getSelection()[0]); 1264 } 1265 }); 1266 1267 menu_item_explore_snmp = new MenuItem(menu_action, SWT.PUSH); 1269 menu_item_explore_snmp.setText(getConfig().getString("menu_explore_via_nmap")); 1270 menu_item_explore_snmp.addSelectionListener(new SelectionListener() { 1271 public void widgetDefaultSelected(SelectionEvent e) { 1272 widgetSelected(e); 1273 } 1274 1275 public void widgetSelected(SelectionEvent e) { 1276 if (tree.getSelectionCount() == 1) exploreNmap(tree.getSelection()[0]); 1277 } 1278 }); 1279 1280 new MenuItem(menu_action, SWT.SEPARATOR); 1281 1282 menu_item_remove_action = new MenuItem(menu_action, SWT.PUSH); 1284 menu_item_remove_action.setText(getConfig().getString("menu_drop_action")); 1285 menu_item_remove_action.setImage(new Image(display, "pictures/button_cancel-af.png")); 1286 menu_item_remove_action.addListener(SWT.Selection, new Listener() { 1287 public void handleEvent(final Event e) { 1288 if (tree.getSelectionCount() == 1) removeActions(tree.getSelection()[0]); 1289 } 1290 }); 1291 1292 menu_item_remove_action_ping = new MenuItem(menu_action, SWT.PUSH); 1294 menu_item_remove_action_ping.setText(getConfig().getString("menu_drop_action_ping")); 1295 menu_item_remove_action_ping.addListener(SWT.Selection, new Listener() { 1296 public void handleEvent(final Event e) { 1297 if (tree.getSelectionCount() == 1) removeActionsPing(tree.getSelection()[0]); 1298 } 1299 }); 1300 1301 menu_item_remove_action_flood = new MenuItem(menu_action, SWT.PUSH); 1303 menu_item_remove_action_flood.setText(getConfig().getString("menu_drop_action_flood")); 1304 menu_item_remove_action_flood.addListener(SWT.Selection, new Listener() { 1305 public void handleEvent(final Event e) { 1306 if (tree.getSelectionCount() == 1) removeActionsFlood(tree.getSelection()[0]); 1307 } 1308 }); 1309 1310 menu_item_remove_action_explore = new MenuItem(menu_action, SWT.PUSH); 1312 menu_item_remove_action_explore.setText(getConfig().getString("menu_drop_action_explore")); 1313 menu_item_remove_action_explore.addListener(SWT.Selection, new Listener() { 1314 public void handleEvent(final Event e) { 1315 if (tree.getSelectionCount() == 1) removeActionsExplore(tree.getSelection()[0]); 1316 } 1317 }); 1318 1319 new MenuItem(menu_action, SWT.SEPARATOR); 1320 1321 menu_item_remove_view = new MenuItem(menu_action, SWT.PUSH); 1323 menu_item_remove_view.setText(getConfig().getString("menu_drop_view")); 1324 menu_item_remove_view.addListener(SWT.Selection, new Listener() { 1325 public void handleEvent(final Event e) { 1326 if (tree.getSelectionCount() == 1) removeViews(tree.getSelection()[0]); 1327 } 1328 }); 1329 1330 menu_item_remove_view_ping = new MenuItem(menu_action, SWT.PUSH); 1332 menu_item_remove_view_ping.setText(getConfig().getString("menu_drop_view_ping")); 1333 menu_item_remove_view_ping.addListener(SWT.Selection, new Listener() { 1334 public void handleEvent(final Event e) { 1335 if (tree.getSelectionCount() == 1) removeViewsPing(tree.getSelection()[0]); 1336 } 1337 }); 1338 1339 menu_item_remove_view_flood = new MenuItem(menu_action, SWT.PUSH); 1341 menu_item_remove_view_flood.setText(getConfig().getString("menu_drop_view_flood")); 1342 menu_item_remove_view_flood.addListener(SWT.Selection, new Listener() { 1343 public void handleEvent(final Event e) { 1344 if (tree.getSelectionCount() == 1) removeViewsFlood(tree.getSelection()[0]); 1345 } 1346 }); 1347 1348 menu_item_remove_view_explore = new MenuItem(menu_action, SWT.PUSH); 1350 menu_item_remove_view_explore.setText(getConfig().getString("menu_drop_view_explore")); 1351 menu_item_remove_view_explore.addListener(SWT.Selection, new Listener() { 1352 public void handleEvent(final Event e) { 1353 if (tree.getSelectionCount() == 1) removeViewsExplore(tree.getSelection()[0]); 1354 } 1355 }); 1356 1357 final Menu menu_view = new Menu(shell, SWT.DROP_DOWN); 1359 final MenuItem menu_item_view = new MenuItem(menu_bar, SWT.CASCADE); 1360 menu_item_view.setText(getConfig().getString("menu_snmp_info")); 1361 menu_item_view.setMenu(menu_view); 1362 1363 final MenuItem menu_item_open_view = new MenuItem(menu_view, SWT.PUSH); 1365 menu_item_open_view.setText(getConfig().getString("menu_get_system_description")); 1366 menu_item_open_view.setImage(new Image(display, "pictures/multirow.png")); 1367 menu_item_open_view.addSelectionListener(new SelectionListener() { 1368 public void widgetDefaultSelected(SelectionEvent e) { 1369 widgetSelected(e); 1370 } 1371 1372 public void widgetSelected(SelectionEvent e) { 1373 if (tree.getSelectionCount() == 1) getSysdescr(tree.getSelection()[0]); 1374 } 1375 }); 1376 1377 1398 1399 final Menu menu_status = new Menu(shell, SWT.DROP_DOWN); 1401 final MenuItem menu_item_status = new MenuItem(menu_bar, SWT.CASCADE); 1402 menu_item_status.setText(getConfig().getString("menu_status")); 1403 menu_item_status.setMenu(menu_status); 1404 1405 final MenuItem menu_item_local_interfaces = new MenuItem(menu_status, SWT.PUSH); 1407 menu_item_local_interfaces.setText(getConfig().getString("menu_local_interfaces")); 1408 menu_item_local_interfaces.addListener(SWT.Selection, new Listener() { 1409 public void handleEvent(final Event e) { 1410 appendNetworkInterfaces(); 1411 } 1412 }); 1413 1414 final Menu menu_help = new Menu(shell, SWT.DROP_DOWN); 1416 final MenuItem menu_item_help = new MenuItem(menu_bar, SWT.CASCADE); 1417 menu_item_help.setText(getConfig().getString("menu_help")); 1418 menu_item_help.setMenu(menu_help); 1419 1420 final MenuItem menu_item_welcome = new MenuItem(menu_help, SWT.PUSH); 1422 menu_item_welcome.setText(getConfig().getString("menu_welcome")); 1423 menu_item_welcome.addListener(SWT.Selection, new Listener() { 1424 public void handleEvent(final Event e) { 1425 tab_folder.setSelection(tab_item1); 1426 } 1427 }); 1428 1429 final MenuItem menu_item_help_contents = new MenuItem(menu_help, SWT.PUSH); 1431 menu_item_help_contents.setText(getConfig().getString("menu_help_contents")); 1432 menu_item_help_contents.addListener(SWT.Selection, new Listener() { 1433 public void handleEvent(final Event e) { 1434 tab_folder.setSelection(tab_item2); 1435 } 1436 }); 1437 1438 new MenuItem(menu_help, SWT.SEPARATOR); 1439 1440 final MenuItem menu_item_about = new MenuItem(menu_help, SWT.PUSH); 1442 menu_item_about.setText(getConfig().getString("menu_about")); 1443 menu_item_about.setImage(new Image(display, "pictures/info.png")); 1444 menu_item_about.addListener(SWT.Selection, new Listener() { 1445 public void handleEvent(final Event e) { 1446 final DialogAbout dialog = new DialogAbout(gui, shell); 1447 dialog.open(); 1448 } 1449 }); 1450 1451 1463 1464 1467 toolbar = new ToolBar(shell, SWT.FLAT); 1468 final ToolItem item_exit = new ToolItem(toolbar, SWT.PUSH); 1469 item_exit.setImage(new Image(display, "pictures/exit.png")); 1470 item_exit.setToolTipText(getConfig().getString("exit")); 1471 item_exit.addListener(SWT.Selection, new Listener() { 1472 public void handleEvent(final Event e) { 1473 menu_item_exit.notifyListeners(SWT.Selection, e); 1474 } 1475 }); 1476 1477 new ToolItem(toolbar, SWT.SEPARATOR); 1478 1479 item_discover_start = new ToolItem(toolbar, SWT.PUSH); 1480 item_discover_start.setImage(new Image(display, "pictures/exec.png")); 1481 item_discover_start.setToolTipText(getConfig().getString("start_sniffer")); 1482 item_discover_start.addListener(SWT.Selection, new Listener() { 1483 public void handleEvent(final Event e) { 1484 menu_item_discover_start.notifyListeners(SWT.Selection, e); 1485 } 1486 }); 1487 1488 item_discover_stop = new ToolItem(toolbar, SWT.PUSH); 1489 item_discover_stop.setImage(new Image(display, "pictures/fileclose.png")); 1490 item_discover_stop.setToolTipText(getConfig().getString("stop_sniffer")); 1491 item_discover_stop.setEnabled(false); 1492 item_discover_stop.addListener(SWT.Selection, new Listener() { 1493 public void handleEvent(final Event e) { 1494 menu_item_discover_stop.notifyListeners(SWT.Selection, e); 1495 } 1496 }); 1497 1498 new ToolItem(toolbar, SWT.SEPARATOR); 1499 1500 final ToolItem item_expand_all = new ToolItem(toolbar, SWT.PUSH); 1501 item_expand_all.setImage(new Image(display, "pictures/show_table_column.png")); 1502 item_expand_all.setToolTipText(getConfig().getString("expand_all")); 1503 item_expand_all.addListener(SWT.Selection, new Listener() { 1504 public void handleEvent(final Event e) { 1505 menu_item_expand_all.notifyListeners(SWT.Selection, e); 1506 } 1507 }); 1508 1509 final ToolItem item_merge_all = new ToolItem(toolbar, SWT.PUSH); 1510 item_merge_all.setImage(new Image(display, "pictures/hide_table_column.png")); 1511 item_merge_all.setToolTipText(getConfig().getString("collapse_all")); 1512 item_merge_all.addListener(SWT.Selection, new Listener() { 1513 public void handleEvent(final Event e) { 1514 menu_item_merge_all.notifyListeners(SWT.Selection, e); 1515 } 1516 }); 1517 1518 new ToolItem(toolbar, SWT.SEPARATOR); 1519 1520 item_add_host = new ToolItem(toolbar, SWT.PUSH); 1521 item_add_host.setImage(new Image(display, "pictures/network_local.png")); 1522 item_add_host.setToolTipText(getConfig().getString("add_ipv4_host")); 1523 item_add_host.addListener(SWT.Selection, new Listener() { 1524 public void handleEvent(final Event e) { 1525 menu_item_add_host.notifyListeners(SWT.Selection, e); 1526 } 1527 }); 1528 1529 item_add_network = new ToolItem(toolbar, SWT.PUSH); 1530 item_add_network.setImage(new Image(display, "pictures/network.png")); 1531 item_add_network.setToolTipText(getConfig().getString("add_network")); 1532 item_add_network.addListener(SWT.Selection, new Listener() { 1533 public void handleEvent(final Event e) { 1534 menu_item_add_network.notifyListeners(SWT.Selection, e); 1535 } 1536 }); 1537 1538 final ToolItem item_remove_target = new ToolItem(toolbar, SWT.PUSH); 1539 item_remove_target.setImage(new Image(display, "pictures/nomailappt.png")); 1540 item_remove_target.setToolTipText(getConfig().getString("remove_element")); 1541 item_remove_target.addListener(SWT.Selection, new Listener() { 1542 public void handleEvent(final Event e) { 1543 menu_item_remove_target.notifyListeners(SWT.Selection, e); 1544 } 1545 }); 1546 1547 new ToolItem(toolbar, SWT.SEPARATOR); 1548 1549 final ToolItem item_add_ping = new ToolItem(toolbar, SWT.PUSH); 1550 item_add_ping.setImage(new Image(display, "pictures/yahoo_idle-af.png")); 1551 item_add_ping.setToolTipText("ping"); 1552 item_add_ping.addListener(SWT.Selection, new Listener() { 1553 public void handleEvent(final Event e) { 1554 menu_item_add_ping.notifyListeners(SWT.Selection, e); 1555 } 1556 }); 1557 1558 final ToolItem item_remove_action = new ToolItem(toolbar, SWT.PUSH); 1559 item_remove_action.setImage(new Image(display, "pictures/button_cancel-af.png")); 1560 item_remove_action.setToolTipText(getConfig().getString("drop_action")); 1561 item_remove_action.addListener(SWT.Selection, new Listener() { 1562 public void handleEvent(final Event e) { 1563 menu_item_remove_action.notifyListeners(SWT.Selection, e); 1564 } 1565 }); 1566 1567 1579 1580 1599 1600 new ToolItem(toolbar, SWT.SEPARATOR); 1601 1602 ToolItem item_about = new ToolItem(toolbar, SWT.PUSH); 1603 item_about.setImage(new Image(display, "pictures/info.png")); 1604 item_about.setToolTipText(getConfig().getString("help")); 1605 item_about.addListener(SWT.Selection, new Listener() { 1606 public void handleEvent(final Event e) { 1607 menu_item_about.notifyListeners(SWT.Selection, e); 1608 } 1609 }); 1610 1611 toolbar_grid_data = new GridData(GridData.FILL_HORIZONTAL); 1613 toolbar.setLayoutData(toolbar_grid_data); 1614 1615 vertical_sash = new SashForm(shell, SWT.VERTICAL); 1617 vertical_sash_grid_data = new GridData(GridData.FILL_BOTH); 1618 vertical_sash.setLayoutData(vertical_sash_grid_data); 1619 1621 horizontal_composite = new Composite(vertical_sash, SWT.FLAT); 1623 horizontal_composite_layout = new GridLayout(); 1625 horizontal_composite_layout.numColumns = 2; 1626 horizontal_composite_layout.marginHeight = 0; 1627 horizontal_composite_layout.marginWidth = 0; 1628 horizontal_composite.setLayout(horizontal_composite_layout); 1629 1630 text_console = new Browser(vertical_sash, SWT.BORDER | SWT.FILL); 1632 appendConsole(htmlFace("GNetWatch - © 2006, 2007<BR/>")); 1633 text_console.addProgressListener(new ProgressListener() { 1634 public void changed(ProgressEvent e) {} 1635 public void completed(ProgressEvent e) { 1636 if (text_console_do_not_go_on_top > 0) text_console_do_not_go_on_top--; 1638 else text_console.execute("window.scroll(0,1000000);"); 1639 } 1640 }); 1641 1642 vertical_sash.setWeights(new int [] { 4, 1 }); 1644 1645 groups_composite = new Composite(horizontal_composite, SWT.FLAT); 1647 groups_composite_layout = new RowLayout(SWT.VERTICAL); 1648 groups_composite_layout.fill = true; 1649 groups_composite_layout.marginTop = 0; 1650 groups_composite_layout.marginBottom = 0; 1651 groups_composite.setLayout(groups_composite_layout); 1652 groups_composite_grid_data = new GridData(GridData.FILL_VERTICAL); 1653 groups_composite.setLayoutData(groups_composite_grid_data); 1654 1655 1657 group_target_subnet = new Group(groups_composite, SWT.SHADOW_ETCHED_IN); 1658 group_target_subnet_layout = new GridLayout(); 1659 group_target_subnet_layout.numColumns = 2; 1660 group_target_subnet.setLayout(group_target_subnet_layout); 1661 group_target_subnet.setText(getConfig().getString("create_network_target")); 1662 1663 label1 = new Label(group_target_subnet, SWT.SHADOW_IN); 1664 label1.setText(getConfig().getString("address")); 1665 label1.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 1666 target_subnet_address = new Text(group_target_subnet, SWT.READ_ONLY | SWT.SINGLE); 1667 target_subnet_address.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END | GridData.FILL_VERTICAL)); 1668 target_subnet_address.setBackground(new Color(display, bglevel, bglevel, bglevel)); 1669 target_subnet_address.setForeground(display.getSystemColor(SWT.COLOR_WHITE)); 1670 new IpAddressEditor(getConfig(), target_subnet_address); 1671 1672 label2 = new Label(group_target_subnet, SWT.SHADOW_IN); 1673 label2.setText(getConfig().getString("netmask")); 1674 label2.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 1675 target_subnet_mask = new Text(group_target_subnet, SWT.READ_ONLY | SWT.SINGLE); 1676 target_subnet_mask.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END | GridData.FILL_VERTICAL)); 1677 target_subnet_mask.setBackground(new Color(display, bglevel, bglevel, bglevel)); 1678 target_subnet_mask.setBackground(new Color(display, bglevel, bglevel, bglevel)); 1679 target_subnet_mask.setForeground(display.getSystemColor(SWT.COLOR_WHITE)); 1680 new IpAddressEditor(getConfig(), target_subnet_mask); 1681 1682 new Label(group_target_subnet, SWT.SHADOW_NONE); 1683 1684 target_subnet_push = new Button(group_target_subnet, SWT.PUSH); 1685 target_subnet_push.setText(getConfig().getString("add_subnet")); 1686 target_subnet_push.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL)); 1687 target_subnet_push.addSelectionListener(new SelectionListener() { 1688 public void widgetDefaultSelected(SelectionEvent e) { 1689 try { 1690 synchronized (sync_tree) { 1691 addTargetAtCurrentPosition(new TargetIPv4Subnet("added by GUI", 1692 GenericTools.stringToInet4Address(target_subnet_address.getText()), 1693 GenericTools.stringToInet4Address(target_subnet_mask.getText()))); 1694 target_subnet_address.setText("000.000.000.000"); 1695 target_subnet_mask.setText("000.000.000.000"); 1696 } 1697 } catch (final UnknownHostException ex) { 1698 log.error("Exception", ex); 1699 } catch (final AlgorithmException ex) { 1700 log.error("Exception", ex); 1701 System.exit(1); 1702 } 1703 } 1704 public void widgetSelected(SelectionEvent e) { 1705 widgetDefaultSelected(e); 1706 } 1707 }); 1708 1709 1711 group_target_range = new Group(groups_composite, SWT.SHADOW_ETCHED_IN); 1712 group_target_range_layout = new GridLayout(); 1713 group_target_range_layout.numColumns = 2; 1714 group_target_range.setLayout(group_target_range_layout); 1715 group_target_range.setText(getConfig().getString("create_range_target")); 1716 1717 label3 = new Label(group_target_range, SWT.SHADOW_IN); 1718 label3.setText(getConfig().getString("first_address")); 1719 label3.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 1720 target_range_begin = new Text(group_target_range, SWT.READ_ONLY | SWT.SINGLE); 1721 target_range_begin.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END | GridData.FILL_VERTICAL)); 1722 target_range_begin.setBackground(new Color(display, bglevel, bglevel, bglevel)); 1723 target_range_begin.setForeground(display.getSystemColor(SWT.COLOR_WHITE)); 1724 new IpAddressEditor(getConfig(), target_range_begin); 1725 1726 label4 = new Label(group_target_range, SWT.SHADOW_IN); 1727 label4.setText(getConfig().getString("last_address")); 1728 label4.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 1729 target_range_end = new Text(group_target_range, SWT.READ_ONLY | SWT.SINGLE); 1730 target_range_end.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END | GridData.FILL_VERTICAL)); 1731 target_range_end.setBackground(new Color(display, bglevel, bglevel, bglevel)); 1732 target_range_end.setForeground(display.getSystemColor(SWT.COLOR_WHITE)); 1733 new IpAddressEditor(getConfig(), target_range_end); 1734 1735 new Label(group_target_range, SWT.SHADOW_NONE); 1736 1737 target_range_push = new Button(group_target_range, SWT.PUSH); 1738 target_range_push.setText(getConfig().getString("add_range")); 1739 target_range_push.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL)); 1740 target_range_push.addSelectionListener(new SelectionListener() { 1741 public void widgetDefaultSelected(SelectionEvent e) { 1742 try { 1743 synchronized (sync_tree) { 1744 addTargetAtCurrentPosition(new TargetIPv4Range("added by GUI", 1745 GenericTools.stringToInet4Address(target_range_begin.getText()), 1746 GenericTools.stringToInet4Address(target_range_end.getText()))); 1747 target_range_begin.setText("000.000.000.000"); 1748 target_range_end.setText("000.000.000.000"); 1749 } 1750 } catch (final UnknownHostException ex) { 1751 log.error("Exception", ex); 1752 } catch (final AlgorithmException ex) { 1753 log.error("Exception", ex); 1754 System.exit(1); 1755 } 1756 } 1757 public void widgetSelected(SelectionEvent e) { 1758 widgetDefaultSelected(e); 1759 } 1760 }); 1761 1762 1764 group_target_host = new Group(groups_composite, SWT.SHADOW_ETCHED_IN); 1765 group_target_host_layout = new GridLayout(); 1766 group_target_host_layout.numColumns = 2; 1767 group_target_host.setLayout(group_target_host_layout); 1768 group_target_host.setText(getConfig().getString("create_ipv4_target")); 1769 1770 label5 = new Label(group_target_host, SWT.SHADOW_IN); 1771 label5.setText(getConfig().getString("host_address")); 1772 label5.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 1773 target_host_value = new Text(group_target_host, SWT.READ_ONLY | SWT.SINGLE); 1774 target_host_value.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END | GridData.FILL_VERTICAL)); 1775 target_host_value.setBackground(new Color(display, bglevel, bglevel, bglevel)); 1776 target_host_value.setForeground(display.getSystemColor(SWT.COLOR_WHITE)); 1777 new IpAddressEditor(getConfig(), target_host_value); 1778 1779 new Label(group_target_host, SWT.SHADOW_NONE); 1780 1781 target_host_push = new Button(group_target_host, SWT.PUSH); 1782 target_host_push.setText(getConfig().getString("add_ipv4_host")); 1783 target_host_push.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL)); 1784 target_host_push.addSelectionListener(new SelectionListener() { 1785 public void widgetDefaultSelected(SelectionEvent e) { 1786 try { 1787 synchronized (sync_tree) { 1788 final TargetIPv4 foo = new TargetIPv4("added by GUI", 1789 GenericTools.stringToInet4Address(target_host_value.getText()), snmp_manager); 1790 if (addTargetAtCurrentPosition(foo) == true) foo.checkSNMPAwareness(); 1791 target_host_value.setText("000.000.000.000"); 1792 } 1793 } catch (final UnknownHostException ex) { 1794 log.error("Exception", ex); 1795 } catch (final AlgorithmException ex) { 1796 log.error("Exception", ex); 1797 System.exit(1); 1798 } 1799 } 1800 public void widgetSelected(SelectionEvent e) { 1801 widgetDefaultSelected(e); 1802 } 1803 }); 1804 1805 target_host_push.addControlListener(new ControlListener() { 1806 public void controlMoved(final ControlEvent e) {} 1807 1808 public void controlResized(final ControlEvent e) { 1809 final GC gc = new GC(target_host_value); 1810 gc.setFont(target_host_value.getFont()); 1811 ((GridData) (target_group_value.getLayoutData())).widthHint = gc.stringExtent(target_host_value.getText()).x; 1812 ((GridData) (target_host6_value.getLayoutData())).widthHint = gc.stringExtent(target_host_value.getText()).x; 1813 shell.changed(new Control [] { target_group_value, target_host6_value }); 1814 } 1815 }); 1816 1817 1819 group_target_host6 = new Group(groups_composite, SWT.SHADOW_ETCHED_IN); 1820 group_target_host6_layout = new GridLayout(); 1821 group_target_host6_layout.numColumns = 2; 1822 group_target_host6.setLayout(group_target_host6_layout); 1823 group_target_host6.setText(getConfig().getString("create_ipv6_target")); 1824 1825 label7 = new Label(group_target_host6, SWT.SHADOW_IN); 1826 label7.setText(getConfig().getString("ipv6_address")); 1827 label7.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 1828 target_host6_value = new Text(group_target_host6, SWT.SINGLE); 1829 target_host6_value.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END | GridData.FILL_VERTICAL)); 1830 target_host6_value.setBackground(new Color(display, bglevel, bglevel, bglevel)); 1831 target_host6_value.setForeground(display.getSystemColor(SWT.COLOR_WHITE)); 1832 1833 new Label(group_target_host6, SWT.SHADOW_NONE); 1834 1835 target_host6_push = new Button(group_target_host6, SWT.PUSH); 1836 target_host6_push.setText(getConfig().getString("add_ipv6_host")); 1837 target_host6_push.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL)); 1838 target_host6_push.addSelectionListener(new SelectionListener() { 1839 public void widgetDefaultSelected(SelectionEvent e) { 1840 try { 1841 final Inet6Address address = GenericTools.stringToInet6Address(target_host6_value.getText()); 1842 if (address == null) { 1843 final MessageBox dialog = new MessageBox(shell, SWT.ICON_ERROR | SWT.OK); 1844 dialog.setText(getConfig().getString("gnetwatch_error")); 1845 dialog.setMessage(getConfig().getString("cannot_parse_ipv6")); 1846 dialog.open(); 1847 return; 1848 } 1849 synchronized (sync_tree) { 1850 final TargetIPv6 foo = new TargetIPv6("added by GUI", address, snmp_manager); 1851 if (addTargetAtCurrentPosition(foo) == true) foo.checkSNMPAwareness(); 1852 target_host6_value.setText(""); 1853 } 1854 } catch (final UnknownHostException ex) { 1855 log.error("Exception", ex); 1856 final MessageBox dialog = new MessageBox(shell, SWT.ICON_ERROR | SWT.OK); 1857 dialog.setText("GNetWatch - Error"); 1858 dialog.setMessage(getConfig().getString("cannot_parse_ipv6")); 1859 dialog.open(); 1860 } catch (final AlgorithmException ex) { 1861 log.error("Exception", ex); 1862 System.exit(1); 1863 } 1864 } 1865 public void widgetSelected(final SelectionEvent e) { 1866 widgetDefaultSelected(e); 1867 } 1868 }); 1869 1870 1872 group_target_group = new Group(groups_composite, SWT.SHADOW_ETCHED_IN); 1873 group_target_group_layout = new GridLayout(); 1874 group_target_group_layout.numColumns = 2; 1875 group_target_group.setLayout(group_target_group_layout); 1876 group_target_group.setText(getConfig().getString("create_group_target")); 1877 1878 label6 = new Label(group_target_group, SWT.SHADOW_IN); 1879 label6.setText(getConfig().getString("group_name")); 1880 label6.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 1881 target_group_value = new Text(group_target_group, SWT.SINGLE); 1882 target_group_value.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END | GridData.FILL_VERTICAL)); 1883 target_group_value.setBackground(new Color(display, bglevel, bglevel, bglevel)); 1884 target_group_value.setForeground(display.getSystemColor(SWT.COLOR_WHITE)); 1885 1886 new Label(group_target_group, SWT.SHADOW_NONE); 1887 1888 target_group_push = new Button(group_target_group, SWT.PUSH); 1889 target_group_push.setText(getConfig().getString("add_group")); 1890 target_group_push.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL)); 1891 target_group_push.addSelectionListener(new SelectionListener() { 1892 public void widgetDefaultSelected(SelectionEvent e) { 1893 try { 1894 if (target_group_value.getText() != "") 1895 synchronized (sync_tree) { 1896 addTargetAtCurrentPosition(new TargetGroup("added by GUI", target_group_value.getText())); 1897 } else { 1898 final MessageBox dialog = new MessageBox(shell, SWT.ICON_ERROR | SWT.OK); 1899 dialog.setText(getConfig().getString("gnetwatch_error")); 1900 dialog.setMessage(getConfig().getString("cannot_add_group")); 1901 dialog.open(); 1902 } target_group_value.setText(""); 1903 } catch (final AlgorithmException ex) { 1904 log.error("Exception", ex); 1905 System.exit(1); 1906 } 1907 } 1908 public void widgetSelected(final SelectionEvent e) { 1909 widgetDefaultSelected(e); 1910 } 1911 }); 1912 1913 new Label(groups_composite, SWT.SHADOW_ETCHED_IN); 1915 1916 1918 1925 1926 horizontal_sash = new SashForm(horizontal_composite, SWT.HORIZONTAL); 1928 horizontal_sash_grid_data = new GridData(GridData.FILL_BOTH); 1929 horizontal_sash.setLayoutData(horizontal_sash_grid_data); 1930 1931 tree = new Tree(horizontal_sash, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL); 1933 tree.addSelectionListener(new SelectionListener() { 1934 public void widgetDefaultSelected(SelectionEvent e) { 1935 if (tree.getSelectionCount() == 1) { 1936 TreeItem current_item = tree.getSelection()[0]; 1937 if (current_item != null) { 1938 synchronized (sync_tree) { 1939 final VisualElement visual_element = (VisualElement) current_item.getData(VisualElement.class.toString()); 1940 if (visual_element != null) visual_element.informSelected(); 1941 } 1942 widgetSelected(e); 1943 } 1944 } 1945 } 1946 1947 public void widgetSelected(SelectionEvent e) { 1948 if (tree.getSelectionCount() == 1) { 1949 TreeItem current_item = tree.getSelection()[0]; 1950 if (current_item != null) { 1951 synchronized (sync_tree) { 1952 final VisualElement visual_element = (VisualElement) current_item.getData(VisualElement.class.toString()); 1953 1954 if (visual_element.getProgress() != -1) setProgress(visual_element.getProgress()); 1955 1956 if (previous_selection != null) previous_selection.unselected(); 1957 visual_element.selected(); 1958 previous_selection = visual_element; 1959 1960 if (TargetIPv4.class.isInstance(visual_element) || TargetIPv6.class.isInstance(visual_element)) { 1961 menu_item_credentials.setEnabled(true); 1962 menu_item_ip_options.setEnabled(true); 1963 menu_item_http_options.setEnabled(true); 1964 } else { 1965 menu_item_credentials.setEnabled(false); 1966 menu_item_ip_options.setEnabled(false); 1967 menu_item_http_options.setEnabled(false); 1968 } 1969 1970 if (ActionFlood.class.isInstance(visual_element)) { 1971 menu_item_add_ping.setEnabled(false); 1972 menu_item_add_flood.setEnabled(false); 1973 menu_item_explore_snmp.setEnabled(false); 1974 menu_item_remove_action.setEnabled(true); 1975 menu_item_remove_action_ping.setEnabled(false); 1976 menu_item_remove_action_flood.setEnabled(true); 1977 menu_item_remove_action_explore.setEnabled(false); 1978 menu_item_remove_view.setEnabled(false); 1979 menu_item_remove_view_ping.setEnabled(false); 1980 menu_item_remove_view_flood.setEnabled(false); 1981 menu_item_remove_view_explore.setEnabled(false); 1982 } else if (ActionPing.class.isInstance(visual_element)) { 1983 menu_item_add_ping.setEnabled(false); 1984 menu_item_add_flood.setEnabled(false); 1985 menu_item_explore_snmp.setEnabled(false); 1986 menu_item_remove_action.setEnabled(true); 1987 menu_item_remove_action_ping.setEnabled(true); 1988 menu_item_remove_action_flood.setEnabled(false); 1989 menu_item_remove_action_explore.setEnabled(false); 1990 menu_item_remove_view.setEnabled(false); 1991 menu_item_remove_view_ping.setEnabled(false); 1992 menu_item_remove_view_flood.setEnabled(false); 1993 menu_item_remove_view_explore.setEnabled(false); 1994 } else if (ActionSNMP.class.isInstance(visual_element)) { 1995 menu_item_add_ping.setEnabled(false); 1996 menu_item_add_flood.setEnabled(false); 1997 menu_item_explore_snmp.setEnabled(false); 1998 menu_item_remove_action.setEnabled(true); 1999 menu_item_remove_action_ping.setEnabled(false); 2000 menu_item_remove_action_flood.setEnabled(false); 2001 menu_item_remove_action_explore.setEnabled(true); 2002 menu_item_remove_view.setEnabled(false); 2003 menu_item_remove_view_ping.setEnabled(false); 2004 menu_item_remove_view_flood.setEnabled(false); 2005 menu_item_remove_view_explore.setEnabled(false); 2006 } else if (ReachableView.class.isInstance(visual_element)) { 2007 menu_item_add_ping.setEnabled(false); 2008 menu_item_add_flood.setEnabled(false); 2009 menu_item_explore_snmp.setEnabled(false); 2010 menu_item_remove_action.setEnabled(false); 2011 menu_item_remove_action_ping.setEnabled(false); 2012 menu_item_remove_action_flood.setEnabled(false); 2013 menu_item_remove_action_explore.setEnabled(false); 2014 menu_item_remove_view.setEnabled(true); 2015 menu_item_remove_view_ping.setEnabled(true); 2016 menu_item_remove_view_flood.setEnabled(false); 2017 menu_item_remove_view_explore.setEnabled(false); 2018 } else if (FloodView.class.isInstance(visual_element)) { 2019 menu_item_add_ping.setEnabled(false); 2020 menu_item_add_flood.setEnabled(false); 2021 menu_item_explore_snmp.setEnabled(false); 2022 menu_item_remove_action.setEnabled(false); 2023 menu_item_remove_action_ping.setEnabled(false); 2024 menu_item_remove_action_flood.setEnabled(false); 2025 menu_item_remove_action_explore.setEnabled(false); 2026 menu_item_remove_view.setEnabled(true); 2027 menu_item_remove_view_ping.setEnabled(false); 2028 menu_item_remove_view_flood.setEnabled(true); 2029 menu_item_remove_view_explore.setEnabled(false); 2030 } else if (BytesReceivedView.class.isInstance(visual_element) || BytesSentView.class.isInstance(visual_element)) { 2031 menu_item_add_ping.setEnabled(false); 2032 menu_item_add_flood.setEnabled(false); 2033 menu_item_explore_snmp.setEnabled(false); 2034 menu_item_remove_action.setEnabled(false); 2035 menu_item_remove_action_ping.setEnabled(false); 2036 menu_item_remove_action_flood.setEnabled(false); 2037 menu_item_remove_action_explore.setEnabled(false); 2038 menu_item_remove_view.setEnabled(true); 2039 menu_item_remove_view_ping.setEnabled(false); 2040 menu_item_remove_view_flood.setEnabled(false); 2041 menu_item_remove_view_explore.setEnabled(true); 2042 } else { 2043 menu_item_add_ping.setEnabled(true); 2044 menu_item_add_flood.setEnabled(true); 2045 menu_item_explore_snmp.setEnabled(true); 2046 menu_item_remove_action.setEnabled(true); 2047 menu_item_remove_action_ping.setEnabled(true); 2048 menu_item_remove_action_flood.setEnabled(true); 2049 menu_item_remove_action_explore.setEnabled(true); 2050 menu_item_remove_view.setEnabled(true); 2051 menu_item_remove_view_ping.setEnabled(true); 2052 menu_item_remove_view_flood.setEnabled(true); 2053 menu_item_remove_view_explore.setEnabled(true); 2054 } 2055 2056 if (net.fenyo.gnetwatch.actions.Action.class.isInstance(visual_element)) { 2057 setEnableGroupTargetSubnet(false); 2058 setEnableGroupTargetRange(false); 2059 setEnableGroupTargetHost(false); 2060 setEnableGroupTargetGroup(false); 2061 } else if (Target.class.isInstance(visual_element)) { 2062 try { 2063 boolean foo; 2064 2065 final TargetGroup target_group = new TargetGroup("", ""); 2066 target_group.initialize(gui); 2067 foo = target_group.canAddTarget(visual_element) && visual_element.canManageThisChild(target_group); 2068 setEnableGroupTargetGroup(foo); 2069 2070 final Inet4Address bar = (Inet4Address) Inet4Address.getByAddress("bar", new byte [] { 0, 0, 0, 0 }); 2072 2073 final TargetIPv4 target_ipv4 = new TargetIPv4("", bar, null); 2074 target_ipv4.initialize(gui); 2075 foo = target_ipv4.canAddTarget(visual_element) && visual_element.canManageThisChild(target_ipv4); 2076 setEnableGroupTargetHost(foo); 2077 2078 final TargetIPv4Range target_ipv4_range = new TargetIPv4Range("", bar, bar); 2079 target_ipv4_range.initialize(gui); 2080 foo = target_ipv4_range.canAddTarget(visual_element) && visual_element.canManageThisChild(target_ipv4_range); 2081 setEnableGroupTargetRange(foo); 2082 2083 final TargetIPv4Subnet target_ipv4_subnet = new TargetIPv4Subnet("", bar, bar); 2084 target_ipv4_subnet.initialize(gui); 2085 foo = target_ipv4_subnet.canAddTarget(visual_element) && visual_element.canManageThisChild(target_ipv4_subnet); 2086 setEnableGroupTargetSubnet(foo); 2087 } catch (final AlgorithmException ex) { 2088 log.error("Exception", ex); 2089 } catch (final UnknownHostException ex) { 2090 log.error("Exception", ex); 2091 } 2092 } else if (net.fenyo.gnetwatch.activities.Queue.class.isInstance(visual_element)) { 2093 setEnableGroupTargetSubnet(false); 2094 setEnableGroupTargetRange(false); 2095 setEnableGroupTargetHost(false); 2096 setEnableGroupTargetGroup(false); 2097 } else if (DataView.class.isInstance(visual_element)) { 2098 setEnableGroupTargetSubnet(false); 2099 setEnableGroupTargetRange(false); 2100 setEnableGroupTargetHost(false); 2101 setEnableGroupTargetGroup(false); 2102 } else if (visual_element.equals(visual_transient)) { 2103 setEnableGroupTargetSubnet(false); 2104 setEnableGroupTargetRange(false); 2105 setEnableGroupTargetHost(false); 2106 setEnableGroupTargetGroup(true); 2107 } else { 2108 setEnableGroupTargetSubnet(false); 2109 setEnableGroupTargetRange(false); 2110 setEnableGroupTargetHost(false); 2111 setEnableGroupTargetGroup(false); 2112 } 2113 } 2114 } 2115 } 2116 2117 } 2118 }); 2119 tree.setHeaderVisible(true); 2120 tree_column1 = new TreeColumn(tree, SWT.LEFT); 2121 tree_column1.setText(getConfig().getString("items")); 2122 tree_column1.setWidth(150); 2123 tree_column2 = new TreeColumn(tree, SWT.LEFT); 2124 tree_column2.setText("Type"); 2125 tree_column2.setWidth(50); 2126 tree_column3 = new TreeColumn(tree, SWT.RIGHT); 2127 tree_column3.setText("Description"); 2128 tree_column3.setWidth(50); 2129 2130 image_folder = new Image(display, "pictures/folder_violet.png"); 2132 image_oscillo = new Image(display, "pictures/oscilloscope-af.png"); 2133 image_multirow = new Image(display, "pictures/multirow.png"); 2134 image_exec = new Image(display, "pictures/exec.png"); 2135 image_watch = new Image(display, "pictures/yahoo_idle-af.png"); 2136 image_host = new Image(display, "pictures/network_local.png"); 2137 image_host6 = new Image(display, "pictures/network_local-6-af.png"); 2138 image_interface = new Image(display, "pictures/memory.png"); 2139 image_queue = new Image(display, "pictures/jabber_group.png"); 2140 image_network = new Image(display, "pictures/network.png"); 2141 image_host_snmp = new Image(display, "pictures/network_local_snmp.png"); 2142 image_host6_snmp = new Image(display, "pictures/network_local-6-af-snmp.png"); 2143 2144 visual_root = new VisualElement(); 2145 visual_root.setParent(this, tree); 2146 visual_root.setItem(config.getString("collected_data")); 2147 2148 visual_queues = new VisualElement(); 2149 visual_queues.setParent(this, tree); 2150 visual_queues.setItem(config.getString("queues")); 2151 2152 visual_transient = new VisualElement(); 2153 visual_transient.setParent(this, visual_root); 2154 visual_transient.setItem(config.getString("targets")); 2155 2156 visual_thishost = new TargetGroup("added by GUI", config.getString("local_host")); 2157 visual_thishost.setParent(this, visual_transient); 2158 2159 visual_transient_all = new TargetGroup("added by GUI", config.getString("every_host")); 2160 visual_transient_all.setParent(this, visual_transient); 2161 2162 visual_transient_networks = new TargetGroup("added by GUI", config.getString("every_network")); 2163 visual_transient_networks.setParent(this, visual_transient); 2164 2165 user_defined = new TargetGroup("added by GUI", config.getString("user_defined")); 2166 user_defined.setParent(this, visual_transient); 2167 user_defined.setImage(getImageFolder()); 2168 2169 2180 2181 for (final Enumeration nifs = NetworkInterface.getNetworkInterfaces(); nifs.hasMoreElements(); ) { 2182 final NetworkInterface nif = (NetworkInterface) nifs.nextElement(); 2183 for (final Enumeration addrs = nif.getInetAddresses(); addrs.hasMoreElements(); ) { 2184 final InetAddress addr = (InetAddress) addrs.nextElement(); 2185 if (Inet4Address.class.isInstance(addr)) { 2186 final TargetIPv4 foo = new TargetIPv4("transient localhost", (Inet4Address) addr, snmp_manager); 2187 if (foo.addTarget(this, visual_thishost) == true) foo.checkSNMPAwareness(); 2188 } 2189 2190 if (Inet6Address.class.isInstance(addr)) { 2191 final TargetIPv6 target = new TargetIPv6("transient localhost", (Inet6Address) addr, snmp_manager); 2193 target.setParent(this, visual_thishost); 2194 } 2195 } 2196 } 2197 2198 tab_folder = new CTabFolder(horizontal_sash, SWT.BORDER); 2200 tab_folder.setSimple(false); 2201 2202 tab_item1 = new CTabItem(tab_folder, SWT.None); 2203 tab_item1.setText(getConfig().getString("about_the_author")); 2204 final Browser browser = new Browser(tab_folder, SWT.BORDER | SWT.MULTI); 2205 browser.setUrl("http://www.fenyo.net"); 2206 tab_item1.setControl(browser); 2208 2209 tab_item2 = new CTabItem(tab_folder, SWT.None); 2210 tab_item2.setText("Documentation"); 2211 final Browser browser2 = new Browser(tab_folder, SWT.BORDER | SWT.MULTI); 2212 browser2.setUrl("http://gnetwatch.sourceforge.net/docs"); 2213 tab_item2.setControl(browser2); 2214 2215 status = new StyledText(shell, SWT.BORDER); 2217 status_grid_data = new GridData(GridData.FILL_HORIZONTAL); 2218 status.setLayoutData(status_grid_data); 2219 status.setEditable(false); 2220 status.setEnabled(false); 2221 status.setText("Loading..."); 2222 status.setBackground(shell.getBackground()); 2223 2224 progress_bar = new ProgressBar(shell, SWT.SMOOTH); 2226 progress_bar.setBounds(10, 10, 200, 32); 2227 progress_bar.setSelection(0); 2228 progress_bar_grid_data = new GridData(GridData.FILL_HORIZONTAL); 2229 progress_bar.setLayoutData(progress_bar_grid_data); 2230 2231 2233 final String [] queue_names = background.getQueues().keySet().toArray(new String [] {}); 2234 Arrays.sort(queue_names); 2235 for (final String queue_name : queue_names) 2236 background.getQueues().get(queue_name).setParent(this, visual_queues); 2237 2238 menu_item_credentials.setEnabled(false); 2240 menu_item_ip_options.setEnabled(false); 2241 menu_item_http_options.setEnabled(false); 2242 setEnableGroupTargetSubnet(false); 2243 setEnableGroupTargetRange(false); 2244 setEnableGroupTargetHost(false); 2245 setEnableGroupTargetGroup(false); 2246 2247 } tree.setBackground(getBackgroundColor()); 2249 2250 tab_folder.setSelection(tab_item2); 2252 2253 shell.pack(); 2255 shell.open(); 2256 2257 visual_root.expandTreeItems(true); 2258 visual_queues.expandTreeItems(true); 2259 visual_transient.expandTreeItems(true); 2260 tree.setSelection(visual_root.getTreeItems().get(0)); 2261 tree.setFocus(); 2262 2263 synchronized (GUI_created) { 2264 GUI_created[0] = true; 2265 GUI_created.notifyAll(); 2266 } 2267 2268 text_console_do_not_go_on_top = 1; 2270 appendNetworkInterfaces(); 2271 2272 awtGUI = new AwtGUI(config); 2273 awtGUI.createAwtGUI(); 2274} 2275 2276 public void informTargetHasNewEventClass(final Target target) { 2278 asyncExecIfNeeded(new Runnable () { 2279 public void run() { 2280 views.refreshDataViews(target); 2281 } 2282 }); 2283 } 2284 2285 2292 public void waitForCreation() { 2293 synchronized (GUI_created) { 2294 while (GUI_created[0] == false) { 2295 try { 2296 GUI_created.wait(); 2297 } 2298 catch (final InterruptedException e) { 2299 log.debug("waitForCreation(): " + e); 2300 } 2301 } 2302 } 2303 } 2304 2305 2310 public void run() { 2311 try { 2312 createGUI(); 2313 } catch (final Exception ex) { 2314 log.error("Exception", ex); 2315 } 2316 2317 while (!shell.isDisposed()) { 2318 if (!display.readAndDispatch()) 2319 display.sleep(); 2320 } 2321 2322 try { 2323 display.dispose(); 2324 } catch (final SWTException ex) { 2325 log.warn("Exception", ex); 2326 } 2327 } 2328 2329 2336 public GUI(final Config config, final Background background, final Main main, final SNMPManager snmp_manager) { 2337 this.config = config; 2338 this.background = background; 2339 this.main = main; 2340 this.snmp_manager = snmp_manager; 2341 this.views = new Views(this); 2342 thread = new Thread (this, "GUI"); 2343 2344 2346 thread.start(); 2347 } 2348 2349 public void end() throws InterruptedException { 2351 awtGUI.end(); 2352 } 2353 2354 2360 public void join() { 2361 try { 2362 thread.join(); 2363 } 2364 catch (final InterruptedException e) { 2365 log.debug("GUI thread already terminated."); 2366 } 2367 } 2368 2369 2374 private void setEnableGroupTargetSubnet(final boolean enable) { 2375 label1.setEnabled(enable); 2376 label2.setEnabled(enable); 2377 group_target_subnet.setEnabled(enable); 2378 target_subnet_address.setEnabled(enable); 2379 target_subnet_mask.setEnabled(enable); 2380 target_subnet_push.setEnabled(enable); 2381 menu_item_add_network.setEnabled(enable); 2382 item_add_network.setEnabled(enable); 2383 } 2384 2385 2390 private void setEnableGroupTargetRange(final boolean enable) { 2391 label3.setEnabled(enable); 2392 label4.setEnabled(enable); 2393 group_target_range.setEnabled(enable); 2394 target_range_begin.setEnabled(enable); 2395 target_range_end.setEnabled(enable); 2396 target_range_push.setEnabled(enable); 2397 menu_item_add_range.setEnabled(enable); 2398 } 2399 2400 2405 private void setEnableGroupTargetHost(final boolean enable) { 2406 label5.setEnabled(enable); 2407 label7.setEnabled(enable); 2408 group_target_host.setEnabled(enable); 2409 group_target_host6.setEnabled(enable); 2410 target_host_value.setEnabled(enable); 2411 target_host6_value.setEnabled(enable); 2412 target_host_push.setEnabled(enable); 2413 target_host6_push.setEnabled(enable); 2414 menu_item_add_host.setEnabled(enable); 2415 menu_item_add_host6.setEnabled(enable); 2416 item_add_host.setEnabled(enable); 2417 } 2418 2419 2424 private void setEnableGroupTargetGroup(final boolean enable) { 2425 label6.setEnabled(enable); 2426 group_target_group.setEnabled(enable); 2427 target_group_value.setEnabled(enable); 2428 target_group_push.setEnabled(enable); 2429 menu_item_add_group.setEnabled(enable); 2430 } 2431 2432 2437 public void createFromXML(final String filename) { 2438 final GUI gui = this; 2439 2440 asyncExecIfNeeded(new Runnable () { 2441 public void run() { 2442 try { 2443 final XMLConfiguration initial = new XMLConfiguration(filename); 2444 initial.setExpressionEngine(new XPathExpressionEngine()); 2445 2446 2448 for (final HierarchicalConfiguration subconf : (java.util.List <HierarchicalConfiguration>) 2449 initial.configurationsAt("/objects/target")) { 2450 if (subconf.getProperty("@targetType").equals("group")) { 2451 final String name = subconf.getString("name"); 2452 2453 final java.util.List <String > parents = (java.util.List <String >) subconf.getList("parent[@parentType='group']"); 2454 if (parents.size() == 0) 2455 new TargetGroup("added by initial configuration", name).addTarget(gui, user_defined); 2456 else for (final String parent : parents) { 2457 final TargetGroup foo = new TargetGroup("temporary", parent); 2458 final TargetGroup target_parent = (TargetGroup) getCanonicalInstance(foo); 2459 if (target_parent == foo) log.error("Initial configuration: parent does not exist"); 2460 else new TargetGroup("added by initial configuration", name).addTarget(gui, target_parent); 2461 } 2462 } 2463 2464 if (subconf.getProperty("@targetType").equals("ipv4")) { 2465 final String address = subconf.getString("address"); 2466 2467 java.util.List <String > parents = (java.util.List <String >) subconf.getList("parent[@parentType='group']"); 2468 if (parents.size() != 0) for (final String parent : parents) { 2469 final TargetGroup foo = new TargetGroup("temporary", parent); 2470 final TargetGroup target_parent = (TargetGroup) getCanonicalInstance(foo); 2471 if (target_parent == foo) log.error("Initial configuration: parent does not exist"); 2472 else { 2473 final TargetIPv4 target = new TargetIPv4("added by initial configuration", GenericTools.stringToInet4Address(address), snmp_manager); 2474 target.addTarget(gui, target_parent); 2475 if (subconf.getString("snmp/version") != null) { 2476 if (subconf.getString("snmp/version").equals("v1")) target.getSNMPQuerier().setVersion(0); 2477 if (subconf.getString("snmp/version").equals("v2c")) target.getSNMPQuerier().setVersion(1); 2478 if (subconf.getString("snmp/version").equals("v3")) target.getSNMPQuerier().setVersion(2); 2479 } 2480 if (subconf.getString("community") != null) 2481 target.getSNMPQuerier().setCommunity(subconf.getString("community")); 2482 if (subconf.getString("password-auth") != null) 2483 target.getSNMPQuerier().setPasswordAuth(subconf.getString("password-auth")); 2484 if (subconf.getString("password-priv") != null) 2485 target.getSNMPQuerier().setPasswordPriv(subconf.getString("password-priv")); 2486 if (subconf.getString("pdu-max-size") != null) 2487 target.getSNMPQuerier().setPDUMaxSize(subconf.getInt("pdu-max-size")); 2488 if (subconf.getString("port") != null) 2489 target.getSNMPQuerier().setPort(subconf.getInt("port")); 2490 if (subconf.getString("retries") != null) 2491 target.getSNMPQuerier().setRetries(subconf.getInt("retries")); 2492 if (subconf.getString("security") != null && subconf.getString("security").equals("NOAUTH_NOPRIV")) 2493 target.getSNMPQuerier().setSec(SecurityLevel.NOAUTH_NOPRIV); 2494 if (subconf.getString("security") != null && subconf.getString("security").equals("AUTH_NOPRIV")) 2495 target.getSNMPQuerier().setSec(SecurityLevel.AUTH_NOPRIV); 2496 if (subconf.getString("security") != null && subconf.getString("security").equals("AUTH_PRIV")) 2497 target.getSNMPQuerier().setSec(SecurityLevel.AUTH_PRIV); 2498 if (subconf.getString("timeout") != null) 2499 target.getSNMPQuerier().setTimeout(subconf.getInt("timeout")); 2500 target.getSNMPQuerier().update(); 2501 } 2502 } 2503 } 2504 2505 if (subconf.getProperty("@targetType").equals("ipv6")) { 2506 final String address = subconf.getString("address"); 2507 2508 java.util.List <String > parents = (java.util.List <String >) subconf.getList("parent[@parentType='group']"); 2509 if (parents.size() != 0) for (final String parent : parents) { 2510 final TargetGroup foo = new TargetGroup("temporary", parent); 2511 final TargetGroup target_parent = (TargetGroup) getCanonicalInstance(foo); 2512 if (target_parent == foo) log.error("Initial configuration: parent does not exist"); 2513 else new TargetIPv6("added by initial configuration", GenericTools.stringToInet6Address(address), snmp_manager).addTarget(gui, target_parent); 2514 } 2515 } 2516 2517 if (subconf.getProperty("@targetType").equals("ipv4range")) { 2518 final String begin = subconf.getString("begin"); 2519 final String end = subconf.getString("end"); 2520 2521 java.util.List <String > parents = (java.util.List <String >) subconf.getList("parent[@parentType='group']"); 2522 if (parents.size() != 0) for (final String parent : parents) { 2523 final TargetGroup foo = new TargetGroup("temporary", parent); 2524 final TargetGroup target_parent = (TargetGroup) getCanonicalInstance(foo); 2525 if (target_parent == foo) log.error("Initial configuration: parent does not exist"); 2526 else new TargetIPv4Range("added by initial configuration", GenericTools.stringToInet4Address(begin), GenericTools.stringToInet4Address(end)).addTarget(gui, target_parent); 2527 } 2528 } 2529 2530 if (subconf.getProperty("@targetType").equals("ipv4subnet")) { 2531 final String network = subconf.getString("network"); 2532 final String netmask = subconf.getString("netmask"); 2533 2534 java.util.List <String > parents = (java.util.List <String >) subconf.getList("parent[@parentType='group']"); 2535 if (parents.size() != 0) for (final String parent : parents) { 2536 final TargetGroup foo = new TargetGroup("temporary", parent); 2537 final TargetGroup target_parent = (TargetGroup) getCanonicalInstance(foo); 2538 if (target_parent == foo) log.error("Initial configuration: parent does not exist"); 2539 else new TargetIPv4Subnet("added by initial configuration", GenericTools.stringToInet4Address(network), GenericTools.stringToInet4Address(netmask)).addTarget(gui, target_parent); 2540 } 2541 } 2542 } 2543 2544 shell.setActive(); 2546 } 2547 catch(final ConfigurationException ex) { 2548 log.warn("Exception", ex); 2549 } 2550 catch(final AlgorithmException ex) { 2551 log.error("Exception", ex); 2552 } 2553 catch(final UnknownHostException ex) { 2554 log.error("Exception", ex); 2555 } 2556 } 2557 }); 2558 } 2559} | Popular Tags |