SessionID = params['SessionID']
QueryInput = params['QueryInput']
proxy = 'https://'+sHost+'/AFA/php/ws.php?wsdl'
namespace = 'https://www.algosec.com/afa-ws'
server = SOAPProxy(proxy, namespace)
if (DebugMode):
server.config.dumpHeadersIn = 1
server.config.dumpHeadersOut = 1
server.config.dumpSOAPOut = 1
server.config.dumpSOAPIn = 1
response = server.QueryRequest(SessionID=SessionID, QueryInput=QueryInput)
return response
def DisconnectAFA(params):
SessionID = params['SessionID']
proxy = 'https://'+sHost+'/AFA/php/ws.php?wsdl'
namespace = 'https://www.algosec.com/afa-ws'
server = SOAPProxy(proxy, namespace)
if (DebugMode):
server.config.dumpHeadersIn = 1
server.config.dumpHeadersOut = 1
server.config.dumpSOAPOut = 1
server.config.dumpSOAPIn = 1
response = server.DisconnectRequest(SessionID=SessionID)
return response
sHost = '192.168.3.82'
DebugMode = False
print "\n" + "Submitting connect request:" + "\n"
values = {'UserName': 'admin', 'Password': 'algosec', 'Domain': ''}
afa_connect = ConnectAFA(values)
SessionID = afa_connect
print "Returned Session ID: "+repr(SessionID)
print "\n" + "Submitting query request:" + "\n"
QueryParams = {'SessionID': SessionID,'QueryInput': {'Source': '192.168.1.100', 'Destination': '10.228.16.10', 'Service': 'tcp/22'}}
QueryResult = SendQueryRequest(QueryParams)
print QueryResult
print "\n" + "Submitting disconnect request:" + "\n"
DisconnectParams = {'SessionID': SessionID}
DisconnectResult = DisconnectAFA(DisconnectParams)
print DisconnectResult
#!/usr/bin/perl -w
use Data::Dumper;
use SOAP::Lite;
my $soap = SOAP::Lite->proxy('https://localhost/contoh-script/isi.php?wsdl');
$soap->transport->ssl_opts(
verify_hostname => 0,
SSL_verify_mode => 0x00
);
sub ConnectAFA
{
my $sUserName = shift; # User name
my $sPassword = shift; # Password
my $sDomain = shift; # Domain name or empty for non domain envirnment
$sDomain = (!defined $sDomain) ? '' : $sDomain;
my $method = SOAP::Data->name('ConnectRequest')->attr({xmlns => 'https://www.algosec.com/afa-ws'});
my @params = (
SOAP::Data->name(UserName => $sUserName),
SOAP::Data->name(Password => $sPassword),
SOAP::Data->name(Domain => $sDomain)
);
my $sSessionID = $soap->call($method => @params)->result;
}
sub ExecQuery
{
my $sSessionID = shift;
my $sQueryTarget = shift;
$sQueryTarget = (!defined $sQueryTarget) ? '' : $sQueryTarget;
my $method = SOAP::Data->name('QueryRequest')->attr({xmlns => 'https://www.algosec.com/afa-ws'});
my $QueryInput = SOAP::Data->name('QueryRequest')->attr({xmlns => 'https://www.algosec.com/afa-ws'});
my @params = (
SOAP::Data->name(SessionID => $sSessionID),
SOAP::Data->name(QueryInput => \SOAP::Data->value(
SOAP::Data->name(Source => '*'),
SOAP::Data->name(Destination => '*'),
SOAP::Data->name(Service => '80'),
SOAP::Data->name(Service => '443')
)
),
SOAP::Data->name(QueryTarget => $sQueryTarget)
);
return $soap->call($method => @params);
}
sub DisconnectAFA
{
my $sSessionID = shift;
my $method = SOAP::Data->name('DisconnectRequest')->attr({xmlns => 'https://www.algosec.com/afa-ws'});
my @params = (
SOAP::Data->name(SessionID => $sSessionID),
);
return $soap->call($method => @params)->valueof('//DisconnectResponse');
}
my $sSessionID = ConnectAFA('admin', 'algosec', '');
print "\n";
print "Session ID: '" . $sSessionID ."'";
print "\n";
my $QueryResult = ExecQuery($sSessionID, 'afa-276');
foreach my $Result ($QueryResult->valueof('//QueryResult/')) {
print Dumper($Result);
}
print "\n";
my $Disconnect = DisconnectAFA($sSessionID);
print "Disconnect: ";
print $Disconnect;
print "\n";
Lebih lanjut tentang REST API
Apakah REST API itu ? REST adalah singkatan dari Representational State Transfer, yang memiliki arsitektur dengan secara sistematis yang membuat program dapat berkomunikasi satu sama lain, yang berfungsi sesuai komponen beberapa file, media hingga obyek terhadap beberapa hardware.
REST hadir untuk memenuhi ketidakstabilan dari SOAP yang memberikan kemudahan bagi developer atau programmer atau para pembuat software untuk menciptakan program secara mudah mengakses web service, secara arsitektur service, REST disebut sebagai RESTful, sekarang ini memang banyak developer yang merancang Public API.
Saat akan menentukan apakah memakai SOAP atau REST, tentu harus mengetahui dasarnya, yaitu jika memakai REST, lebih berbasis data, yang bergantung dengan protokol komunikasi tanpa status men-detail, atau yang bisa disebut dengan HTTP.
REST bisa mengolah data berupa YAML, XML ataupun format lainnya, sederhananya, REST memakai format JSON dan SOAP memakai XML.