Platon Technologies
neprihlásený Prihlásiť Registrácia
SlovakEnglish
open source software development oslavujeme 10 rokov vývoja otvoreného softvéru! Piatok, 29. marec 2024

Súbor: [Platon] / scripts / shell / atlantis / add-profile-line.sh (stiahnutie)

Revízia 1.5, Sun Nov 9 19:13:55 2003 UTC (20 years, 4 months ago) by nepto


Zmeny od 1.4: +4 -4 [lines]

Changed $Id$ for $Platon$.

#!/bin/sh

#
# add-profile-line.sh - simple Atlantis.SK profile appender
#
# Written by Martin Karas <wolcano@platon.sk>
# Multiple lines feature by Ondrej Jombik [03/09/2002]
# Adds input data to current Atlantis.SK profile
# Copyright (c) 2002-2003 Platon SDG, http://www.platon.sk/
# Licensed under terms of GNU General Public License.
#

# $Platon: add-profile-line.sh,v 1.4 2002/09/03 13:44:25 nepto Exp $

CONFIG_FILE="$HOME/.atlantis.conf";

if [ -f "$CONFIG_FILE" ]; then
    NAME=`grep -E '^username[ ]*=[ ]*' $CONFIG_FILE \
        | sed 's/^username[ ]*=[ ]*\(.*\)$/\1/' \
        | head -n 1`;
    PASS=`grep -E '^password[ ]*=[ ]*' $CONFIG_FILE \
        | sed 's/^password[ ]*=[ ]*\(.*\)$/\1/' \
        | head -n 1`;
fi

if [ -z "$NAME" ]; then
    echo -n 'Enter username: ';
    IF= read NAME;
else
    echo "Using username '$NAME' from configuration file '$CONFIG_FILE'.";
fi

if [ -z "$NAME" ]; then
    echo "Empty username is not allowed.";
    exit 1;
fi

if [ -z "$PASS" ]; then
    echo -n 'Enter password: ';
    stty -echo;
    IF= read PASS;
    stty echo;
    echo "<censored>"; # to write newline on output
fi

if [ -z "$PASS" ]; then
    echo "Empty password is not allowed.";
    exit 1;
fi

echo -n 'Enter lines to be appended';
echo ' (empty data removes whole profile; use ^c to abort):';
text=`cat` # text from stdin, multiple lines
text=`echo -n "$text" \
    | awk 'BEGIN { ORS="\n" } \
    {   gsub(/%/,  "%25"); \
        gsub(/\+/, "%2B"); \
        gsub(/[ ]/,  "+"); \
        gsub(/\&/, "%26"); \
        print; }' \
    | perl -wpe 's/\n/%0A/g;s/\r/%0D/g'`;
text="$text";

# download the file via special wget which stores session cookie to a file
# debug
#echo "Logging in as '$NAME':'$PASS'";
GET http://www.atlantis.sk/profile/index.php?username="$NAME"\&password="$PASS"\&action=login >tmp.html;

PHPSESSID=`grep '<input type="hidden" name="PHPSESSID" value="[a-f0-9]*" \/><' tmp.html | head -n 1 | sed 's/.*<input type="hidden" name="PHPSESSID" value="\([a-f0-9]\+\)" \/>.*/\1/'`
ORIG_PROFILE=`awk 'BEGIN { haluz=0;} /<textarea/ { haluz=1; gsub(/^.*textarea([^>]*)>/ , ""); print; next; } /^<\/textarea/ {haluz=0; next;} // { if (haluz==1) print; } ' tmp.html`

if [ "X$text" = "X" ]; then
    echo "Empty data, removing whole profile.";
    NEW_PROFILE="";
else
    NEW_PROFILE=`echo -n "$ORIG_PROFILE" \
        | awk 'BEGIN { ORS="\n" } \
        {   gsub(/%/,  "%25"); \
            gsub(/\+/, "%2B"); \
            gsub(/[ ]/,  "+"); \
            gsub(/\&/, "%26"); \
            print; }' \
        | perl -wpe 's/\n/%0A/g;s/\r/%0D/g'`;
    NEW_PROFILE="$NEW_PROFILE$text";
fi

#echo "NEW_PROFILE=[$NEW_PROFILE]";

GET -H "Cookie: PHPSESSID=$PHPSESSID" \
    http://www.atlantis.sk/profile/index.php?PHPSESSID="$PHPSESSID"\&action=save\&pro="$NEW_PROFILE" \
    > tmp2.html;

rm tmp.html
rm tmp2.html


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