Create a Post
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Simple bash script to build from

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

1 Reply
Not applicable

Lon, great work, simple, elegant and quite fast. I do worry you could overwhelm a lesser machine with this script, but thats a bigger discussion around making sure you manage your api calls through a controller or gateway.

I have taken your curl approach, replaced it in the cpdeploy scripts I have been using to create a container to command line script aws and azure deployments. I still need to document the heck out of it, but basically all your variables are stored in /cpdeploy/VAR and all the scripts are in the subdirectories for gw, mg, and app. It still needs work, and I'll post separately on it to track the documentation and builds, but if you want to take it for a test spin. . . .

docker run --name cpdeploy -i -t kellman/cpdeploy

that should do it. It's your curl code that does the management api. THANK YOU!

Kellman

0 Kudos

Leaderboard

Epsum factorial non deposit quid pro quo hic escorol.

Upcoming Events

    CheckMates Events