Skip to content
This repository has been archived by the owner on Oct 27, 2022. It is now read-only.

Commit

Permalink
Merge pull request #13 from DeBaschdi/master
Browse files Browse the repository at this point in the history
tkm - use php-curl for cookie handling
  • Loading branch information
sunsettrack4 authored Oct 7, 2019
2 parents cbe1e73 + fd88b0f commit d052abf
Show file tree
Hide file tree
Showing 7 changed files with 356 additions and 207 deletions.
21 changes: 21 additions & 0 deletions epg.sh
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,18 @@ then
ERROR="true"
fi

if [ ! -e tkm/proxy.sh ]
then
printf "\nMissing file in MagentaTV folder: tkm/ch_json2xml.pl"
ERROR="true"
fi

if [ ! -e tkm/web_magentatv_de.php ]
then
printf "\nMissing file in MagentaTV folder: tkm/chlist_printer.pl"
ERROR="true"
fi

if [ ! -e tkm/cid_json.pl ]
then
printf "\nMissing file in MagentaTV folder: tkm/cid_json.pl"
Expand Down Expand Up @@ -281,6 +293,13 @@ then
ERROR="true"
fi

if [ ! -e tkm/web_magentatv_de.php ]
then
printf "\nMissing file in MagentaTV folder: tkm/web_magentatv_de.php"
ERROR="true"
fi


if [ ! -e tkm/url_printer.pl ]
then
printf "\nMissing file in MagentaTV folder: tkm/url_printer.pl"
Expand Down Expand Up @@ -1396,6 +1415,8 @@ do
cp tkm/chlist_printer.pl tkm/de/
cp tkm/compare_menu.pl tkm/de/
cp tkm/url_printer.pl tkm/de/
cp tkm/web_magentatv_de.php tkm/de/
cp tkm/proxy.sh tkm/de/
cd tkm/de && bash settings.sh
cd - > /dev/null

Expand Down
162 changes: 162 additions & 0 deletions tkm/proxy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
#!/bin/bash

# default hostname
HOST=127.0.0.1
# default port number
PORT=8000
# script name
NAME=${0##*/}

usage () {
cat <<EOF
$NAME (PHP built-in web server manager) Version 0.2.0
PHP builtin server manager on port $PORT
usage: ./$NAME <command> [<hostname>:<port>]
Available commands:
start Starts PHP built-in web server server on specified hostname:port, default is localhost:$PORT
stop Stops the PHP built-in web server
restart Stops and Starts on previously specified hostname:port
status Status of "$NAME" process
log Show the PHP built-in web server logs. Use the -f option for a live update
report bugs to me@cubny.com
$NAME homepage: <https://github.com/cubny/php-built-in-server-manager>
EOF
return 0
}

setup_colors() {

if which tput >/dev/null 2>&1; then
ncolors=$(tput colors)
fi
if [ -t 1 ] && [ -n "$ncolors" ] && [ "$ncolors" -ge 8 ]; then
RED="$(tput setaf 1)"
GREEN="$(tput setaf 2)"
YELLOW="$(tput setaf 3)"
BLUE="$(tput setaf 4)"
BOLD="$(tput bold)"
NORMAL="$(tput sgr0)"
else
RED=""
GREEN=""
YELLOW=""
BLUE=""
BOLD=""
NORMAL=""
fi
}

# if no command specified exit and show usage
if [[ $# < 1 ]]; then
echo $NAME: no command specified
usage
exit 1
fi

# if hostname:port specified override defaults
if [[ $# > 1 ]]; then
IFS=':' read -r -a hostport <<< "$2"
if [[ ! -z "${hostport[0]}" ]]; then
HOST=${hostport[0]}
fi
if [[ ! -z "${hostport[1]}" ]]; then
PORT=${hostport[1]}
fi
fi

# pidfile contents would be hostname:port:pid
PIDFILE="$NAME".pid
LOGFILE="$NAME".log

validate_server () {
which php &> /dev/null
if [[ $? -eq 1 ]]; then
printf "${YELLOW}Error: PHP not found. ${NORMAL}Please install PHP version 5.4 or greater!\n"
return 1
fi

php -h | grep -q -- '-S'
if [[ $? -eq 1 ]]; then
printf "${YELLOW}Error: PHP version must be 5.4 or greater!${NORMAL}\n"
return 1
fi

return 0
}

start_server () {

validate_server
if [[ $? -eq 1 ]]; then
return 1
fi

if [[ -e "$PIDFILE" ]]; then
printf "${YELLOW}Server seems to be running!${NORMAL}\n"
echo
echo if not, there is probably a zombie "$PIDFILE" in this directory.
echo if you are sure no server is running just remove "$PIDFILE" manually and start again
return 1
else
printf "${GREEN}"$NAME" started on $HOST:$PORT${NORMAL}\n"
php -S "$HOST":"$PORT" >> "$LOGFILE" 2>&1 &
echo "$HOST":"$PORT":$! > $PIDFILE
return 0
fi
}

read_pidfile() {
if [[ -e "$PIDFILE" ]]; then
PIDFILECONTENT=`cat "$PIDFILE"`
IFS=: read HOST PORT PID <<< "$PIDFILECONTENT:"
return 0
else
return 1
fi

}
stop_server () {
if read_pidfile; then
kill -9 "$PID"
rm -f "$PIDFILE"
printf "${GREEN}"$NAME" stopped!${NORMAL}\n"
return 0
else
printf "${YELLOW}"$NAME" is not running!${NORMAL}\n"
return 1
fi
}

status_server() {
if read_pidfile && kill -0 "$PID" ; then
printf "${BLUE}"$NAME" is running on ${HOST}:${PORT}${NORMAL}\n"
else
printf "${YELLOW}"$NAME" is not running!${NORMAL}\n"
fi
}


log_server() {
if read_pidfile && kill -0 "$PID" ; then
if [[ "$1" = "-f" ]]; then
TAIL_OPTS="-f"
fi
tail $TAIL_OPTS "$LOGFILE"
else
printf "${YELLOW}"$NAME" is not running!${NORMAL}\n"
fi
}


setup_colors

case $1 in
start) start_server;;
stop) stop_server;;
restart) stop_server; start_server ;;
status) status_server;;
log) log_server $2;;
-h) usage ;;
--help) usage ;;
*) usage;;
esac
38 changes: 13 additions & 25 deletions tkm/settings.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,30 +20,12 @@
# along with easyepg. If not, see <http://www.gnu.org/licenses/>.

# ######################################
# LOADING COOKIE DATA / GET SESSION ID #
# START PHP PROXY SERVER #
# ######################################

printf "\rLoading cookie data..."

# REFRESH COOKIE
rm /tmp/cookie 2> /dev/null

# AUTH
curl -s --cookie "/tmp/cookie" --cookie-jar "/tmp/cookie" -d '{"userId":"Guest","mac":"00:00:00:00:00:00"}' 'https://web.magentatv.de/EPG/JSON/Login' > /dev/null

# LOGIN
curl -s --cookie "/tmp/cookie" --cookie-jar "/tmp/cookie" -d '{"terminalid":"00:00:00:00:00:00","mac":"00:00:00:00:00:00","terminaltype":"WEBTV","utcEnable":1,"timezone":"UTC","userType":3,"terminalvendor":"Unknown","preSharedKeyID":"PC01P00002","cnonce":"5c6ff0b9e4e5efb1498e7eaa8f54d9fb"}' 'https://web.magentatv.de/EPG/JSON/Authenticate?SID=firstup' > /dev/null

# GET SESSION ID
grep "CSRFSESSION" /tmp/cookie > /tmp/session && sed -i 's/\(.*\)\(CSRFSESSION\) \(.*\)/X_CSRFToken: \3/g' /tmp/session

if ! grep -q "X_CSRFToken" /tmp/session
then
echo " FAILED" && printf "\n"
exit 0
else
session=$(</tmp/session)
fi
printf "\rStarting Proxy Server\n"
bash proxy.sh start
sleep 1s

rm /tmp/settings_new 2> /dev/null

Expand Down Expand Up @@ -191,9 +173,8 @@ do
then
# E1100 MENU OVERLAY
echo 'dialog --backtitle "[E1100] EASYEPG SIMPLE XMLTV GRABBER > MAGENTA SETTINGS > CHANNEL LIST" --title "CHANNELS" --checklist "Please choose the channels you want to grab:" 15 50 10 \' > /tmp/chmenu

printf "\rFetching channel list... "
curl -s --cookie "/tmp/cookie" --cookie-jar "/tmp/cookie" -X POST -H "$session" -d '{"properties":[{"name":"logicalChannel","include":"/channellist/logicalChannel/contentId,/channellist/logicalChannel/type,/channellist/logicalChannel/name,/channellist/logicalChannel/chanNo,/channellist/logicalChannel/pictures/picture/imageType,/channellist/logicalChannel/pictures/picture/href,/channellist/logicalChannel/foreignsn,/channellist/logicalChannel/externalCode,/channellist/logicalChannel/sysChanNo,/channellist/logicalChannel/physicalChannels/physicalChannel/mediaId,/channellist/logicalChannel/physicalChannels/physicalChannel/fileFormat,/channellist/logicalChannel/physicalChannels/physicalChannel/definition"}],"metaDataVer":"Channel/1.1","channelNamespace":"2","filterlist":[{"key":"IsHide","value":"-1"}],"returnSatChannel":0}' "https://web.magentatv.de/EPG/JSON/AllChannel?SID=first" > /tmp/workfile
curl -s 'http://127.0.0.1:8000/web_magentatv_de.php?type=2' > /tmp/workfile
jq '.' /tmp/workfile > /tmp/chlist

printf "\rLoading channel configuration..."
Expand Down Expand Up @@ -463,7 +444,8 @@ do
elif grep -q "7" /tmp/value
then
clear

printf "\rStopping Proxy Server\n"
bash proxy.sh stop
echo ""
echo " --------------------------------------------"
echo " TELEKOM EPG SIMPLE XMLTV GRABBER "
Expand All @@ -481,6 +463,8 @@ do
cd - > /dev/null

read -n 1 -s -r -p "Press any key to continue..."
printf "\rStarting Proxy Server\n"
bash proxy.sh start
echo "H" > /tmp/value


Expand All @@ -506,6 +490,8 @@ do
then
dialog --backtitle "[E1920] EASYEPG SIMPLE XMLTV GRABBER > MAGENTA SETTINGS > DELETE INSTANCE" --title "INFO" --msgbox "Service deleted!" 5 30
rm channels.json
printf "\rStopping Proxy Server\n"
bash proxy.sh stop
echo "M" > /tmp/value

# E19X0 EXIT
Expand All @@ -521,6 +507,8 @@ do
# ############

else
printf "\rStopping Proxy Server\n"
bash proxy.sh stop
echo "M" > /tmp/value
fi

Expand Down
Loading

0 comments on commit d052abf

Please sign in to comment.