fix new checkers + URL 200

This commit is contained in:
Cyrille L 2022-02-15 17:56:45 +01:00
parent d7bb4c4a4e
commit d552f298fd
8 changed files with 234 additions and 75 deletions

View File

@ -8,6 +8,7 @@ webserver.
# Dependancies # Dependancies
- bash - bash
- coreutils - coreutils
- curl (to check Posts links response)
# GSL: Installation # GSL: Installation

View File

@ -121,12 +121,12 @@ case "$1" in
;; ;;
check|-C) check|-C)
gsl__find_domain && exit 1 gsl__find_domain || exit 1
gsl__check_source "$gsl_dir_scripts/gsl__auth_manager" || exit 1 gsl__check_source "$gsl_dir_scripts/gsl__auth_manager" || exit 1
gsl__authors_list check && exit 1 gsl__authors_list check || exit 1
gsl__check_source "$gsl_dir_scripts/gsl__post_manager" || exit 1 gsl__check_source "$gsl_dir_scripts/gsl__post_manager" || exit 1
gsl__check_source "$gsl_dir_scripts/gsl__post_checkers" || exit 1 gsl__check_source "$gsl_dir_scripts/gsl__post_checkers" || exit 1
gsl__check_nbr_posts && exit 1 gsl__check_nbr_posts || exit 1
gsl__check_source "$gsl_dir_scripts/gsl__db_manager" || exit 1 gsl__check_source "$gsl_dir_scripts/gsl__db_manager" || exit 1
case "$2" in case "$2" in

View File

@ -8,6 +8,7 @@ webserver.
# Dependancies # Dependancies
- bash - bash
- coreutils - coreutils
- curl (to check Posts links response)
# GSL: Installation # GSL: Installation

View File

@ -11,8 +11,10 @@ gsl__authors_check() {
gsl_save_dir_ndd=`grep "$gsl_find_domain" "$gsl_file_db_domains"` gsl_save_dir_ndd=`grep "$gsl_find_domain" "$gsl_file_db_domains"`
gsl_file_auth_ndd="$gsl_save_dir_ndd/$gsl_filename_auth" gsl_file_auth_ndd="$gsl_save_dir_ndd/$gsl_filename_auth"
! [[ -f "$gsl_file_auth_ndd" ]] \ [[ -f "$gsl_file_auth_ndd" ]] \
&& touch "$gsl_file_auth_ndd" && return
touch "$gsl_file_auth_ndd"
} }
#======================================================================= #=======================================================================
@ -21,20 +23,23 @@ gsl_file_auth_ndd="$gsl_save_dir_ndd/$gsl_filename_auth"
gsl__authors_list() { gsl__authors_list() {
gsl__authors_check gsl__authors_check
[[ -z `grep '[^[:space:]]' "$gsl_file_auth_ndd"` ]] \ ! [[ -z `grep '[^[:space:]]' "$gsl_file_auth_ndd"` ]] \
&& echo "! No Registred authors yet." \ && gsl_authors=true \
&& return && return
echo "! No Registred authors yet..."
case "$1" in case "$1" in
check) check)
return [[ $gsl_authors ]] && return
;; return
;;
esac esac
echo -e "\n# Authors Registred:" echo -e "\n# Authors Registred:"
while read -r "line_nbr" "author" while read -r "line_nbr" "author"
do do
echo " $line_nbr: $author" echo " $line_nbr: $author"
done < <(cat -n "$gsl_file_auth_ndd") done < <(cat -n "$gsl_file_auth_ndd")
} }
@ -56,13 +61,13 @@ echo -ne "# Add author(s) name : " && IFS="," read -a gsl_new_authors
gsl_nbr_authors=${#gsl_new_authors[@]} gsl_nbr_authors=${#gsl_new_authors[@]}
for i in `seq 0 $(( gsl_nbr_authors - 1 ))` for i in `seq 0 $(( gsl_nbr_authors - 1 ))`
do do
echo "${gsl_new_authors[i]}" >> "$gsl_file_auth_ndd" && \ echo "${gsl_new_authors[i]}" >> "$gsl_file_auth_ndd" && \
gsl__logs_print \ gsl__logs_print \
"$gsl_log_i" \ "$gsl_log_i" \
"Author" \ "Author" \
"Added" \ "Added" \
"${gsl_new_authors[i]} for domain $gsl_find_domain" \ "${gsl_new_authors[i]} for domain $gsl_find_domain" \
"$gsl_file_auth_ndd" "$gsl_file_auth_ndd"
done done
gsl__authors_list gsl__authors_list
@ -86,23 +91,23 @@ gsl_rm_authors=($gsl_rm_authors)
gsl_nbr_authors=`cat $gsl_file_auth_ndd | wc -l` gsl_nbr_authors=`cat $gsl_file_auth_ndd | wc -l`
for line in ${gsl_rm_authors[@]} for line in ${gsl_rm_authors[@]}
do do
[[ $line =~ ^[0-9]+$ ]] || continue [[ $line =~ ^[0-9]+$ ]] || continue
(( $line < 1 )) && continue (( $line < 1 )) && continue
(( $line > $gsl_nbr_authors )) && continue (( $line > $gsl_nbr_authors )) && continue
if [[ $rm_line ]];then if [[ $rm_line ]];then
! (( $line == 1 )) && line=$(( line - 1 )) ! (( $line == 1 )) && line=$(( line - 1 ))
fi fi
gsl_rm_author=`awk -v n="$line" 'NR == n' "$gsl_file_auth_ndd"` gsl_rm_author=`awk -v n="$line" 'NR == n' "$gsl_file_auth_ndd"`
sed -i "${line}d" "$gsl_file_auth_ndd" && \ sed -i "${line}d" "$gsl_file_auth_ndd" && \
gsl__logs_print \ gsl__logs_print \
"$gsl_log_i" \ "$gsl_log_i" \
"Author" \ "Author" \
"Removed" \ "Removed" \
"$gsl_rm_author for domain $gsl_find_domain" \ "$gsl_rm_author for domain $gsl_find_domain" \
"$gsl_file_auth_ndd" "$gsl_file_auth_ndd"
echo " - Removed > $gsl_rm_author <" echo " - Removed > $gsl_rm_author <"
rm_line=true rm_line=true
done done
gsl__authors_list gsl__authors_list

View File

@ -36,17 +36,13 @@ gsl__logs_show() {
[[ "$gsl_logs_err" ]] \ [[ "$gsl_logs_err" ]] \
&& gsl_logs_filter="$gsl_log_e" && gsl_logs_filter="$gsl_log_e"
[[ "$gsl_logs_last_session" ]] \
&& gsl_log_show_session="Last session" \
|| gsl_log_show_session="All"
# Last session show or not # Last session show or not
if [[ "$gsl_logs_last_session" ]];then if [[ "$gsl_logs_last_session" ]];then
gsl_log_start_line=` gsl_log_start_line=`
grep -n "Starting" "$gsl_file_logs" \ grep -n "Starting" "$gsl_file_logs" \
| tail -1 \ | tail -1 \
| awk -F: '{print $1}'` | awk -F: '{print $1}'`
echo
awk -v sl="$gsl_log_start_line" \ awk -v sl="$gsl_log_start_line" \
'NR >= sl' \ 'NR >= sl' \
"$gsl_file_logs" \ "$gsl_file_logs" \

View File

@ -11,11 +11,11 @@ gsl__post_all_checkers() {
clear clear
unset gsl_check_done unset gsl_check_done
echo -n ": Searching for needed Headers..." echo -n ": Searching for NEEDED HEADERS..."
gsl__post_check_needed_headers gsl__post_check_needed_headers
echo -ne "\r\033[2K: Searching for #1..." echo -ne "\r\033[2K: Searching for #1..."
gsl__post_check_h1 gsl__post_check_h1
echo -ne "\r\033[2K: Searching for Paragraphs" echo -ne "\r\033[2K: Searching for PARAGRAPHS"
gsl__post_check_paragraphs gsl__post_check_paragraphs
echo -ne "\r\033[2K: Searching for Content MARKERS..." echo -ne "\r\033[2K: Searching for Content MARKERS..."
gsl__post_check_markers gsl__post_check_markers
@ -23,10 +23,15 @@ echo -ne "\r\033[2K: Searching for BLOCKQUOTEs..."
gsl__post_check_blockquote gsl__post_check_blockquote
echo -ne "\r\033[2K: Searching for ABBRs..." echo -ne "\r\033[2K: Searching for ABBRs..."
gsl__post_check_abbr gsl__post_check_abbr
echo -ne "\r\033[2K: Searching for LINKs.." echo -ne "\r\033[2K: Searching for LINKs..."
gsl__post_check_links gsl__post_check_links
echo -ne "\r\033[2K: Searching for FILES..."
gsl__post_check_files
echo -ne "\r\033[2K: Searching for IMAGES..."
gsl__post_check_images
echo -ne "\r\033[2K" echo -ne "\r\033[2K"
# End of checkers : show logs for war and err # End of checkers : show logs for war and err
[[ "$gsl_checker_war" ]] \ [[ "$gsl_checker_war" ]] \
&& gsl log -s -w && gsl log -s -w
@ -319,9 +324,11 @@ gsl__post_check_abbr() {
gsl_post_stat_abbr=0 gsl_post_stat_abbr=0
while read -r "gsl_header_content_line" while read -r "gsl_header_content_line"
do do
# Get & Check HEADER CONTENT # Get & Check HEADER CONTENT
gsl__get_header_fields "$gsl_marker_abbr" gsl__get_header_fields "$gsl_marker_abbr"
gsl__check_header_fields "Post" "ABBR" "$gsl_log_act_abbr" || continue gsl__check_header_fields "Post" "ABBR" "$gsl_log_act_abbr" \
|| continue
# Check POST CONTENT # Check POST CONTENT
[[ `gsl__get_content_line \ [[ `gsl__get_content_line \
@ -338,6 +345,7 @@ do
"Missing Content: $gsl_post_header_field_1" \ "Missing Content: $gsl_post_header_field_1" \
"${PWD}/$gsl_post" "${PWD}/$gsl_post"
gsl_checker_err=true gsl_checker_err=true
done < <(gsl__get_header "$gsl_marker_abbr" "$gsl_post") done < <(gsl__get_header "$gsl_marker_abbr" "$gsl_post")
gsl__logs_print \ gsl__logs_print \
@ -357,29 +365,28 @@ while read -r "gsl_header_content_line"
do do
# Get & Check Header CONTENT # Get & Check Header CONTENT
gsl__get_header_fields "$gsl_marker_link" gsl__get_header_fields "$gsl_marker_link"
gsl__check_header_fields "Post" "Link" "$gsl_log_act_link" || continue gsl__check_header_fields "Post" "Link" "$gsl_log_act_link" \
|| continue
# Not ALT TEXT ? # Not ALT TEXT ?
if ! [[ "$gsl_post_header_field_3" ]];then gsl__check_header_field3 "Post" "Link"
gsl__logs_print \
"$gsl_log_w" \
"Post" \
"Link" \
"Line:$gsl_post_header_line_nbr > No ALT TEXT ?" \
"${PWD}/$gsl_post"
gsl_checker_war=true
fi
# Find if ref is in CONTENT # Find if ref is in CONTENT
if [[ `gsl__get_content_finder \ [[ `gsl__get_content_with_markers "$gsl_mo_link" "$gsl_mc_link"` ]] \
-o "$gsl_mo_link" \ && gsl_post_stat_link=$(( $gsl_post_stat_link + 1 )) \
-b "$gsl_post_header_field_1" \ && continue
-c "$gsl_mc_link" \
-f "$gsl_post" \ # Check URL
| tail -1 ` ]];then (( `curl -o /dev/null --silent --head --write-out \
(( gsl_post_stat_link ++ )) '%{http_code}' \
continue "$gsl_post_header_field_2"` == 200 )) \
fi && continue \
|| gsl__logs_print \
"$gsl_log_e" \
"Post" \
"Link" \
"URL offline: $gsl_post_header_field_2" \
"${PWD}/$gsl_post"
# Missing CONTENT # Missing CONTENT
gsl__logs_print \ gsl__logs_print \
@ -389,6 +396,92 @@ do
"Missing Content: [_${gsl_post_header_field_1}_]" \ "Missing Content: [_${gsl_post_header_field_1}_]" \
"${PWD}/$gsl_post" "${PWD}/$gsl_post"
gsl_checker_err=true gsl_checker_err=true
done < <(gsl__get_header "$gsl_marker_link" "$gsl_post") done < <(gsl__get_header "$gsl_marker_link" "$gsl_post")
} }
#=======================================================================
# Check Post for FILES HEADER + Content
#=======================================================================
gsl__post_check_files() {
gsl_post_stat_file=0
while read -r "gsl_header_content_line"
do
# Get & Check Header CONTENT
gsl__get_header_fields "$gsl_marker_file"
gsl__check_header_fields "Post" "File" "$gsl_log_act_file" \
|| continue
# Not ALT TEXT ?
gsl__check_header_field3 "Post" "File"
# Find if ref is in CONTENT
[[ `gsl__get_content_with_markers "$gsl_mo_file" "$gsl_mc_file"` ]] \
&& gsl_post_stat_file=$(( $gsl_post_stat_file + 1 )) \
&& continue
[[ -f "$gsl_dir_domain_files/$gsl_post_header_field_2" ]] \
&& continue \
|| gsl__logs_print \
"$gsl_log_e" \
"Post" \
"File" \
"Not found: $gsl_post_header_field_2" \
"$gsl_dir_domain_files/$gsl_post_header_field_2"
# Missing CONTENT
gsl__logs_print \
"$gsl_log_e" \
"Post" \
"File" \
"Missing Content: <_${gsl_post_header_field_1}_>" \
"${PWD}/$gsl_post"
gsl_checker_err=true
done < <(gsl__get_header "$gsl_marker_file" "$gsl_post")
}
#=======================================================================
# Check Post for IMAGES HEADER + Content
#=======================================================================
gsl__post_check_images() {
gsl_post_stat_image=0
while read -r "gsl_header_content_line"
do
# Get & Check Header CONTENT
gsl__get_header_fields "$gsl_marker_image"
gsl__check_header_fields "Post" "Image" "$gsl_log_act_image" \
|| continue
# Not ALT TEXT ?
gsl__check_header_field3 "Post" "Image"
# Find if ref is in CONTENT
[[ `gsl__get_content_line \
"$gsl_mark_image : $gsl_post_header_field_1" \
"$gsl_post"` ]] \
&& gsl_post_stat_image=$(( $gsl_post_stat_image + 1 )) \
&& continue
[[ -f "$gsl_dir_domain_files/$gsl_post_header_field_2" ]] \
&& continue \
|| gsl__logs_print \
"$gsl_log_e" \
"Post" \
"image" \
"Not found: $gsl_post_header_field_2" \
"$gsl_dir_domain_files/$gsl_post_header_field_2"
# Missing CONTENT
gsl__logs_print \
"$gsl_log_e" \
"Post" \
"Image" \
"Missing Content: _image_ : ${gsl_post_header_field_1}" \
"${PWD}/$gsl_post"
gsl_checker_err=true
done < <(gsl__get_header "$gsl_marker_image" "$gsl_post")
}

View File

@ -10,8 +10,10 @@
gsl__check_nbr_posts() { gsl__check_nbr_posts() {
gsl_nbr_posts=`ls -1 *.gsl 2>/dev/null | wc -l` gsl_nbr_posts=`ls -1 *.gsl 2>/dev/null | wc -l`
(( $gsl_nbr_posts == 0 )) \ (( $gsl_nbr_posts >= 1 )) \
&& echo "! No Posts found with .gsl extension" && return
echo "! No Posts found with .gsl extension"
} }
#======================================================================= #=======================================================================
@ -138,6 +140,19 @@ awk -v line="$gsl_post_begin" -v s="$1" \
"$2" || return "$2" || return
} }
#=======================================================================
# Check CONTENT Post with markers... $1: Open Marker | $2: Close Marker
#=======================================================================
gsl__get_content_with_markers() {
gsl__get_content_finder \
-o "$1" \
-b "$gsl_post_header_field_1" \
-c "$2" \
-f "$gsl_post" \
| tail -1 \
|| return
}
#======================================================================= #=======================================================================
# Get CONTENT with marks | ! find from ONE line content # Get CONTENT with marks | ! find from ONE line content
#======================================================================= #=======================================================================
@ -182,11 +197,11 @@ gsl__get_line "$1$gsl_post_header_field_1" "$gsl_post"`
} }
#======================================================================= #=======================================================================
# Get Fields and line nbr from header from marker # Check NEEDED Fields from HEADER
#======================================================================= #=======================================================================
gsl__check_header_fields() { gsl__check_header_fields() {
if ! [[ "$gsl_post_header_field_1" ]] || \ if ! [[ "$gsl_post_header_field_1" ]] || \
! [[ "$gsl_post_header_field_2" ]];then ! [[ "$gsl_post_header_field_2" ]];then
gsl__logs_print \ gsl__logs_print \
"$gsl_log_e" \ "$gsl_log_e" \
@ -198,3 +213,31 @@ if ! [[ "$gsl_post_header_field_1" ]] || \
return return
fi fi
} }
#=======================================================================
# Check OPTIONAL Field 3 from HEADER
#=======================================================================
gsl__check_header_field3() {
if ! [[ "$gsl_post_header_field_3" ]];then
case "$2" in
Image)
gsl__logs_print \
"$gsl_log_e" \
"$1" \
"$2" \
"Line:$gsl_post_header_line_nbr > No ALT TEXT ?" \
"${PWD}/$gsl_post"
gsl_checker_err=true
;;
*)
gsl__logs_print \
"$gsl_log_w" \
"$1" \
"$2" \
"Line:$gsl_post_header_line_nbr > No ALT TEXT ?" \
"${PWD}/$gsl_post"
gsl_checker_war=true
;;
esac
fi
}

View File

@ -78,16 +78,36 @@ if [[ "$gsl_find_domain" ]];then
<<< $gsl_find_domain` <<< $gsl_find_domain`
gsl_find_domain=${gsl_find_domain,,} gsl_find_domain=${gsl_find_domain,,}
gsl__check_domain "$gsl_find_domain" gsl__check_domain "$gsl_find_domain" || return
fi fi
} }
#======================================================================= #=======================================================================
# Check and set domain from db # Check and set domain from DB
#======================================================================= #=======================================================================
gsl__check_domain() { gsl__check_domain() {
gsl_this_conf_domain=`grep "$1" "$gsl_file_db_domains"` gsl_this_conf_domain=`grep "$1" "$gsl_file_db_domains"`
! [[ "$gsl_this_conf_domain" ]] \ ! [[ "$gsl_this_conf_domain" ]] \
&& echo "! Domain Not found: $1" && echo "! Domain Not found: $1" \
&& return
gsl_dir_domain_tpl="$gsl_this_conf_domain/templates"
gsl_dir_domain_files="$gsl_this_conf_domain/files"
gsl_dir_domain_images="$gsl_this_conf_domain/images"
for gsl_new_dir in `set -o posix ; set \
| grep "gsl_dir_domain" \
| awk -F= '{print $2}'`
do
if ! [[ -d "$gsl_new_dir" ]];then
mkdir -p "$gsl_new_dir" 2>/dev/null && \
gsl__logs_print \
"$gsl_log_i" \
"Folder" \
"Init..." \
"Created" \
"$gsl_new_dir"
fi
done
} }