#!/usr/bin/env bash

# Prowler - the handy cloud security tool (copyright 2018) by Toni de la Fuente
#
# 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.


# Function test_tcp_connectivity is in include/os_detector 

# see here https://gist.github.com/rsvp/1171304/3d6714a469105faf03943b685090f90f576cf904

# Functions to connection responses initially used for Elasticsearch related checks
httpStatus(){ 
    case $1 in 
      000) SERVER_RESPONSE="000 Not responding" ;;
      200) SERVER_RESPONSE="200 Successful" ;;
      300) SERVER_RESPONSE="300 Multiple Choices" ;;
      301) SERVER_RESPONSE="301 Moved Permanently" ;;
      302) SERVER_RESPONSE="302 Found residing temporarily under different URI" ;;
      303) SERVER_RESPONSE="303 See Other" ;;
      304) SERVER_RESPONSE="304 Not Modified" ;;
      305) SERVER_RESPONSE="305 Use Proxy" ;;
      306) SERVER_RESPONSE="306 Status not defined" ;;
      307) SERVER_RESPONSE="307 Temporary Redirect" ;;
      301) SERVER_RESPONSE="301 Moved" ;;
      400) SERVER_RESPONSE="400 Error: Bad Request" ;;
      401) SERVER_RESPONSE="401 Error: Unauthorized" ;;
      403) SERVER_RESPONSE="403 Error: Forbidden" ;;
      404) SERVER_RESPONSE="404 Error: Not Found" ;;
      407) SERVER_RESPONSE="407 Error: Proxy Authentication Required" ;;
      408) SERVER_RESPONSE="408 Error: Request Timeout" ;;
      500) SERVER_RESPONSE="500 Error: Internal Server Error" ;;
      502) SERVER_RESPONSE="502 Error: Bad Gateway" ;;
      503) SERVER_RESPONSE="503 Error: Service Unavailable" ;;
      504) SERVER_RESPONSE="504 Error: Gateway Timeout" ;;
      505) SERVER_RESPONSE="505 Error: HTTP Version Not Supported" ;;
      *)   SERVER_RESPONSE="HTTP: SERVER_RESPONSE not defined." ;;
    esac
  }
