Changeset 1558 for honeyclient/trunk
- Timestamp:
- 04/24/08 17:14:36 (7 months ago)
- Files:
-
- honeyclient/trunk/lib/HoneyClient/Manager.pm (modified) (5 diffs)
- honeyclient/trunk/lib/HoneyClient/Manager/Database.pm (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
honeyclient/trunk/lib/HoneyClient/Manager.pm
r1547 r1558 241 241 use Data::Dumper; 242 242 243 # Make sure Sys::Hostname loads. 244 BEGIN { use_ok('Sys::Hostname') or diag("Can't load Sys::Hostname package. Check to make sure the package library is correctly listed within the path."); } 245 require_ok('Sys::Hostname'); 246 use Sys::Hostname; 247 248 # Make sure Sys::HostIP loads. 249 BEGIN { use_ok('Sys::HostIP') or diag("Can't load Sys::HostIP package. Check to make sure the package library is correctly listed within the path."); } 250 require_ok('Sys::HostIP'); 251 use Sys::HostIP; 252 243 253 =end testing 244 254 … … 264 274 # Include Database Libraries 265 275 use HoneyClient::Manager::Database; 276 277 # Use Hostname Libraries 278 use Sys::Hostname::Long; 279 280 # Use HostIP Libraries 281 use Sys::HostIP; 266 282 267 283 # Use Dumper Library … … 540 556 } 541 557 558 # Helper function designed to get new URLs from the Drone 559 # database. If it's the first attempt at obtaining URLs, 560 # then it will ask the Drone database for any existing, 561 # pre-assigned URLs. Otherwise, it will ask the Drone 562 # database for new, unassigned URLs. 563 # 564 # Inputs: first_attempt 565 # Outputs: Hashref of (url => priority) pairs. 566 sub _get_urls { 567 568 # Extract arguments. 569 my (%args) = @_; 570 571 # Returned argument. 572 my $ret = { }; 573 574 # If this is the first attempt, then get any pre-assigned URLs. 575 if ($args{'first_attempt'}) { 576 $ret = HoneyClient::Manager::Database::get_queue_urls_by_hostname(Sys::Hostname::Long::hostname_long); 577 } else { 578 $ret = HoneyClient::Manager::Database::get_new_queue_urls(Sys::Hostname::Long::hostname_long, getVar(name => "num_urls_to_process")); 579 } 580 return $ret; 581 } 542 582 543 583 # Signal handler to help give user immediate feedback during … … 644 684 } 645 685 686 # Register the host system with the database, if need be. 687 if (getVar(name => "enable", 688 namespace => "HoneyClient::Manager::Database")) { 689 690 my $host = { 691 org => getVar(name => "organization"), 692 hostname => Sys::Hostname::Long::hostname_long, 693 ip => Sys::HostIP->ip, 694 }; 695 HoneyClient::Manager::Database::insert_host($host); 696 } 697 646 698 # If supported, get a URL list from the database. 647 699 my $remoteLinksExist = 0; 648 700 my $queue_url_list = {}; 649 701 my $tid = undef; 702 my $first_access_attempt = 1; 650 703 while (getVar(name => "enable", 651 704 namespace => "HoneyClient::Manager::Database")) { 652 705 $LOG->info("Waiting for new URLs from database."); 653 # TODO: Fix this.654 #$queue_url_list = HoneyClient::Manager::Database::get_queue_urls(getVar(name => "num_urls_to_process"), $vm->database_id);655 $queue_url_list = HoneyClient::Manager::Database::get_queue_urls(getVar(name => "num_urls_to_process"), 1145); 706 $queue_url_list = _get_urls(first_attempt => $first_access_attempt); 707 $first_access_attempt = 0; 708 656 709 $remoteLinksExist = scalar(%{$queue_url_list}); 657 710 while (!$localLinksExist && !$remoteLinksExist) { … … 661 714 # XXX: Trap/ignore all errors and simply retry. 662 715 eval { 663 # TODO: Fix this. 664 #$queue_url_list = HoneyClient::Manager::Database::get_queue_urls(getVar(name => "num_urls_to_process"), $vm->database_id); 665 $queue_url_list = HoneyClient::Manager::Database::get_queue_urls(getVar(name => "num_urls_to_process"), 1145); 716 $queue_url_list = _get_urls(first_attempt => 0); 666 717 $remoteLinksExist = scalar(%{$queue_url_list}); 667 718 }; honeyclient/trunk/lib/HoneyClient/Manager/Database.pm
r1532 r1558 296 296 297 297 # XXX: Need to comment this further. 298 sub get_queue_urls {299 $AUTOLOAD = "Database::get_queue_urls ";298 sub get_queue_urls_by_hostname { 299 $AUTOLOAD = "Database::get_queue_urls_by_hostname"; 300 300 # Results from this call are YAML-encoded; need to deserialize them. 301 301 return YAML::XS::Load(_AUTOLOAD(@_)); 302 302 } 303 304 # XXX: Need to comment this further. 305 sub get_new_queue_urls { 306 $AUTOLOAD = "Database::get_new_queue_urls"; 307 # Results from this call are YAML-encoded; need to deserialize them. 308 return YAML::XS::Load(_AUTOLOAD(@_)); 309 } 310 303 311 304 312 # XXX: Need to comment this further.
