bill вер. 4.6 сборка 212 от 01.10.2009 17:38:50
ipn вер. 4.6 сборка 213 от 09.10.2009 18:23:03
После наката обновления, для корректной работы с Микротиком, перестали управляться шлюзы DLink, использую скриптовый шлюз из википелии:
Код:
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()
{
try
{
String host = gate.getHost();
int port = gate.getPort();
DefaultServerSetup gateSetup = new DefaultServerSetup( gate.getConfig(), "\r\n" );
String pswd = gate.getKeyword();
String login = gateSetup.getStringValue( "login");
StringBuffer result = new StringBuffer();
if( log.isDebugEnabled() )
{
//log.debug( gate.getId() + " gate: " + host + ":" + port + " login: " + login + " pswd: " + pswd );
}
TelnetSession session = new TelnetSession( host, port);
session.setLoginPromptSequence( ":" );
//log.debug( "before connect" );
session.connect();
//log.debug( "after connect" );
result.append( session.doCommand( login ) );
//log.debug( "after command" );
session.setLoginPromptSequence( "#" );
result.append( session.doCommand( pswd ) );
//log.debug( "before pswd" );
//log.debug( "execute commands" );
doCommands( session, result, gateSetup);
//TODO commands here
session.setLoginPromptSequence( "****" );
result.append( session.doCommand( "logout" ) );
log.info( result.toString() );
//log.debug( "ok" );
} catch (Exception e)
{
throw new RuntimeException ( e );
}
}
private void doCommands( TelnetSession session, StringBuffer result, DefaultServerSetup gateSetup)
throws IOException, OperationTimedoutException
{
String openAddress = gateSetup.getStringValue( "open.address", "255.255.255.255" ) ;
//log.debug( "openAddress = " + openAddress );
uplinks = Utils.stringToIntegerList( gateSetup.getStringValue( "uplink" ) );
List ports = getUserList( statusList );
String [] openRules = new String [] {
//Профиль 20 Разрешаем клиенту видеть мир
// разрешающие правила добавляются с номером порта клиента
"config access_profile profile_id 20 add access_id ${port} ip source_ip ${ip} destination_ip 0.0.0.0 port ${port} permit"};
String [] closeRules = new String [] {
// Профиль 8 разрешаем клиенту видеть Стат+ДНС сервер
// разрешающие правила добавляются с номером порта клиента
"config access_profile profile_id 8 add access_id ${port} ip source_ip ${ip} destination_ip ${openAdress} port ${port} permit",
//Профиль 12 Разрешаем ИП запросы на аплинках на адрес клиента со статистики
"config access_profile profile_id 12 add access_id ${mod}${port} ip source_ip ${openAdress} destination_ip ${ip} port ${upport} permit",
//16 Запрещаем ИП запросы на аплинках на адрес клиента
"config access_profile profile_id 16 add access_id ${mod}${port} ip source_ip 0.0.0.0 destination_ip ${ip} port ${upport} deny"};
for( UserPortStatus port : ports )
{
//log.debug("port.ipAddr=" + port.ipAddr);
//удаляюшие правила
if ( port.status.status == IPNContractStatus.STATUS_REMOVED )
{
int [] profiles = new int [] { 8, 20 };
for (int profile : profiles)
{
String rule = "config access_profile profile_id " + profile + " delete access_id " + port.port;
//log.debug("rule=" + rule);
result.append( session.doCommand( rule ) );
}
int [] profiles = new int [] { 12, 16 };
for (int profile : profiles)
{
for (int j = 0; j < uplinks.size(); j++)
{
Integer upport = uplinks.get(j);
pref = j > 0 ? String.valueOf( j * 10 ) : "";
String rule = "config access_profile profile_id " + profile + " delete access_id " + pref + port.port;
//log.debug("rule=" + rule);
result.append( session.doCommand( rule ) );
}
}
}
else
if ( port.status.status == IPNContractStatus.STATUS_OPEN )
{
int [] profiles = new int [] { 8 };
for (int profile : profiles)
{
String rule = "config access_profile profile_id " + profile + " delete access_id " + port.port;
//log.debug("rule=" + rule);
result.append( session.doCommand( rule ) );
}
int [] profiles = new int [] { 12, 16 };
for (int profile : profiles)
{
for (int j = 0; j < uplinks.size(); j++)
{
Integer upport = uplinks.get(j);
pref = j > 0 ? String.valueOf( j * 10 ) : "";
String rule = "config access_profile profile_id " + profile + " delete access_id " + pref + port.port;
//log.debug("rule=" + rule);
result.append( session.doCommand( rule ) );
}
}
//20
rule = openRules[0];
rule = setValues( rule, port.port, port.ipAddr, openAddress, "" );
log.info("rule=" + rule);
result.append( session.doCommand( rule ) );
}
else //close
{
int [] profiles = new int [] { 20 };
for (int profile : profiles)
{
String rule = "config access_profile profile_id " + profile + " delete access_id " + port.port;
//log.debug("rule=" + rule);
result.append( session.doCommand( rule ) );
}
//8
rule = closeRules[0];
rule = setValues( rule, port.port, port.ipAddr, openAddress, "" );
log.info("rule=" + rule);
result.append( session.doCommand( rule ) );
//12, 16
for (int j = 0; j < uplinks.size(); j++)
{
Integer upport = uplinks.get(j);
for (int i = 1; i < 3; i++)
{
rule = closeRules[i];
rule = setValues( rule, port.port, port.ipAddr, openAddress, String.valueOf( upport ) );
rule = rule.replaceAll( "\\$\\{mod\\}" , String.valueOf( j * 10 ) );
log.info("rule=" + rule);
result.append( session.doCommand( rule ) );
}
}
}
}
}
private String setValues( String rule, int port, String ip, String openAddress, String upport )
{
rule = rule.replaceAll( "\\$\\{port\\}", String.valueOf( port ) );
rule = rule.replaceAll( "\\$\\{ip\\}" , ip );
rule = rule.replaceAll( "\\$\\{openAdress\\}", openAddress );
rule = rule.replaceAll( "\\$\\{upport\\}", upport );
return rule;
}
protected void doParentSync()
{
}
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;
}
пытаюсь открыть\закрыть\удалить шлюз, в логи сыпется следующее:
Код:
[root@bill log]# grep "Thread-42" server.log
10-13/00:32:14 DEBUG [Thread-42] DlinkGateWorker - run
10-13/00:32:14 DEBUG [Thread-42] DlinkGateWorker - doParentSync
10-13/00:32:14 INFO [Thread-42] DlinkGateWorker - Running script
10-13/00:32:14 INFO [Thread-42] DlinkGateWorker - Process time => 0
10-13/00:32:14 DEBUG [Thread-42] DHCPGateWorker - parentSync
10-13/00:32:14 DEBUG [Thread-42] DHCPGateWorker - 3 gate: 127.0.0.1:1868
10-13/00:32:14 INFO [Thread-42] DlinkGateWorker - Running script
10-13/00:32:14 ERROR [Thread-42] DlinkGateWorker - Eval error2: Sourced file: inline evaluation of: ``import java.io.IOException; import java.util.ArrayList; import java.util.HashMap . . . '' : Class: OperationTimedoutException not found in namespace
10-13/00:32:14 ERROR [Thread-42] LoggingPrintStream - java.lang.RuntimeException: Sourced file: inline evaluation of: ``import java.io.IOException; import java.util.ArrayList; import java.util.HashMap . . . '' : Class: OperationTimedoutException not found in namespace : at Line: 88 : in file: inline evaluation of: ``import java.io.IOException; import java.util.ArrayList; import java.util.HashMap . . . '' : OperationTimedoutException
10-13/00:32:14 ERROR [Thread-42] LoggingPrintStream - at bitel.billing.server.ipn.GateWorker$Scripter.runScriptSync(GateWorker.java:230)
10-13/00:32:14 ERROR [Thread-42] LoggingPrintStream - at bitel.billing.server.ipn.GateWorker.runSync(GateWorker.java:106)
10-13/00:32:14 ERROR [Thread-42] LoggingPrintStream - at bitel.billing.server.ipn.GateWorker.run(GateWorker.java:85)
10-13/00:32:14 ERROR [Thread-42] LoggingPrintStream - Caused by: Sourced file: inline evaluation of: ``import java.io.IOException; import java.util.ArrayList; import java.util.HashMap . . . '' : Class: OperationTimedoutException not found in namespace : at Line: 88 : in file: inline evaluation of: ``import java.io.IOException; import java.util.ArrayList; import java.util.HashMap . . . '' : OperationTimedoutException
10-13/00:32:14 ERROR [Thread-42] LoggingPrintStream - at bsh.BSHAmbiguousName.toClass(Unknown Source)
10-13/00:32:14 ERROR [Thread-42] LoggingPrintStream - at bsh.BSHMethodDeclaration.evalNodes(Unknown Source)
10-13/00:32:14 ERROR [Thread-42] LoggingPrintStream - at bsh.BSHMethodDeclaration.eval(Unknown Source)
10-13/00:32:14 ERROR [Thread-42] LoggingPrintStream - at bsh.Interpreter.eval(Unknown Source)
10-13/00:32:14 ERROR [Thread-42] LoggingPrintStream - at bsh.Interpreter.eval(Unknown Source)
10-13/00:32:14 ERROR [Thread-42] LoggingPrintStream - at bsh.Interpreter.eval(Unknown Source)
10-13/00:32:14 ERROR [Thread-42] LoggingPrintStream - at bitel.billing.server.ipn.GateWorker$Scripter.runScriptSync(GateWorker.java:216)
10-13/00:32:14 ERROR [Thread-42] LoggingPrintStream - ... 2 more
10-13/00:32:14 ERROR [Thread-42] DlinkGateWorker - Gate unaccesible - 172.31.0.13
10-13/00:32:14 ERROR [Thread-42] DlinkGateWorker - -------------------------
10-13/00:32:14 ERROR [Thread-42] DlinkGateWorker - error: Sourced file: inline evaluation of: ``import java.io.IOException; import java.util.ArrayList; import java.util.HashMap . . . '' : Class: OperationTimedoutException not found in namespace : at Line: 88 : in file: inline evaluation of: ``import java.io.IOException; import java.util.ArrayList; import java.util.HashMap . . . '' : OperationTimedoutException
почитав соседние темы, добавил в конфиг шлюза
timeout=2000Код:
login=admin
timeout=2000
#Роутер(ы), если несколько - через запятую
dhcp.router=172.31.0.253
#DNS сервер(а), если несколько - через запятую
dhcp.dns=172.31.0.254,172.31.0.253
#Маска подсети
#dhcp.subnetMask=255.0.0.0
dhcp.subnetMask=255.255.0.0
#маска открытых серверов
open.mask=255.255.255.255
#адрес открытого сервера
open.address=172.31.0.254
#количество портов
ports=28
#номера uplink портов (связь с другими коммутаторами)
uplink=25,26,27,28
#занимаемые профили
profile.4=4
profile.8=8
profile.12=12
profile.16=16
profile.20=20
profile.24=24
profile.28=28
не помогло