Advertisement
Guest User

Untitled

a guest
Jul 3rd, 2015
289
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 11.81 KB | None | 0 0
  1. import java.awt.EventQueue;
  2.  
  3. import javax.naming.InvalidNameException;
  4. import javax.naming.ldap.LdapName;
  5. import javax.swing.JFrame;
  6. import javax.swing.JButton;
  7.  
  8. import java.awt.BorderLayout;
  9. import java.awt.event.ActionListener;
  10. import java.awt.event.ActionEvent;
  11. import java.awt.GridLayout;
  12.  
  13. import javax.naming.ldap.LdapName;
  14. import javax.swing.JTextField;
  15. import javax.swing.JLabel;
  16. import javax.swing.SwingUtilities;
  17. import javax.swing.UIManager;
  18.  
  19. import java.awt.Color;
  20. import java.awt.Font;
  21. import java.io.BufferedReader;
  22. import java.io.BufferedWriter;
  23. import java.io.DataInputStream;
  24. import java.io.File;
  25. import java.io.FileInputStream;
  26. import java.io.FileNotFoundException;
  27. import java.io.FileReader;
  28. import java.io.FileWriter;
  29. import java.io.IOException;
  30. import java.io.InputStreamReader;
  31. import java.net.Inet4Address;
  32. import java.net.UnknownHostException;
  33. import java.util.regex.Matcher;
  34. import java.util.regex.Pattern;
  35.  
  36. import javax.swing.JTextArea;
  37. import javax.swing.JTable;
  38.  
  39. public class MISControlPanel {
  40.  
  41.     JFrame frame;
  42.     static JTextField textField;
  43.     private JTextField textField_1;
  44.     final JTextArea textArea = new JTextArea();
  45.     JLabel selectedComputerFromAD = new JLabel("testing");
  46.     String sCurrentLine = null;
  47.     String CN = null;
  48.     JLabel testLabel = new JLabel("test");
  49.  
  50.     /**
  51.      * Launch the application.
  52.      */
  53.     public static void main(String[] args) {
  54.         EventQueue.invokeLater(new Runnable() {
  55.             public void run() {
  56.                 try {
  57.                     MISControlPanel window = new MISControlPanel();
  58.                     window.frame.setVisible(true);
  59.                     // testLabel.setText(CN);
  60.                 } catch (Exception e) {
  61.                     e.printStackTrace();
  62.                 }
  63.             }
  64.         });
  65.     }
  66.  
  67.     /**
  68.      * Create the application.
  69.      *
  70.      * @throws IOException
  71.      *
  72.      * @wbp.parser.entryPoint
  73.      */
  74.     public MISControlPanel() throws IOException {
  75.         initialize();
  76.     }
  77.  
  78.     /**
  79.      * Initialize the contents of the frame.
  80.      *
  81.      * @throws IOException
  82.      */
  83.     private void initialize() throws IOException {
  84.         frame = new JFrame();
  85.         frame.getContentPane().setBackground(Color.LIGHT_GRAY);
  86.         frame.getContentPane().setForeground(Color.RED);
  87.         frame.setBounds(100, 100, 658, 618);
  88.         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  89.         frame.getContentPane().setLayout(null);
  90.         frame.setTitle("MIS Advanced Computerers");
  91.         frame.setResizable(false);
  92.         FileWriter fw = new FileWriter("C:\\Users\\anoc5f\\Desktop\\Output.txt");
  93.         File tempFile = new File("myTempFile.txt");
  94.         JButton searchComputerButton = new JButton("Search");
  95.         searchComputerButton.addActionListener(new ActionListener() {
  96.             public void actionPerformed(ActionEvent e) {
  97.  
  98.                 String line;
  99.                 BufferedWriter bw = null;
  100.                 BufferedWriter writer = null;
  101.                 try {
  102.                     writer = new BufferedWriter(new FileWriter(tempFile));
  103.                 } catch (IOException e1) {
  104.                     // TODO Auto-generated catch block
  105.                     e1.printStackTrace();
  106.                 }
  107.                 // String lineToRemove = "OU=Workstations";
  108.  
  109.                 String s = null;
  110.  
  111.                 Process p = null;
  112.                 /*
  113.                  * try { // p = Runtime.getRuntime().exec(
  114.                  * "cmd /c start c:\\computerQuery.bat computerName"); } catch
  115.                  * (IOException e1) { // TODO Auto-generated catch block
  116.                  * e1.printStackTrace(); }
  117.                  */
  118.                 try {
  119.  
  120.                     p = Runtime.getRuntime().exec("c:\\computerQuery.bat");
  121.  
  122.                 } catch (IOException e1) {
  123.  
  124.                     // TODO Auto-generated catch block
  125.  
  126.                     e1.printStackTrace();
  127.  
  128.                 }
  129.                 StringBuffer sbuffer = new StringBuffer();
  130.                 BufferedReader in = new BufferedReader(new InputStreamReader(p
  131.                         .getInputStream()));
  132.  
  133.                 try {
  134.  
  135.                     while ((line = in.readLine()) != null) {
  136.  
  137.                         System.out.println(line);
  138.  
  139.                         // textArea.append(line);
  140.  
  141.                         String dn = "CN=FDCD111304,OU=Workstations,OU=SIM,OU=Accounts,DC=FL,DC=NET";
  142.                         LdapName ldapName = new LdapName(dn);
  143.                         String commonName = (String) ldapName.getRdn(
  144.                                 ldapName.size() - 1).getValue();
  145.  
  146.                     }
  147.                     ComputerQuery.sendParam();
  148.  
  149.                 } catch (IOException e1) {
  150.  
  151.                     // TODO Auto-generated catch block
  152.  
  153.                     e1.printStackTrace();
  154.  
  155.                 } catch (InvalidNameException e1) {
  156.                     // TODO Auto-generated catch block
  157.                     e1.printStackTrace();
  158.                 } finally
  159.  
  160.                 {
  161.                     try {
  162.                         fw.close();
  163.  
  164.                     }
  165.  
  166.                     catch (IOException e1) {
  167.                         // TODO Auto-generated catch block
  168.                         e1.printStackTrace();
  169.                     }
  170.                 }
  171.  
  172.                 try {
  173.  
  174.                     in.close();
  175.  
  176.                 } catch (IOException e1) {
  177.  
  178.                     // TODO Auto-generated catch block
  179.  
  180.                     e1.printStackTrace();
  181.  
  182.                 }
  183.  
  184.                 ComputerQuery.sendParam();
  185.  
  186.             }
  187.         });
  188.  
  189.         try (BufferedReader br = new BufferedReader(new FileReader(
  190.                 "resultofbatch.txt"))) {
  191.  
  192.             final Pattern PATTERN = Pattern.compile("CN=([^,]+).*");
  193.             try {
  194.                 while ((sCurrentLine = br.readLine()) != null) {
  195.  
  196.                     String[] tokens = PATTERN.split(","); // This will return
  197.                                                             // you a array,
  198.                                                             // containing the
  199.                                                             // string array
  200.                                                             // splitted by what
  201.                                                             // you write inside
  202.                                                             // it.
  203.                     // should be in your case the split, since they are
  204.                     // seperated by ","
  205.                     // System.out.println(sCurrentLine);
  206.                     CN = sCurrentLine.split("CN=", -1)[1].split(",", -1)[0];
  207.  
  208.                     System.out.println(CN);
  209.                     testLabel.setText(CN);
  210.                 }
  211.  
  212.             } catch (IOException e1) {
  213.                 // TODO Auto-generated catch block
  214.                 e1.printStackTrace();
  215.             }
  216.         } catch (IOException e2) {
  217.             // TODO Auto-generated catch block
  218.             e2.printStackTrace();
  219.         }
  220.         // SwingUtilities.invokeLater(updateCN());
  221.         searchComputerButton.setBounds(419, 19, 89, 20);
  222.         frame.getContentPane().add(searchComputerButton);
  223.  
  224.         textField = new JTextField();
  225.         textField.setBounds(285, 19, 124, 20);
  226.         frame.getContentPane().add(textField);
  227.         textField.setColumns(10);
  228.  
  229.         JLabel lblComputerName = new JLabel("Computer Name:");
  230.         lblComputerName.setForeground(Color.BLACK);
  231.         lblComputerName.setFont(new Font("Tahoma", Font.BOLD, 14));
  232.         lblComputerName.setBounds(159, 13, 124, 29);
  233.         frame.getContentPane().add(lblComputerName);
  234.  
  235.         JLabel lblSelectedComputer = new JLabel("Selected Computer:");
  236.         lblSelectedComputer.setFont(new Font("Tahoma", Font.BOLD, 14));
  237.         lblSelectedComputer.setBounds(205, 78, 143, 30);
  238.         frame.getContentPane().add(lblSelectedComputer);
  239.         java.net.InetAddress localMachine = null;
  240.         try {
  241.             localMachine = java.net.InetAddress.getLocalHost();
  242.         } catch (UnknownHostException e2) {
  243.             // TODO Auto-generated catch block
  244.             e2.printStackTrace();
  245.         }
  246.  
  247.         textArea.setBackground(Color.GRAY);
  248.         textArea.setForeground(Color.WHITE);
  249.         textArea.setFont(textArea.getFont().deriveFont(Font.BOLD));
  250.         textArea.setBounds(10, 387, 632, 191);
  251.         textArea.setEditable(false); // might cause design view not to come up
  252.         frame.getContentPane().add(textArea);
  253.  
  254.         JButton btnNewButton = new JButton("SSO REPAIR");
  255.         btnNewButton.addActionListener(new ActionListener() {
  256.             public void actionPerformed(ActionEvent e) {
  257.  
  258.             }
  259.         });
  260.         btnNewButton.setBounds(36, 183, 132, 23);
  261.         frame.getContentPane().add(btnNewButton);
  262.  
  263.         JLabel lblNewLabel = new JLabel("Batch File Fixes");
  264.         lblNewLabel.setFont(new Font("Tahoma", Font.BOLD, 12));
  265.         lblNewLabel.setBounds(53, 158, 115, 14);
  266.         frame.getContentPane().add(lblNewLabel);
  267.  
  268.         JLabel lblIpAddress = new JLabel("IP Address:");
  269.         lblIpAddress.setFont(new Font("Tahoma", Font.BOLD, 14));
  270.         lblIpAddress.setBounds(261, 104, 102, 22);
  271.         frame.getContentPane().add(lblIpAddress);
  272.  
  273.         JLabel label = null;
  274.         try {
  275.             label = new JLabel(Inet4Address.getLocalHost().getHostAddress()); // Get
  276.                                                                                 // User
  277.                                                                                 // ID
  278.         } catch (UnknownHostException e1) {
  279.             // TODO Auto-generated catch block
  280.             e1.printStackTrace();
  281.         }
  282.         label.setFont(new Font("Tahoma", Font.BOLD, 14));
  283.         label.setForeground(Color.RED);
  284.         label.setBounds(349, 105, 99, 21);
  285.         frame.getContentPane().add(label);
  286.  
  287.         JLabel lblPcCommunication = new JLabel("PC Communication");
  288.         lblPcCommunication.setFont(new Font("Tahoma", Font.BOLD, 12));
  289.         lblPcCommunication.setBounds(279, 158, 115, 14);
  290.         frame.getContentPane().add(lblPcCommunication);
  291.  
  292.         JButton btnPingComputer = new JButton("PING");
  293.  
  294.         btnPingComputer.addActionListener(new ActionListener() {
  295.  
  296.             public void actionPerformed(ActionEvent arg0) {
  297.             }
  298.  
  299.         });
  300.  
  301.         btnPingComputer.setBounds(306, 183, 64, 23);
  302.         frame.getContentPane().add(btnPingComputer);
  303.  
  304.         JButton remoteAssistanceButton = new JButton(
  305.                 "Remote Assistance by PC Name");
  306.         remoteAssistanceButton.addActionListener(new ActionListener() {
  307.             public void actionPerformed(ActionEvent e) {
  308.             }
  309.         });
  310.  
  311.         remoteAssistanceButton.setBounds(215, 251, 246, 23);
  312.         frame.getContentPane().add(remoteAssistanceButton);
  313.  
  314.         JButton btnPingIndefinetely = new JButton("PING INDEFINETELY");
  315.         btnPingIndefinetely.setBounds(260, 217, 156, 23);
  316.         frame.getContentPane().add(btnPingIndefinetely);
  317.  
  318.         JButton btnRdcByIp = new JButton("RDC by IP Address");
  319.         btnRdcByIp.setBounds(261, 353, 156, 23);
  320.         frame.getContentPane().add(btnRdcByIp);
  321.  
  322.         JButton btnRdcByName = new JButton("RDC by PC Name");
  323.         btnRdcByName.addActionListener(new ActionListener() {
  324.             public void actionPerformed(ActionEvent e) {
  325.             }
  326.         });
  327.         btnRdcByName.setBounds(248, 319, 180, 23);
  328.         frame.getContentPane().add(btnRdcByName);
  329.  
  330.         JLabel lblLoggedInOpid = new JLabel("Logged in OPID:");
  331.         lblLoggedInOpid.setFont(new Font("Tahoma", Font.BOLD, 14));
  332.         lblLoggedInOpid.setBounds(228, 127, 135, 20);
  333.         frame.getContentPane().add(lblLoggedInOpid);
  334.  
  335.         JLabel lblNewLabel_1 = new JLabel(System.getProperty("user.name")
  336.                 .toUpperCase());
  337.         lblNewLabel_1.setFont(new Font("Tahoma", Font.BOLD, 14));
  338.         lblNewLabel_1.setForeground(Color.RED);
  339.         lblNewLabel_1.setBounds(348, 130, 86, 14);
  340.         frame.getContentPane().add(lblNewLabel_1);
  341.  
  342.         JButton btnHiddenShare = new JButton("HIDDEN SHARE");
  343.         btnHiddenShare.addActionListener(new ActionListener() {
  344.             public void actionPerformed(ActionEvent arg0) {
  345.             }
  346.         });
  347.         btnHiddenShare.setBounds(484, 183, 132, 23);
  348.         frame.getContentPane().add(btnHiddenShare);
  349.  
  350.         JLabel lblAdditionalTools = new JLabel("Tools");
  351.         lblAdditionalTools.setFont(new Font("Tahoma", Font.BOLD, 12));
  352.         lblAdditionalTools.setBounds(526, 157, 126, 20);
  353.         frame.getContentPane().add(lblAdditionalTools);
  354.  
  355.         JButton btnNewButton_1 = new JButton("Remote Assistance by IP Address");
  356.         btnNewButton_1.setBounds(215, 285, 246, 23);
  357.         frame.getContentPane().add(btnNewButton_1);
  358.  
  359.         JButton gpUpdate = new JButton("GP UPDATE");
  360.         gpUpdate.addActionListener(new ActionListener() {
  361.             public void actionPerformed(ActionEvent arg0) {
  362.             }
  363.         });
  364.         gpUpdate.setBounds(36, 217, 132, 23);
  365.         frame.getContentPane().add(gpUpdate);
  366.  
  367.         JButton btnForced = new JButton("NURMED REG FIX");
  368.         btnForced.addActionListener(new ActionListener() {
  369.             public void actionPerformed(ActionEvent e) {
  370.             }
  371.         });
  372.         btnForced.setBounds(36, 251, 132, 23);
  373.         frame.getContentPane().add(btnForced);
  374.  
  375.         JButton btnCleaConsoler = new JButton("CLEAR");
  376.         btnCleaConsoler.addActionListener(new ActionListener() {
  377.             public void actionPerformed(ActionEvent arg0) {
  378.                 textArea.setText("");
  379.             }
  380.         });
  381.         btnCleaConsoler.setBounds(563, 353, 79, 23);
  382.         frame.getContentPane().add(btnCleaConsoler);
  383.  
  384.         JLabel lblOpid = new JLabel("Find Computer by OPID:");
  385.         lblOpid.setFont(new Font("Tahoma", Font.BOLD, 14));
  386.         lblOpid.setBounds(104, 53, 180, 14);
  387.         frame.getContentPane().add(lblOpid);
  388.  
  389.         textField_1 = new JTextField();
  390.         textField_1.setBounds(285, 50, 124, 20);
  391.         frame.getContentPane().add(textField_1);
  392.         textField_1.setColumns(10);
  393.  
  394.         JButton btnNewButton_2 = new JButton("Search");
  395.         btnNewButton_2.setBounds(419, 50, 89, 23);
  396.         frame.getContentPane().add(btnNewButton_2);
  397.         testLabel.setForeground(Color.RED);
  398.         testLabel.setFont(new Font("Tahoma", Font.BOLD, 14));
  399.  
  400.         testLabel.setBounds(358, 78, 150, 24);
  401.         frame.getContentPane().add(testLabel);
  402.  
  403.     }
  404.  
  405. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement