Platon Technologies
neprihlásený Prihlásiť Registrácia
SlovakEnglish
open source software development oslavujeme 10 rokov vývoja otvoreného softvéru! Utorok, 20. október 2026

Rozdiely pre scripts/shell/sms/sms.sh medzi verziami 1.1 a 1.2

verzia 1.1, 2003/01/08 16:47:17 verzia 1.2, 2003/01/26 21:08:52
Riadok 20 
Riadok 20 
   
 umask 077  umask 077
   
   # remove next line to turn debug off
   #DEBUG="yes"
   
 # Uncoment following line, if you will use /usr/bin/GET, or specify  # Uncoment following line, if you will use /usr/bin/GET, or specify
 # to your own 'GET' program. Program must accept '-e' '-P' '-H' options  # to your own 'GET' program. Program must accept '-e' '-P' '-H' options
 # and use cookies.  # and use cookies.
 #GET="/usr/bin/GET"  #GET="/usr/bin/GET"
 GET="make_http_request_GET" # use build-in function  GET="make_http_request_GET" # use build-in function
   
   
 # default  # default
 CONFIG_DIR="$HOME/.sms.sh"  CONFIG_DIR="$HOME/.sms.sh"
 CONFIG_FILE="$CONFIG_DIR/conf";  CONFIG_FILE="$CONFIG_DIR/conf";
Riadok 59  EOF
Riadok 63  EOF
         exit 1;          exit 1;
 }  }
 # usage() }}}  # usage() }}}
 # Function make_http_request_GET() {{{  
 make_http_request_GET()  
 {  
   
         # if --debug option is specified, save output from $GET to $TMP_FILE,  
         echo "## Time: "          >> $TMP_FILE  
         echo "## Request: $* {{{" >> $TMP_FILE  
   
         for option  
         do  
                 case "$option" in  
   
                         -*) ;; # ignore  
   
                         Cookie:*) cookies="`echo $option | sed 's/^Cookie: //;'`" ;;  
                         http:*)   http="$option" ;;  
   
                 esac  
         done  
         if [ ! -z "$DEBUG" ]; then  
                 echo "GET -H 'Cookie: $cookies' '$http'" > /dev/stderr  
         fi  
         echo "$cookies $http" | perl -w -e '  
         #!/usr/bin/perl -w  
   
         use IO::Socket;  
         $| = 1;    # autoflush  
   
         sub http_get  
         {  
                 my $proxy   = shift;  
                 my $url     = shift;  
                 my $cookies = shift;  
                 my $port    = 80;  
   
                 my $msg   = "";  
                 my $sock  = undef;  
                 my $tries = 0;  
   
                 while ( !$sock && $tries < 5 ) {  
                         $sock = new IO::Socket::INET( Proto => "tcp",  
                         PeerAddr => $proxy,  
                         PeerPort => $port,  
                         Type     => SOCK_STREAM,  
                         );  
                         if ( !$sock ) {  
                                 print;  
                                 print "Can NOT connect to ${proxy}:${port} ! Trying again ...";  
                                 $tries++;  
                         }  
                 }  
                 if ( !$sock ) {  
                         print "$proxy is death... :(\n\n";  
                         return;  
                 }  
   
                 # make http request  
                 print $sock "GET $url HTTP/1.1\r\n";  
                 print $sock "TE: deflate, gzip;q=0.3\r\n";  
                 print $sock "Connection: TE, close\r\n";  
                 print $sock "Host: $proxy\r\n";  
                 print $sock "User-Agent: Mozilla/4.0 (compatible; MSIE 5.0; Linux [en]\r\n";  
                 if ($cookies =~ "Cookie: ") {  
                         print $sock "$cookies\r\n";  
                 }  
                 print $sock "\r\n";  
   
   
                 $sock->flush();  
                 while (<$sock>) {  
                         print;  
                 }  
                 $sock->close();  
                 return;  
         }  
   
         while (<STDIN>) {  
                 my $http;  
                 my $server;  
                 my $url;  
                 my $cookies = "";  
   
                 chomp;  
                 ($cookies, $http) = split /http:\/\//, $_, 2;  
                 #$http =~ s|^http://||;  
                 ($server, $url) = split /\//, $http, 2;  
                 substr($cookies, 0, 0) = "Cookie: "; # put string at begin  
                 substr($url, 0, 0) = "/";  
   
                 #print "http=$http\ncookies=$cookies\nurl=$url\nserver=$server\n";  
                 http_get($server, $url, $cookies);  
         }  
         exit;' | tee -a $TMP_FILE  
         echo "## }}} request done " >> $TMP_FILE  
   
 }  
   
 # make_http_request_GET() }}}  
 # implementation of img2text {{{  
 img2text()  
 {  
   
         awk '#!/usr/bin/awk -f  
   
         # $Id$  
   
         # Author:  Lubomir Host rajo <rajo AT host.sk>  
         # License: GNU GPL  
   
         # Script for converting images to text files.  
         # Usefull for script, which will send SMS message over public SMS gateway. ;)  
   
         # Usage: cat img.png | convert - text:- | ./img2text  
         # Enjoy flooding sms gateway! ;))  
   
         BEGIN {  
                 FS="[,:# \t]+"  
                 prev_line = 0;  
                 line   = 1;  
                 column = 0;  
                 color  = "";  
                 start_char = 41;  
         }  
   
         {  
                 n = split($0, a, FS);  
   
                 column = a[1];  
                 line   = a[2];  
                 color  = a[6];  
                 if (colormap[color] == 0) {  
                         #printf "adding color %s to colormap\n", color;  
                         colormap[color] = ++start_char;  
                 }  
                 if (column == 0 && line == 0) {  
                         # first pixel 0,0 is probably background color,  
                         # we will background filled with spaces  
                         colormap[color] = 32;  
                 }  
                 output[line] = sprintf("%s%c", output[line], colormap[color]);  
         }  
   
         END {  
         for (i = 0; i <= line; i++) {  
                 if (output[i] !~ /^ +$/)  
                         printf "%s\n", output[i];  
                 }  
         }'  
   
 } # }}} img2text()  
   
 if [ "$#" -lt 1 ]; then  if [ "$#" -lt 1 ]; then
         usage          usage
Riadok 324  else
Riadok 178  else
         && TMP_FILE="/dev/null"          && TMP_FILE="/dev/null"
 fi  fi
   
 number=`echo "$prev_number" | grep '^[0-9]\+$'`;  NUMBER=`echo "$prev_number" | grep '^[0-9]\+$'`;
   
 # check for alias {{{  # check for alias {{{
 if [ -z "$number" ]; then  if [ -z "$NUMBER" ]; then
         if [ ! -z "$DEBUG" ]; then          if [ ! -z "$DEBUG" ]; then
                 echo "Parameter '$prev_number' treated as an alias.";                  echo "Parameter '$prev_number' treated as an alias.";
                 echo -n "Looking for alias file '$ALIAS_FILE'... ";                  echo -n "Looking for alias file '$ALIAS_FILE'... ";
Riadok 337  if [ -z "$number" ]; then
Riadok 191  if [ -z "$number" ]; then
                         echo "found.";                          echo "found.";
                 fi                  fi
                 echo -n "Looking for alias '$prev_number'... ";                  echo -n "Looking for alias '$prev_number'... ";
                 number=`awk "BEGIN { alias=tolower(\"$prev_number\"); } \                  NUMBER=`awk "BEGIN { alias=tolower(\"$prev_number\"); } \
                         /^#/ { next; } \                          /^#/ { next; } \
                         // { \\$0 = tolower(\\$0); } \                          // { \\$0 = tolower(\\$0); } \
                         \\$0 ~ alias { if (NF > 2) { print \\$3; } \                          \\$0 ~ alias { if (NF > 2) { print \\$3; } \
                                 else { print \\$2; } exit; }" "$ALIAS_FILE"`;                                  else { print \\$2; } exit; }" "$ALIAS_FILE"`;
                 if [ "$number" ]; then                  if [ "$NUMBER" ]; then
                         echo "found number '$number'.";                          echo "found number '$NUMBER'.";
                 else                  else
                         echo "not found.";                          echo "not found.";
                         exit 1;                          exit 1;
Riadok 402  if [ -f "$CONFIG_FILE" ]; then
Riadok 256  if [ -f "$CONFIG_FILE" ]; then
         if [ ! -z "$DEBUG" ]; then          if [ ! -z "$DEBUG" ]; then
                 echo -n "Looking for password... ";                  echo -n "Looking for password... ";
         fi          fi
         PASS=`awk 'BEGIN { FS="[    =]+" } /^#/ { next; } \          PASSWD=`awk 'BEGIN { FS="[    =]+" } /^#/ { next; } \
                 /^pass/ { if (NF > 2) { print $3; exit; } \                  /^pass/ { if (NF > 2) { print $3; exit; } \
                         else { print $2; } exit; }' "$CONFIG_FILE"`;                          else { print $2; } exit; }' "$CONFIG_FILE"`;
         if [ ! -z "$DEBUG" ]; then          if [ ! -z "$DEBUG" ]; then
                 if [ -z "$PASS" ]; then                  if [ -z "$PASSWD" ]; then
                         echo "not found.";                          echo "not found.";
                 else                  else
                         echo "found.";                          echo "found.";
Riadok 441  if [ -z "$NAME" ]; then
Riadok 295  if [ -z "$NAME" ]; then
         exit 1;          exit 1;
 fi  fi
   
 if [ -z "$PASS" ]; then  if [ -z "$PASSWD" ]; then
         echo -n 'Enter password: ';          echo -n 'Enter password: ';
         stty -echo;          stty -echo;
         IF= read PASS;          IF= read PASSWD;
         stty echo;          stty echo;
         echo "<censored>"; # to write newline on output          echo "<censored>"; # to write newline on output
 fi  fi
Riadok 454  fi
Riadok 308  fi
 # FUNCTIONS  # FUNCTIONS
 #  #
 # {{{  # {{{
 http_set_cookies()  
 {  strip_html_tags()
         echo "parameter=$BASE_URL/$1"  { # {{{
         COOKIE_tmp="`$GET -P -e "$BASE_URL/$1" \          awk '{
                 | awk 'BEGIN { FS="[ ;]+" } /^Set-Cookie:/ { print $2; }'`";                  gsub(/<[^>]*>/, "");
         if [ -z "$COOKIE" ]; then                  gsub(/<[^>]*$/, "");
                 COOKIE="$COOKIE_tmp"                  gsub(/^[^>]*>/, "");
         else                  gsub(/^[        ]*$/, "");
                 COOKIE="$COOKIE; $COOKIE_tmp"                  print;
           }' | cat -s
   } # }}}
   
   img2text()
   { # {{{
   
           awk '#!/usr/bin/awk -f
   
           # $Id$
   
           # Author:  Lubomir Host rajo <rajo AT host.sk>
           # License: GNU GPL
   
           # Script for converting images to text files.
           # Usefull for script, which will send SMS message over public SMS gateway. ;)
   
           # Usage: cat img.png | convert - text:- | ./img2text
           # Enjoy flooding sms gateway! ;))
   
           BEGIN {
                   FS="[,:# \t]+"
                   prev_line = 0;
                   line   = 1;
                   column = 0;
                   color  = "";
                   start_char = 41;
           }
   
           {
                   n = split($0, a, FS);
   
                   column = a[1];
                   line   = a[2];
                   color  = a[6];
                   if (colormap[color] == 0) {
                           #printf "adding color %s to colormap\n", color;
                           #colormap[color] = ++start_char; # different char. for colors
                           colormap[color] = 35; # same char. for colors
   
                   }
                   if (column == 0 && line == 0 ||
                           column == 1 && line == 1) {
                           # first pixel 0,0 or 1,1 is probably background color,
                           # we will background filled with spaces
                           colormap[color] = 32;
                   }
                   output[line] = sprintf("%s%c", output[line], colormap[color]);
           }
   
           END {
           for (i = 0; i <= line; i++) {
                   if (output[i] !~ /^ +$/)
                           printf "%s\n", output[i];
                   }
           }'
   
   } # }}} img2text()
   
   make_http_request_GET()
   { # {{{
   
           # if --debug option is specified, save output from $GET to $TMP_FILE,
           echo "## Time: `date`"          >> $TMP_FILE
           echo "## Request: $* {{{"       >> $TMP_FILE
   
           for option
           do
                   case "$option" in
   
                           -*) ;; # ignore
   
                           Cookie:*)
                                   cookies="`echo $option | sed 's/^Cookie: //;'`" ;;
                           http:*)
                                   eval "http=\"$option\"" ;;
                   esac
           done
           if [ -z "$cookies" ]; then
                   cookies="$COOKIE"
         fi          fi
         echo "Cookies are '$COOKIE'"          if [ ! -z "$DEBUG" ]; then
 }                  echo "GET -H 'Cookie: $cookies' '$http'" > /dev/stderr
           fi
           echo "$cookies $http" | perl -w -e '
           #!/usr/bin/perl -w
           # GET implementation {{{
   
 make_request()          use IO::Socket;
 {          $| = 1;    # autoflush
 for request_type  
 do  
         case "$request_type" in  
   
                 http_get_cookies*)          sub http_get
                         http_set_cookies "${!request_type}";;          {
                   my $proxy   = shift;
                   my $url     = shift;
                   my $cookies = shift;
                   my $port    = 80;
   
                 *)                  my $msg   = "";
                         echo "Unknown request type $request";                  my $sock  = undef;
                         exit 1 ;;                  my $tries = 0;
         esac  
 done  
 }  
 # FUNCTIONS }}}  
   
 #                  while ( !$sock && $tries < 5 ) {
 # MAIN                          $sock = new IO::Socket::INET( Proto => "tcp",
 #                          PeerAddr => $proxy,
 # {{{                          PeerPort => $port,
 if [ -z "$HTTP_REQUESTS_ORDER" ]; then                          Type     => SOCK_STREAM,
         echo 'Did you specify $HTTP_REQUESTS_ORDER in your plugin??'                          );
         exit 1                          if ( !$sock ) {
 fi                                  print;
 for curr_request in $HTTP_REQUESTS_ORDER; do                                  print "Can NOT connect to ${proxy}:${port} ! Trying again ...";
         echo "Requesting ${!curr_request}";                                  $tries++;
         make_request $curr_request                          }
 done                  }
                   if ( !$sock ) {
                           print "$proxy is death... :(\n\n";
                           return;
                   }
   
 # SUCCESS ! ;)                  # make http request
 exit                  print $sock "GET $url HTTP/1.1\r\n";
                   print $sock "TE: deflate, gzip;q=0.3\r\n";
                   print $sock "Connection: TE, close\r\n";
                   print $sock "Host: $proxy\r\n";
                   print $sock "User-Agent: Mozilla/4.0 (compatible; MSIE 5.0; Linux [en]\r\n";
                   if ($cookies =~ "Cookie: ") {
                           print $sock "$cookies\r\n";
                   }
                   print $sock "\r\n";
   
 # MAIN }}}  
   
 # Get cookies {{{                  $sock->flush();
 # download the file via special wget which stores session cookie to a file                  while (<$sock>) {
 # Cookies format:                          print;
 # ^Set-Cookie: id=0a06b40e84a780fa;expires=Saturday, 07-Sep-2002 07:43:41 GMT                  }
 # ^Set-Cookie: SITY=32E0DDB9AF9293E774AA1C0B5BCC0992;path=/$                  $sock->close();
 echo 'Logging in...';                  return;
 COOKIE=`$GET -P -e -H "Cookie: SITY=SITY" \          }
         $WWW/pls/sity/u_registrate2.login2?NAME="$NAME"\&PASSWD="$PASS"\&ASERVICE=0\&CMD=%21u_sms.home\&SERVICE=0 \  
         | awk 'BEGIN { FS="[ ;]+" } /^Set-Cookie:/ { print $2; }'`;  
 # }}}  
   
 # Retrieving submit forms... {{{          while (<STDIN>) {
 echo 'Retrieving submit forms...';                  my $http;
                   my $server;
                   my $url;
                   my $cookies = "";
   
 #we now extract textarea name, which will be used later                  chomp;
 request=` $GET -P -H "Cookie: $COOKIE" \                  ($cookies, $http) = split /http:\/\//, $_, 2;
         $WWW/pls/sity/\!u_sms.home \                  #$http =~ s|^http://||;
         | awk -v number="$number" '                  ($server, $url) = split /\//, $http, 2;
 BEGIN { printf "&SMSMsgLen=480&SMScount=&"; }                  substr($cookies, 0, 0) = "Cookie: "; # put string at begin
 /textarea cols/ {                  substr($url, 0, 0) = "/";
         sub(/^.*name="/, "");  
         sub(/".*$/, "");                  #print "http=$http\ncookies=$cookies\nurl=$url\nserver=$server\n";
         printf "%s=%s&BT.x=0&BT.y=0&DETAIL=", $0, number;                  http_get($server, $url, $cookies);
 }          }
 /DETAIL/ {          # end of GET implementation }}}
         sub(/^.*value="/, "");          exit;' | tee -a $TMP_FILE
         sub(/".*$/, "");          echo "## }}} request done " >> $TMP_FILE
         printf "%s", $0;  
 }  } # }}}
   
   http_set_cookies()
   { # {{{
           #echo "http_set_cookies: parameter=$1"
           COOKIE_tmp="`$GET -P -e "$BASE_URL$1" \
                   | awk 'BEGIN { FS="[ ;]+" } /^Set-Cookie:/ { print $2; }'`";
           if [ ! -z "$COOKIE_tmp" ]; then
                   if [ -z "$COOKIE" ]; then
                           COOKIE="$COOKIE_tmp"
                   else
                           if [ -z "`echo '$COOKIE' | grep '$COOKIE_tmp'`" ]; then
                                   COOKIE="$COOKIE; $COOKIE_tmp"
                           fi
                   fi
                   # create also variable COOKIE_<variable_name>
                   eval "COOKIE_$COOKIE_tmp"
                   #echo "created variable COOKIE_$COOKIE_tmp"
                   #echo "Cookies are '$COOKIE'"
           else
                   if [ ! -z "$DEBUG" ]; then
                           echo "No cookies found at '$1'"
                   fi
           fi
   } # }}}
   
 /CHECK/ { # kontrolny retazec  http_authentification()
         sub(/^.*src="/, "");  { # {{{
         sub(/>.*$/, "");          # $1 = "/pls/ezones/!e_single_sign_on.login"
         printf "CHECK=%s", $0;          # $2 = "http_auth_request"
           # http_auth_request = "frame=0&page=&menu=&extrapar=&user_name=$NAME&passwd=$PASSWD"
           url="$1?${!2}" # total cool brutal ;)
   
 } '`          #echo "http_authentification: parameter=$BASE_URL$1"
           eval "http_set_cookies \"$url\""
   
 # }}}  } # }}}
   
 # Getting check code {{{  make_request()
 url=`echo $request | sed 's/.*CHECK=\([^"]\+\)".*$/\1/;'`  { # {{{
 # we must set id=... also as cookies :-)          for request
 COOKIE=`echo "$url; $COOKIE" | sed 's/^[^?]*?//g;'`          do
                   case "$request" in
   
                           read_message*)
                                   read_message ;;
   
 if [ ! -z "$DEBUG" ]; then                          http_get_cookies*)
         echo "image URL: $WWW$url"                                  http_set_cookies "${!request}";;
 fi  
 while [ -z "$checkcode" ]; do  
         $GET -P -H "Cookie: $COOKIE" "$WWW$url" \  
                 | perl -e 'while (<STDIN>) { chomp; last unless (m/\S/); } my $haluz=<STDIN>; while (<STDIN>) { print; }' \  
                 | convert - txt:- | img2text | head -n 15  
   
         echo -en "Please enter CHECK code (or press Ctrl+d to obtain another version): "                          http_auth*)
         read checkcode;                                  http_authentification "${!request}" "${request}_request";;
 done  
 request=`echo $request | sed "s/CHECK=[^\"]\+\"\(.*\)$/CHECK=$checkcode\&\1/g;"`  
   
 # }}}                          http_check_image*)
                                   get_check_code "${!request}";;
   
 # Checking number of free SMSs {{{                          http_send_msg*)
 echo -n 'Checking number of free SMSs... ';                                  http_send_msg "${!request}";;
 smss_sent=`$GET -P -H "Cookie: $COOKIE" \  
         $WWW/pls/sity/u_profil.show_stat \  
         | awk '/^<TD>[0-9]+<\/TD>$/ { gsub(/[><]/, " "); print $2;  exit; } '`;  
   
 echo "100-$smss_sent" | bc;                          *)
 # }}}                          echo "Unknown request type $request";
                           exit 1 ;;
                   esac
           done
   } # }}}
   
 # Read message from stdin {{{  read_message()
 echo 'Enter your message (max 420 chars, end with CTRL-D):';  { # {{{
 echo 'Please wait at least 4 seconds to submit form.';          echo 'Enter your message (max 420 chars, end with CTRL-D):';
 text=`cat` # text from stdin, multiple lines          echo 'Please wait at least 4 seconds to submit form.';
 text="`echo \"$text\" \          TEXT=`cat` # text from stdin, multiple lines
           TEXT="`echo \"$TEXT\" \
         | awk 'BEGIN { ORS="+" } \          | awk 'BEGIN { ORS="+" } \
         {   gsub(/%/,  "%25"); \                  {   gsub(/%/,  "%25"); \
                 gsub(/\+/, "%2B"); \                          gsub(/\+/, "%2B"); \
                 gsub(/ /,  "+"); \                          gsub(/ /,  "+"); \
                 gsub(/\&/, "%26"); \                          gsub(/\&/, "%26"); \
                 print; }'`"                          print;
 # }}}                  }'`"
           TEXT_LEN="`echo \"$TEXT\" | wc -c | awk '{ print $1}'`"
   
 if [ "x$text" == "x+" ]; then          if [ "x$TEXT" == "x+" ]; then
         echo "Empty message is not allowed.";                  echo "Empty message is not allowed.";
         exit 1;                  exit 1;
 fi          fi
   } # }}}
   
 # Submitting SMS... {{{  get_check_code()
 echo 'Submitting SMS...';  { # {{{
 smss_left=`$GET -P -H "Cookie: $COOKIE" \          if [ ! -z "$DEBUG" ]; then
         $WWW/pls/sity/\!u_sms.send_sms?MSG_TEXT="$text""$request" \                  echo "image URL: $1"
         | grep "Tento mesiac" \          fi
         | sed 's/.*va \([0-9]*\) spr.*/\1/'` ;          while [ -z "$CHECKCODE" ]; do
 # }}}                  $GET -P -H "Cookie: $COOKIE" "$BASE_URL$1" \
                   | perl -e 'while (<STDIN>) { chomp; last unless (m/\S/); } my $haluz=<STDIN>; while (<STDIN>) { print; }' \
                   | convert - txt:- | img2text
   
 if [ $smss_left ]; then                  echo -en "Please enter CHECK code (or press Ctrl+d to obtain another version): "
         echo "Message sent. $smss_left SMSs left for this month.";                  read CHECKCODE;
 else          done
         if [ -z "$DEBUG" ]; then  } # }}}
                 echo "Something went wrong, please use '--debug' option for debugging";  
   http_send_msg()
   { # {{{
           if [ -z "$OUTPUT_FILTER" ]; then
                   $GET -P -H "Cookie: $COOKIE" "$BASE_URL$1";
         else          else
                 echo "Something went wrong, tmp file $TMP_FILE not removed for debug purposes!";                  eval "$GET -P -H \"Cookie: $COOKIE\" \"$BASE_URL$1\" | $OUTPUT_FILTER"
         fi          fi
   
   } # }}}
   
   # FUNCTIONS }}}
   
   #
   # MAIN
   #
   #
   if [ -z "$HTTP_REQUESTS_ORDER" ]; then
           echo 'Did you specify $HTTP_REQUESTS_ORDER in your plugin??'
           exit 1
 fi  fi
   for curr_request in $HTTP_REQUESTS_ORDER; do
           #echo "Requesting ${!curr_request}";
           make_request $curr_request
   done
   
   # SUCCESS ! ;)
   
   exit
   
 # Modeline {{{  # Modeline {{{
 # vim:set ts=4:  # vim:set ts=4:

Legend:
Odstranené z verzie1.1  
zmenené riadky
  Pridané vo verzii1.2

Platon Group <platon@platon.sk> http://platon.sk/
Copyright © 2002-2006 Platon Group
Stránka používa redakčný systém Metafox
Na začiatok