lkautcd2961a5-dfe6-4386-9561-8c1c80e3eec8

Simple bash script to build from

Discussion created by lkautcd2961a5-dfe6-4386-9561-8c1c80e3eec8 Employee on Apr 9, 2016
Latest reply on Apr 28, 2016 by KMEGH692125a8-83d3-3c18-96e2-503d0c4d8bad

Hello,

 

I thought I would post this for someone that wants to get started in automating some tasks in R80.X

This script uses curl to post to the web API in Check Point R80.

The process of this script simply logs in, creates a host, publishes, and logs out.

--==--

 

#!/bin/bash

 

username="admin"

password="vpn123"

host="192.168.1.1"

baseurl=https://$host/web_api

 

#Used these two curl lines with fiddler or ZAP proxy running for degug

#curl_cmd="curl -x http://localhost:8080 --silent --insecure -X POST"

#curl_cmd="curl -x http://localhost:8888 --silent --insecure -X POST"

curl_cmd="curl  --silent --insecure -X POST"

 

#This logs in but captures the session ID into variable "SID".  I also use STDIN with curl so I don't have to escape all the """ "-d @-" just tells curl to read the data from STDIN.

SID=`${curl_cmd} -H "Content-Type: application/json" -d @- $baseurl/login <<. | awk -F\" '/sid/ {print $4}'

{

  "user":"$username" ,

  "password":"$password" ,

  "session-name":"TACO"

}

.`

#This ends the login, but below this you can run any other code and interact with the R80 API prior to logging out

#Add Test Host

${curl_cmd} -H "Content-Type: application/json" -H "X-chkp-sid: $SID" -d @- $baseurl/add-host <<.

{

  "name":"Test_Host2",

  "ip-address":"1.2.3.5",

  "color":"dark orchid"

}

.

 

#Publish

${curl_cmd} -H "Content-Type: application/json" -H "X-chkp-sid: $SID" -d "{}" $baseurl/publish

#Logout

${curl_cmd} -H "Content-Type: application/json" -H "X-chkp-sid: $SID" -d "{}" $baseurl/logout

 

 

--==--

-Lon

Outcomes