- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
#!/bin/bash
#
# program file name: urlmin.sh
# program version: 0.4
_help()
{
prg=$(basename $0)
cat << EOF
options:
-h See this page
-l Viewed all names of minifer sites
-s
lb.vg
minify.me
is.gd
-r Random mode of minifiers
-u url link
examples:
random mode - minifiers: ${prg} -r -u 'http://wikimapia.org/#lat=36.7923994&lon=53.1100881&z=18&l=1&m=b'
only 1 minifier - is.gd minifier: ${prg} -s is.gd -u 'http://wikimapia.org/#lat=36.7923994&lon=53.1100881&z=18&l=1&m=b'
or lb.vg minifier: ${prg} -s lb.vg -u 'http://wikimapia.org/#lat=36.7923994&lon=53.1100881&z=18&l=1&m=b'
and other
EOF
exit 0
}
[ ! -f "$(which curl)" ] && { echo "Установите утилиту curl" ; exit 1 ;}
_user_agent="Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.4) Gecko/20100503 Firefox/3.6.4"
_sets_minifiers=( "lb.vg" "is.gd" "minify.me" )
_e() { echo -e "${*}" ;}
_get_page() { curl -s -A "$USER_AGENT" ${1} | tr -d '\n' || { clear ; echo -e "${B_T}${RC}Error${CRS}! curl in function _get_page has exited abnormaly: ${1}" ; exit 1 ;} ;}
_post_page() { curl -s -A "$USER_AGENT" -d "${2}" "${1}" | tr -d "\n" || { clear ; echo -e "${B_T}${RC}Error!${CRS} curl in function _post_page has exited abnormaly: ${1} -> ${2}" ; exit 1 ;} ;}
_urlencode() { LANG=C awk 'BEGIN { EOL = "%0A" ; split ("1 2 3 4 5 6 7 8 9 A B C D E F", hextab, " ") ; hextab [0] = 0 ; for ( i=1; i<=255; ++i ) ord [ sprintf ("%c", i) "" ] = i + 0 } ; { encoded = "" ; for ( i=1; i<=length ($0); ++i ) { c = substr ($0, i, 1) ; if ( c ~ /[a-zA-Z0-9.-]/ ) { encoded = encoded c } else if ( c == " " ) { encoded = encoded "+" } else { lo = ord [c] % 16 ; hi = int (ord [c] / 16); encoded = encoded "%" hextab [hi] hextab [lo] } } ; printf ("%s", encoded EOL) } END { }' "$@" | sed 's|%0A||g' ;}
_random() { [ -n "${1}" ] && { while :; do zz=$(y=0;for ((x=${1};x>=y;y++)) ; do [ "$y" == "${RANDOM[@]:2:1}" ] && [ -n "$y" ] && { echo $y ; break ;} ; done ) ; [ -n "$zz" ] && { echo "$zz" ; break ;} ; done ;} ;}
# sets
while getopts "hu:s:rl" option ; do case $option in
h) _help ;;
u) url_path="$OPTARG" ;;
s) _set_min="$OPTARG" ; set_min_num=$(j=0 ; for x in ${_sets_minifiers[*]} ; do [ "${x}" == "${_set_min}" ] && _e "${j}" ; ((j++)) ; done) ;;
r) mode_random="yes" ; set_min_num="$(_random $((${#_sets_minifiers[*]}-1)) )" ;;
l) list_mins="yes" ;;
v) set_verbose="-v" ;;
esac ; done
case $set_min_num in
0)
_url_enc=$(_e "${url_path}" | _urlencode)
_url_host="${_sets_minifiers[$set_min_num]}"
_obtained=$(_post_page "http://${_url_host}/default.asp" "Orig_URL=${_url_enc}&show_ve=1&Categ=Humor" | egrep -o "http://${_url_host}/[a-Z0-9]+'" | sort -u | sed "s|'||g;s|http://||g") ;;
1)
_url_enc=$(_e "${url_path}" | _urlencode)
_url_host="${_sets_minifiers[$set_min_num]}"
_obtained=$(_post_page "http://${_url_host}/create.php" "URL=${_url_enc}" | egrep -o "http://${_url_host}/[a-Z0-9]+\" target" | sed 's|\" target||g;s|http://||g') ;;
2)
_url_enc=$(_e "${url_path}" | _urlencode)
_url_host="${_sets_minifiers[$set_min_num]}"
_obtained=$(_post_page "http://${_url_host}/create.php" "url=${_url_enc}" | egrep -o "http://${_url_host}/\?[a-Z0-9]+" | sed 's|http://||g') ;;
esac
[ -z "$1" ] && _help
[ -n "$set_min_num" ] && _e "Link: ${_obtained}"
[ -n "$list_mins" ] && _e "Minifiers:\n\n$(for i in ${_sets_minifiers[*]} ; do _e " ${i}" ; done)\n"
# eof urlmin.sh