1
0

fetch_new_arp.pl 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508
  1. #!/usr/bin/perl
  2. #
  3. # Copyright (C) Roman Dmitriev, rnd@rajven.ru
  4. #
  5. use utf8;
  6. use warnings;
  7. use Encode;
  8. use open qw(:std :encoding(UTF-8));
  9. no warnings 'utf8';
  10. use English;
  11. use base;
  12. use FindBin '$Bin';
  13. use lib "/opt/Eye/scripts";
  14. use strict;
  15. use DBI;
  16. use Time::Local;
  17. use Net::Patricia;
  18. use Data::Dumper;
  19. use Date::Parse;
  20. use Socket;
  21. use eyelib::config;
  22. use eyelib::main;
  23. use eyelib::logconfig;
  24. use eyelib::net_utils;
  25. use eyelib::snmp;
  26. use eyelib::database;
  27. use eyelib::common;
  28. use NetAddr::IP;
  29. use Fcntl qw(:flock);
  30. use Parallel::ForkManager;
  31. # Ensure only one instance of the script runs at a time
  32. open(SELF, "<", $0) or die "Cannot open $0 - $!";
  33. flock(SELF, LOCK_EX | LOCK_NB) or exit 1;
  34. # Lower process priority to minimize system impact
  35. setpriority(0, 0, 19);
  36. # Skip discovery if the system is in configuration mode
  37. if ($config_ref{config_mode}) {
  38. log_info("System in configuration mode! Skip discovery.");
  39. exit;
  40. }
  41. # Clean up empty user accounts and associated devices for dynamic users and hotspot
  42. db_log_verbose($dbh, 'Clearing empty records.');
  43. db_log_info($dbh, 'Clearing empty user accounts and associated devices for dynamic users and hotspot');
  44. my $u_sql = "SELECT * FROM user_list AS U WHERE (U.ou_id = ? OR U.ou_id = ?) AND (SELECT COUNT(*) FROM user_auth WHERE user_auth.deleted = 0 AND user_auth.user_id = U.id) = 0";
  45. my @u_ref = get_records_sql($dbh, $u_sql, $default_user_ou_id, $default_hotspot_ou_id);
  46. foreach my $row (@u_ref) {
  47. db_log_info($dbh, "Remove empty dynamic user with id: $row->{id} login: $row->{login}");
  48. delete_user($dbh, $row->{id});
  49. }
  50. # Clean up empty non-permanent user accounts that have no authentications or auth rules
  51. #if ($config_ref{clean_empty_user}) {
  52. # db_log_info($dbh, 'Clearing empty non-permanent user accounts and associated devices');
  53. # my $u_sql = "SELECT * FROM user_list AS U WHERE U.permanent = 0 AND (SELECT COUNT(*) FROM user_auth WHERE user_auth.deleted = 0 AND user_auth.user_id = U.id) = 0 AND (SELECT COUNT(*) FROM auth_rules WHERE auth_rules.user_id = U.id) = 0;";
  54. # my @u_ref = get_records_sql($dbh, $u_sql);
  55. # foreach my $row (@u_ref) {
  56. # db_log_info($dbh, "Remove empty user with id: $row->{id} login: $row->{login}");
  57. # delete_user($dbh, $row->{id});
  58. # }
  59. #}
  60. # Clean temporary (dynamic) user authentication records that have expired
  61. my $now = DateTime->now(time_zone => 'local');
  62. my $clear_time_str = $now->strftime('%Y-%m-%d %H:%M:%S');
  63. my $users_sql = "SELECT * FROM user_auth WHERE deleted = 0 AND dynamic = 1 AND end_life <= ?";
  64. my @users_auth = get_records_sql($dbh, $users_sql, $clear_time_str);
  65. if (@users_auth and scalar @users_auth) {
  66. foreach my $row (@users_auth) {
  67. delete_user_auth($dbh, $row->{id});
  68. db_log_info($dbh, "Removed dynamic user auth record for auth_id: $row->{'id'} by end_life time: $row->{'end_life'}", $row->{'id'});
  69. my $u_count = get_count_records($dbh, 'user_auth', 'deleted = 0 AND user_id = ? ', $row->{user_id});
  70. if (!$u_count) {
  71. delete_user($dbh, $row->{'user_id'});
  72. }
  73. }
  74. }
  75. # Track MAC address history for change detection
  76. my %mac_history;
  77. # Get current timestamp components
  78. my ($sec, $min, $hour, $day, $month, $year, $zone) = localtime(time());
  79. $month += 1;
  80. $year += 1900;
  81. # Set parallelization level: 5 processes per CPU core
  82. my $fork_count = $cpu_count * 5;
  83. # Optional: disable forking during debugging (currently descriptioned out)
  84. # if ($debug) { $fork_count = 0; }
  85. my $now_str = sprintf "%04d-%02d-%02d %02d:%02d:%02d", $year, $month, $day, $hour, $min, $sec;
  86. my $now_day = sprintf "%04d-%02d-%02d", $year, $month, $day;
  87. db_log_verbose($dbh, 'ARP discovery started.');
  88. # If script is called with an argument, perform active ping-based network discovery
  89. if ($ARGV[0]) {
  90. db_log_verbose($dbh, 'Active network check started!');
  91. my $subnets = get_subnets_ref($dbh);
  92. my @fping_cmd = ();
  93. foreach my $net (keys %$subnets) {
  94. next if (!$net);
  95. next if (!$subnets->{$net}{discovery});
  96. my $run_cmd = "$fping -g $subnets->{$net}{subnet} -B1.0 -c 1 >/dev/null 2>&1";
  97. db_log_debug($dbh, "Checked network $subnets->{$net}{subnet}") if ($debug);
  98. push(@fping_cmd, $run_cmd);
  99. }
  100. $parallel_process_count = $cpu_count * 2;
  101. run_in_parallel(@fping_cmd);
  102. }
  103. # Fetch all SNMP-enabled routers and L3 switches eligible for ARP discovery
  104. my @router_ref = get_records_sql($dbh, "SELECT * FROM devices WHERE deleted = 0 AND (device_type = 2 OR device_type = 0) AND discovery = 1 AND snmp_version > 0 ORDER BY ip");
  105. # Release main DB handle before forking
  106. $dbh->disconnect;
  107. my @arp_array = ();
  108. # Initialize parallel manager for ARP table collection
  109. my $pm_arp = Parallel::ForkManager->new($fork_count);
  110. # Callback to collect ARP table results from child processes
  111. $pm_arp->run_on_finish(
  112. sub {
  113. my ($pid, $exit_code, $ident, $exit_signal, $core_dump, $data_structure_reference) = @_;
  114. if (defined($data_structure_reference)) {
  115. my $result = ${$data_structure_reference};
  116. push(@arp_array, $result);
  117. }
  118. }
  119. );
  120. # Iterate over each router and collect its ARP table in parallel
  121. DATA_LOOP:
  122. foreach my $router (@router_ref) {
  123. my $router_ip = $router->{ip};
  124. setCommunity($router);
  125. if (!(HostIsLive($router_ip) && snmp_ping($router_ip, $router->{snmp}))) {
  126. log_info("Host id: $router->{id} name: $router->{device_name} ip: $router_ip is down or not snmp access! Skip.");
  127. next;
  128. }
  129. $pm_arp->start() and next DATA_LOOP;
  130. my $arp_table;
  131. my $tmp_dbh = init_db();
  132. if (apply_device_lock($tmp_dbh, $router->{id},0)) {
  133. $arp_table = get_arp_table($router_ip, $router->{snmp});
  134. log_debug("ARP table for $router_ip: ".Dumper($arp_table));
  135. unset_lock_discovery($tmp_dbh, $router->{id});
  136. }
  137. $tmp_dbh->disconnect;
  138. $pm_arp->finish(0, \$arp_table);
  139. }
  140. # Wait for all ARP collection processes to finish
  141. $pm_arp->wait_all_children;
  142. ########################### End ARP collection forks #########################
  143. # Reconnect to database after forking
  144. $dbh = init_db();
  145. # Load all active user authentications indexed by IP
  146. my @authlist_ref = get_records_sql($dbh, "SELECT * FROM user_auth WHERE deleted = 0 ORDER BY ip_int");
  147. # full user ip records
  148. my $users = Net::Patricia->new;
  149. my %ip_list;
  150. foreach my $row (@authlist_ref) {
  151. $users->add_string($row->{ip}, $row->{id});
  152. $ip_list{$row->{id}}->{id} = $row->{id};
  153. $ip_list{$row->{id}}->{ip} = $row->{ip};
  154. $ip_list{$row->{id}}->{mac} = mac_splitted($row->{mac}) || '';
  155. }
  156. log_debug("Found ARP tables: ".Dumper(\@arp_array));
  157. # Process all collected ARP tables
  158. foreach my $arp_table (@arp_array) {
  159. foreach my $ip (keys %$arp_table) {
  160. next if (!$arp_table->{$ip});
  161. my $mac = trim($arp_table->{$ip});
  162. $mac = mac_splitted($mac);
  163. next if (!$mac);
  164. next if ($mac =~ /ff:ff:ff:ff:ff:ff/i); # Skip broadcast MAC
  165. next if ($mac !~ /(\S{2}):(\S{2}):(\S{2}):(\S{2}):(\S{2}):(\S{2})/); # Validate MAC format
  166. my $simple_mac = mac_simplify($mac);
  167. $ip = trim($ip);
  168. my $ip_aton = StrToIp($ip);
  169. # Skip IPs outside configured office networks
  170. next if (!$office_networks->match_string($ip));
  171. log_debug("Analyze ip: $ip mac: $mac") if ($debug);
  172. my $auth_id = $users->match_string($ip);
  173. my $arp_record;
  174. $arp_record->{ip} = $ip;
  175. $arp_record->{mac} = $mac;
  176. $arp_record->{type} = 'arp';
  177. $arp_record->{ip_aton} = $ip_aton;
  178. $arp_record->{hotspot} = is_hotspot($dbh, $ip);
  179. # Attempt to resurrect or map this ARP entry to a known auth record
  180. my $cur_auth_id = resurrection_auth($dbh, $arp_record);
  181. if (!$cur_auth_id) {
  182. log_warning("Unknown record " . Dumper($arp_record))
  183. }
  184. }
  185. }
  186. db_log_verbose($dbh, 'MAC (FDB) discovery started.');
  187. # Load existing port connections for authenticated users
  188. my %connections = ();
  189. my @connections_list = get_records_sql($dbh, "SELECT * FROM connections ORDER BY auth_id");
  190. foreach my $connection (@connections_list) {
  191. next if (!$connection);
  192. $connections{$connection->{auth_id}}{port} = $connection->{port_id};
  193. $connections{$connection->{auth_id}}{id} = $connection->{id};
  194. }
  195. # Build operational and full MAC-to-auth lookup tables
  196. my $auth_sql = "SELECT id, mac FROM user_auth WHERE mac IS NOT NULL AND deleted = 0 AND arp_found >= ? ORDER BY id ASC";
  197. my @auth_list = get_records_sql($dbh, $auth_sql, $now_day);
  198. my %auth_table;
  199. foreach my $auth (@auth_list) {
  200. next if (!$auth || !$auth->{mac});
  201. my $auth_mac = mac_simplify($auth->{mac});
  202. $auth_table{oper_table}{$auth_mac} = $auth->{id};
  203. }
  204. $auth_sql = "SELECT id, mac FROM user_auth WHERE mac IS NOT NULL AND deleted = 0 ORDER BY arp_found DESC, id DESC";
  205. my @auth_full_list = get_records_sql($dbh, $auth_sql);
  206. foreach my $auth (@auth_full_list) {
  207. next if (!$auth || !$auth->{mac});
  208. my $auth_mac = mac_simplify($auth->{mac});
  209. next if (exists $auth_table{full_table}{$auth_mac});
  210. $auth_table{full_table}{$auth_mac} = $auth->{id};
  211. }
  212. # Load unknown MAC addresses from the database
  213. my @unknown_list = get_records_sql($dbh, "SELECT id, mac, port_id, device_id FROM unknown_mac WHERE mac IS NOT NULL ORDER BY mac;");
  214. my %unknown_table;
  215. foreach my $unknown (@unknown_list) {
  216. next if (!$unknown);
  217. next if (!$unknown->{mac});
  218. my $unknown_mac = mac_simplify($unknown->{mac});
  219. $unknown_table{$unknown_mac}{unknown_id} = $unknown->{id};
  220. $unknown_table{$unknown_mac}{port_id} = $unknown->{port_id};
  221. $unknown_table{$unknown_mac}{device_id} = $unknown->{device_id};
  222. }
  223. # Fetch all SNMP-enabled devices (switches, routers, etc.) for FDB discovery
  224. my @device_list = get_records_sql($dbh,"SELECT * FROM devices WHERE deleted = 0 AND device_type <= 2 AND discovery = 1 AND snmp_version > 0");
  225. my @fdb_array = ();
  226. # Initialize parallel manager for FDB (forwarding database) collection
  227. my $pm_fdb = Parallel::ForkManager->new($fork_count);
  228. # Callback to collect FDB results from child processes
  229. $pm_fdb->run_on_finish(
  230. sub {
  231. my ($pid, $exit_code, $ident, $exit_signal, $core_dump, $data_structure_reference) = @_;
  232. if (defined($data_structure_reference)) {
  233. my $result = ${$data_structure_reference};
  234. push(@fdb_array, $result);
  235. }
  236. }
  237. );
  238. # Release main DB handle before forking
  239. $dbh->disconnect;
  240. # Collect FDB tables from each device in parallel
  241. FDB_LOOP:
  242. foreach my $device (@device_list) {
  243. setCommunity($device);
  244. if (!(HostIsLive($device->{ip}) && snmp_ping($device->{ip}, $device->{snmp}))) {
  245. log_info("Host id: $device->{id} name: $device->{device_name} ip: $device->{ip} is down or not snmp access! Skip.");
  246. next;
  247. }
  248. $pm_fdb->start() and next FDB_LOOP;
  249. my $result;
  250. my $tmp_dbh = init_db();
  251. if (apply_device_lock($tmp_dbh, $device->{id},0)) {
  252. my $fdb = get_fdb_table($device->{ip}, $device->{snmp});
  253. log_debug("MAC table for device $device->{ip}: ".Dumper($fdb));
  254. unset_lock_discovery($tmp_dbh, $device->{id});
  255. $result->{id} = $device->{id};
  256. $result->{fdb} = $fdb;
  257. }
  258. $tmp_dbh->disconnect;
  259. $pm_fdb->finish(0, \$result);
  260. }
  261. # Wait for all FDB collection processes to finish
  262. $pm_fdb->wait_all_children;
  263. # Index FDB results by device ID
  264. my %fdb_ref;
  265. foreach my $fdb_table (@fdb_array) {
  266. next if (!$fdb_table);
  267. $fdb_ref{$fdb_table->{id}}{fdb} = $fdb_table->{fdb};
  268. }
  269. ################################ End FDB collection forks ##############################
  270. # Reconnect to database after forking
  271. $dbh = init_db();
  272. # Process FDB data for each device
  273. foreach my $device (@device_list) {
  274. my %port_snmp_index = (); # SNMP index → logical port number
  275. my %port_index = (); # logical port number → DB port ID
  276. my %mac_port_count = (); # port → number of learned MACs
  277. my %mac_address_table = (); # MAC → port
  278. my %port_links = (); # port → uplink/downlink target port ID
  279. my $dev_id = $device->{id};
  280. my $dev_name = $device->{device_name};
  281. my $fdb = $fdb_ref{$dev_id}{fdb};
  282. next if (!$fdb);
  283. # Load device port mappings from database
  284. my @device_ports = get_records_sql($dbh, "SELECT * FROM device_ports WHERE device_id = ?", $dev_id);
  285. foreach my $port_data (@device_ports) {
  286. my $fdb_port_index = $port_data->{port};
  287. my $port_id = $port_data->{id};
  288. if (!$port_data->{snmp_index}) {
  289. $port_data->{snmp_index} = $port_data->{port};
  290. }
  291. $fdb_port_index = $port_data->{snmp_index};
  292. next if ($port_data->{skip});
  293. $port_snmp_index{$port_data->{snmp_index}} = $port_data->{port};
  294. $port_index{$port_data->{port}} = $port_id;
  295. $port_links{$port_data->{port}} = $port_data->{target_port_id};
  296. $mac_port_count{$port_data->{port}} = 0;
  297. }
  298. # Special handling for MikroTik: skip device's own MAC addresses
  299. my $sw_mac;
  300. if ($device->{vendor_id} eq '9') {
  301. my $sw_auth = get_record_sql($dbh, "SELECT mac FROM user_auth WHERE deleted = 0 AND ip = ?", $device->{ip});
  302. if (!$sw_auth->{mac}) {
  303. log_error("Mac for $dev_name is undefined!");
  304. $sw_mac='undef';
  305. } else {
  306. $sw_mac = mac_simplify($sw_auth->{mac});
  307. $sw_mac =~ s/.{2}$//s; # Strip last two hex chars for prefix match
  308. }
  309. }
  310. # Process each MAC in the FDB
  311. foreach my $mac (keys %$fdb) {
  312. my $port = $fdb->{$mac};
  313. next if (!$port);
  314. # Resolve SNMP index to logical port number
  315. if (exists $port_snmp_index{$port}) {
  316. $port = $port_snmp_index{$port};
  317. }
  318. next if (!exists $port_index{$port});
  319. # Skip MikroTik's own MACs
  320. if ($sw_mac && $mac =~ /^$sw_mac/i) {
  321. next;
  322. }
  323. $mac_port_count{$port}++;
  324. $mac_address_table{$mac} = $port;
  325. }
  326. # Update MAC count per port in the database (skip uplinks/downlinks)
  327. foreach my $port (keys %mac_port_count) {
  328. next if (!$port || !exists $port_index{$port} || $port_links{$port} > 0);
  329. my $dev_ports;
  330. $dev_ports->{last_mac_count} = $mac_port_count{$port};
  331. update_record($dbh, 'device_ports', $dev_ports, "device_id = ? AND port = ?", $dev_id, $port);
  332. }
  333. # Process each learned MAC address
  334. foreach my $mac (keys %mac_address_table) {
  335. my $port = $mac_address_table{$mac};
  336. next if (!$port || !exists $port_index{$port} || $port_links{$port} > 0);
  337. my $simple_mac = mac_simplify($mac);
  338. my $mac_splitted = mac_splitted($mac);
  339. $mac_history{$simple_mac}{port_id} = $port_index{$port};
  340. $mac_history{$simple_mac}{dev_id} = $dev_id;
  341. $mac_history{$simple_mac}{changed} //= 0;
  342. my $port_id = $port_index{$port};
  343. # Case 1: MAC belongs to a known authenticated user
  344. if (exists $auth_table{full_table}{$simple_mac} || exists $auth_table{oper_table}{$simple_mac}) {
  345. my $auth_id = exists $auth_table{oper_table}{$simple_mac}
  346. ? $auth_table{oper_table}{$simple_mac}
  347. : $auth_table{full_table}{$simple_mac};
  348. unless (exists $auth_table{oper_table}{$simple_mac}) {
  349. log_debug($dbh, "MAC not found in current ARP table. Using historical auth_id: $auth_id [$simple_mac] at device $dev_name [$port]", $auth_id);
  350. }
  351. $mac_history{$simple_mac}{auth_id} = $auth_id;
  352. $mac_history{$simple_mac}{changed} = 0;
  353. my $auth_rec;
  354. $auth_rec->{last_found} = $now_str;
  355. $auth_rec->{mac_found} = $now_str;
  356. #update_record($dbh, 'user_auth', $auth_rec, "id = ?", $auth_id);
  357. # update ALL active ip record
  358. update_records($dbh, 'user_auth', "deleted = 0 AND mac = ?", $auth_rec, $mac_splitted);
  359. if (exists $connections{$auth_id}) {
  360. if ($port_id == $connections{$auth_id}{port}) {
  361. # No port change: just update last seen time if in current MAC
  362. if (exists $auth_table{oper_table}{$simple_mac}) {
  363. my $auth_rec;
  364. $auth_rec->{last_found} = $now_str;
  365. $auth_rec->{mac_found} = $now_str;
  366. update_record($dbh, 'user_auth', $auth_rec, "id = ?", $auth_id);
  367. }
  368. next;
  369. }
  370. # Port changed: update connection and log
  371. $connections{$auth_id}{port} = $port_id;
  372. $mac_history{$simple_mac}{changed} = 1;
  373. db_log_info($dbh, "Found auth_id: $auth_id mac: [$mac_splitted] at device $dev_name [$port]. Update connection.", $auth_id);
  374. my $conn_rec;
  375. $conn_rec->{port_id} = $port_id;
  376. $conn_rec->{device_id} = $dev_id;
  377. update_record($dbh, 'connections', $conn_rec, "auth_id = ?", $auth_id);
  378. } else {
  379. # New connection for known user
  380. $mac_history{$simple_mac}{changed} = 1;
  381. $connections{$auth_id}{port} = $port_id;
  382. db_log_info($dbh, "Found auth_id: $auth_id mac: [$mac_splitted] at device $dev_name [$port]. Create connection.", $auth_id);
  383. my $conn_rec;
  384. $conn_rec->{port_id} = $port_id;
  385. $conn_rec->{device_id} = $dev_id;
  386. $conn_rec->{auth_id} = $auth_id;
  387. insert_record($dbh, 'connections', $conn_rec);
  388. }
  389. }
  390. # Case 2: MAC is unknown
  391. else {
  392. if (exists $unknown_table{$simple_mac}{unknown_id}) {
  393. # MAC already known but moved
  394. next if ($unknown_table{$simple_mac}{port_id} == $port_id && $unknown_table{$simple_mac}{device_id} == $dev_id);
  395. $mac_history{$simple_mac}{changed} = 1;
  396. $mac_history{$simple_mac}{auth_id} = 0;
  397. db_log_debug($dbh, "Unknown MAC $mac_splitted moved to $dev_name [$port]") if ($debug);
  398. my $unknown_rec;
  399. $unknown_rec->{port_id} = $port_id;
  400. $unknown_rec->{device_id} = $dev_id;
  401. update_record($dbh, 'unknown_mac', $unknown_rec, "id = ?", $unknown_table{$simple_mac}{unknown_id});
  402. } else {
  403. # Brand new unknown MAC
  404. $mac_history{$simple_mac}{changed} = 1;
  405. $mac_history{$simple_mac}{auth_id} = 0;
  406. db_log_debug($dbh, "Unknown MAC $mac_splitted found at $dev_name [$port]") if ($debug);
  407. my $unknown_rec;
  408. $unknown_rec->{port_id} = $port_id;
  409. $unknown_rec->{device_id} = $dev_id;
  410. $unknown_rec->{mac} = mac_splitted($simple_mac);
  411. insert_record($dbh, 'unknown_mac', $unknown_rec);
  412. }
  413. }
  414. }
  415. }
  416. # Log all MAC movement/history events
  417. foreach my $mac (keys %mac_history) {
  418. next if (!$mac || !$mac_history{$mac}->{changed});
  419. my $h_dev_id = $mac_history{$mac}->{dev_id} || '';
  420. my $h_port_id = $mac_history{$mac}->{port_id} || '';
  421. my $h_ip = $mac_history{$mac}->{ip};
  422. my $h_auth_id = $mac_history{$mac}->{auth_id} || 0;
  423. next if (!$h_dev_id);
  424. my $history_rec;
  425. $history_rec->{device_id} = $h_dev_id;
  426. $history_rec->{port_id} = $h_port_id;
  427. $history_rec->{mac} = mac_splitted($mac);
  428. $history_rec->{ip} = $h_ip if ($h_ip);
  429. $history_rec->{auth_id} = $h_auth_id;
  430. insert_record($dbh, 'mac_history', $history_rec);
  431. }
  432. log_info("Work finished.");
  433. $dbh->disconnect;
  434. exit 0;