1 19 20 package com.sslexplorer.upgrade; 21 22 import java.io.File ; 23 import java.sql.Connection ; 24 import java.sql.PreparedStatement ; 25 import java.sql.ResultSet ; 26 import java.sql.Statement ; 27 28 public class TunnelsUpgrade extends AbstractDatabaseUpgrade { 29 30 TunnelsUpgrade(File oldDbDir, File newDbDir) { 31 super("SSL Tunnels", "Copies all SSL Tunnels to the new installation. " 32 + "Any user created tunnels are also copied (with the owner " 33 + "username appended to the new resource name). The resource " + "will not be attached to any policies.", 34 true, "explorer_configuration", "explorer_configuration", oldDbDir, newDbDir); 35 } 36 37 public void doUpgrade(Upgrader upgrader, Connection oldConx, Connection newConx) throws Exception { 38 upgrader.info("Migrating all SSL tunnels"); 40 Statement stmt = oldConx.createStatement(); 41 try { 42 ResultSet rs = stmt.executeQuery("SELECT * FROM TUNNELS"); 43 try { 44 while (rs.next()) { 45 int tunnelId = rs.getInt("TUNNEL_ID"); 46 PreparedStatement ps = newConx.prepareStatement("INSERT INTO TUNNELS (NAME," 47 + "DESCRIPTION, TYPE, TRANSPORT, USERNAME, SOURCE_PORT," 48 + " DESTINATION_PORT, DESTINATION_HOST, AUTO_START, " 49 + "ALLOW_EXTERNAL_HOSTS, PARENT_RESOURCE_PERMISSION, " 50 + "DATE_CREATED, DATE_AMENDED) VALUES (?,?,?,?,?,?,?,?,?,?,?,NOW(),NOW())"); 51 try { 52 upgrader.info(" " + tunnelId); 53 String resourceName = "Tunnel ID " + tunnelId; 54 String username = rs.getString("USERNAME"); 55 if (username.equals("")) { 56 resourceName += " (System)"; 57 } else { 58 resourceName += " (" + username + ")"; 59 } 60 ps.setString(1, resourceName); 61 ps.setString(2, resourceName); 62 ps.setInt(3, rs.getInt("TYPE")); 63 ps.setString(4, rs.getString("TRANSPORT")); 64 ps.setString(5, rs.getString("USERNAME")); 65 ps.setInt(6, rs.getInt("SOURCE_PORT")); 66 ps.setInt(7, rs.getInt("DESTINATION_PORT")); 67 ps.setString(8, rs.getString("DESTINATION_HOST")); 68 ps.setInt(9, rs.getInt("AUTO_START")); 69 ps.setInt(10, rs.getInt("ALLOW_EXTERNAL_HOSTS")); 70 ps.setInt(11, 0); 71 try { 72 ps.execute(); 73 } catch (Exception e) { 74 upgrader.warn("Failed to insert tunnel " + tunnelId + ". Probably already exists."); 75 } 76 } finally { 77 ps.close(); 78 } 79 } 80 } finally { 81 rs.close(); 82 } 83 } finally { 84 stmt.close(); 85 } 86 87 } 88 89 } 90 | Popular Tags |