<commit_before>#!/usr/bin/perl

# To do
# add create virtual server code
# add create pool code

use warnings;
use strict;
#use SOAP::Lite +debug => 'all', +trace => 'all';
use SOAP::Lite;
use Data::Dumper;

my($client, $soapResponse, $user, $password, $server, $partition);
my $password_file = "$ENV{HOME}/.f5_login";
if (-e $password_file)
{
	open(LOGIN, "<", $password_file) or warn $!;
	my @login_creds = <LOGIN>;
	($user,$password) = split(/\s/, $login_creds[0]);
} else {print "error in opening file\n";}

my $help_message = q/
		Commands:
			login - login to specified server format: login server username password
			system_information - display basic system information
			list_partition - list system partitions
			set_partition - set active partition
			get_active_partition - display active partition
			list_virtual_servers - display virtual servers in active partition
			list_rules - list irules for specified virtual server
			add_rule - add irule to virtual server
			help - print this menu
/;


print "F5 Interactive Shell\n";
print "$help_message\n";
print ">";

while (my $command = <STDIN>)
{
	chomp($command);

	if($command =~ m/^login/)
	{
		if ($password_file)
		{
			(undef, $server) = split(/\s/, $command);
		} else {
			(undef, $server, $user, $password) = split(/\s/, $command);
		}
		sub SOAP::Transport::HTTP::Client::get_basic_credentials {
			return $user => $password;
		}
		# define client proxy
		$client = SOAP::Lite->proxy("https://$server/iControl/iControlPortal.cgi", ssl_opts => [ verify_hostname => 0, debug => 1 ]);
		# Grab current active partition
		$partition = &get_active_partition;
	}
	elsif ($command eq 'exit')
	{
		exit();
	}
	elsif ($command eq 'system_information')
	{
		&system_information;
	}
	elsif ($command eq 'add')
	{
		my ($virtual_server_status) = &create_virtual;
		print $virtual_server_status,"\n";
	}
	elsif ($command eq 'list_partition')
	{
		&list_partition;
	}
	elsif ($command eq 'set_partition')
	{
		&set_partition;
		$partition = &get_active_partition;
	}
	elsif ($command eq 'get_active_partition')
	{
		&get_active_partition;
	}
	elsif ($command eq 'list_virtual_servers')
	{
		&list_virtual_servers;
	}
	elsif ($command eq 'list_rules')
	{
		&list_virtual_rules;
	}
	elsif ($command eq 'add_rule')
	{
		&add_virtual_irule;
	}
	elsif ($command =~ /^del_rule/)
	{
		&del_virtual_irule;
	}
	elsif ($command eq 'help')
	{
		print $help_message;
	}
	else
	{
		print "Error: Command not found\n";
	}
	print "$server -> $partition>";
}

sub system_information
{
	# Used for basic connectivity testing
	# once user logs into the system, they run system_information and the basic info of the system should be displayed
	# Refer to URL_HERE for more information and adding functionality.
	#	my $SystemInfo = SOAP::Lite
	#		-> uri('urn:iControl:System/SystemInfo')
	#		-> proxy("http://$server/iControl/iControlPortal.cgi");
	my $SystemInfo = $client->uri('urn:iControl:System/SystemInfo');
	# The line below is used to encode username and password with the http requests
	eval { $SystemInfo->transport->http_request->header ( 'Authorization' => 'Basic ' . MIME::Base64::encode("$user:$password", '')); };

	$soapResponse = $SystemInfo->get_version();
	my ($version) = $soapResponse->result;
	print "Version: $version\n";
	$soapResponse = $SystemInfo->get_system_id();
	my ($system_id) = $soapResponse->result;
	print "System ID: $system_id\n";
	$soapResponse = $SystemInfo->get_uptime();
	my (@uptime) = $soapResponse->result;
	printf("Uptime: %ld\n", $uptime[0]);
	$soapResponse = $SystemInfo->get_system_information();
	# System information is returned as an array of hashes
	my (@system_information) = $soapResponse->result;
	print "System Information:\n";
	print "\tHostname: $system_information[0]->{host_name}\n";
	print "\tSystem Name: $system_information[0]->{system_name}\n";
	print "\tPlatform: $system_information[0]->{platform}\n";
}

sub checkResponse()
{
	my ($soapResponse) = (@_);<commit_msg>added routine to display all information from get_system_information call<commit_after>#!/usr/bin/perl

# To do
# add create virtual server code
# add create pool code

use warnings;
use strict;
#use SOAP::Lite +debug => 'all', +trace => 'all';
use SOAP::Lite;
use Data::Dumper;

my($client, $soapResponse, $user, $password, $server, $partition);
my $password_file = "$ENV{HOME}/.f5_login";
if (-e $password_file)
{
	open(LOGIN, "<", $password_file) or warn $!;
	my @login_creds = <LOGIN>;
	($user,$password) = split(/\s/, $login_creds[0]);
} else {print "error in opening file\n";}

my $help_message = q/
		Commands:
			login - login to specified server format: login server username password
			system_information - display basic system information
			list_partition - list system partitions
			set_partition - set active partition
			get_active_partition - display active partition
			list_virtual_servers - display virtual servers in active partition
			list_rules - list irules for specified virtual server
			add_rule - add irule to virtual server
			help - print this menu
/;


print "F5 Interactive Shell\n";
print "$help_message\n";
print ">";

while (my $command = <STDIN>)
{
	chomp($command);

	if($command =~ m/^login/)
	{
		if ($password_file)
		{
			(undef, $server) = split(/\s/, $command);
		} else {
			(undef, $server, $user, $password) = split(/\s/, $command);
		}
		sub SOAP::Transport::HTTP::Client::get_basic_credentials {
			return $user => $password;
		}
		# define client proxy
		$client = SOAP::Lite->proxy("https://$server/iControl/iControlPortal.cgi", ssl_opts => [ verify_hostname => 0, debug => 1 ]);
		# Grab current active partition
		$partition = &get_active_partition;
	}
	elsif ($command eq 'exit')
	{
		exit();
	}
	elsif ($command eq 'system_information')
	{
		&system_information;
	}
	elsif ($command eq 'add')
	{
		my ($virtual_server_status) = &create_virtual;
		print $virtual_server_status,"\n";
	}
	elsif ($command eq 'list_partition')
	{
		&list_partition;
	}
	elsif ($command eq 'set_partition')
	{
		&set_partition;
		$partition = &get_active_partition;
	}
	elsif ($command eq 'get_active_partition')
	{
		&get_active_partition;
	}
	elsif ($command eq 'list_virtual_servers')
	{
		&list_virtual_servers;
	}
	elsif ($command eq 'list_rules')
	{
		&list_virtual_rules;
	}
	elsif ($command eq 'add_rule')
	{
		&add_virtual_irule;
	}
	elsif ($command =~ /^del_rule/)
	{
		&del_virtual_irule;
	}
	elsif ($command eq 'help')
	{
		print $help_message;
	}
	else
	{
		print "Error: Command not found\n";
	}
	print "$server -> $partition>";
}

sub system_information
{
	# Used for basic connectivity testing
	# once user logs into the system, they run system_information and the basic info of the system should be displayed
	# Refer to URL_HERE for more information and adding functionality.
	#	my $SystemInfo = SOAP::Lite
	#		-> uri('urn:iControl:System/SystemInfo')
	#		-> proxy("http://$server/iControl/iControlPortal.cgi");
	my $SystemInfo = $client->uri('urn:iControl:System/SystemInfo');
	# The line below is used to encode username and password with the http requests
	eval { $SystemInfo->transport->http_request->header ( 'Authorization' => 'Basic ' . MIME::Base64::encode("$user:$password", '')); };

	$soapResponse = $SystemInfo->get_version();
	my ($version) = $soapResponse->result;
	print "Version: $version\n";
	$soapResponse = $SystemInfo->get_system_id();
	my ($system_id) = $soapResponse->result;
	print "System ID: $system_id\n";
	$soapResponse = $SystemInfo->get_uptime();
	my (@uptime) = $soapResponse->result;
	printf("Uptime: %ld\n", $uptime[0]);
	$soapResponse = $SystemInfo->get_system_information();
	# System information is returned as an array of hashes
	my (@system_information) = $soapResponse->result;
	print "System Information:\n";
	foreach my $sysinfo (@system_information)
	{
		foreach my $keys (keys %{$sysinfo})
		{
			print "\t$keys: " . %{$sysinfo}->{$keys} . "\n";
		}
	}
#	print "\tHostname: $system_information[0]->{host_name}\n";
#	print "\tSystem Name: $system_information[0]->{system_name}\n";
#	print "\tPlatform: $system_information[0]->{platform}\n";
}

sub checkResponse()
{
	my ($soapResponse) = (@_);
{'fraction_non_alphanumeric': 0.1517156862745098, 'fraction_numerical': 0.002696078431372549, 'mean_word_length': 4.651662049861496, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 64, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '166523', 'n_tokens_mistral': 2885, 'n_tokens_neox': 2775, 'n_words': 711}