// // astcrm - General purpose CRM // // General purpose CRM software for asterisk // // Copyright (C) 2006, GnuDialer Project // // Heath Schultz // Richard Lyman // // this program started its life as AstMonitor.java // which is the CRM for the GnuDialer Project // after ripping its guts out, and a few late nights // this is the result. // // please excuse the whitespace, they were very late nights. // // This program is free software, distributed under the terms of // the GNU General Public License. // import java.awt.*; import java.awt.event.*; import java.io.*; import java.net.*; import java.applet.*; import java.util.Date; import java.util.Timer; import java.util.TimerTask; import java.util.ArrayList; import java.util.Vector; import java.util.Collections; import java.util.NoSuchElementException; import java.text.SimpleDateFormat; import java.util.GregorianCalendar; import java.lang.String; import java.lang.Object; import javax.swing.*; public class AstDisplay extends java.applet.Applet implements ActionListener, Runnable { boolean keepTrying = true; public static final String daVersion = "v0.3.3"; public static final boolean debugMode = false; public static final int DEBUG_LIMIT = 1000; public static final int DEBUG_HEIGHT = 5; public static final int DEBUG_WIDTH = 100; public static final int ZAP_CHANS = 192; String message, message2, disposition, transfer, campaign, leadid, channel; String tmpAgent, tmpName, tmpStatus, tmpChannel, tmpState, tmpAlarm, s2; String tmpZap, tmpZap1, tmpZap2, tmpClid, tmpClid1, tmpClid2, tmpStuff; String tmpChannel1, tmpChannel2, tmpCallerid1, tmpCallerid2; String tmpTech, tmpDev, tmpOccur, tmpLds, tmpReason, tmpReasonStr; boolean isLinked, isPaused; int tmpIndex; Frame frame1; TextField text; TextArea debug_message, lds, bogus, OS_message, OF_message, CI_message; int DEBUG_COUNT, OS_count, OF_count, number_count, CI_count; int port; Timer timer; Thread astThread; //Button callback = new Button("0 Callback"); Label[] labels; Label[] clrids; Label[] states; Label[] agents; Label[] queues; Panel main_panel; Panel zap_panel; Panel msg_panel; GridLayout grid, msg; GridBagLayout grid2, mess; Container container; public void init() { // frame1 = new Frame(); // frame1.setSize(500,500); container = new Container(); resize(985,984); setForeground( java.awt.Color.black ); setBackground( java.awt.Color.white ); setFont( new Font("Tacoma", Font.PLAIN, 12) ); setLayout(new BorderLayout()); main_panel = new Panel(); zap_panel = new Panel(); msg_panel = new Panel(); labels = new Label[ZAP_CHANS+1]; clrids = new Label[ZAP_CHANS+1]; states = new Label[ZAP_CHANS+1]; agents = new Label[ZAP_CHANS+1]; GridBagConstraints g = new GridBagConstraints(); g.fill = GridBagConstraints.VERTICAL; grid = new GridLayout(ZAP_CHANS/4,ZAP_CHANS/4*4,1,1); // zap_panel.setLayout(new ColumnLayout(ColumnLayout.LEFT)); zap_panel.setLayout(grid); g.weightx = 0.0; g.weighty = 1.0; g.gridheight = 1; // g.gridx = 0; // g.gridy = 0; g.gridwidth = 1; for ( int idx = 1; idx < labels.length; idx++ ) { labels[idx] = new Label("unused"); clrids[idx] = new Label("-"); states[idx] = new Label("-"); agents[idx] = new Label("-"); //grid2.setConstraints(labels[idx], g); //grid2.setConstraints(clrids[idx], g); //grid2.setConstraints(states[idx], g); zap_panel.add(labels[idx]); zap_panel.add(clrids[idx]); zap_panel.add(states[idx]); } debug_message = new TextArea("",((debugMode) ? (DEBUG_HEIGHT * 3) : DEBUG_HEIGHT),DEBUG_WIDTH); debug_message.setFont(new Font("SansSerif", Font.PLAIN, 12)); debug_message.setEditable(false); lds = new TextArea("",((debugMode) ? (DEBUG_HEIGHT * 3) : DEBUG_HEIGHT),DEBUG_WIDTH); lds.setFont(new Font("SansSerif", Font.PLAIN, 12)); lds.setEditable(false); bogus = new TextArea("",((debugMode) ? (DEBUG_HEIGHT * 3) : DEBUG_HEIGHT),DEBUG_WIDTH); bogus.setFont(new Font("SansSerif", Font.PLAIN, 12)); bogus.setEditable(false); OS_message = new TextArea("",((debugMode) ? (DEBUG_HEIGHT * 3) : DEBUG_HEIGHT),DEBUG_WIDTH); OS_message.setFont(new Font("SansSerif", Font.PLAIN, 12)); OS_message.setBackground(Color.green); OS_message.setEditable(false); OF_message = new TextArea("",((debugMode) ? (DEBUG_HEIGHT * 3) : DEBUG_HEIGHT),DEBUG_WIDTH); OF_message.setFont(new Font("SansSerif", Font.PLAIN, 12)); OF_message.setBackground(Color.pink); OF_message.setEditable(false); CI_message = new TextArea("",((debugMode) ? (DEBUG_HEIGHT * 3) : DEBUG_HEIGHT),DEBUG_WIDTH); CI_message.setFont(new Font("SansSerif", Font.PLAIN, 12)); CI_message.setEditable(false); GridBagConstraints m = new GridBagConstraints(); m.fill = GridBagConstraints.BOTH; mess = new GridBagLayout(); msg_panel.setLayout(mess); m.weightx = 1.0; m.weighty = 1.0; m.gridheight = 2; m.gridx = 0; m.gridy = 0; m.gridwidth = 1; mess.setConstraints(debug_message, m); msg_panel.add(debug_message); m.gridheight = 1; m.gridx = 1; m.gridy = 0; m.gridwidth = 1; mess.setConstraints(OS_message, m); msg_panel.add(OS_message); m.gridx = 2; m.gridy = 0; m.gridwidth = 1; mess.setConstraints(OF_message, m); msg_panel.add(OF_message); m.gridx = 1; m.gridy = 1; m.gridwidth = 0; mess.setConstraints(CI_message, m); msg_panel.add(CI_message); add(zap_panel, BorderLayout.CENTER); add(msg_panel, BorderLayout.NORTH); setVisible(true); astThread = new Thread(this); astThread.start(); } void addButton(Container p, String name) { // Create a button with the given name and add it // to the given panel. Set up the button to send // events to the applet. JButton b = new JButton(name); p.add(b); b.addActionListener(this); } void addButton(JPanel p, String name, Object option) { // Same as above, but use the "option" object // as an additional parameter in the add method. JButton b = new JButton(name); p.add(b, option); b.addActionListener(this); } public void destroy() { keepTrying = false; astThread = null; } public void run() { String thehost = getParameter("thehost"); String manuser = getParameter("manageruser"); String manpass = getParameter("managerpass"); String theport = getParameter("theport"); if (theport == null) { theport = "5038"; writeDebug("Defaulting port: "+theport+" (edit display.html)"); } if (thehost == null) { thehost = "192.168.1.2"; //thehost = "somehost.somedomain.com"; writeDebug("Defaulting host: "+thehost+" (edit display.html)"); } if (manuser == null) { manuser = "display"; writeDebug("Defaulting manuser: "+manuser+" (edit display.html)"); } if (manpass == null) { manpass = "1234"; writeDebug("Defaulting manpass: "+manpass+" (edit display.html)"); } keepTrying = true; writeDebug("AstDisplay (" + daVersion + ") Munch'D by Richard"); while(keepTrying) { try { writeDebug("AstConnect - Attempt - " + thehost + ":" + theport); System.out.println("AstConnect - Attempt - " + thehost + ":" + theport); AstConnect(thehost,theport,manuser,manpass); } catch (SecurityException e) { writeDebug("AstConnect - Failed - Check Authorization"); System.out.println("AstConnect - Failed - Check Authorization"); Toolkit.getDefaultToolkit().beep(); } catch (Exception e) { e.printStackTrace(); } } } public void actionPerformed(ActionEvent e) { String command = e.getActionCommand(); String thebase = "http://" + getCodeBase().getHost(); if (command.equals("logout")) { //getAppletContext().showDocument(String2Url(thebase + "/crm/crmlogin.html"),"_parent"); //actionSocket("Logoff",true,getParameter("thehost"),getParameter("station"),getParameter("manageruser"),getParameter("managerpass")); stop(); } } public void paint(Graphics g) { g.setColor( Color.black ); g.drawString(" " + message,0,250); //showStatus("yadda yadda something text here"); //hideStatus(); } public void actionSocket(String theAction, boolean tf, String host, String theport, String manuser, String manpass) { Socket astActionSocket = null; DataOutputStream osA = null; BufferedReader isA = null; port = Integer.parseInt(theport); try { //astActionSocket = new Socket(getCodeBase().getHost(), 5038); astActionSocket = new Socket(host, port); osA = new DataOutputStream(astActionSocket.getOutputStream()); isA = new BufferedReader(new InputStreamReader(astActionSocket.getInputStream())); } catch (SocketException e) { System.err.println("actionSocket - SocketException: " + e); e.printStackTrace(); } catch (UnknownHostException e) { System.err.println("actionSocket - Unknown host: " + e); } catch (IOException e) { System.err.println("actionSocket - IOException: " + e); e.printStackTrace(); } if (astActionSocket != null && osA != null && isA != null) { try { // this opens the manager session osA.writeBytes("Action: Login\r\n"); osA.writeBytes("UserName: " + manuser + "\r\n"); osA.writeBytes("Secret: " + manpass + "\r\n\r\n"); String resp, block = new String(); // handle all the action events here //if (theAction == "Logoff") { // osA.writeBytes("Action: Agentlogoff\r\n"); // osA.writeBytes("Agent: " + agent + "\r\n\r\n"); //} //if (theAction == "AgentLogoff") { // osA.writeBytes("Action: Agentlogoff\r\n"); // osA.writeBytes("Agent: " + agent + "\r\n\r\n"); //} //if (theAction == "AgentPause") { // osA.writeBytes("Action: QueuePause\r\n"); // osA.writeBytes("Interface: Agent/" + agent + "\r\n"); // if (tf) { // osA.writeBytes("Paused: 1\r\n\r\n"); // } else { // osA.writeBytes("Paused: 0\r\n\r\n"); // } //} // this closes the manager session //osA.writeBytes("Action: Logoff\r\n\r\n"); //osA.close(); //isA.close(); //astActionSocket.close(); } catch (SocketException e) { System.err.println("actionSocket - SocketException: " + e); e.printStackTrace(); } catch (UnknownHostException e) { System.err.println("actionSocket - Unknown host: " + e); } catch (IOException e) { System.err.println("actionSocket - IOException: " + e); e.printStackTrace(); } finally { try { osA.close(); isA.close(); astActionSocket.close(); } catch (IOException e) { System.err.println("actionSocket - IOException: " + e); e.printStackTrace(); } } } } public void AstConnect(String host, String theport, String manuser, String manpass) { Socket AstSocket = null; DataOutputStream os = null; BufferedReader is = null; port = Integer.parseInt(theport); try { //AstSocket = new Socket(getCodeBase().getHost(), 5038); AstSocket = new Socket(host, port); os = new DataOutputStream(AstSocket.getOutputStream()); is = new BufferedReader(new InputStreamReader(AstSocket.getInputStream())); } catch (SocketException e) { System.err.println("AstConnect - SocketException: " + e); e.printStackTrace(); } catch (UnknownHostException e) { System.err.println("AstConnect - Unknown host: " + e); } catch (IOException e) { System.err.println("AstConnect - IOException: " + e); e.printStackTrace(); } if (AstSocket != null && os != null && is != null) { try { os.writeBytes("Action: Login\r\n"); os.writeBytes("UserName: " + manuser + "\r\n"); os.writeBytes("Secret: " + manpass + "\r\n\r\n"); String resp, block = new String(); int pos = 0; int end = 0; while ((resp = is.readLine()) != null) { if (resp.indexOf(":") != -1 || resp.indexOf("Agent") != -1) block += resp + "\n"; else { if (debugMode) writeDebug(block); if (block.indexOf("Event: AgentsComplete",0) != -1) { try { writeDebug("Tx - Status"); System.out.println("Tx - Status"); os.writeBytes("Action: Status\r\n\r\n"); // new Reminder ( 10 ); } catch (Exception e) { e.printStackTrace(); } } if (block.indexOf("Event: ZapShowChannelsComplete",0) != -1) { try { writeDebug("Tx - Agents"); System.out.println("Tx - Agents"); os.writeBytes("Action: Agents\r\n\r\n"); } catch (Exception e) { e.printStackTrace(); } } if (block.indexOf("Response: Success",0) != -1 && block.indexOf("Message: Authentication accepted",0) != -1) { //logged in trigger try { writeDebug("Tx - ZapShowChannels"); System.out.println("Tx - ZapShowChannels"); os.writeBytes("Action: ZapShowChannels\r\n\r\n"); } catch (Exception e) { e.printStackTrace(); } } //if (block.indexOf("Goodbye",0) != -1) { // os.close(); // is.close(); // AstSocket.close(); // keepTrying = false; // stop(); //} //-------------------------------------------------- // new stuff if (block.indexOf("Event: Newstate") != -1 && block.indexOf("Channel") != -1 && block.indexOf("Zap/") != -1) { if (block.indexOf("Channel: ") != -1) { pos = block.indexOf("Channel: "); end = block.indexOf("\n",pos); tmpChannel = block.substring(pos+9,end); pos = tmpChannel.indexOf("Zap/"); end = tmpChannel.indexOf("-",pos); tmpZap = tmpChannel.substring(pos+4,end); s2 = tmpChannel.replaceAll("/", ""); } if (block.indexOf("State: ") != -1) { pos = block.indexOf("State: "); end = block.indexOf("\n",pos); tmpState = block.substring(pos+7,end); if (tmpState.equals("Down")) { states[Integer.valueOf( tmpZap ).intValue()].setBackground(Color.white); } else if (tmpState.equals("Rsrvd")) { states[Integer.valueOf( tmpZap ).intValue()].setBackground(Color.yellow); } else if (tmpState.equals("Offhook")) { states[Integer.valueOf( tmpZap ).intValue()].setBackground(Color.yellow); } else if (tmpState.equals("Dialing")) { states[Integer.valueOf( tmpZap ).intValue()].setBackground(Color.yellow); } else if (tmpState.equals("Ring")) { states[Integer.valueOf( tmpZap ).intValue()].setBackground(Color.pink); } else if (tmpState.equals("Ringing")) { states[Integer.valueOf( tmpZap ).intValue()].setBackground(Color.pink); } else if (tmpState.equals("Up")) { states[Integer.valueOf( tmpZap ).intValue()].setBackground(Color.green); } else if (tmpState.equals("Busy")) { states[Integer.valueOf( tmpZap ).intValue()].setBackground(Color.blue); } else if (tmpState.equals("Mute")) { states[Integer.valueOf( tmpZap ).intValue()].setBackground(Color.cyan); } else if (tmpState.equals("Prering")) { states[Integer.valueOf( tmpZap ).intValue()].setBackground(Color.yellow); } else { tmpState = ""; states[Integer.valueOf( tmpZap ).intValue()].setBackground(Color.white); } states[Integer.valueOf( tmpZap ).intValue()].setText(tmpState); } if (block.indexOf("CallerID: ") != -1) { pos = block.indexOf("CallerID: "); end = block.indexOf("\n",pos); tmpState = block.substring(pos+10,end); tmpState = strip91(tmpState); if (tmpState.equals("") || tmpState.equals("")) { //do nothing } else { clrids[Integer.valueOf( tmpZap ).intValue()].setText(tmpState); } } writeDebug("Rx - Event: Newstate - " + tmpZap + " " + tmpState); repaint(); } //Zap if (block.indexOf("Event: Newchannel") != -1 && block.indexOf("Channel") != -1 && block.indexOf("Zap/") != -1) { if (block.indexOf("Channel: ") != -1) { pos = block.indexOf("Channel: "); end = block.indexOf("\n",pos); tmpChannel = block.substring(pos+9,end); pos = tmpChannel.indexOf("Zap/"); end = tmpChannel.indexOf("-",pos); tmpZap = tmpChannel.substring(pos+4,end); s2 = tmpChannel.replaceAll("/", ""); } if (block.indexOf("State: ") != -1) { pos = block.indexOf("State: "); end = block.indexOf("\n",pos); tmpState = block.substring(pos+7,end); if (tmpState.equals("Down")) { states[Integer.valueOf( tmpZap ).intValue()].setBackground(Color.white); } else if (tmpState.equals("Rsrvd")) { states[Integer.valueOf( tmpZap ).intValue()].setBackground(Color.yellow); } else if (tmpState.equals("Offhook")) { states[Integer.valueOf( tmpZap ).intValue()].setBackground(Color.yellow); } else if (tmpState.equals("Dialing")) { states[Integer.valueOf( tmpZap ).intValue()].setBackground(Color.yellow); } else if (tmpState.equals("Ring")) { states[Integer.valueOf( tmpZap ).intValue()].setBackground(Color.pink); } else if (tmpState.equals("Ringing")) { states[Integer.valueOf( tmpZap ).intValue()].setBackground(Color.pink); } else if (tmpState.equals("Up")) { states[Integer.valueOf( tmpZap ).intValue()].setBackground(Color.green); } else if (tmpState.equals("Busy")) { states[Integer.valueOf( tmpZap ).intValue()].setBackground(Color.blue); } else if (tmpState.equals("Mute")) { states[Integer.valueOf( tmpZap ).intValue()].setBackground(Color.cyan); } else if (tmpState.equals("Prering")) { states[Integer.valueOf( tmpZap ).intValue()].setBackground(Color.yellow); } else { tmpState = ""; states[Integer.valueOf( tmpZap ).intValue()].setBackground(Color.white); } states[Integer.valueOf( tmpZap ).intValue()].setText(tmpState); } writeDebug("Rx - Event: Newchannel - " + tmpZap + " " + tmpState); repaint(); } //Agent if (block.indexOf("Event: Newchannel") != -1 && block.indexOf("Channel") != -1 && block.indexOf("Agent/") != -1) { // if (block.indexOf("Channel: ") != -1) { // pos = block.indexOf("Channel: "); // end = block.indexOf("\n",pos); // tmpChannel = block.substring(pos+9,end); // pos = tmpChannel.indexOf("Agent/"); // end = tmpChannel.indexOf("\n",pos); // tmpZap = tmpChannel.substring(pos+6,end); // s2 = tmpChannel.replaceAll("/", ""); // } if (block.indexOf("Channel: Agent/") != -1) { pos = block.indexOf("Channel: Agent/"); end = block.indexOf("\n",pos); tmpChannel = block.substring(pos+15,end); } int tmpIndex = 0; if (!tmpChannel.equalsIgnoreCase("")) { for ( int lidx = 1; lidx < labels.length; lidx++ ) { if (agents[lidx].getText().equals(tmpChannel)) { tmpIndex = lidx; } } } if (block.indexOf("State: ") != -1) { pos = block.indexOf("State: "); end = block.indexOf("\n",pos); tmpState = block.substring(pos+7,end); if (tmpState.equals("Down")) { states[tmpIndex].setBackground(Color.white); } else if (tmpState.equals("Rsrvd")) { states[tmpIndex].setBackground(Color.yellow); } else if (tmpState.equals("Offhook")) { states[tmpIndex].setBackground(Color.yellow); } else if (tmpState.equals("Dialing")) { states[tmpIndex].setBackground(Color.yellow); } else if (tmpState.equals("Ring")) { states[tmpIndex].setBackground(Color.pink); } else if (tmpState.equals("Ringing")) { states[tmpIndex].setBackground(Color.pink); } else if (tmpState.equals("Up")) { states[tmpIndex].setBackground(Color.green); } else if (tmpState.equals("Busy")) { states[tmpIndex].setBackground(Color.blue); } else if (tmpState.equals("Mute")) { states[tmpIndex].setBackground(Color.cyan); } else if (tmpState.equals("Prering")) { states[tmpIndex].setBackground(Color.yellow); } states[tmpIndex].setText(tmpState); } if (block.indexOf("CallerID: ") != -1) { pos = block.indexOf("CallerID: "); end = block.indexOf("\n",pos); tmpClid = block.substring(pos+10,end); tmpClid = strip91(tmpClid); clrids[tmpIndex].setText(tmpClid); } writeDebug("Rx - Event: Newchannel - " + tmpChannel + " " + tmpState); repaint(); } if (block.indexOf("Event: Newcallerid") != -1 && block.indexOf("Channel") != -1 && block.indexOf("Zap/") != -1) { if (block.indexOf("Channel: ") != -1) { pos = block.indexOf("Channel: "); end = block.indexOf("\n",pos); tmpChannel = block.substring(pos+9,end); pos = tmpChannel.indexOf("Zap/"); end = tmpChannel.indexOf("-",pos); tmpZap = tmpChannel.substring(pos+4,end); s2 = tmpChannel.replaceAll("/", ""); } if (block.indexOf("CallerID: ") != -1) { pos = block.indexOf("CallerID: "); end = block.indexOf("\n",pos); tmpState = block.substring(pos+10,end); tmpState = strip91(tmpState); if (tmpState.equalsIgnoreCase("")) { //do nothing } else { clrids[Integer.valueOf( tmpZap ).intValue()].setText(tmpState); } } writeDebug("Rx - Event: Newcallerid - " + tmpZap + " " + tmpState); repaint(); } if (block.indexOf("Event: Newexten") != -1 && block.indexOf("Channel: Zap/") != -1) { if (block.indexOf("Channel: ") != -1) { pos = block.indexOf("Channel: "); end = block.indexOf("\n",pos); tmpChannel = block.substring(pos+9,end); pos = tmpChannel.indexOf("Zap/"); end = tmpChannel.indexOf("-",pos); tmpZap = tmpChannel.substring(pos+4,end); s2 = tmpChannel.replaceAll("/", ""); } if (block.indexOf("Extension: ") != -1) { pos = block.indexOf("Extension: "); end = block.indexOf("\n",pos); tmpState = block.substring(pos+11,end); tmpState = strip91(tmpState); } if (block.indexOf("Application: Dial") != -1 && block.indexOf("AppData:") != -1) { pos = block.indexOf("AppData: "); end = block.indexOf("\n",pos); tmpLds = block.substring(pos+9,end); writeLastNumberDialed(tmpLds); } if (tmpState.equals("s") || tmpState.length() > 8) { //do nothing } else { try { labels[Integer.valueOf( tmpZap ).intValue()].setText("Zap/"+tmpZap+" - "+tmpState); if (tmpState.equals("699")) { labels[Integer.valueOf( tmpZap ).intValue()].setBackground(Color.magenta); } } catch (Exception e) {} } writeDebug("Rx - Event: Newexten - " + tmpZap + " " + tmpState); repaint(); } if (block.indexOf("Event: Hangup") != -1 && block.indexOf("Channel") != -1 && block.indexOf("Zap/") != -1) { if (block.indexOf("Channel: ") != -1) { pos = block.indexOf("Channel: "); end = block.indexOf("\n",pos); tmpChannel = block.substring(pos+9,end); pos = tmpChannel.indexOf("Zap/"); end = tmpChannel.indexOf("-",pos); tmpZap = tmpChannel.substring(pos+4,end); tmpZap = tmpZap.replaceAll("/", ""); states[Integer.valueOf( tmpZap ).intValue()].setBackground(Color.white); states[Integer.valueOf( tmpZap ).intValue()].setText("-"); labels[Integer.valueOf( tmpZap ).intValue()].setBackground(Color.white); labels[Integer.valueOf( tmpZap ).intValue()].setText("Zap/"+tmpZap); clrids[Integer.valueOf( tmpZap ).intValue()].setText("-"); agents[Integer.valueOf( tmpZap ).intValue()].setText("-"); } writeDebug("Rx - Event: Hangup - " + tmpZap); repaint(); } //Event: ZapShowChannels //Channel: 96 //Signalling: E & M Immediate //Context: fake_out //DND: Disabled //Alarm: Red Alarm if (block.indexOf("Event: ZapShowChannels") != -1 && block.indexOf("Channel:") != -1) { if (block.indexOf("Channel: ") != -1) { pos = block.indexOf("Channel: "); end = block.indexOf("\n",pos); tmpChannel = block.substring(pos+9,end); } if (block.indexOf("Alarm: ") != -1) { pos = block.indexOf("Alarm: "); end = block.indexOf("\n",pos); tmpAlarm = block.substring(pos+7,end); } //if (labels[Integer.valueOf( tmpChannel ).intValue()].getText().equalsIgnoreCase("unused")) { labels[Integer.valueOf( tmpChannel ).intValue()].setBackground(Color.white); labels[Integer.valueOf( tmpChannel ).intValue()].setText("Zap/"+tmpChannel); //} if (tmpAlarm.equals("Unknown Alarm") ||tmpAlarm.equals("Red Alarm") || tmpAlarm.equals("Yellow Alarm") || tmpAlarm.equals("Blue Alarm") || tmpAlarm.equals("Recovering") || tmpAlarm.equals("Loopback")) { states[Integer.valueOf( tmpChannel ).intValue()].setBackground(Color.LIGHT_GRAY); states[Integer.valueOf( tmpChannel ).intValue()].setText(tmpAlarm); } //writeDebug("Rx - Event: ZapShowChannels - " + tmpChannel + " " + tmpAlarm); repaint(); } //Event: OriginateSuccess //Privilege: call,all //Channel: Zap/g1/4087208676 //Context: gdincoming //Exten: //Reason: 4 //Uniqueid: 1166288802.7608 //CallerID: 9999999999 //CallerIDName: ~308CLD04-6087-true~ if (block.indexOf("Event: OriginateSuccess") != -1 && block.indexOf("Channel:") != -1) { if (block.indexOf("Channel: ") != -1) { pos = block.indexOf("Channel: "); end = block.indexOf("\n",pos); tmpChannel = block.substring(pos+9,end); writeOSMessage(tmpChannel); } writeDebug("Rx - Event: OriginateSuccess - " + tmpChannel); repaint(); } if (block.indexOf("Event: OriginateFailure") != -1 && block.indexOf("Channel:") != -1) { if (block.indexOf("Channel: ") != -1) { pos = block.indexOf("Channel: "); end = block.indexOf("\n",pos); tmpChannel = block.substring(pos+9,end); } if (block.indexOf("Reason: ") != -1) { pos = block.indexOf("Reason: "); end = block.indexOf("\n",pos); tmpReason = block.substring(pos+8,end); //unknown failure, disconnect if (tmpReason.equals("0")) { tmpReasonStr = "disconnect"; } // AST_CONTROL_RINGING //timed out while ringing, no answer if (tmpReason.equals("3")) { tmpReasonStr = "ringing-na"; } // AST_CONTROL_BUSY //busy if (tmpReason.equals("5")) { tmpReasonStr = "busy"; } // AST_CONTROL_HANGUP //hangup, no answer if (tmpReason.equals("1")) { tmpReasonStr = "hangup-na"; } // AST_CONTROL_CONGESTION //congestion if (tmpReason.equals("8")) { tmpReasonStr = "congestion"; } } writeOFMessage(tmpChannel + " (" + tmpReasonStr + ")"); writeDebug("Rx - Event: OriginateFailure - " + tmpChannel + " (" + tmpReasonStr + ")"); repaint(); } //Event: Status //Privilege: Call //Channel: IAX2/pchammer-2 //CallerID: 4083760400 //CallerIDName: PcHammer //Account: pchammer //State: Up //Context: dialerlogin //Extension: s //Priority: 1 //Seconds: 76 //Uniqueid: 1166116930.9794 if (block.indexOf("Event: Status") != -1 && block.indexOf("Channel: Zap/") != -1) { if (block.indexOf("Channel: ") != -1) { pos = block.indexOf("Channel: "); end = block.indexOf("\n",pos); tmpChannel = block.substring(pos+9,end); pos = tmpChannel.indexOf("Zap/"); end = tmpChannel.indexOf("-",pos); tmpZap = tmpChannel.substring(pos+4,end); tmpZap = tmpZap.replaceAll("/", ""); } if (block.indexOf("State: ") != -1) { pos = block.indexOf("State: "); end = block.indexOf("\n",pos); tmpState = block.substring(pos+7,end); if (tmpState.equals("Down")) { states[Integer.valueOf( tmpZap ).intValue()].setBackground(Color.white); } else if (tmpState.equals("Rsrvd")) { states[Integer.valueOf( tmpZap ).intValue()].setBackground(Color.yellow); } else if (tmpState.equals("Offhook")) { states[Integer.valueOf( tmpZap ).intValue()].setBackground(Color.yellow); } else if (tmpState.equals("Dialing")) { states[Integer.valueOf( tmpZap ).intValue()].setBackground(Color.yellow); } else if (tmpState.equals("Ring")) { states[Integer.valueOf( tmpZap ).intValue()].setBackground(Color.pink); } else if (tmpState.equals("Ringing")) { states[Integer.valueOf( tmpZap ).intValue()].setBackground(Color.pink); } else if (tmpState.equals("Up")) { states[Integer.valueOf( tmpZap ).intValue()].setBackground(Color.green); } else if (tmpState.equals("Busy")) { states[Integer.valueOf( tmpZap ).intValue()].setBackground(Color.blue); } else if (tmpState.equals("Mute")) { states[Integer.valueOf( tmpZap ).intValue()].setBackground(Color.cyan); } else if (tmpState.equals("Prering")) { states[Integer.valueOf( tmpZap ).intValue()].setBackground(Color.yellow); } else { tmpState = ""; states[Integer.valueOf( tmpZap ).intValue()].setBackground(Color.white); } states[Integer.valueOf( tmpZap ).intValue()].setText(tmpState); } writeDebug("Rx - Event: Status - " + tmpZap + " " + tmpState); repaint(); } //Event: Agents //Agent: 210 //Name: MCDONALD T //Status: AGENT_LOGGEDOFF //LoggedInChan: n/a //LoggedInTime: 0 //TalkingTo: n/a //Event: Agents //Agent: 300 //Name: TBS AGENT //Status: AGENT_IDLE //LoggedInChan: IAX2/pchammer-2 //LoggedInTime: 1166116939 //TalkingTo: n/a if (block.indexOf("Event: Agents") != -1 && block.indexOf("Agent:") != -1 && block.indexOf("Zap/") != -1) { if (block.indexOf("Agent: ") != -1) { pos = block.indexOf("Agent: "); end = block.indexOf("\n",pos); tmpAgent = block.substring(pos+7,end); } if (block.indexOf("Name: ") != -1) { pos = block.indexOf("Name: "); end = block.indexOf("\n",pos); tmpName = block.substring(pos+6,end); } if (block.indexOf("Status: ") != -1) { pos = block.indexOf("Status: "); end = block.indexOf("\n",pos); tmpStatus = block.substring(pos+8,end); } if (block.indexOf("LoggedInChan: ") != -1) { pos = block.indexOf("LoggedInChan: "); end = block.indexOf("\n",pos); tmpChannel = block.substring(pos+14,end); pos = tmpChannel.indexOf("Zap/"); end = tmpChannel.indexOf("-",pos); tmpZap = tmpChannel.substring(pos+4,end); tmpZap = tmpZap.replaceAll("/", ""); } //if (agents[Integer.valueOf( tmpAgent ).intValue()].getText().equals("-")) { labels[Integer.valueOf( tmpZap ).intValue()].setBackground(Color.cyan); agents[Integer.valueOf( tmpZap ).intValue()].setText(tmpAgent); labels[Integer.valueOf( tmpZap ).intValue()].setText("Zap/"+tmpZap+" - "+tmpAgent); //repaint(); //} writeDebug("Rx - Event: Agents - " + tmpAgent + " " + tmpName + " " + tmpStatus); repaint(); } if (block.indexOf("Event: ManagerUserEvent") != -1 && block.indexOf("Event: CampaignInfo") != -1 && block.indexOf("Zap/") != -1) { if (block.indexOf("Body: ") != -1) { pos = block.indexOf("Body: "); end = block.indexOf("\n",pos); tmpStuff = block.substring(pos+6,end); writeCampaignInfoMessage(tmpStuff); repaint(); } writeDebug("Rx - Event: CampaignInfo - " + tmpStuff); repaint(); } //action: ping //Response: Pong if (block.indexOf("Response: Pong") != -1) { //agents[Integer.valueOf( tmpAgent ).intValue()].setBackground(Color.white); writeDebug("Rx - Event: Pong"); repaint(); } if (block.indexOf("Event: Link") != -1 && block.indexOf("Channel1: Zap/") != -1 && block.indexOf("Channel2: Zap/") != -1) { if (block.indexOf("Channel1: ") != -1) { pos = block.indexOf("Channel1: "); end = block.indexOf("\n",pos); tmpChannel1 = block.substring(pos+10,end); pos = tmpChannel1.indexOf("Zap/"); end = tmpChannel1.indexOf("-",pos); tmpZap1 = tmpChannel1.substring(pos+4,end); tmpZap1 = tmpZap1.replaceAll("/", ""); } if (block.indexOf("Channel2: ") != -1) { pos = block.indexOf("Channel2: "); end = block.indexOf("\n",pos); tmpChannel2 = block.substring(pos+10,end); pos = tmpChannel2.indexOf("Zap/"); end = tmpChannel2.indexOf("-",pos); tmpZap2 = tmpChannel2.substring(pos+4,end); tmpZap2 = tmpZap2.replaceAll("/", ""); } if (!tmpZap1.equalsIgnoreCase("")) { labels[Integer.valueOf( tmpZap1 ).intValue()].setText("Zap/"+tmpZap1+" - "+tmpZap2); tmpClid = clrids[Integer.valueOf( tmpZap2 ).intValue()].getText(); } if (!tmpZap2.equalsIgnoreCase("")) { labels[Integer.valueOf( tmpZap2 ).intValue()].setText("Zap/"+tmpZap2+" - "+tmpZap1); clrids[Integer.valueOf( tmpZap1 ).intValue()].setText(tmpClid); } writeDebug("Rx - Event: Link - " + tmpChannel1 + " " + tmpChannel2); repaint(); } if ((block.indexOf("Event: Link") != -1 || block.indexOf("Event: Unlink") != -1 )&& block.indexOf("Channel1: Zap/") != -1 && block.indexOf("Channel2: Agent/") != -1) { isLinked = false; if (block.indexOf("Link") != -1) { isLinked = true; } if (block.indexOf("Channel1: ") != -1) { pos = block.indexOf("Channel1: "); end = block.indexOf("\n",pos); tmpChannel1 = block.substring(pos+10,end); pos = tmpChannel1.indexOf("Zap/"); end = tmpChannel1.indexOf("-",pos); tmpZap1 = tmpChannel1.substring(pos+4,end); tmpZap1 = tmpZap1.replaceAll("/", ""); } if (block.indexOf("Channel2: Agent/") != -1) { pos = block.indexOf("Channel2: Agent/"); end = block.indexOf("\n",pos); tmpChannel2 = block.substring(pos+16,end); } tmpIndex = 0; for ( int lidx = 1; lidx < labels.length; lidx++ ) { if (agents[lidx].getText().equals(tmpChannel2)) { tmpIndex = lidx; } } if (isLinked) { labels[Integer.valueOf( tmpZap1 ).intValue()].setText("Zap/"+tmpZap1+" - "+tmpChannel2); tmpClid = clrids[Integer.valueOf( tmpZap1 ).intValue()].getText(); clrids[tmpIndex].setText(tmpClid); labels[tmpIndex].setBackground(Color.pink); } else { labels[tmpIndex].setBackground(Color.cyan); labels[Integer.valueOf( tmpZap1 ).intValue()].setText("Zap/"+tmpZap1); clrids[tmpIndex].setText(""); } writeDebug("Rx - Event: Link - " + tmpChannel1 + " " + tmpChannel2); repaint(); } //-------- // for ( int idx = 1; idx < labels.length; idx++ ) { // labels[idx] = new Label("unused"); //------- //Event: Agentlogin //Privilege: agent,all //Agent: 300 //Channel: IAX2/pchammer-2 //Uniqueid: 1165938396.10152 if (block.indexOf("Event: Agentlogin") != -1 && block.indexOf("Agent:") != -1 && block.indexOf("Zap/") != -1) { if (block.indexOf("Agent: ") != -1) { pos = block.indexOf("Agent: "); end = block.indexOf("\n",pos); tmpAgent = block.substring(pos+7,end); } if (block.indexOf("Channel: ") != -1) { pos = block.indexOf("Channel: "); end = block.indexOf("\n",pos); tmpChannel = block.substring(pos+9,end); pos = tmpChannel.indexOf("Zap/"); end = tmpChannel.indexOf("-",pos); tmpZap = tmpChannel.substring(pos+4,end); s2 = tmpChannel.replaceAll("/", ""); labels[Integer.valueOf( tmpZap ).intValue()].setBackground(Color.cyan); agents[Integer.valueOf( tmpZap ).intValue()].setText(tmpAgent); labels[Integer.valueOf( tmpZap ).intValue()].setText("Zap/"+tmpZap+" - "+tmpAgent); } writeDebug("Rx - Event: Agentlogin - " + tmpAgent + " " + tmpChannel); repaint(); } //Event: Agentlogoff //Privilege: agent,all //Agent: 300 //Logintime: 20 //Uniqueid: 1165938396.10152 if (block.indexOf("Event: Agentlogoff") != -1 && block.indexOf("Agent:") != -1 && block.indexOf("Zap/") != -1) { if (block.indexOf("Agent: ") != -1) { pos = block.indexOf("Agent: "); end = block.indexOf("\n",pos); tmpAgent = block.substring(pos+7,end); } if (block.indexOf("Channel: ") != -1) { pos = block.indexOf("Channel: "); end = block.indexOf("\n",pos); tmpChannel = block.substring(pos+9,end); pos = tmpChannel.indexOf("Zap/"); end = tmpChannel.indexOf("-",pos); tmpZap = tmpChannel.substring(pos+4,end); s2 = tmpChannel.replaceAll("/", ""); labels[Integer.valueOf( tmpZap ).intValue()].setBackground(Color.white); agents[Integer.valueOf( tmpZap ).intValue()].setText(""); labels[Integer.valueOf( tmpZap ).intValue()].setText("Zap/"+tmpZap); } writeDebug("Rx - Event: Agentlogoff - " + tmpAgent + " " + tmpChannel); repaint(); } if (block.indexOf("Event: ManagerUserEvent") != -1 && (block.indexOf("Event: AgentPause") != -1 || block.indexOf("Event: AgentUnPause") != -1)) { isPaused = true; if (block.indexOf("UnPause") != -1) { isPaused = false; } if (block.indexOf("Agent: ") != -1) { pos = block.indexOf("Agent: "); end = block.indexOf("\n",pos); tmpAgent = block.substring(pos+7,end); } tmpIndex = 0; for ( int lidx = 1; lidx < labels.length; lidx++ ) { if (agents[lidx].getText().equals(tmpAgent)) { tmpIndex = lidx; } } if (isPaused) { labels[tmpIndex].setBackground(Color.yellow); } else { labels[tmpIndex].setBackground(Color.cyan); } writeDebug("Rx - Event: MUE AgentPause/UnPause - " + tmpAgent + " " + isPaused); repaint(); } block = ""; } } os.close(); is.close(); AstSocket.close(); } catch (UnknownHostException e) { System.err.println("AstConnect - Unknown host: " + e); } catch (IOException e) { System.err.println("AstConnect - IOException: " + e); e.printStackTrace(); } finally { try { os.close(); is.close(); AstSocket.close(); } catch (IOException e) { System.err.println("actionSocket - IOException: " + e); e.printStackTrace(); } } } } public static String strip91(String before) { if (before.length() > 3) if (before.substring(0,2).equals("91")) return before.substring(2,before.length()); return before; } public void writeDebug(String daMessage) { if (DEBUG_COUNT > DEBUG_LIMIT) { DEBUG_COUNT = 0; debug_message.setText(""); } debug_message.append(daMessage+ "\n"); DEBUG_COUNT++; } public void writeLastNumberDialed(String daNumber) { if (number_count > 500) { number_count = 0; lds.setText(""); } lds.append(daNumber+ "\n"); number_count++; } public void writeOSMessage(String daOSNumber) { if (OS_count > 500) { OS_count = 0; OS_message.setText(""); } OS_message.append(daOSNumber+ "\n"); OS_count++; } public void writeOFMessage(String daOFNumber) { if (OF_count > 500) { OF_count = 0; OF_message.setText(""); } OF_message.append(daOFNumber+ "\n"); OF_count++; } public void writeCampaignInfoMessage(String daStats) { if (CI_count > 500) { CI_count = 0; CI_message.setText(""); } CI_message.append(daStats+ "\n"); CI_count++; } // public class Reminder { // Timer timer; // // public Reminder(int seconds) { // timer = new Timer(); // timer.schedule(new RemindTask(), seconds*1000); // } // class RemindTask extends TimerTask { // public void run() { // System.out.println("Time's up!"); // timer.cancel(); //Terminate the timer thread // } // } // public static void main(String args[]) { // new Reminder(5); // System.out.println("Task scheduled."); // } // } public static URL String2Url(String theString) { URL theUrl = null; try { theUrl = new URL(theString); return theUrl; } catch (Exception e) {} return theUrl; } } //holding area for misc code //------------------------------------------------------------------------------------------------------------- //switch (clicked) //{ // case 0: setBackground(Color.red); // break; // case 1: setBackground(Color.blue); // break; // case 2: setBackground(Color.green); // break; // case 3: setBackground(Color.yellow); // break; // case 4: setBackground(Color.black); // break; //} // while (count < 25) { // p.add(new Label("Zap" + (count))); // p.add(new Label("Zap" + (count+24))); // p.add(new Label("Zap" + (count+48))); // p.add(new Label("Zap" + (count+72))); // p.add(new Label("Agent" + (count+299))); // count++; // } // int count = 1; // while (count < 3) { // p.add("Zap"+count++, new Label("Zap"+count++)); // count++; // } // callback.setActionCommand("callback"); // callback.addActionListener(this); // this.add(callback); // int count = 1; // while (count < 25) { // addButton(this,"Zap" + (count)); // addButton(this,"Zap" + (count+24)); // addButton(this,"Zap" + (count+48)); // addButton(this,"Zap" + (count+72)); // addButton(this,"Agent" + (count+299)); // count++; // } // setSize (775, 475); // setVisible (true); //JCheckBox showTime = new JCheckBox("Show Current Time"); // public void actionPerformed(ActionEvent evt) { // Object source = evt.getSource(); // if (source == cb1) { // boolean newState = ((JCheckBox)cb1).getSelected(); // ... // respond to the change of state // } // else if (source == cb2) { // boolean newState = ((JCheckBox)cb2).getSelected(); // ... // respond to the change of state // } // } // public void mousePressed(MouseEvent evt) { // // React when user presses the mouse by // // starting or stopping the timer. // if (running == false) { // // Record the time and start the timer. // running = true; // startTime = evt.getWhen(); // Time when mouse was clicked. // setText("Timing...."); // } // else { // // Stop the timer. Compute the elapsed time since the // // timer was started and display it. // running = false; // long endTime = evt.getWhen(); // double seconds = (endTime - startTime) / 1000.0; // setText("Time: " + seconds + " sec."); // } // } // // public void mouseReleased(MouseEvent evt) { } // public void mouseClicked(MouseEvent evt) { } // public void mouseEntered(MouseEvent evt) { } // public void mouseExited(MouseEvent evt) { } //--------------------------------------------------------------------------------------------------