|
24 | 24 | import java.net.URISyntaxException; |
25 | 25 | import java.net.URL; |
26 | 26 | import java.nio.channels.SocketChannel; |
| 27 | +import java.rmi.RemoteException; |
27 | 28 | import java.util.HashMap; |
28 | 29 | import java.util.List; |
29 | 30 | import java.util.Map; |
|
77 | 78 | import com.cloud.agent.api.routing.IpAssocCommand; |
78 | 79 | import com.cloud.agent.api.routing.LoadBalancerConfigCommand; |
79 | 80 | import com.cloud.agent.api.routing.NetworkElementCommand; |
| 81 | +import com.cloud.agent.api.routing.RemoteAccessVpnCfgCommand; |
80 | 82 | import com.cloud.agent.api.routing.SavePasswordCommand; |
81 | 83 | import com.cloud.agent.api.routing.SetFirewallRulesAnswer; |
82 | 84 | import com.cloud.agent.api.routing.SetFirewallRulesCommand; |
|
91 | 93 | import com.cloud.agent.api.routing.SetStaticRouteCommand; |
92 | 94 | import com.cloud.agent.api.routing.Site2SiteVpnCfgCommand; |
93 | 95 | import com.cloud.agent.api.routing.VmDataCommand; |
| 96 | +import com.cloud.agent.api.routing.VpnUsersCfgCommand; |
94 | 97 | import com.cloud.agent.api.to.DhcpTO; |
95 | 98 | import com.cloud.agent.api.to.FirewallRuleTO; |
96 | 99 | import com.cloud.agent.api.to.IpAddressTO; |
@@ -381,7 +384,11 @@ public final Answer executeRequest(final Command cmd) { |
381 | 384 | } else if (clazz == Site2SiteVpnCfgCommand.class) { |
382 | 385 | answer = execute((Site2SiteVpnCfgCommand)cmd); |
383 | 386 | } else if (clazz == CheckS2SVpnConnectionsCommand.class) { |
384 | | - answer = execute((CheckS2SVpnConnectionsCommand)cmd); |
| 387 | + answer = execute((CheckS2SVpnConnectionsCommand) cmd); |
| 388 | + } else if (clazz == RemoteAccessVpnCfgCommand.class) { |
| 389 | + answer = execute((RemoteAccessVpnCfgCommand) cmd); |
| 390 | + } else if (clazz == VpnUsersCfgCommand.class) { |
| 391 | + answer = execute((VpnUsersCfgCommand) cmd); |
385 | 392 | } else if (clazz == SetStaticRouteCommand.class) { |
386 | 393 | answer = execute((SetStaticRouteCommand) cmd); |
387 | 394 | } else if (clazz == SetMonitorServiceCommand.class) { |
@@ -416,7 +423,91 @@ public final Answer executeRequest(final Command cmd) { |
416 | 423 | } |
417 | 424 | return answer; |
418 | 425 | } |
| 426 | + |
| 427 | + protected Answer execute(final RemoteAccessVpnCfgCommand cmd) { |
| 428 | + String controlIp = getRouterSshControlIp(cmd); |
| 429 | + StringBuffer argsBuf = new StringBuffer(); |
| 430 | + if (cmd.isCreate()) { |
| 431 | + argsBuf.append(" -r ").append(cmd.getIpRange()).append(" -p ").append(cmd.getPresharedKey()).append(" -s ").append(cmd.getVpnServerIp()).append(" -l ").append(cmd.getLocalIp()) |
| 432 | + .append(" -c "); |
| 433 | + |
| 434 | + } else { |
| 435 | + argsBuf.append(" -d ").append(" -s ").append(cmd.getVpnServerIp()); |
| 436 | + } |
| 437 | + argsBuf.append(" -C ").append(cmd.getLocalCidr()); |
| 438 | + argsBuf.append(" -i ").append(cmd.getPublicInterface()); |
| 439 | + |
| 440 | + try { |
| 441 | + |
| 442 | + if (s_logger.isDebugEnabled()) { |
| 443 | + s_logger.debug("Executing /opt/cloud/bin/vpn_lt2p.sh "); |
| 444 | + } |
| 445 | + |
| 446 | + Pair<Boolean, String> result = SshHelper.sshExecute(controlIp, DEFAULT_DOMR_SSHPORT, "root", getSystemVMKeyFile(), null, "/opt/cloud/bin/vpn_l2tp.sh " + argsBuf.toString()); |
| 447 | + |
| 448 | + if (!result.first()) { |
| 449 | + s_logger.error("RemoteAccessVpnCfg command on domR failed, message: " + result.second()); |
| 450 | + |
| 451 | + return new Answer(cmd, false, "RemoteAccessVpnCfg command failed due to " + result.second()); |
| 452 | + } |
| 453 | + |
| 454 | + if (s_logger.isInfoEnabled()) { |
| 455 | + s_logger.info("RemoteAccessVpnCfg command on domain router " + argsBuf.toString() + " completed"); |
| 456 | + } |
| 457 | + |
| 458 | + } catch (Throwable e) { |
| 459 | + if (e instanceof RemoteException) { |
| 460 | + s_logger.warn(e.getMessage()); |
| 461 | + } |
| 462 | + |
| 463 | + String msg = "RemoteAccessVpnCfg command failed due to " + e.getMessage(); |
| 464 | + s_logger.error(msg, e); |
| 465 | + return new Answer(cmd, false, msg); |
| 466 | + } |
| 467 | + |
| 468 | + return new Answer(cmd); |
| 469 | + } |
| 470 | + |
| 471 | + protected Answer execute(final VpnUsersCfgCommand cmd) { |
| 472 | + |
| 473 | + String controlIp = getRouterSshControlIp(cmd); |
| 474 | + for (VpnUsersCfgCommand.UsernamePassword userpwd : cmd.getUserpwds()) { |
| 475 | + StringBuffer argsBuf = new StringBuffer(); |
| 476 | + if (!userpwd.isAdd()) { |
| 477 | + argsBuf.append(" -U ").append(userpwd.getUsername()); |
| 478 | + } else { |
| 479 | + argsBuf.append(" -u ").append(userpwd.getUsernamePassword()); |
| 480 | + } |
| 481 | + |
| 482 | + try { |
| 483 | + |
| 484 | + if (s_logger.isDebugEnabled()) { |
| 485 | + s_logger.debug("Executing /opt/cloud/bin/vpn_lt2p.sh "); |
| 486 | + } |
| 487 | + |
| 488 | + Pair<Boolean, String> result = SshHelper.sshExecute(controlIp, DEFAULT_DOMR_SSHPORT, "root", getSystemVMKeyFile(), null, "/opt/cloud/bin/vpn_l2tp.sh " + argsBuf.toString()); |
| 489 | + |
| 490 | + if (!result.first()) { |
| 491 | + s_logger.error("VpnUserCfg command on domR failed, message: " + result.second()); |
| 492 | + |
| 493 | + return new Answer(cmd, false, "VpnUserCfg command failed due to " + result.second()); |
| 494 | + } |
| 495 | + } catch (Throwable e) { |
| 496 | + if (e instanceof RemoteException) { |
| 497 | + s_logger.warn(e.getMessage()); |
| 498 | + } |
| 499 | + |
| 500 | + String msg = "VpnUserCfg command failed due to " + e.getMessage(); |
| 501 | + s_logger.error(msg, e); |
| 502 | + return new Answer(cmd, false, msg); |
| 503 | + } |
| 504 | + } |
| 505 | + |
| 506 | + return new Answer(cmd); |
| 507 | + } |
419 | 508 |
|
| 509 | + |
| 510 | + |
420 | 511 | private SetStaticRouteAnswer execute(SetStaticRouteCommand cmd) { |
421 | 512 | if (s_logger.isInfoEnabled()) { |
422 | 513 | s_logger.info("Executing resource SetStaticRouteCommand: " + s_gson.toJson(cmd)); |
|
0 commit comments