forum.bitel.ru http://forum.bitel.ru/ |
|
Отладка скриптового шлюза http://forum.bitel.ru/viewtopic.php?f=7&t=3906 |
Страница 1 из 1 |
Автор: | skyb [ 16 апр 2010, 05:43 ] |
Заголовок сообщения: | Отладка скриптового шлюза |
взял за основу http://wiki.bgbilling.ru/index.php/%D0% ... 1%8B%D1%85 шлюз. Переделал(правда не я) его до состояния что команды можно писать в правилах. Только теперь, хотя как и раньше, такое ощущение что команды вообще не выполняются. и не ругаются не на че ![]() вот скрип переделанный Код: import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.StringTokenizer; import java.util.regex.Matcher; import java.util.regex.Pattern; import bitel.billing.common.IPUtils; import bitel.billing.common.module.ipn.IPNContractStatus; import bitel.billing.server.ipn.UserStatus; import bitel.billing.server.ipn.bean.ManadUtils; import bitel.billing.server.ipn.bean.VlanManager; import bitel.billing.server.ipn.dlink.UserPortStatus; import bitel.billing.server.util.DefaultServerSetup; import bitel.billing.server.util.Utils; import bitel.billing.server.util.telnet.OperationTimedoutException; import bitel.billing.server.util.telnet.TelnetSession; /* protected void doSync(){ log.info( "script started" ); }; */ protected void doSync(){ log.info( "script started" ); try { log.info( "script started 1" ); host = gate.getHost(); port = gate.getPort(); DefaultServerSetup gateSetup = new DefaultServerSetup( gate.getConfig(), "\r\n" ); pswd = gate.getKeyword(); login = gateSetup.getStringValue( "login"); result = new StringBuffer(); if( log.isDebugEnabled() ) { log.info( gate.getId() + " gate: " + host + ":" + port + " login: " + login + " pswd: " + pswd ); } TelnetSession session = new TelnetSession( host, port); session.setLoginPromptSequence( ":" ); log.info( "before connect" ); session.connect(); log.info( "after connect" ); result.append( session.doCommand( login ) ); log.info( "after command" ); session.setLoginPromptSequence( "#" ); result.append( session.doCommand( pswd ) ); log.info( "before pswd" ); log.info( "execute commands" ); doCommands( session, result, gateSetup); //TODO commands here session.setLoginPromptSequence( "****" ); result.append( session.doCommand( "logout" ) ); log.info( result.toString() ); log.info( "ok" ); } catch (Exception e) { throw new RuntimeException ( e ); } }; getOpenRules( status) { return getRules( status, "\\[OPEN\\](.*)\\[/OPEN\\]" ); } getCloseRules( status ) { return getRules( status, "\\[CLOSE\\](.*)\\[/CLOSE\\]" ); } getRemoveRules( status ) { return getRules( status, "\\[REMOVE\\](.*)\\[/REMOVE\\]" ); } getRules( status, template ) { // пользовательское правило, без типа - то все оставляем как есть rule = status.rule.getRuleText(); log.info("rule=" + rule); //типизированное правило if( status.ruleType != null ) { rule = generateRule( rule, status.gateType, status.ruleType ); } log.info("rule=" + rule); pattern = Pattern.compile( template, Pattern.DOTALL ); m = pattern.matcher( rule ); if (m.find()) { rule = m.group( 1 ); } rule.replaceAll( "\r", "" ); parts = rule.split( "\n" ); result = new ArrayList(); for ( String part : parts ) { if ( !Utils.isEmptyString( part )) { result.add( part ); } } String [] resultStr = new String [ result.size() ]; for ( int i = 0; i < resultStr.length; i++ ) { resultStr [i] = result.get( i ); } return resultStr; } generateRule( addresses, gateType, ruleType ) { ruleText = ManadUtils.getRule( gateType, ruleType ); replacements = new HashMap(); loops = new ArrayList(); return ManadUtils.generateRule( ruleText, replacements, ruleType, loops ); } public List getUserList( List statusList ) { List userList = new ArrayList(); for( UserStatus status : statusList ) { String rule = status.rule.getRuleText(); StringTokenizer st = new StringTokenizer( rule, ";" ); while( st.hasMoreTokens() ) { String token = st.nextToken().trim(); data = token.split( ":" ); if( data.length == 2 ) { UserPortStatus portStatus = new UserPortStatus(); portStatus.port = Utils.parseIntString( data[0] ); portStatus.ipAddr = data[1]; portStatus.status = status; userList.add( portStatus ); } else if ( data.length == 3 ) { UserPortStatus portStatus = new UserPortStatus(); portStatus.port = Utils.parseIntString( data[0] ); portStatus.macAddr = data[1].toUpperCase().replaceAll( "\\-", " " ); portStatus.ipAddr = data[2]; portStatus.status = status; userList.add( portStatus ); } } } return userList; } private void doCommands( TelnetSession session, StringBuffer result, DefaultServerSetup gateSetup) throws IOException, OperationTimedoutException { ports = getUserList( statusList ); openAddress = gateSetup.getStringValue( "open.address", "255.255.255.255" ) ; log.info( "openAddress = " + openAddress ); uplinks = Utils.stringToIntegerList( gateSetup.getStringValue( "uplink" ) ); int j=1; for( UserPortStatus port : ports ) { OpenRules = getOpenRules( port.status ); CloseRules = getCloseRules ( port.status ); RemoveRules = getRemoveRules ( port.status ); { log.info("port.ipAddr=" + port.ipAddr); switch (port.status.status) { case IPNContractStatus.STATUS_OPEN: ApplyRules = OpenRules; log.info("open_user"); break; case IPNContractStatus.STATUS_REMOVED: ApplyRules = RemoveRules; log.info("remove_user"); break; default: ApplyRules = CloseRules; log.info("close_user"); break; }; for (i = 0; i < ApplyRules.length; i++){ // for (String proto_rule : ApplyRules){ ip_hex=Convert2hex(port.ipAddr); rule=setValues(ApplyRules[i], port.port, port.ipAddr, openAddress, ip_hex , j); log.info("rule=" + rule); result.append( session.doCommand( rule ) ); } j=j+1; } }; private String setValues( String rule, int port, String ip, String openAddress, String ip_hex , int mod) { aid=26*mod+port; rule = rule.replaceAll( "\\$\\{port\\}", String.valueOf( port ) ); rule = rule.replaceAll( "\\$\\{ip\\}" , ip ); rule = rule.replaceAll( "\\$\\{openAdress\\}", openAddress ); rule = rule.replaceAll( "\\$\\{ip_hex\\}", ip_hex ); rule = rule.replaceAll( "\\$\\{aid\\}", String.valueOf(aid) ); return rule; } private String Convert2hex( String ip ){ addr=InetAddress.getByName(ip); bytes=addr.getAddress(); str=""; for(b : bytes){ str=str+b2h(b & 0xff); } return str; } private String b2h( b ){ hexChars = new String []{ "0", "1", "2", "3", "4", "5", "6", "7", "8","9", "A", "B", "C", "D", "E", "F" }; return (hexChars[b/16]+hexChars[b%16]); } protected void doParentSync() { } } Вот команды...это я пробовал смотреть вообще что происходит...он даже не заругался Код: [DEFAULT] [OPEN] gswgs [/OPEN] [CLOSE] sdfvsdvs [/CLOSE] [REMOVE] sdfsdfs [/REMOVE] [/DEFAULT] конфигурация Код: user_rule.editor.class=bitel.billing.module.services.ipn.editor.ManadContractRuleEditor gate_manager.class=bitel.billing.server.ipn.ManadGateWorker use.script=1 Пробовыл и с такой Код: user_rule.editor.class=bitel.billing.module.services.ipn.editor.DlinkContractRuleEditor gate_manager.class=bitel.billing.server.ipn.DlinkGateWorker use.script=1 Результат один и тот же вот что пишет в логах Код: 04-16/09:24:41 INFO [Thread-77] ManadGateWorker - Running script
04-16/09:24:41 INFO [Thread-77] ManadGateWorker - script started 04-16/09:24:41 INFO [Thread-77] ManadGateWorker - script started 1 04-16/09:24:41 INFO [Thread-77] ManadGateWorker - before connect 04-16/09:24:41 INFO [Thread-77] ManadGateWorker - after connect 04-16/09:24:41 INFO [Thread-77] ManadGateWorker - after command 04-16/09:24:41 INFO [Thread-77] ManadGateWorker - before pswd 04-16/09:24:41 INFO [Thread-77] ManadGateWorker - execute commands 04-16/09:24:41 INFO [Thread-77] ManadGateWorker - openAddress = 255.255.255.255 04-16/09:24:42 INFO [Thread-77] ManadGateWorker - login PassWord:******* test:4#logout Command: logout test:4# ********** * Logout * ********** 04-16/09:24:42 INFO [Thread-77] ManadGateWorker - ok 04-16/09:24:42 INFO [Thread-77] ManadGateWorker - Process time => 532 04-16/09:24:47 INFO [http-8081-3] EventProcessor - Add event to queue Event bitel.billing.server.script.bean.event.ContractTariffUpdateEvent cid: 2041; module: 0; type: 32 04-16/09:25:07 INFO [http-8081-3] EventProcessor - Add event to queue Event bitel.billing.server.script.bean.event.ContractTariffUpdateEvent cid: 2041; module: 0; type: 32 04-16/09:27:49 INFO [http-8081-3] EventProcessor - Add event to queue Event bitel.billing.server.script.bean.event.ContractTariffUpdateEvent cid: 2041; module: 0; type: 32 04-16/09:28:07 INFO [http-8081-7] EventProcessor - Add event to queue Event bitel.billing.server.script.bean.event.ContractTariffUpdateEvent cid: 2041; module: 0; type: 32 04-16/09:28:34 INFO [http-8081-3] EventProcessor - Add event to queue Event bitel.billing.server.script.bean.event.ContractTariffUpdateEvent cid: 2041; module: 0; type: 32 04-16/09:29:30 INFO [http-8081-7] EventProcessor - Add event to queue Event bitel.billing.server.script.bean.event.ContractTariffUpdateEvent cid: 2041; module: 0; type: 32 04-16/09:31:28 INFO [http-8081-7] ScriptInstance - Invoke method ScriptLibrary [id:3; name:user] : getCurrentUserParam 04-16/09:31:28 INFO [http-8081-7] ScriptInstance - Invoke method ScriptLibrary [id:3; name:user] : getCurrentUserParam 04-16/09:31:28 INFO [http-8081-7] ScriptInstance - Invoke method ScriptLibrary [id:3; name:user] : getCurrentUserParam 04-16/09:31:28 INFO [http-8081-7] ScriptInstance - Invoke method ScriptLibrary [id:3; name:user] : getCurrentUserParam 04-16/09:34:56 INFO [http-8081-7] EventProcessor - Add event to queue Event bitel.billing.server.script.bean.event.ContractTariffDeleteEvent cid: 2041; module: 0; type: 33 04-16/09:35:00 INFO [http-8081-7] EventProcessor - Add event to queue Event bitel.billing.server.script.bean.event.ContractTariffDeleteEvent cid: 2041; module: 0; type: 33 04-16/09:35:04 INFO [http-8081-7] EventProcessor - Add event to queue Event bitel.billing.server.script.bean.event.ContractTariffDeleteEvent cid: 2041; module: 0; type: 33 04-16/09:35:07 INFO [http-8081-7] EventProcessor - Add event to queue Event bitel.billing.server.script.bean.event.ContractTariffDeleteEvent cid: 2041; module: 0; type: 33 04-16/09:35:10 INFO [http-8081-7] EventProcessor - Add event to queue Event bitel.billing.server.script.bean.event.ContractTariffDeleteEvent cid: 2041; module: 0; type: 33 04-16/09:38:30 INFO [http-8081-7] EventProcessor - Add event to queue Event bitel.billing.server.script.bean.event.ContractTariffUpdateEvent cid: 2041; module: 0; type: 32 04-16/09:40:51 INFO [http-8081-7] EventProcessor - Add event to queue Event bitel.billing.server.script.bean.event.ContractTariffUpdateEvent cid: 2041; module: 0; type: 32 04-16/09:41:08 INFO [http-8081-6] EventProcessor - Add event to queue Event bitel.billing.server.script.bean.event.ContractTariffUpdateEvent cid: 2041; module: 0; type: 32 04-16/09:41:55 INFO [http-8081-6] ScriptInstance - Invoke method ScriptLibrary [id:3; name:user] : getCurrentUserParam 04-16/09:41:55 INFO [http-8081-6] ScriptInstance - Invoke method ScriptLibrary [id:3; name:user] : getCurrentUserParam 04-16/09:41:55 INFO [http-8081-6] ScriptInstance - Invoke method ScriptLibrary [id:3; name:user] : getCurrentUserParam 04-16/09:41:55 INFO [http-8081-6] ScriptInstance - Invoke method ScriptLibrary [id:3; name:user] : getCurrentUserParam 04-16/09:42:19 INFO [http-8081-7] EventProcessor - Add event to queue Event bitel.billing.server.script.bean.event.ContractTariffUpdateEvent cid: 2041; module: 0; type: 32 04-16/09:42:29 INFO [http-8081-7] EventProcessor - Add event to queue Event bitel.billing.server.script.bean.event.ContractTariffUpdateEvent cid: 2041; module: 0; type: 32 04-16/09:43:07 INFO [http-8081-6] EventProcessor - Add event to queue Event bitel.billing.server.script.bean.event.ContractTariffUpdateEvent cid: 2041; module: 0; type: 32 04-16/09:43:45 INFO [http-8443-5] EventProcessor - Add event to queue Event ru.bitel.bgbilling.plugins.crm.server.bean.event.RegisterTaskAddEvent cid: 1903; module: 0; type: 12 04-16/09:43:53 INFO [http-8443-5] EventProcessor - Add event to queue Event ru.bitel.bgbilling.plugins.crm.server.bean.event.RegisterTaskClosedEvent cid: 1903; module: 0; type: 6 |
Автор: | stark [ 16 апр 2010, 11:30 ] |
Заголовок сообщения: | Re: Отладка скриптового шлюза |
похоже что для шлюза не завели ни одного порта в биллинге , поэтому ни одна команда и не выполняется .. покажите как вы добавили порты в договор |
Автор: | skyb [ 16 апр 2010, 11:34 ] | ||
Заголовок сообщения: | Re: Отладка скриптового шлюза | ||
stark писал(а): похоже что для шлюза не завели ни одного порта в биллинге , поэтому ни одна команда и не выполняется ..
покажите как вы добавили порты в договор
|
Автор: | stark [ 16 апр 2010, 11:36 ] |
Заголовок сообщения: | Re: Отладка скриптового шлюза |
так работать не будет ...шлюз расичтан на использование портов из шлюза dlink .Чтобы брать эти порты , нужно скрипт поменять |
Автор: | skyb [ 16 апр 2010, 11:41 ] |
Заголовок сообщения: | Re: Отладка скриптового шлюза |
stark писал(а): так работать не будет ...шлюз расичтан на использование портов из шлюза dlink .Чтобы брать эти порты , нужно скрипт поменять А как и в какую сторону?? или если не меняя скрипт както сделать чтоб порты выводил? |
Автор: | stark [ 16 апр 2010, 12:51 ] |
Заголовок сообщения: | Re: Отладка скриптового шлюза |
вот тут : http://wiki.bgbilling.ru/index.php/%D0% ... -1228G_%29 Во втором шлюзе (шлюз доступа) как раз берутся порты с этой вкладки |
Автор: | stark [ 20 апр 2010, 15:01 ] |
Заголовок сообщения: | Re: Отладка скриптового шлюза |
вот по этой причине : viewtopic.php?f=7&t=3890 Исправлено недавно |
Автор: | skyb [ 21 апр 2010, 05:44 ] |
Заголовок сообщения: | Re: Отладка скриптового шлюза |
stark писал(а): О...заработало ![]() |
Страница 1 из 1 | Часовой пояс: UTC + 5 часов [ Летнее время ] |
Powered by phpBB® Forum Software © phpBB Group http://www.phpbb.com/ |