Skip to content

Instantly share code, notes, and snippets.

@p-rs
Last active August 17, 2024 06:10
Show Gist options
  • Save p-rs/5e67b811efd30ef704be7078cbd758a8 to your computer and use it in GitHub Desktop.
Save p-rs/5e67b811efd30ef704be7078cbd758a8 to your computer and use it in GitHub Desktop.
Automates install OpenCTI based on manual deployment: https://www.notion.so/Manual-deployment-b911beba44234f179841582ab3894bb1 - Tested successfully on Ubuntu 18.04/20.04 and OpenCTI 3.3.2
#! /bin/bash -e
# script: ubuntu_opencti_installer.sh
# purpose: to automate install opencti based on manual deployment below
# process: https://www.notion.so/Manual-deployment-b911beba44234f179841582ab3894bb1
# disclaimer: script is written for testing and runs as root
# check the code and use at your own risk!
# The author is not liable for any damages or unexpected explosions!
# license: Apache 2.0
# banner -----------------------------------------------------------
echo -e "\n\n\x1B[1;49;34mMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM"
echo -e "MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM"
echo -e "MMMMMMMMMMMMMWK00000000000000000000000000000000000000000XWMWXKKKKKKNWMMMMMMMMMMMMM"
echo -e "MMMMMMMMMMMMMXdcccccccccccccccccccccccccccccccccccccccclxNMW0dooooo0WMMMMMMMMMMMMM"
echo -e "MMMMMMMMMMMMMXdccdkOOOOOOOOOOOOOOOOOOOOOOOOkkOOOOOOOOOOOKWWWNKOkdooOWMMMMMMMMMMMMM"
echo -e "MMMMMMMMMMMMMXdclkNMMMMMMMMMMMMMMMMMMMMMWN0k0WMMMMMMMMMMMMXXWMWKxooOWMMMMMMMMMMMMM"
echo -e "MMMMMMMMMMMMMXdclkNMMMMMMMMMMMMMMMMMMMMNOdodxkO0KXNWMMMMMWKOXMMXxooOWMMMMMMMMMMMMM"
echo -e "MMMMMMMMMMMMMXdcckNMMMMMMMMMMMMMMMMMMWKdldOKK00OkkkkO0KXXN0x0WWXxooOWMMMMMMMMMMMMM"
echo -e "MMMMMMMMMMMMMXdclkNMMMMMMMMMMMMMMMMMMXdldkkkkOO0KKKK0OOkkkxoONWXxooOWMMMMMMMMMMMMM"
echo -e "MMMMMMMMMMMMMXdclkNMMMMMMMMMMMMMMMMMWOlokKKKK0OOkkkkO00KKKkokNWKdooOWMMMMMMMMMMMMM"
echo -e "MMMMMMMMMMMMMXdclkNMMMMMMMMMMMMMMMMMNxcoxkkkkO00KKKK0OkkkkdoOWNOoooOWMMMMMMMMMMMMM"
echo -e "MMMMMMMMMMMMMXdclkNMMMMMMMMMMMMMMMMMNkcoOKKKK0OkkkkkO0KK0xoxXN0doooOWMMMMMMMMMMMMM"
echo -e "MMMMMMMMMMMMMXdclkNMMMMMMMMMMMMMMMMMWOllokkkOO0KKKK00OxddoxKNKxooooOWMMMMMMMMMMMMM"
echo -e "MMMMMMMMMMMMMXdclkNMMMMMMMMMMMMMMMMMMKdcd0KKK0OkkkkOOkdodOXXOddddooOWMMMMMMMMMMMMM"
echo -e "MMMMMMMMMMMMMXdclkNMMMMMMMMMMMMMMMMMMWOlloxkOO0K0kdooox0XNKxdkK0xooOWMMMMMMMMMMMMM"
echo -e "MMMMMMMMMMMMMXdclkNMMMMMMMMMMMMMMMWWWMXxllxkxooooodkOKNN0kkOXWWXxooOWMMMMMMMMMMMMM"
echo -e "MMMMMMMMMMMMMXdclkNMMMMMMMMMMWXXXNNWWWXklclooodkOKNWNXK00XNWMMMXxooOWMMMMMMMMMMMMM"
echo -e "MMMMMMMMMMMMMXdcckNMMMMMMWX0OO0XNWNKOxdoolclkKNWWWWNXXNWMMMMMMMXxooOWMMMMMMMMMMMMM"
echo -e "MMMMMMMMMMMMMXdclkNMMMWN0xdx0NWX0kdoolldkxlldXMMMWWWMMMMMMMMMMMXxooOWMMMMMMMMMMMMM"
echo -e "MMMMMMMMMMMMMXdcckNMMN0dld0WWXOdollx0KOkxdlclkNMMMMMMM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KNWMMMMMMMMMMMMMMMMMMMMMMMM"
echo -e "MMMMMMMMMMMMMMMMMMMMMMMMMMWN0xod0NMMWNWWWMWNX0OxdooxOKWMMMMMMMMMMMMMMMMMMMMMMMMMMM"
echo -e "MMMMMMMMMMMMMMMMMMMMMMMMMMMMMWXNWWX0kxxkOOkxdoodxOKNWMMMMMMMMMMMMMMMMMMMMMMMMMMMMM"
echo -e "MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMWX0kxdoooddkO0XNWMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM"
echo -e "MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMWWNXKKXNWWMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM"
echo -e "MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM OPENCTI INSTALLER MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM"
echo -e "MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM\x1B[0m\n\n"
# check root -------------------------------------------------------
if [ "$EUID" -ne 0 ]
then
echo "Elevated privileges required. Please run with sudo or as root."
exit
fi
# warn user --------------------------------------------------------
echo -e "\x1B[0;49;91mThis script runs with elevated access, check the code and use at your own risk!\x1B[0m"
echo
# check ubuntu ver for python - 18 uses 3.6 (will install 3.7) - 20 uses 3.8
if [[ $(grep "Ubuntu " /etc/lsb-release | cut -d" " -f2 | cut -d\. -f1) == 18 ]]
then
distro="bionic"
run_python="python3.7"
elif [[ $(grep "Ubuntu " /etc/lsb-release | cut -d" " -f2 | cut -d\. -f1) == 20 ]]
then
distro="bionic" # usebionic as focal not avaialble yet for rabbitMQ
run_python="python3"
fi
# enter root scripts directory -------------------------------------
script_pwd="$(dirname "$0")"
if [[ -d "${script_pwd}" ]]
then
cd "${script_pwd}"
echo -e "${script_pwd}"
fi
# const ------------------------------------------------------------
# opencti
opencti_email="email@company.example"
opencti_ver="3.3.2"
opencti_dir="/opt/opencti"
opencti_worker_count=2
# minio
minio_dir="/opt/minio/data"
# redis
redis_ver="6.0.5"
# rabbitmq
rabbitmq_ver="3.8.5-1"
# grakn
grakn_core_server_ver="1.7.2"
grakn_console_ver="1.0.5"
grakn_core_all_ver="1.7.2"
# def --------------------------------------------------------------
# echo str params
function quit_on_error () {
if [[ $? -gt 0 ]]
then
echo -e "\n\n $@ ...FAIL";
exit 10
else
echo "$@ ...OK"
fi
}
# no params
function update_apt_pkg () {
DEBIAN_FRONTEND=noninteractive apt-get -qq update
quit_on_error "Checking packages"
}
# $1 is apt-get pkg - $2 is apt-ver
function check_apt_pkg () {
if [[ $(dpkg -l | grep $1) ]]
then
echo >&2 "$1 found, attempting upgrade:";
DEBIAN_FRONTEND=noninteractive apt -qq install --only-upgrade "$1""$2" > /dev/null 2>&1;
quit_on_error "Upgrading $1$2"
else
echo >&2 "$1 missing, attempting install:";
DEBIAN_FRONTEND=noninteractive apt -qq -y install "$1""$2" > /dev/null 2>&1;
quit_on_error "Installing $1$2"
fi
}
# $1 is service name, matching grakn service output
function check_service () {
if [[ $(systemctl show -p ActiveState --value "$1") == "active" ]]
then
echo "$1: RUNNING"
else
echo "$1: NOT RUNNING"
fi
}
# $1 is service name
function enable_service () {
if [[ $(systemctl is-enabled "$1") == "disabled" ]]
then
echo "$1 service not enabled."
systemctl enable --now "$1"
quit_on_error "Enabling $1"
elif [[ $(systemctl show -p SubState --value "$1") == "running" ]]
then
echo "$1 service already running."
systemctl restart "$1"
quit_on_error "Restarting $1"
else
echo "$1 service not running."
systemctl start "$1"
quit_on_error "Starting $1"
fi
sleep 5 # wait for services to be ready
}
# $1 is service name
function disable_service () {
if [[ $(systemctl is-enabled "$1") == "enabled" ]]
then
echo "$1 service enabled. Disabling."
systemctl disable --now "$1"
quit_on_error "Disabling $1"
elif [[ $(systemctl show -p SubState --value "$1") == "running" ]]
then
echo "$1 service still running. Stopping."
systemctl stop "$1"
quit_on_error "Stopping $1"
else
echo "$1 service not running."
quit_on_error "Skipping $1"
fi
}
# prerequisites script ---------------------------------------------
# disable/stop services
for i in $(seq 1 $opencti_worker_count)
do
disable_service "opencti-worker@$i"
done
disable_service 'opencti-server'
disable_service 'elasticsearch'
disable_service 'redis-server'
disable_service 'rabbitmq-server'
disable_service 'minio'
disable_service 'grakn'
# init update repos
update_apt_pkg
# required
check_apt_pkg 'wget'
check_apt_pkg 'tar'
check_apt_pkg 'git'
check_apt_pkg 'openssl'
check_apt_pkg 'curl'
check_apt_pkg 'software-properties-common'
check_apt_pkg 'apt-transport-https'
# nodejs
check_apt_pkg 'nodejs'
check_apt_pkg 'npm'
npm install -g n
n lts
sed -i 's|PATH.*|'"${PATH}:/usr/local/bin/node"'|g' /etc/environment
export PATH="$PATH:/usr/local/bin/node"
npm rebuild
# yarn
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
update_apt_pkg
check_apt_pkg 'yarn'
# python
check_apt_pkg "${run_python}"
check_apt_pkg "python3-pip"
# fix pyyaml ver
${run_python} -m pip install --upgrade pip
${run_python} -m pip -q install --ignore-installed PyYAML
# grakn
apt-key adv --keyserver keyserver.ubuntu.com --recv 8F3DA4B5E9AEF44C
add-apt-repository 'deb [ arch=all ] https://repo.grakn.ai/repository/apt/ trusty main'
update_apt_pkg
check_apt_pkg 'grakn-core-server' "=${grakn_core_server_ver}"
check_apt_pkg 'grakn-console' "=${grakn_console_ver}"
check_apt_pkg 'grakn-core-all' "=${grakn_core_all_ver}"
# make systemd unit file
cat <<EOT > /etc/systemd/system/grakn.service
[Unit]
Description=Grakn.AI Server daemon
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/bin/grakn server start
ExecStop=/usr/local/bin/grakn server stop
ExecReload=/usr/local/bin/grakn server stop && /usr/local/bin/grakn server start
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
EOT
systemctl daemon-reload
enable_service 'grakn'
# elasticsearch
wget -qO - 'https://artifacts.elastic.co/GPG-KEY-elasticsearch' | apt-key add -
add-apt-repository "deb https://artifacts.elastic.co/packages/7.x/apt stable main"
update_apt_pkg
check_apt_pkg 'elasticsearch'
enable_service 'elasticsearch'
# minio
wget --quiet -O minio https://dl.min.io/server/minio/release/linux-amd64/minio
chmod +x minio
mv minio "/usr/local/bin/"
if [[ ! -d "${minio_dir}" ]]
then
mkdir -p "${minio_dir}"
fi
# https://github.com/minio/minio-service/blob/master/linux-systemd/minio.service
if [[ ! -f "/etc/default/minio" ]]
then
# .minio.access_key
RMINIOAK="$(openssl rand -hex 12)"
# .minio.secret_key
RMINIOSK="$(openssl rand -base64 25 | tr -d '/')"
cat <<-EOT > /etc/default/minio
# Volume to be used for MinIO server.
MINIO_VOLUMES="/opt/minio/data/"
# Use if you want to run MinIO on a custom port.
# MINIO_OPTS="--address :9199"
# Access Key of the server.
MINIO_ACCESS_KEY=${RMINIOAK}
# Secret key of the server.
MINIO_SECRET_KEY=${RMINIOSK}
EOT
else
RMINIOAK="$(grep -o 'MINIO_ACCESS_KEY=.*' /etc/default/minio | cut -f2- -d=)"
RMINIOSK="$(grep -o 'MINIO_SECRET_KEY=.*' /etc/default/minio | cut -f2- -d=)"
fi
curl "https://raw.githubusercontent.com/minio/minio-service/master/linux-systemd/minio.service" -o "/etc/systemd/system/minio.service"
sed -i'' -e 's/User=minio-user/User=root/g' "/etc/systemd/system/minio.service"
sed -i'' -e 's/Group=minio-user/Group=root/g' "/etc/systemd/system/minio.service"
systemctl daemon-reload
enable_service 'minio'
# redis
update_apt_pkg
check_apt_pkg 'gcc'
check_apt_pkg 'build-essential'
check_apt_pkg 'libsystemd-dev' # required for systemd notify to work
check_apt_pkg 'pkg-config'
if [[ ! -f "/usr/local/bin/redis-server" ]]
then
wget "http://download.redis.io/releases/redis-${redis_ver}.tar.gz"
tar xzf redis-${redis_ver}.tar.gz
cd redis-${redis_ver}
make -s
quit_on_error "Building Redis ${redis_ver}..."
make -s install
quit_on_error "Installing Redis ${redis_ver}..."
cd ..
fi
if [[ ! $(id redis) ]]
then
adduser --system --group --no-create-home redis
usermod -L redis
fi
if [[ ! -d "/var/lib/redis/" ]]
then
mkdir -p "/var/lib/redis"
chown redis:redis "/var/lib/redis"
chmod ug+rwX "/var/lib/redis"
fi
if [[ ! -d "/etc/redis/" ]]
then
mkdir -p "/etc/redis/"
chown -R redis:redis "/etc/redis/"
fi
if [[ ! -f "/etc/redis/redis.conf" ]]
then
cp "redis-${redis_ver}/redis.conf" "/etc/redis/redis.conf"
sed -i 's/^supervised no/supervised systemd/' "/etc/redis/redis.conf"
chown redis:redis "/etc/redis/redis.conf"
fi
if [[ ! -f "/etc/default/redis-server" ]]
then
touch "/etc/default/redis-server"
echo 'ULIMIT=65536' >> "/etc/default/redis-server"
fi
if [[ ! -f "/etc/systemd/system/redis-server.service" ]]
then
cat <<- EOT > /etc/systemd/system/redis-server.service
[Unit]
Description=Redis persistent key-value storage
After=network.target
[Service]
Type=notify
ExecStart=/usr/local/bin/redis-server /etc/redis/redis.conf
ExecStop=/usr/local/bin/redis-cli -p 6379 shutdown
ExecReload=/bin/kill -USR2 \$MAINPID
TimeoutStartSec=10
TimeoutStopSec=10
Restart=on-failure
[Install]
WantedBy=multi-user.target
EOT
systemctl daemon-reload
fi
enable_service 'redis-server'
# rabbitmq
RMQ_release_url="https://github.com/rabbitmq/signing-keys/releases/download/2.0/rabbitmq-release-signing-key.asc"
curl -fsSL "${RMQ_release_url}" | apt-key add -
tee /etc/apt/sources.list.d/bintray.rabbitmq.list <<EOT
## Installs the latest Erlang 22.x release.
## Change component to "erlang-21.x" to install the latest 21.x version.
## "bionic" as distribution name should work for any later Ubuntu or Debian release.
## See the release to distribution mapping table in RabbitMQ doc guides to learn more.
deb [trusted=yes] https://dl.bintray.com/rabbitmq-erlang/debian ${distro} erlang
deb [trusted=yes] https://dl.bintray.com/rabbitmq/debian ${distro} main
EOT
update_apt_pkg
check_apt_pkg 'rabbitmq-server' "=${rabbitmq_ver}"
enable_service 'rabbitmq-server'
RRMQUNAME="rabbitadmin"
# rabbitmq doesn't like '/'
RRMQPASS="$(openssl rand -base64 25 | tr -d '/' | tr -d '+')"
# get the info once
RMQ_user_list="$(rabbitmqctl list_users)"
if grep 'guest' <<< "${RMQ_user_list}"
then
rabbitmqctl delete_user guest
fi
if ! grep "${RRMQUNAME}" <<< "${RMQ_user_list}"
then
rabbitmqctl add_user "${RRMQUNAME}" "${RRMQPASS}"
else
rabbitmqctl change_password "${RRMQUNAME}" "${RRMQPASS}"
fi
rabbitmqctl set_user_tags "${RRMQUNAME}" administrator
rabbitmqctl set_permissions -p / "${RRMQUNAME}" ".*" ".*" ".*"
rabbitmqctl start_app
rabbitmq-plugins enable rabbitmq_management
RMQ_user_list="$(rabbitmqctl list_users)"
echo -e "${RMQ_user_list}"
# check service status
check_service 'elasticsearch'
check_service 'redis-server'
check_service 'rabbitmq-server'
check_service 'minio'
check_service 'grakn'
# opencti script ---------------------------------------------------
# get opencti
wget --quiet -O opencti-release-${opencti_ver}.tar.gz "https://github.com/OpenCTI-Platform/opencti/releases/download/${opencti_ver}/opencti-release-${opencti_ver}.tar.gz"
tar -xzf "opencti-release-${opencti_ver}.tar.gz" --directory "/opt/"
echo "Changing owner of ${opencti_dir} to:" $(whoami)":"$(id -gn)
chown -R $(whoami):$(id -gn) "${opencti_dir}"
# install python reqs
${run_python} -m pip -q install -r "${opencti_dir}/connectors/export-file-stix/src/requirements.txt"
${run_python} -m pip -q install -r "${opencti_dir}/connectors/import-file-stix/src/requirements.txt"
${run_python} -m pip -q install -r "${opencti_dir}/src/python/requirements.txt"
${run_python} -m pip -q install -r "${opencti_dir}/worker/requirements.txt"
${run_python} -m pip install requests==2.23.0
# edit configs - copy default json and replace the email and
# let the script take care of the rest
# .app.admin.password
RADMINPASS="$(openssl rand -base64 25 | tr -d '/')"
# .app.admin.token
RADMINTOKEN="$(uuidgen -r | tr -d '\n' | tr '[:upper:]' '[:lower:]')"
# copy proper configs
cat "${script_pwd}/default.json" | jq '.app.admin.email="'"${opencti_email}"'" | .app.admin.password="'"${RADMINPASS}"'" | .app.admin.token="'"${RADMINTOKEN}"'" | .minio.access_key="'"${RMINIOAK}"'" | .minio.secret_key="'"${RMINIOSK}"'" | .rabbitmq.username="'"${RRMQUNAME}"'" | .rabbitmq.password="'"${RRMQPASS}"'"' > "$opencti_dir/config/production.json"
# build unit file
cat <<EOT > /etc/systemd/system/opencti-server.service
[Unit]
Description=OpenCTI Server daemon
After=network.target
[Service]
Type=simple
WorkingDirectory=${opencti_dir}/
ExecStart=/usr/bin/yarn serv
ExecReload=/bin/kill -s HUP \$MAINPID
ExecStop=/bin/kill -s TERM \$MAINPID
Restart=on-failure
[Install]
WantedBy=multi-user.target
EOT
# copy worker config
cp "${script_pwd}/config.yml.sample" "$opencti_dir/worker/config.yml"
# edit worker config
sed -i'' -e 's/token: '"'"'ChangeMe'"'"'/token: '"${RADMINTOKEN}"'/g' "$opencti_dir/worker/config.yml"
cat <<EOT > /etc/systemd/system/opencti-worker@.service
[Unit]
Description=OpenCTI Worker daemon %i
After=network.target opencti-server.service
[Service]
Type=simple
WorkingDirectory=${opencti_dir}/worker/
ExecStart=/usr/bin/${run_python} "${opencti_dir}/worker/worker.py"
ExecReload=/bin/kill -s HUP \$MAINPID
ExecStop=/bin/kill -s TERM \$MAINPID
PrivateTmp=true
Restart=always
[Install]
WantedBy=multi-user.target
EOT
systemctl daemon-reload
# start services - sleep for waiting on service boot
enable_service 'opencti-server'
sleep 30 # waiting for opencti to check all services
check_service 'opencti-server'
for i in $(seq 1 $opencti_worker_count)
do
sleep 5
enable_service "opencti-worker@$i"
sleep 5
check_service "opencti-worker@$i"
done
#! /bin/bash -e
# script: ubuntu_opencti_connectors.sh
# purpose: to automate install opencti connectors based on manual deployment below
# process: https://www.notion.so/Connectors-4586c588462d4a1fb5e661f2d9837db8
# disclaimer: script is written for testing and runs as root
# check the code and use at your own risk!
# The author is not liable for any damages or unexpected explosions!
# license: Apache 2.0
# banner -----------------------------------------------------------
echo -e "\n\n\x1B[1;49;34mMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM"
echo -e "MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM"
echo -e "MMMMMMMMMMMMMWK00000000000000000000000000000000000000000XWMWXKKKKKKNWMMMMMMMMMMMMM"
echo -e "MMMMMMMMMMMMMXdcccccccccccccccccccccccccccccccccccccccclxNMW0dooooo0WMMMMMMMMMMMMM"
echo -e "MMMMMMMMMMMMMXdccdkOOOOOOOOOOOOOOOOOOOOOOOOkkOOOOOOOOOOOKWWWNKOkdooOWMMMMMMMMMMMMM"
echo -e "MMMMMMMMMMMMMXdclkNMMMMMMMMMMMMMMMMMMMMMWN0k0WMMMMMMMMMMMMXXWMWKxooOWMMMMMMMMMMMMM"
echo -e "MMMMMMMMMMMMMXdclkNMMMMMMMMMMMMMMMMMMMMNOdodxkO0KXNWMMMMMWKOXMMXxooOWMMMMMMMMMMMMM"
echo -e "MMMMMMMMMMMMMXdcckNMMMMMMMMMMMMMMMMMMWKdldOKK00OkkkkO0KXXN0x0WWXxooOWMMMMMMMMMMMMM"
echo -e "MMMMMMMMMMMMMXdclkNMMMMMMMMMMMMMMMMMMXdldkkkkOO0KKKK0OOkkkxoONWXxooOWMMMMMMMMMMMMM"
echo -e "MMMMMMMMMMMMMXdclkNMMMMMMMMMMMMMMMMMWOlokKKKK0OOkkkkO00KKKkokNWKdooOWMMMMMMMMMMMMM"
echo -e "MMMMMMMMMMMMMXdclkNMMMMMMMMMMMMMMMMMNxcoxkkkkO00KKKK0OkkkkdoOWNOoooOWMMMMMMMMMMMMM"
echo -e "MMMMMMMMMMMMMXdclkNMMMMMMMMMMMMMMMMMNkcoOKKKK0OkkkkkO0KK0xoxXN0doooOWMMMMMMMMMMMMM"
echo -e "MMMMMMMMMMMMMXdclkNMMMMMMMMMMMMMMMMMWOllokkkOO0KKKK00OxddoxKNKxooooOWMMMMMMMMMMMMM"
echo -e "MMMMMMMMMMMMMXdclkNMMMMMMMMMMMMMMMMMMKdcd0KKK0OkkkkOOkdodOXXOddddooOWMMMMMMMMMMMMM"
echo -e "MMMMMMMMMMMMMXdclkNMMMMMMMMMMMMMMMMMMWOlloxkOO0K0kdooox0XNKxdkK0xooOWMMMMMMMMMMMMM"
echo -e "MMMMMMMMMMMMMXdclkNMMMMMMMMMMMMMMMWWWMXxllxkxooooodkOKNN0kkOXWWXxooOWMMMMMMMMMMMMM"
echo -e "MMMMMMMMMMMMMXdclkNMMMMMMMMMMWXXXNNWWWXklclooodkOKNWNXK00XNWMMMXxooOWMMMMMMMMMMMMM"
echo -e "MMMMMMMMMMMMMXdcckNMMMMMMWX0OO0XNWNKOxdoolclkKNWWWWNXXNWMMMMMMMXxooOWMMMMMMMMMMMMM"
echo -e "MMMMMMMMMMMMMXdclkNMMMWN0xdx0NWX0kdoolldkxlldXMMMWWWMMMMMMMMMMMXxooOWMMMMMMMMMMMMM"
echo -e "MMMMMMMMMMMMMXdcckNMMN0dld0WWXOdollx0KOkxdlclkNMMMMMMMMMMMMMMMMKxooOWMMMMMMMMMMMMM"
echo -e "MMMMMMMMMMMMMNxccxNMXkllkNMNOdldO0kxxk0KXKkdllOWMMMMMMMMMMMMMMWKdod0WMMMMMMMMMMMMM"
echo -e "MMMMMMMMMMMMMWOlco0NkllkNMNkodxdxO0KK0kxxk0OocdKMMMMMMMMMMMMMMNOooxXMMMMMMMMMMMMMM"
echo -e "MMMMMMMMMMMMMMXxclxOocxXMW0olxKX0OxxxOKXKOxdlclOWMMMMMMMMMMMMWKdooOWMMMMMMMMMMMMMM"
echo -e "MMMMMMMMMMMMMMW0ocllll0WMNkoxxxxk0KK0kxxk0KKOdcdXMMMMMMMMMMMWXkookXMMMMMMMMM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MMMMMMMMMMMMMMMMMMMM"
echo -e "MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM OPENCTI CONNECTORS MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM"
echo -e "MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM\x1B[0m\n\n"
# check root -------------------------------------------------------
if [ "$EUID" -ne 0 ]
then
echo "Elevated privileges required. Please run with sudo or as root."
exit
fi
# warn user
echo -e "\x1B[0;49;91mThis script runs with elevated access, check the code and use at your own risk!\x1B[0m\n"
# check ubuntu ver for python - 18 uses 3.6 (will install 3.7) - 20 uses 3.8
if [[ $(grep "Ubuntu " /etc/lsb-release | cut -d" " -f2 | cut -d\. -f1) == 18 ]]
then
python_ver="3.7"
elif [[ $(grep "Ubuntu " /etc/lsb-release | cut -d" " -f2 | cut -d\. -f1) == 20 ]]
then
python_ver="3"
fi
# const ------------------------------------------------------------
# opencti
opencti_dir="/opt/opencti"
# connectors
opencti_connector_dir="${opencti_dir}/connectors"
opencti_url="http://localhost:4000"
opencti_token=$(grep token ${opencti_dir}/config/production.json | cut -d\" -f4)
# def --------------------------------------------------------------
# echo str params
function quit_on_error () {
if [[ $? -gt 0 ]]
then
echo -e "\n\n $@ ...FAIL";
exit 10
else
echo "$@ ...OK"
fi
}
# connectors script ------------------------------------------------
# 1 enable, 0 disable
# this will only set up your instance for the connectors enabled
# you must supply an API token (eg. alienvault token) and enable the service
# it should be safe to run this after changing configs or enabling services
declare -A CONNECTORS;
CONNECTORS['alienvault']=0
CONNECTORS['amitt']=0
CONNECTORS['crowdstrike']=0
CONNECTORS['cryptolaemus']=0
CONNECTORS['cve']=1
CONNECTORS['cyber-threat-coalition']=0
CONNECTORS['cybercrime-tracker']=0
CONNECTORS['export-file-csv']=1
CONNECTORS['export-file-stix']=1
CONNECTORS['hygiene']=0
CONNECTORS['import-file-pdf-observables']=1
CONNECTORS['import-file-stix']=1
CONNECTORS['ipinfo']=0
CONNECTORS['lastinfosec']=0
CONNECTORS['malpedia']=0
CONNECTORS['misp']=1
CONNECTORS['mitre']=1
CONNECTORS['opencti']=1
CONNECTORS['valhalla']=0
CONNECTORS['virustotal']=1
echo "The following connectors will be installed:"
for i in "${!CONNECTORS[@]}"
do
if [[ ${CONNECTORS[$i]} == 1 ]]
then
echo $i
fi
done
echo
read -p "Are you sure you want to continue with the list above? " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]
then
echo 'User backed out. Exiting.'
exit 1
fi
for i in "${!CONNECTORS[@]}"
do
if [[ ${CONNECTORS[$i]} == 1 ]]
then
python${python_ver} -m pip -q install -r ${opencti_connector_dir}/$i/src/requirements.txt
if [[ -f "${opencti_connector_dir}/$i/src/config.yml" ]]
then
sed -i"" -e "s=http://localhost:8080=${opencti_url}=g" "${opencti_connector_dir}/$i/src/config.yml"
sed -i"" -e "s/token: 'ChangeMe'/token: '${opencti_token}'/g" "${opencti_connector_dir}/$i/src/config.yml"
sed -i"" -e "s/id: 'ChangeMe'/id: '$(grep id: ${opencti_connector_dir}/$i/src/config.yml | cut -d\' -f2)'/g" "${opencti_connector_dir}/$i/src/config.yml"
else
cp "${opencti_connector_dir}/$i/src/config.yml.sample" "${opencti_connector_dir}/$i/src/config.yml"
sed -i"" -e "s=http://localhost:8080=${opencti_url}=g" "${opencti_connector_dir}/$i/src/config.yml"
sed -i"" -e "s/token: 'ChangeMe'/token: '${opencti_token}'/g" "${opencti_connector_dir}/$i/src/config.yml"
sed -i"" -e "s/id: 'ChangeMe'/id: '$(uuidgen -r | tr -d '\n' | tr '[:upper:]' '[:lower:]')'/g" "${opencti_connector_dir}/$i/src/config.yml"
fi
if [[ ! -f "/etc/systemd/system/opencti-connector-$i.service" ]]
then
cat <<-EOT > /etc/systemd/system/opencti-connector-$i.service
[Unit]
Description=OpenCTI Connector - $i
After=network.target
[Service]
Type=simple
WorkingDirectory=${opencti_connector_dir}/$i/src
ExecStart=/usr/bin/python${python_ver} "${opencti_connector_dir}/$i/src/$i.py"
ExecReload=/bin/kill -s HUP \$MAINPID
ExecStop=/bin/kill -s TERM \$MAINPID
PrivateTmp=true
Restart=always
[Install]
WantedBy=multi-user.target
EOT
fi
if [[ $(systemctl status --no-pager opencti-connector-$i.service | grep 'Active: active') ]]
then
echo "opencti-connector-$i.service is already running, restarting due to config changes!"
systemctl restart opencti-connector-$i.service
fi
quit_on_error "Installing service for connector: $i"
fi
done
echo -e "\nFinished.\n"
systemctl daemon-reload
quit_on_error "Reloading systemctl daemon"
#! /bin/bash -e
# script: ubuntu_opencti_remover.sh
# purpose: to automate removal of opencti
# disclaimer: this script uses 'rm' functions and runs with elevated access,
# check the code and use at your own risk!
# The author is not liable for any damages or unexpected explosions!
# license: Apache 2.0
# banner -----------------------------------------------------------
echo -e "\n\n\x1B[1;49;34mMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM"
echo -e "MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM"
echo -e "MMMMMMMMMMMMMWK00000000000000000000000000000000000000000XWMWXKKKKKKNWMMMMMMMMMMMMM"
echo -e "MMMMMMMMMMMMMXdcccccccccccccccccccccccccccccccccccccccclxNMW0dooooo0WMMMMMMMMMMMMM"
echo -e "MMMMMMMMMMMMMXdccdkOOOOOOOOOOOOOOOOOOOOOOOOkkOOOOOOOOOOOKWWWNKOkdooOWMMMMMMMMMMMMM"
echo -e "MMMMMMMMMMMMMXdclkNMMMMMMMMMMMMMMMMMMMMMWN0k0WMMMMMMMMMMMMXXWMWKxooOWMMMMMMMMMMMMM"
echo -e "MMMMMMMMMMMMMXdclkNMMMMMMMMMMMMMMMMMMMMNOdodxkO0KXNWMMMMMWKOXMMXxooOWMMMMMMMMMMMMM"
echo -e "MMMMMMMMMMMMMXdcckNMMMMMMMMMMMMMMMMMMWKdldOKK00OkkkkO0KXXN0x0WWXxooOWMMMMMMMMMMMMM"
echo -e "MMMMMMMMMMMMMXdclkNMMMMMMMMMMMMMMMMMMXdldkkkkOO0KKKK0OOkkkxoONWXxooOWMMMMMMMMMMMMM"
echo -e "MMMMMMMMMMMMMXdclkNMMMMMMMMMMMMMMMMMWOlokKKKK0OOkkkkO00KKKkokNWKdooOWMMMMMMMMMMMMM"
echo -e "MMMMMMMMMMMMMXdclkNMMMMMMMMMMMMMMMMMNxcoxkkkkO00KKKK0OkkkkdoOWNOoooOWMMMMMMMMMMMMM"
echo -e "MMMMMMMMMMMMMXdclkNMMMMMMMMMMMMMMMMMNkcoOKKKK0OkkkkkO0KK0xoxXN0doooOWMMMMMMMMMMMMM"
echo -e "MMMMMMMMMMMMMXdclkNMMMMMMMMMMMMMMMMMWOllokkkOO0KKKK00OxddoxKNKxooooOWMMMMMMMMMMMMM"
echo -e "MMMMMMMMMMMMMXdclkNMMMMMMMMMMMMMMMMMMKdcd0KKK0OkkkkOOkdodOXXOddddooOWMMMMMMMMMMMMM"
echo -e "MMMMMMMMMMMMMXdclkNMMMMMMMMMMMMMMMMMMWOlloxkOO0K0kdooox0XNKxdkK0xooOWMMMMMMMMMMMMM"
echo -e "MMMMMMMMMMMMMXdclkNMMMMMMMMMMMMMMMWWWMXxllxkxooooodkOKNN0kkOXWWXxooOWMMMMMMMMMMMMM"
echo -e "MMMMMMMMMMMMMXdclkNMMMMMMMMMMWXXXNNWWWXklclooodkOKNWNXK00XNWMMMXxooOWMMMMMMMMMMMMM"
echo -e "MMMMMMMMMMMMMXdcckNMMMMMMWX0OO0XNWNKOxdoolclkKNWWWWNXXNWMMMMMMMXxooOWMMMMMMMMMMMMM"
echo -e "MMMMMMMMMMMMMXdclkNMMMWN0xdx0NWX0kdoolldkxlldXMMMWWWMMMMMMMMMMMXxooOWMMMMMMMMMMMMM"
echo -e "MMMMMMMMMMMMMXdcckNMMN0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Odlcox0NMMWNXNWMMMMMWNXOxoodkKNWMMMMMMMMMMMMMMMMMMMMMMMM"
echo -e "MMMMMMMMMMMMMMMMMMMMMMMMMMWN0xod0NMMWNWWWMWNX0OxdooxOKWMMMMMMMMMMMMMMMMMMMMMMMMMMM"
echo -e "MMMMMMMMMMMMMMMMMMMMMMMMMMMMMWXNWWX0kxxkOOkxdoodxOKNWMMMMMMMMMMMMMMMMMMMMMMMMMMMMM"
echo -e "MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMWX0kxdoooddkO0XNWMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM"
echo -e "MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMWWNXKKXNWWMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM"
echo -e "MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM OPENCTI REMOVER MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM"
echo -e "MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM\x1B[0m\n\n"
# check root -------------------------------------------------------
if [ "$EUID" -ne 0 ]
then
echo "Elevated privileges required. Please run with sudo or as root."
exit
fi
# warn user
echo -e "\x1B[0;49;91mThis script uses 'rm' functions with elevated access, check the code and use at your own risk!"
echo
read -p "Are you sure you want to continue? " -n 1 -r
echo
echo -e "\x1B[0m"
if [[ ! $REPLY =~ ^[Yy]$ ]]
then
echo 'User backed out. Exiting.'
exit 1
fi
# check ubuntu ver for python - 18 uses 3.6 (will install 3.7) - 20 uses 3.8
if [[ $(grep "Ubuntu " /etc/lsb-release | cut -d" " -f2 | cut -d\. -f1) == 18 ]]
then
python_ver="3.7"
elif [[ $(grep "Ubuntu " /etc/lsb-release | cut -d" " -f2 | cut -d\. -f1) == 20 ]]
then
python_ver="3"
fi
# const ------------------------------------------------------------
# opencti
opencti_dir="/opt/opencti"
# prerequisites
minio_dir="/opt/minio"
# def --------------------------------------------------------------
# no params
function quit_on_error () {
if [[ $? -gt 0 ]]
then
echo -e "\n\n $@ ...FAIL";
exit 10
else
echo "$@ ...OK"
fi
}
# echo str params
function update_apt_pkg () {
DEBIAN_FRONTEND=noninteractive apt-get -qq update
quit_on_error "Checking packages"
}
# $1 is apt-get pkg
function remove_apt_pkg () {
if [[ $(dpkg -l | grep "$1") ]]
then
echo >&2 "$1 found, attempting uninstall:";
DEBIAN_FRONTEND=noninteractive apt-get -qq purge -y "$1" > /dev/null 2>&1;
quit_on_error "Uninstalling $1"
fi
}
# $1 is service name
function enable_service () {
if [[ $(systemctl is-enabled "$1") == "disabled" ]]
then
echo "$1 service not enabled."
systemctl enable --now "$1"
quit_on_error "Starting $1"
elif [[ $(systemctl show -p SubState --value "$1") == "running" ]]
then
echo "$1 service already running."
systemctl restart "$1"
quit_on_error "Restarting $1"
else
echo "$1 service not running."
systemctl start "$1"
quit_on_error "Starting $1"
fi
sleep 5 # wait for services to be ready
}
# $1 is service name
function disable_service () {
if [[ $(systemctl is-enabled "$1") == "enabled" ]]
then
echo "$1 service enabled. Disabling."
systemctl disable --now "$1"
quit_on_error "Disabling $1"
elif [[ $(systemctl show -p SubState --value "$1") == "running" ]]
then
echo "$1 service still running. Stopping."
systemctl stop "$1"
quit_on_error "Stopping $1"
else
echo "$1 service not running."
quit_on_error "Skipping $1"
fi
}
# prerequisites script ---------------------------------------------
# disable/stop services
disable_service 'opencti-worker@*'
disable_service 'opencti-server'
disable_service 'elasticsearch.service'
disable_service 'redis.service'
disable_service 'rabbitmq-server.service'
disable_service 'minio.service'
disable_service 'grakn.service'
# nodejs
remove_apt_pkg 'nodejs'
remove_apt_pkg 'npm'
npm install -g n
n lts
npm rebuild
# yarn
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key del -
rm -f /etc/apt/sources.list.d/yarn.list
remove_apt_pkg 'yarn'
# python
if [[ ${python_ver} == "3.7" ]]
then
remove_apt_pkg "python3.7"
remove_apt_pkg "python3.7-minimal"
remove_apt_pkg "libpython3.7-minimal"
fi
# grakn
apt-key del 8F3DA4B5E9AEF44C
add-apt-repository -r 'deb [ arch=all ] https://repo.grakn.ai/repository/apt/ trusty main'
remove_apt_pkg 'grakn-core-all'
remove_apt_pkg 'grakn-console'
remove_apt_pkg 'grakn-core-server'
# make systemd unit file
rm -f /etc/systemd/system/grakn.service
# elasticsearch
wget -qO - 'https://artifacts.elastic.co/GPG-KEY-elasticsearch' | apt-key del -
add-apt-repository -r "deb https://artifacts.elastic.co/packages/7.x/apt stable main"
remove_apt_pkg 'elasticsearch'
# minio
rm -f "/usr/local/bin/minio"
rm -rf "${minio_dir}"
rm -f "/etc/default/minio"
rm -f "/etc/systemd/system/minio.service"
# redis
disable_service 'redis-server'
rm -f "/etc/systemd/system/redis-server.service"
remove_apt_pkg 'libsystemd-dev'
remove_apt_pkg 'pkg-config'
rm -f "/usr/local/bin/redis-*"
rm -f redis-${redis_ver}.tar.gz
rm -rf redis-${redis_ver}
rm -rf "/var/lib/redis/"
rm -rf "/etc/redis/"
rm -f "/etc/default/redis-server"
delgroup redis
deluser redis
# rabbitmq
curl -fsSL https://github.com/rabbitmq/signing-keys/releases/download/2.0/rabbitmq-release-signing-key.asc | apt-key del -
rm -f "/etc/apt/sources.list.d/bintray.rabbitmq.list"
remove_apt_pkg 'rabbitmq-server'
# finally, req'd packages
remove_apt_pkg 'software-properties-common'
remove_apt_pkg 'apt-transport-https'
# opencti script ---------------------------------------------------
rm -rf ${opencti_dir}
rm -f "/etc/systemd/system/opencti-server.service"
rm -f "/etc/systemd/system/opencti-worker@.service"
declare -A CONNECTORS;
CONNECTORS['alienvault']=0
CONNECTORS['amitt']=0
CONNECTORS['crowdstrike']=0
CONNECTORS['cryptolaemus']=0
CONNECTORS['cve']=1
CONNECTORS['cyber-threat-coalition']=0
CONNECTORS['cybercrime-tracker']=0
CONNECTORS['export-file-csv']=1
CONNECTORS['export-file-stix']=1
CONNECTORS['hygiene']=0
CONNECTORS['import-file-pdf-observables']=1
CONNECTORS['import-file-stix']=1
CONNECTORS['ipinfo']=0
CONNECTORS['lastinfosec']=0
CONNECTORS['malpedia']=0
CONNECTORS['misp']=1
CONNECTORS['mitre']=1
CONNECTORS['opencti']=1
CONNECTORS['valhalla']=0
CONNECTORS['virustotal']=1
for i in "${!CONNECTORS[@]}"
do
if [[ ${CONNECTORS[$i]} == 1 ]]
then
if [[ -f "/etc/systemd/system/opencti-connector-$i.service" ]]
then
rm -f "/etc/systemd/system/opencti-connector-$i.service"
fi
fi
done
systemctl daemon-reload
update_apt_pkg
apt autoremove -y
opencti:
url: 'http://localhost:4000'
token: 'ChangeMe'
worker:
log_level: 'info'
{
"app": {
"port": 4000,
"logs": "./logs",
"logs_level": "info",
"reactive": true,
"cookie_secure": false,
"base_path" : "",
"default_roles": [],
"admin": {
"email": "admin@opencti.io",
"password": "ChangeMe",
"token": "ChangeMe"
}
},
"grakn": {
"hostname": "localhost",
"port": 48555,
"timeout": 30000
},
"redis": {
"hostname": "localhost",
"port": 6379
},
"elasticsearch": {
"url": "http://localhost:9200",
"noQueryCache": false
},
"minio": {
"endpoint": "localhost",
"port": 9000,
"use_ssl": false,
"access_key": "ChangeMe",
"secret_key": "ChangeMe"
},
"rabbitmq": {
"hostname": "localhost",
"port": 5672,
"port_management": 15672,
"management_ssl": false,
"username": "guest",
"password": "guest"
},
"providers": {
"facebook": {
"client_id": "xxxxxx",
"client_secret": "xxxxxx",
"callback_uri": "http://localhost:4000/auth/facebook/callback"
},
"google": {
"client_id": "xxxxxx",
"client_secret": "xxxxxx",
"callback_uri": "http://localhost:4000/auth/google/callback"
},
"github": {
"client_id": "xxxxxx",
"client_secret": "xxxxxx",
"callback_uri": "http://localhost:4000/auth/github/callback"
}
}
}

Apache License Version 2.0, January 2004 http://www.apache.org/licenses/

TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION

  1. Definitions.

    "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.

    "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.

    "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.

    "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.

    "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.

    "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.

    "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).

    "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.

    "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."

    "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.

  2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.

  3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.

  4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:

    (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and

    (b) You must cause any modified files to carry prominent notices stating that You changed the files; and

    (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and

    (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License.

    You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.

  5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.

  6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.

  7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.

  8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.

  9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.

END OF TERMS AND CONDITIONS

Copyright 2020 Jacob Persinger (p-rs)

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment