внесу ясность:
лог аццесс при создании нового сервиса
Код:
[root@bill log]# cat all.log | grep "sa-p-11-t-94"
connection 12-12/09:12:38 INFO [sa-p-11-t-94] ServiceActivatorSet - Connecting to device
connection 12-12/09:12:38 DEBUG [sa-p-11-t-94] MikrotikServiceActivator - gate: gate.mydomen.ru:22 login: xxxxx+ct pswd: xxxxx
connection 12-12/09:12:39 DEBUG [sa-p-11-t-94] DlinkTelnetServiceActivator - 77 gate: 10.100.100.64:23 login: xxxxx pswd: xxxxx
connection 12-12/09:12:39 DEBUG [sa-p-11-t-94] DlinkTelnetServiceActivator - before connect
connection 12-12/09:12:39 DEBUG [sa-p-11-t-94] DlinkTelnetServiceActivator - after connect
connection 12-12/09:12:39 DEBUG [sa-p-11-t-94] DlinkTelnetServiceActivator - after command
connection 12-12/09:12:39 DEBUG [sa-p-11-t-94] DlinkTelnetServiceActivator - before pswd
connection 12-12/09:12:39 DEBUG [sa-p-11-t-94] DlinkTelnetServiceActivator - before enable
connection 12-12/09:12:39 DEBUG [sa-p-11-t-94] DlinkTelnetServiceActivator - before xxxxx
connection 12-12/09:12:39 DEBUG [sa-p-11-t-94] DlinkTelnetServiceActivator - after enable
connection 12-12/09:12:39 DEBUG [sa-p-11-t-94] AcknowledgeConsumer - Caught BGBillingServer:Event[ru.bitel.bgbilling.modules.inet.access.sa.event.InetSaServModifyEvent] moduleId: 20; pluginId: no; cid: global; scid: -1; userId: -1; oldInetServ: null; newInetServ: интернет : 172.31.103.7 : 14; newInetServState: 1; newInetServOptionList: ; timestamp: 1355289140558
connection 12-12/09:12:39 INFO [sa-p-11-t-94] ServiceActivatorDeviceWorker - Do task deviceId: 77; Event[ru.bitel.bgbilling.modules.inet.access.sa.event.InetSaServModifyEvent] moduleId: 20; pluginId: no; cid: global; scid: -1; userId: -1; oldInetServ: null; newInetServ: интернет : 172.31.103.7 : 14; newInetServState: 1; newInetServOptionList: ; timestamp: 1355289140558
connection 12-12/09:12:39 INFO [sa-p-11-t-94] InetApplication - TariffOptionMap: {}
connection 12-12/09:12:39 INFO [sa-p-11-t-94] ServiceActivatorDeviceWorker - Command result event: ServiceActivatorEvent type=1; inetServId: 6389; call: false; oldState: 0; newState: 1; oldOptionSet: ; newOptionSet: 18
connection 12-12/09:12:39 INFO [sa-p-11-t-94] ServiceActivatorDeviceWorker - Processing deviceId:77; command ServiceActivatorEvent type=1; inetServId: 6389; call: false; oldState: 0; newState: 1; oldOptionSet: ; newOptionSet: 18
connection 12-12/09:12:39 INFO [sa-p-11-t-94] ServiceActivatorSet - Invoking serviceCreate
connection 12-12/09:12:39 DEBUG [sa-p-11-t-94] MikrotikServiceActivator - serviceCreate
connection 12-12/09:12:39 DEBUG [sa-p-11-t-94] MikrotikServiceActivator - oldState=0;newState=1
connection 12-12/09:12:39 DEBUG [sa-p-11-t-94] MikrotikServiceActivator - oldOptions=[];newOptions=[18]
connection 12-12/09:12:39 DEBUG [sa-p-11-t-94] MikrotikServiceActivator - state!=state true
connection 12-12/09:12:39 INFO [sa-p-11-t-94] MikrotikServiceActivator - from =172.31.103.7
connection 12-12/09:12:39 INFO [sa-p-11-t-94] MikrotikServiceActivator - to =172.31.103.7
connection 12-12/09:12:39 INFO [sa-p-11-t-94] MikrotikServiceActivator - 172.31.103.7
connection 12-12/09:12:39 INFO [sa-p-11-t-94] MikrotikServiceActivator - increment =true
connection 12-12/09:12:39 DEBUG [sa-p-11-t-94] MikrotikServiceActivator - optionConfig=list_name=TpLIDER_TURBO
connection 12-12/09:12:39 INFO [sa-p-11-t-94] MikrotikServiceActivator - cid=1475;rule_id=18;optionConfig=list_name=TpLIDER_TURBO
connection 12-12/09:12:39 INFO [sa-p-11-t-94] MikrotikServiceActivator - open
connection 12-12/09:12:39 DEBUG [sa-p-11-t-94] MikrotikServiceActivator - rules.length=1
connection 12-12/09:12:39 DEBUG [sa-p-11-t-94] MikrotikServiceActivator - rule=:global list "";:foreach i in [/ip firewall address-list find] do={:if ([:find [/ip firewall address-list get $i comment] "sid=6389;cid=1475;"]=0) do={[/ip firewall address-list remove $i]}};:global list "";:foreach i in [/ip firewall address-list find] do={:if ([:find [/ip firewall address-list get $i comment] "cid=1475;"]=0) do={[/ip firewall address-list remove $i]}};ip firewall address-list add address=172.31.103.7 list=ACCESS_LIST comment="sid=6389;cid=1475;rid=18;";ip firewall address-list add address=172.31.103.7 list=TpLIDER_TURBO comment="sid=6389;cid=1475;rid=18;";
connection 12-12/09:12:40 DEBUG [sa-p-11-t-94] MikrotikServiceActivator - result = :global list "";:foreach i in [/ip firewall
connection 12-12/09:12:40 DEBUG [sa-p-11-t-94] MikrotikServiceActivator - processed!
connection 12-12/09:12:40 INFO [sa-p-11-t-94] ServiceActivatorDeviceWorker - Process event type[1] result=true
connection 12-12/09:12:40 INFO [sa-p-11-t-94] ServiceActivatorDeviceWorker - Changing InetServ:6389 state and/or options
mq 12-12/09:12:40 DEBUG [sa-p-11-t-94] EventProcessor - Publish: Event[ru.bitel.bgbilling.modules.inet.access.event.InetServDeviceStateAndOptionsModifiedEvent] moduleId: 20; pluginId: no; cid: global; scid: -1; userId: -1; deviceId: 77; inetServId: 6389; state: 1; optionSet: 18; timestamp: 1355289160634
connection 12-12/09:12:45 INFO [sa-p-11-t-94] ServiceActivatorSet - Disconnecting from device
connection 12-12/09:12:45 DEBUG [sa-p-11-t-94] MikrotikServiceActivator - ok
connection 12-12/09:12:45 DEBUG [sa-p-11-t-94] DlinkTelnetServiceActivator - SAVE
connection 12-12/09:12:48 DEBUG [sa-p-11-t-94] DlinkTelnetServiceActivator - AFTER SAVE
connection 12-12/09:12:48 INFO [sa-p-11-t-94] DlinkTelnetServiceActivator - xxxxx
connection 12-12/09:12:48 DEBUG [sa-p-11-t-94] DlinkTelnetServiceActivator - ok
видим что дин. код длинк ничего не формирует и не отправляет на коммутатор:
Код:
connection 12-12/09:12:48 INFO [sa-p-11-t-94] DlinkTelnetServiceActivator - ххххх
PassWord:************
DES-1228/ME:3#enable admin
Command: enable admin
PassWord:*********
DES-1228/ME:4#save
Command: save
Saving all configurations to NV-RAM...... 0 % 50 % 55 % 60 % 65 % 70 % 75 % 80 % 85 % 90 % 95 %100 %Done.
Success.
DES-1228/ME:4#logout
Command: logout
DES-1228/ME:4#
**********
* Logout *
**********
сам дин код:
Код:
package ru.gigacom.inet.dyn.device.dlink;
import java.net.InetSocketAddress;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;
import org.apache.log4j.Logger;
import ru.bitel.bgbilling.modules.inet.access.sa.ServiceActivator;
import ru.bitel.bgbilling.modules.inet.access.sa.ServiceActivatorAdapter;
import ru.bitel.bgbilling.modules.inet.access.sa.ServiceActivatorEvent;
import ru.bitel.bgbilling.modules.inet.api.common.bean.InetDevice;
import ru.bitel.bgbilling.modules.inet.api.common.bean.InetDeviceType;
import ru.bitel.bgbilling.modules.inet.api.common.bean.InetServ;
import ru.bitel.bgbilling.server.util.Setup;
import ru.bitel.common.ParameterMap;
import ru.bitel.common.Preferences;
import ru.bitel.common.Utils;
import ru.bitel.common.inet.IpAddress;
import bitel.billing.common.module.ipn.IPNContractStatus;
import bitel.billing.server.ipn.UserStatus;
import bitel.billing.server.ipn.dlink.UserPortStatus;
import bitel.billing.server.util.telnet.TelnetSession;
/**
* Dlink 3026,3028,1228ME
* @author stark
*
*/
public class DlinkTelnetServiceActivator
extends ServiceActivatorAdapter
implements ServiceActivator
{
private InetDevice inetDevice;
private static final Logger log = Logger.getLogger( DlinkTelnetServiceActivator.class );
private TelnetSession session;
private StringBuffer result ;
private ParameterMap parameterMap;
@Override
public Object init( Setup setup, int moduleId, InetDevice inetDevice, InetDeviceType inetDeviceType, ParameterMap parameterMap )
throws Exception
{
this.inetDevice = inetDevice;
this.parameterMap = parameterMap;
return true;
}
@Override
public Object connect()
throws Exception
{
List< InetSocketAddress> hosts = inetDevice.getHosts();
String host = hosts.get( 0 ).getHostName();
int port = hosts.get( 0 ).getPort();
String pswd = inetDevice.getPassword();
String login = inetDevice.getUsername();
String enablepwd = inetDevice.getSecret();
result = new StringBuffer();
if( log.isDebugEnabled() )
{
log.debug( inetDevice.getId() + " gate: " + host + ":" + port + " login: " + login + " pswd: " + pswd );
}
session = new TelnetSession( host, port);
int timeout = 10000;
session.setTimeout( timeout );
session.setEndString( ":" );
log.debug( "before connect" );
session.connect();
log.debug( "after connect" );
result.append( session.doCommand( login ) );
log.debug( "after command" );
session.setEndString( "#" );
result.append( session.doCommand( pswd ) );
log.debug( "before pswd" );
log.debug( "before enable" );
session.setEndString( ":" );
result.append( session.doCommand( "enable admin" ) );
log.debug( "before enablepwd" );
session.setEndString( "#" );
result.append( session.doCommand( enablepwd ) );
log.debug( "after enable" );
session.setEndString( "#" );
return true;
}
@Override
public Object serviceModify( ServiceActivatorEvent serviceActivatorEvent )
throws Exception
{
log.debug( "newState= " + serviceActivatorEvent.getNewState() );
if ( serviceActivatorEvent.getNewState() != serviceActivatorEvent.getOldState() )
{
int state = serviceActivatorEvent.getNewState();
try
{
InetServ serv = serviceActivatorEvent.getNewInetServ();
log.debug( "execute commands" );
String openAddress = parameterMap.get( "open.address", "255.255.255.255" ) ;
log.debug( "openAddress = " + openAddress );
List<Integer>uplinks = Utils.toListInt( parameterMap.get( "uplink", "" ) );
//List<UserPortStatus> ports = new ArrayList<UserPortStatus>();
//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=" + IpAddress.toString( serv.getAddressFrom() ) );
//удаляюшие правила
if ( state == InetServ.STATE_DELETED )
{
int [] profiles = new int [] { 8, 20 };
for (int profile : profiles)
{
String rule = "config access_profile profile_id " + profile + " delete access_id " + serv.getInterfaceId();
log.debug("rule=" + rule);
result.append( session.doCommand( rule ) );
}
profiles = new int [] { 12, 16 };
for (int profile : profiles)
{
for (int j = 0; j < uplinks.size(); j++)
{
Integer upport = uplinks.get(j);
String pref = j > 0 ? String.valueOf( j * 10 ) : "";
String rule = "config access_profile profile_id " + profile + " delete access_id " + pref + serv.getInterfaceId();
log.debug("rule=" + rule);
result.append( session.doCommand( rule ) );
}
}
}
else
if ( state == InetServ.STATE_ENABLE )
{
int [] profiles = new int [] { 8 };
for (int profile : profiles)
{
String rule = "config access_profile profile_id " + profile + " delete access_id " + serv.getInterfaceId();
log.debug("rule=" + rule);
result.append( session.doCommand( rule ) );
}
profiles = new int [] { 12, 16 };
for (int profile : profiles)
{
for (int j = 0; j < uplinks.size(); j++)
{
Integer upport = uplinks.get(j);
String pref = j > 0 ? String.valueOf( j * 10 ) : "";
String rule = "config access_profile profile_id " + profile + " delete access_id " + pref + serv.getInterfaceId();
log.debug("rule=" + rule);
result.append( session.doCommand( rule ) );
}
}
//20
String rule = openRules[0];
rule = setValues( rule, serv.getInterfaceId(), IpAddress.toString( serv.getAddressFrom() ) , openAddress, "" );
log.info("rule=" + rule);
result.append( session.doCommand( rule ) );
}
if ( state == InetServ.STATE_DISABLE )
{
int [] profiles = new int [] { 20 };
for (int profile : profiles)
{
String rule = "config access_profile profile_id " + profile + " delete access_id " + serv.getInterfaceId();
log.debug("rule=" + rule);
result.append( session.doCommand( rule ) );
}
//8
String rule = closeRules[0];
rule = setValues( rule, serv.getInterfaceId(), IpAddress.toString( serv.getAddressFrom() ), 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, serv.getInterfaceId(), IpAddress.toString( serv.getAddressFrom() ), openAddress, String.valueOf( upport ) );
rule = rule.replaceAll( "\\$\\{mod\\}" , String.valueOf( j * 10 ) );
log.info("rule=" + rule);
result.append( session.doCommand( rule ) );
}
}
}
} catch (Exception e)
{
log.error( "", e );
}
}
return null;
}
@Override
public Object connectionClose( ServiceActivatorEvent serviceActivatorEvent1 )
throws Exception
{
return null;
}
@Override
public Object serviceCreate( ServiceActivatorEvent serviceActivatorEvent1 )
throws Exception
{
return null;
}
@Override
public Object disconnect()
throws Exception
{
session.setEndString( "#" );
log.debug( "SAVE" );
result.append( session.doCommand( "save" ) );
log.debug( "AFTER SAVE" );
session.setEndString ( "****" );
result.append( session.doCommand( "logout" ) );
log.info( result.toString() );
log.debug( "ok" );
return true;
}
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;
}
}
тут ничего не меняли, даже копирайт оставили со времен ТТ в хелпдеске.