// // AstDisplay // // General purpose Display for Zap Channels // // 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.awt.image.*; import java.net.*; import java.applet.*; import java.util.Date; import java.util.Timer; import java.util.TimerTask; import java.util.Calendar; import java.util.Vector; import java.util.ArrayList; import java.util.Iterator; import java.util.Collections; import java.util.Locale; import java.util.ResourceBundle; import java.util.NoSuchElementException; import java.text.SimpleDateFormat; import java.util.GregorianCalendar; import java.lang.String; import java.lang.Object; import javax.imageio.*; import javax.swing.*; import javax.swing.JComponent; import javax.swing.ImageIcon; import javax.swing.border.*; public class AstDisplay extends java.applet.Applet implements ActionListener, Runnable { boolean keepTrying = true; public static final String daVersion = "v0.3.9"; public boolean debugMode = false; public boolean testMode = false; public int DEBUG_HEIGHT = 4; public int DEBUG_WIDTH = 100; public int ZAP_CHANS = 120; public int calls_this_run = 0; public String slang = "english"; public String language; public String country; Locale currentLocale; ResourceBundle configinfo; String message, message2, disposition, transfer, campaign, leadid, channel; String tmpAgent, tmpName, tmpStatus, tmpChannel, tmpChan, tmpState, tmpExten, tmpAlarm, s2; String tmpZap, tmpZap1, tmpZap2, tmpClid, tmpClid1, tmpClid2, tmpStuff; String tmpChan1, tmpChan2, tmpChannel1, tmpChannel2, tmpCallerid1, tmpCallerid2; String tmpTech, tmpDev, tmpOccur, tmpLds, tmpReason, tmpReasonStr; String tmpButton, tmpQueue; boolean isLinked, isPaused; int tmpIndex; Frame frame1; Toolkit toolkit; TextField text; TextArea debug_message, lds, bogus, OS_message, OF_message, CI_message; int DEBUG_COUNT, OS_count, OF_count, number_count, CI_count = 0; int DEBUG_count_limit, OS_count_limit, OF_count_limit, number_count_limit, CI_count_limit = 100; int SCREEN_res_x = 980, SCREEN_res_y = 550, FONT_size = 12; int screenSizeHeight = 1024, screenSizeWidth = 768; boolean FONT_size_override = false; int port; Timer timer; javax.swing.Timer m_t; long startTime; // Start time of timer. long stopTime; // Stop time of timer. Thread astThread; //Button callback = new Button("0 Callback"); ArrayList list,aList,zList,sList,iList,qList; Label[] labels; Label[] labelss; Label[] clrids; Label[] states; Label[] agents; Label[] queues; StopWatch[] timers; SimpleDateFormat format; Panel main_panel; Panel zap_panel; Panel msg_panel; Panel agt_panel; Panel que_panel; Button button; GridLayout grid, msg, agt, que; GridBagLayout grid2, mess; Container container; public void init() { // frame1 = new Frame(); // frame1.setSize(500,500); container = new Container(); // if (slang.equalsIgnoreCase("spanish")) { // language = new String("es"); // country = new String("US"); // } else { language = new String("en"); country = new String("US"); // } currentLocale = new Locale(language, country); configinfo = ResourceBundle.getBundle("AstDisplay",currentLocale); debugMode = Boolean.valueOf( configinfo.getString("debugMode") ).booleanValue(); testMode = Boolean.valueOf( configinfo.getString("testMode") ).booleanValue(); DEBUG_HEIGHT = Integer.valueOf( configinfo.getString("DEBUG_HEIGHT") ).intValue(); DEBUG_WIDTH = Integer.valueOf( configinfo.getString("DEBUG_WIDTH") ).intValue(); //ZAP_CHANS = Integer.valueOf( configinfo.getString("ZAP_CHANS") ).intValue(); DEBUG_count_limit = Integer.valueOf( configinfo.getString("DEBUG_count_limit") ).intValue(); OS_count_limit = Integer.valueOf( configinfo.getString("OS_count_limit") ).intValue(); OF_count_limit = Integer.valueOf( configinfo.getString("OF_count_limit") ).intValue(); SCREEN_res_x = Integer.valueOf( configinfo.getString("SCREEN_res_x") ).intValue(); SCREEN_res_y = Integer.valueOf( configinfo.getString("SCREEN_res_y") ).intValue(); FONT_size_override = Boolean.valueOf( configinfo.getString("FONT_size_override") ).booleanValue(); FONT_size = Integer.valueOf( configinfo.getString("FONT_size") ).intValue(); if (!FONT_size_override) { toolkit = java . awt . Toolkit . getDefaultToolkit (); screenSizeHeight = Toolkit.getDefaultToolkit().getScreenSize().height; screenSizeWidth = Toolkit.getDefaultToolkit().getScreenSize().width; if (screenSizeHeight == 480) { FONT_size = 10; } if (screenSizeHeight == 768) { FONT_size = 12; } if (screenSizeHeight == 1024) { FONT_size = 14; } if (screenSizeHeight >= 1200) { FONT_size = 16; } } String message_connect = configinfo.getString("message_connect"); String message_retry = configinfo.getString("message_retry"); Button callback = new Button(configinfo.getString("callback")); Button noanswer = new Button(configinfo.getString("noanswer")); //container = new Container(); resize(SCREEN_res_x,SCREEN_res_y); setForeground( java.awt.Color.black ); setBackground( java.awt.Color.white ); setFont( new Font("Tacoma", Font.PLAIN, FONT_size) ); setLayout(new BorderLayout()); aList = new ArrayList(); zList = new ArrayList(); sList = new ArrayList(); iList = new ArrayList(); qList = new ArrayList(); main_panel = new Panel(); zap_panel = new Panel(); msg_panel = new Panel(); agt_panel = new Panel(); que_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]; timers = new StopWatch[ZAP_CHANS+1]; GridBagConstraints g = new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(35, 73, 0, 0), 0, 0); g.fill = GridBagConstraints.HORIZONTAL; grid = new GridLayout(ZAP_CHANS/4,ZAP_CHANS/4*4,1,1); zap_panel.setLayout(grid); ImageIcon icon = createImageIcon("images/middle.gif"); g.weightx = 0.0; g.weighty = 1.0; g.gridheight = 1; g.gridwidth = 1; // g.gridx = 0; // g.gridy = 0; for ( int zidx = 0; zidx < ZAP_CHANS+1; zidx++ ) { zList.add(zidx,new String("unused")); } for ( int ridx = 1; ridx < ZAP_CHANS/4+1; ridx++ ) { int tc = 0; for ( int cidx = 0; cidx < 4; cidx++ ) { timers[ridx+tc] = new StopWatch(); timers[ridx+tc].start(); labels[ridx+tc] = new Label("unused"); clrids[ridx+tc] = new Label("-"); states[ridx+tc] = new Label("-"); agents[ridx+tc] = new Label("-"); zap_panel.add(labels[ridx+tc]); // zap_panel.add(agents[ridx+tc]); zap_panel.add(clrids[ridx+tc]); zap_panel.add(states[ridx+tc]); tc = tc + 30; } } System.out.println(zList.size()); // this section works only if you only use iter.next() once. // int counter = 0; // for (Iterator iter = zList.iterator(); iter.hasNext();) { // System.out.println(counter+": "+iter.next()); // counter++; // } // String daChannel = "Zap/23"; // if (zList.contains(daChannel)) { // int zFIndex = zList.indexOf(daChannel); // int zLIndex = zList.lastIndexOf(daChannel); // System.out.println("first occurance: "+zFIndex ); // System.out.println(" last occurance: "+zLIndex ); // } // for ( int i = 0; i < zList.size(); i++ ) { // if (zList.get(i).toString().equals(daChannel)) { // System.out.println ("bingo"); // } // } debug_message = new TextArea("",((debugMode) ? (DEBUG_HEIGHT * 3) : DEBUG_HEIGHT),DEBUG_WIDTH); debug_message.setFont(new Font("SansSerif", Font.PLAIN, FONT_size)); debug_message.setEditable(false); lds = new TextArea("",((debugMode) ? (DEBUG_HEIGHT * 3) : DEBUG_HEIGHT),DEBUG_WIDTH); lds.setFont(new Font("SansSerif", Font.PLAIN, FONT_size)); lds.setEditable(false); bogus = new TextArea("",((debugMode) ? (DEBUG_HEIGHT * 3) : DEBUG_HEIGHT),DEBUG_WIDTH); bogus.setFont(new Font("SansSerif", Font.PLAIN, FONT_size)); bogus.setEditable(false); OS_message = new TextArea("",((debugMode) ? (DEBUG_HEIGHT * 3) : DEBUG_HEIGHT),DEBUG_WIDTH); OS_message.setFont(new Font("SansSerif", Font.PLAIN, FONT_size)); 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, FONT_size)); 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, FONT_size)); CI_message.setBackground(Color.yellow); 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); list = new ArrayList(); agt = new GridLayout(4,4,1,1); agt_panel.setLayout(agt); que = new GridLayout(4,4,1,1); que_panel.setLayout(que); add(zap_panel, BorderLayout.CENTER); add(msg_panel, BorderLayout.NORTH); setVisible(true); astThread = new Thread(this); astThread.start(); } void addFrame(String name, int height, int width, boolean visable) { JFrame frame = new JFrame(name); //frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container c = frame.getContentPane(); //c.setLayout(new FlowLayout(FlowLayout.CENTER, 3, 3)); c.setLayout(new FlowLayout(FlowLayout.LEFT)); labelss = new Label[ZAP_CHANS+1]; for (int i=0;i 0) { 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[zFIndex].setBackground(Color.white); } else if (tmpState.equals("Rsrvd")) { states[zFIndex].setBackground(Color.yellow); } else if (tmpState.equals("Offhook")) { states[zFIndex].setBackground(Color.yellow); } else if (tmpState.equals("Dialing")) { states[zFIndex].setBackground(Color.yellow); } else if (tmpState.equals("Ring")) { states[zFIndex].setBackground(Color.pink); } else if (tmpState.equals("Ringing")) { states[zFIndex].setBackground(Color.pink); } else if (tmpState.equals("Up")) { states[zFIndex].setBackground(Color.green); } else if (tmpState.equals("Busy")) { states[zFIndex].setBackground(Color.blue); } else if (tmpState.equals("Mute")) { states[zFIndex].setBackground(Color.cyan); } else if (tmpState.equals("Prering")) { states[zFIndex].setBackground(Color.yellow); } else { //tmpState = ""; states[zFIndex].setBackground(Color.white); } //states[zFIndex].setText(tmpState+" "+Long.toString(timers[zFIndex].getElapsedTime()/1000)); states[zFIndex].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); if (tmpClid.equals("") || tmpClid.equals("")) { //do nothing } else { clrids[zFIndex].setText(tmpClid); } } } } writeDebug("Rx - Event: Newstate - " + fullChannelName + " " + tmpState); //repaint(); } if (block.indexOf("Event: Newchannel") != -1 && block.indexOf("Channel:") != -1) { String fullChannelName = ""; int zFIndex = 0; if (block.indexOf("Channel: ") != -1) { pos = block.indexOf("Channel: "); end = block.indexOf("\n",pos); tmpChannel = block.substring(pos+9,end); tmpChan = strip2dash(tmpChannel); // if (tmpChan.indexOf("Agent/") != -1) { tmpChan = stripAgent(tmpChan); { fullChannelName = new String(tmpChan); } if (fullChannelName.indexOf("Agent/") != -1) { String tmpAgentChan = stripAgent(fullChannelName); System.out.println(fullChannelName+" "+tmpAgentChan); tmpIndex = 0; for ( int lidx = 1; lidx < labels.length; lidx++ ) { if (agents[lidx].getText().equals(tmpAgentChan)) { tmpIndex = lidx; } } if (tmpIndex > 0) { //fullChannelName = labels[tmpIndex].getText(); //zList.get(i).toString().equals(daChannel)) { fullChannelName = zList.get(tmpIndex).toString(); } System.out.println(fullChannelName); } //} else { if (zList.contains(fullChannelName)) { zFIndex = zList.indexOf(fullChannelName); } else { if (fullChannelName.indexOf("Agent/") != -1) { //do nothing for now } else { //find next unused, and add to list zFIndex = zList.lastIndexOf("unused"); zList.set( zFIndex, fullChannelName); labels[zFIndex].setBackground(Color.white); labels[zFIndex].setText(fullChannelName); repaint(); } } if (zFIndex > 0) { // timers[zFIndex].reset(); // timers[zFIndex].start(); 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[zFIndex].setBackground(Color.white); } else if (tmpState.equals("Rsrvd")) { states[zFIndex].setBackground(Color.yellow); } else if (tmpState.equals("Offhook")) { states[zFIndex].setBackground(Color.yellow); } else if (tmpState.equals("Dialing")) { states[zFIndex].setBackground(Color.yellow); } else if (tmpState.equals("Ring")) { states[zFIndex].setBackground(Color.pink); } else if (tmpState.equals("Ringing")) { states[zFIndex].setBackground(Color.pink); } else if (tmpState.equals("Up")) { states[zFIndex].setBackground(Color.green); } else if (tmpState.equals("Busy")) { states[zFIndex].setBackground(Color.blue); } else if (tmpState.equals("Mute")) { states[zFIndex].setBackground(Color.cyan); } else if (tmpState.equals("Prering")) { states[zFIndex].setBackground(Color.yellow); } else { tmpState = ""; states[zFIndex].setBackground(Color.white); } //states[zFIndex].setText(tmpState+" "+Long.toString(timers[zFIndex].getElapsedTime()/1000)); states[zFIndex].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); if (tmpClid.equals("") || tmpClid.equals("")) { //do nothing } else { clrids[zFIndex].setText(tmpClid); } } } //} writeDebug("Rx - Event: Newstate - " + fullChannelName + " " + tmpState); //repaint(); } if (block.indexOf("Event: Newcallerid") != -1 && block.indexOf("Channel:") != -1) { String fullChannelName = ""; if (block.indexOf("Channel: ") != -1) { pos = block.indexOf("Channel: "); end = block.indexOf("\n",pos); tmpChannel = block.substring(pos+9,end); tmpChan = strip2dash(tmpChannel); // if (tmpChan.indexOf("Agent/") != -1) { tmpChan = stripAgent(tmpChan); } fullChannelName = new String(tmpChan); } if (zList.contains(fullChannelName)) { int zFIndex = zList.indexOf(fullChannelName); if (zFIndex > 0) { int zLIndex = zList.lastIndexOf(fullChannelName); if (block.indexOf("CallerID: ") != -1) { pos = block.indexOf("CallerID: "); end = block.indexOf("\n",pos); tmpClid = block.substring(pos+10,end); tmpClid = strip91(tmpClid); if (tmpClid.equals("") || tmpClid.equals("")) { //do nothing } else { clrids[zFIndex].setText(tmpClid); } } } } writeDebug("Rx - Event: Newcallerid - " + fullChannelName + " " + tmpClid); //repaint(); } if (block.indexOf("Event: Newexten") != -1 && block.indexOf("Channel:") != -1) { String fullChannelName = ""; if (block.indexOf("Channel: ") != -1) { pos = block.indexOf("Channel: "); end = block.indexOf("\n",pos); tmpChannel = block.substring(pos+9,end); tmpChan = strip2dash(tmpChannel); // if (tmpChan.indexOf("Agent/") != -1) { tmpChan = stripAgent(tmpChan); } fullChannelName = new String(tmpChan); } 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 { if (zList.contains(fullChannelName)) { int zFIndex = zList.indexOf(fullChannelName); if (zFIndex > 0) { int zLIndex = zList.lastIndexOf(fullChannelName); //labels[zFIndex].setBackground(Color.white); labels[zFIndex].setText(fullChannelName+" - "+tmpState); //labels[zFIndex].setText(fullChannelName); if (tmpState.equals("699")) { labels[zFIndex].setBackground(Color.magenta); } //states[zFIndex].setText(Long.toString(timers[zFIndex].getElapsedTime()/1000)); //states[zFIndex].setBackground(Color.white); //states[zFIndex].setText("-"); //clrids[zFIndex].setText("-"); //agents[zFIndex].setText("-"); } } } writeDebug("Rx - Event: Newexten - " + fullChannelName); //repaint(); } //********************************************************************************** // //********************************************************************************** if (block.indexOf("Event: Hangup") != -1 && block.indexOf("Channel:") != -1) { String fullChannelName = ""; if (block.indexOf("Channel: ") != -1) { pos = block.indexOf("Channel: "); end = block.indexOf("\n",pos); tmpChannel = block.substring(pos+9,end); tmpChan = strip2dash(tmpChannel); // if (tmpChan.indexOf("Agent/") != -1) { tmpChan = stripAgent(tmpChan); } fullChannelName = new String(tmpChan); //zList.set( Integer.valueOf( tmpZap ).intValue(), fullChannelName); if (zList.contains(fullChannelName)) { int zFIndex = zList.indexOf(fullChannelName); if (zFIndex > 0) { labels[zFIndex].setBackground(Color.white); labels[zFIndex].setText(fullChannelName); states[zFIndex].setBackground(Color.white); //states[zFIndex].setText(Long.toString(timers[zFIndex].getElapsedTime()/1000)); states[zFIndex].setText("-"); clrids[zFIndex].setText("-"); agents[zFIndex].setText("-"); } } } writeDebug("Rx - Event: Hangup - " + fullChannelName); //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) { String fullChannelName = ""; if (block.indexOf("Channel: ") != -1) { pos = block.indexOf("Channel: "); end = block.indexOf("\n",pos); tmpChannel = block.substring(pos+9,end); fullChannelName = new String("Zap/"+tmpChannel); zList.set( Integer.valueOf( tmpChannel ).intValue(), fullChannelName); //System.out.println((String)(zList.get(Integer.valueOf( tmpChannel ).intValue()))); if (zList.contains(fullChannelName)) { int zFIndex = zList.indexOf(fullChannelName); if (zFIndex > 0) { int zLIndex = zList.lastIndexOf(fullChannelName); labels[zFIndex].setBackground(Color.white); labels[zFIndex].setText(fullChannelName); } } //System.out.println((String)(zList.get(Integer.valueOf( tmpChannel ).intValue()))); //zList.get( Integer.valueOf( tmpChannel ), new String("Zap/"+tmpChannel) ); //System.out.println (zList.get(Integer.valueOf( tmpChannel ) )); } if (block.indexOf("Alarm: ") != -1) { pos = block.indexOf("Alarm: "); end = block.indexOf("\n",pos); tmpAlarm = block.substring(pos+7,end); if (tmpAlarm.equals("Unknown Alarm") ||tmpAlarm.equals("Red Alarm") || tmpAlarm.equals("Yellow Alarm") || tmpAlarm.equals("Blue Alarm") || tmpAlarm.equals("Recovering") || tmpAlarm.equals("Loopback")) { if (zList.contains(fullChannelName)) { int zFIndex = zList.indexOf(fullChannelName); if (zFIndex > 0) { states[zFIndex].setBackground(Color.LIGHT_GRAY); states[zFIndex].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) { calls_this_run++; 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) { calls_this_run++; 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 //action: status //Response: Success //Message: Channel status will follow //Event: StatusComplete if (block.indexOf("Event: Status\n") != -1) { String fullChannelName = ""; String tmpExten = ""; int zFIndex = 0; if (block.indexOf("Channel: ") != -1) { pos = block.indexOf("Channel: "); end = block.indexOf("\n",pos); tmpChannel = block.substring(pos+9,end); tmpChan = strip2dash(tmpChannel); // if (tmpChan.indexOf("Agent/") != -1) { tmpChan = stripAgent(tmpChan); } fullChannelName = new String(tmpChan); } if (zList.contains(fullChannelName)) { zFIndex = zList.indexOf(fullChannelName); } else { if (fullChannelName.indexOf("Agent/") != -1) { //do nothing for now } else { //find next unused, and add to list if (fullChannelName != null) { zFIndex = zList.lastIndexOf("unused"); zList.set( zFIndex, fullChannelName); labels[zFIndex].setBackground(Color.white); labels[zFIndex].setText(fullChannelName); repaint(); } } } //int zFIndex = zList.indexOf(fullChannelName); if (zFIndex > 0) { 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[zFIndex].setBackground(Color.white); } else if (tmpState.equals("Rsrvd")) { states[zFIndex].setBackground(Color.yellow); } else if (tmpState.equals("Offhook")) { states[zFIndex].setBackground(Color.yellow); } else if (tmpState.equals("Dialing")) { states[zFIndex].setBackground(Color.yellow); } else if (tmpState.equals("Ring")) { states[zFIndex].setBackground(Color.pink); } else if (tmpState.equals("Ringing")) { states[zFIndex].setBackground(Color.pink); } else if (tmpState.equals("Up")) { states[zFIndex].setBackground(Color.green); } else if (tmpState.equals("Busy")) { states[zFIndex].setBackground(Color.blue); } else if (tmpState.equals("Mute")) { states[zFIndex].setBackground(Color.cyan); } else if (tmpState.equals("Prering")) { states[zFIndex].setBackground(Color.yellow); } else { tmpState = ""; states[zFIndex].setBackground(Color.white); } states[zFIndex].setText(tmpState); } if (block.indexOf("Extension: ") != -1) { pos = block.indexOf("Extension: "); end = block.indexOf("\n",pos); tmpExten = block.substring(pos+11,end); tmpExten = strip91(tmpExten); labels[zFIndex].setText(fullChannelName+" - "+tmpExten); } //} } writeDebug("Rx - Event: Status - " + fullChannelName + " " + 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) { 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); } String fullChannelName = ""; if (block.indexOf("LoggedInChan: ") != -1) { pos = block.indexOf("LoggedInChan: "); end = block.indexOf("\n",pos); tmpChannel = block.substring(pos+14,end); tmpChan = strip2dash(tmpChannel); // if (tmpChan.indexOf("Agent/") != -1) { tmpChan = stripAgent(tmpChan); } fullChannelName = new String(tmpChan); if (zList.contains(fullChannelName)) { int zFIndex = zList.indexOf(fullChannelName); if (zFIndex > 0) { labels[zFIndex].setBackground(Color.cyan); agents[zFIndex].setText(tmpAgent); labels[zFIndex].setText(fullChannelName+" - "+tmpAgent); } } } writeDebug("Rx - Event: Agents - " + fullChannelName + " " + tmpAgent + " " + tmpName + " " + tmpStatus); //repaint(); } if (testMode && block.indexOf("Event: Agents") != -1 && block.indexOf("Agent:") != -1) { if (block.indexOf("Agent: ") != -1) { pos = block.indexOf("Agent: "); end = block.indexOf("\n",pos); tmpAgent = block.substring(pos+7,end); aList.add(new String(tmpAgent)); } if (block.indexOf("Name: ") != -1) { pos = block.indexOf("Name: "); end = block.indexOf("\n",pos); tmpName = block.substring(pos+6,end); } writeDebug("Rx - Event: Agents - " + tmpAgent + " " + tmpName); //repaint(); } if (testMode && block.indexOf("Event: QueueParams") != -1 && block.indexOf("Queue:") != -1) { if (block.indexOf("Queue: ") != -1) { pos = block.indexOf("Queue: "); end = block.indexOf("\n",pos); tmpQueue = block.substring(pos+7,end); } qList.add(new String("Queue/"+tmpAgent)); writeDebug("Rx - Event: QueueParams - " + tmpQueue); //repaint(); } if (block.indexOf("Event: ManagerUserEvent") != -1 && block.indexOf("Event: CampaignInfo") != -1) { if (block.indexOf("Body: ") != -1) { pos = block.indexOf("Body: "); end = block.indexOf("\n",pos); tmpStuff = block.substring(pos+6,end); writeCIMessage(tmpStuff); } writeDebug("Rx - Event: CampaignInfo - " + tmpStuff); //repaint(); } //action: ping //Response: Pong if (block.indexOf("Response: Pong") != -1) { writeDebug("Rx - Event: Pong"); //repaint(); } if (block.indexOf("Event: Link") != -1) { String fullChannelName1 = ""; String fullChannelName2 = ""; if (block.indexOf("Channel1: ") != -1) { pos = block.indexOf("Channel1: "); end = block.indexOf("\n",pos); tmpChannel1 = block.substring(pos+10,end); tmpChan1 = strip2dash(tmpChannel1); if (tmpChan1.indexOf("Agent/") != -1) { tmpChan1 = stripAgent(tmpChan1); } fullChannelName1 = new String(tmpChan1); } if (block.indexOf("Channel2: ") != -1) { pos = block.indexOf("Channel2: "); end = block.indexOf("\n",pos); tmpChannel2 = block.substring(pos+10,end); tmpChan2 = strip2dash(tmpChannel2); if (tmpChan2.indexOf("Agent/") != -1) { tmpChan2 = stripAgent(tmpChan2); } fullChannelName2 = new String(tmpChan2); } if (zList.contains(fullChannelName2)) { int zFIndex2 = zList.indexOf(fullChannelName2); if (zFIndex2 > 0) { labels[zFIndex2].setBackground(Color.pink); //agents[zFIndex2].setText(tmpChan1); labels[zFIndex2].setText(fullChannelName2+" - "+fullChannelName1); tmpClid = clrids[zFIndex2].getText(); } } // fudge Agent channels tmpIndex = 0; for ( int lidx = 1; lidx < labels.length; lidx++ ) { if (agents[lidx].getText().equals(tmpChan2)) { tmpIndex = lidx; } } if (tmpIndex > 0) { labels[tmpIndex].setBackground(Color.pink); //agents[zFIndex2].setText(tmpAgent); //labels[tmpIndex].setText(fullChannelName2+" - "+fullChannelName1); clrids[tmpIndex].setText(tmpClid); } if (zList.contains(fullChannelName1)) { int zFIndex1 = zList.indexOf(fullChannelName1); if (zFIndex1 > 0) { labels[zFIndex1].setBackground(Color.pink); //agents[zFIndex1].setText(tmpAgent); labels[zFIndex1].setText(fullChannelName1+" - "+fullChannelName2); clrids[zFIndex1].setText(tmpClid); } } writeDebug("Rx - Event: Link - " + tmpChan1 + " " + tmpChan2 + " " + fullChannelName1 + " " + fullChannelName2); //repaint(); } if (block.indexOf("Event: Unlink") != -1) { String fullChannelName1 = ""; String fullChannelName2 = ""; if (block.indexOf("Channel1: ") != -1) { pos = block.indexOf("Channel1: "); end = block.indexOf("\n",pos); tmpChannel1 = block.substring(pos+10,end); tmpChan1 = strip2dash(tmpChannel1); if (tmpChan1.indexOf("Agent/") != -1) { tmpChan1 = stripAgent(tmpChan1); } fullChannelName1 = new String(tmpChan1); } if (block.indexOf("Channel2: ") != -1) { pos = block.indexOf("Channel2: "); end = block.indexOf("\n",pos); tmpChannel2 = block.substring(pos+10,end); tmpChan2 = strip2dash(tmpChannel2); if (tmpChan2.indexOf("Agent/") != -1) { tmpChan2 = stripAgent(tmpChan2); } fullChannelName2 = new String(tmpChan2); } if (zList.contains(fullChannelName1)) { int zFIndex1 = zList.indexOf(fullChannelName1); if (zFIndex1 > 0) { labels[zFIndex1].setBackground(Color.white); //agents[zFIndex1].setText(tmpChan1); labels[zFIndex1].setText(fullChannelName1); clrids[zFIndex1].setText("-"); } } // fudge Agent channels tmpIndex = 0; for ( int lidx = 1; lidx < labels.length; lidx++ ) { if (agents[lidx].getText().equals(tmpChan2)) { tmpIndex = lidx; } } if (tmpIndex > 0) { labels[tmpIndex].setBackground(Color.cyan); //agents[zFIndex2].setText(tmpAgent); //labels[tmpIndex].setText(fullChannelName2+" - "+fullChannelName1); clrids[tmpIndex].setText("-"); } if (zList.contains(fullChannelName2)) { int zFIndex2 = zList.indexOf(fullChannelName2); if (zFIndex2 > 0) { labels[zFIndex2].setBackground(Color.white); //agents[zFIndex2].setText(tmpAgent); labels[zFIndex2].setText(fullChannelName2); clrids[zFIndex2].setText("-"); } } writeDebug("Rx - Event: Unlink - " + tmpChan1 + " " + tmpChan2 + " " + fullChannelName1 + " " + fullChannelName2); //repaint(); } //Event: Agentlogin //Privilege: agent,all //Agent: 300 //Channel: IAX2/pchammer-2 //Uniqueid: 1165938396.10152 if (block.indexOf("Event: Agentlogin") != -1 && block.indexOf("Agent:") != -1) { if (block.indexOf("Agent: ") != -1) { pos = block.indexOf("Agent: "); end = block.indexOf("\n",pos); tmpAgent = block.substring(pos+7,end); } String fullChannelName = ""; if (block.indexOf("Channel: ") != -1) { pos = block.indexOf("Channel: "); end = block.indexOf("\n",pos); tmpChannel = block.substring(pos+9,end); tmpChan = strip2dash(tmpChannel); // if (tmpChan.indexOf("Agent/") != -1) { tmpChan = stripAgent(tmpChan); } fullChannelName = new String(tmpChan); } if (zList.contains(fullChannelName)) { int zFIndex = zList.indexOf(fullChannelName); if (zFIndex > 0) { labels[zFIndex].setBackground(Color.cyan); agents[zFIndex].setText(tmpAgent); labels[zFIndex].setText(fullChannelName+" - "+tmpAgent); } } writeDebug("Rx - Event: Agentlogin - " + tmpAgent + " " + fullChannelName); //repaint(); } //Event: Agentlogoff //Privilege: agent,all //Agent: 300 //Logintime: 20 //Uniqueid: 1165938396.10152 if (block.indexOf("Event: Agentlogoff") != -1 && block.indexOf("Agent:") != -1) { if (block.indexOf("Agent: ") != -1) { pos = block.indexOf("Agent: "); end = block.indexOf("\n",pos); tmpAgent = block.substring(pos+7,end); } String fullChannelName = ""; if (block.indexOf("Channel: ") != -1) { pos = block.indexOf("Channel: "); end = block.indexOf("\n",pos); tmpChannel = block.substring(pos+9,end); tmpChan = strip2dash(tmpChannel); // if (tmpChan.indexOf("Agent/") != -1) { tmpChan = stripAgent(tmpChan); } fullChannelName = new String(tmpChan); } if (zList.contains(fullChannelName)) { int zFIndex = zList.indexOf(fullChannelName); if (zFIndex > 0) { int zLIndex = zList.lastIndexOf(fullChannelName); labels[zFIndex].setBackground(Color.white); agents[zFIndex].setText(""); labels[zFIndex].setText(fullChannelName); } } writeDebug("Rx - Event: Agentlogoff - " + tmpAgent + " " + fullChannelName); //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); } block = ""; repaint(); } } 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 static String strip2dash(String before) { //System.err.println("before - " + before); if (before.indexOf("-") != -1) return before.substring(0,before.indexOf("-")); return before; } public static String stripAgent(String before) { //System.err.println("before - " + before); if (before.indexOf("Agent/") != -1) return before.substring(before.indexOf("Agent/")+6,before.length()); return before; } public void writeDebug(String daMessage) { if (DEBUG_COUNT > DEBUG_count_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 > OS_count_limit) { OS_count = 0; OS_message.setText(""); } OS_message.append(daOSNumber+" ("+calls_this_run+")\n"); OS_count++; } public void writeOFMessage(String daOFNumber) { if (OF_count > OF_count_limit) { OF_count = 0; OF_message.setText(""); } OF_message.append(daOFNumber+" ("+calls_this_run+")\n"); OF_count++; } public void writeCIMessage(String daStats) { if (CI_count > CI_count_limit) { CI_count = 0; CI_message.setText(""); } CI_message.append(daStats+ "\n"); CI_count++; } public void writeScreenShot() { try { Robot robot = new Robot(); BufferedImage screenShot = robot.createScreenCapture(new Rectangle(Toolkit.getDefaultToolkit().getScreenSize())); ImageIO.write(screenShot, "JPG", new File("screenShot.jpg")); } catch (AWTException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } /** Returns an ImageIcon, or null if the path was invalid. */ protected static ImageIcon createImageIcon(String path) { java.net.URL imgURL = TabbedPaneDemo.class.getResource(path); if (imgURL != null) { return new ImageIcon(imgURL); } else { System.err.println("Couldn't find file: " + path); return null; } } public static URL String2Url(String theString) { URL theUrl = null; try { theUrl = new URL(theString); return theUrl; } catch (Exception e) {} return theUrl; } }