Created
March 5, 2015 16:50
-
-
Save ejherran/8ff496cb8827d2f45d60 to your computer and use it in GitHub Desktop.
Chilli Config
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/sh | |
| # Copyright (C) 2009-2012 David Bird (Coova Technologies) <[email protected]> | |
| # | |
| # This program is free software: you can redistribute it and/or modify | |
| # it under the terms of the GNU General Public License as published by | |
| # the Free Software Foundation, either version 3 of the License, or | |
| # (at your option) any later version. | |
| # | |
| # This program is distributed in the hope that it will be useful, | |
| # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| # GNU General Public License for more details. | |
| # | |
| # You should have received a copy of the GNU General Public License | |
| # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
| . ./functions.sh | |
| . ./uam.sh | |
| . ./wispr.sh | |
| USERS=/etc/chilli/localusers | |
| COOVA_USERURL=$COOKIE_COOVA_USERURL | |
| COOVA_SESSIONID=$CHI_SESSION_ID | |
| COOVA_CHALLENGE=$CHI_CHALLENGE | |
| PORTAL_SESSIONID=${COOKIE_PORTAL_SESSIONID:-$SESSIONID} | |
| FORM_userurl=${FORM_userurl:-http://www.itclatam.com} | |
| http_redirect2() { | |
| cat <<EOF | |
| HTTP/1.1 302 Redirect | |
| Location: $1 | |
| Set-Cookie: PORTAL_SESSIONID=$PORTAL_SESSIONID | |
| Set-Cookie: COOVA_USERURL=$COOVA_USERURL | |
| Connection: close | |
| EOF | |
| exit | |
| } | |
| http_redirect() { | |
| http_header | |
| cat <<EOF | |
| <body onload="document.form1.submit();"> | |
| <form action="$1" name="form1" id="form1" method="post"> | |
| <input name="res" value="$FORM_res" type="hidden"> | |
| <input name="reply" value="$FORM_reply" type="hidden"> | |
| </form> | |
| </body> | |
| EOF | |
| exit | |
| } | |
| http_header() { | |
| # [ "$HS_MODE" = "hotspot" ] || { | |
| # http_redirect2 "/www/disabled.chi" | |
| # } | |
| cat<<EOF | |
| HTTP/1.1 200 OK | |
| Content-Type: text/html | |
| Set-Cookie: PORTAL_SESSIONID=$PORTAL_SESSIONID | |
| Set-Cookie: COOVA_USERURL=$COOVA_USERURL | |
| Connection: close | |
| Cache: none | |
| EOF | |
| } | |
| header() { | |
| echo "<html><head>" | |
| uamfile title 0 | |
| echo " | |
| <meta http-equiv='Content-Type' content='text/html; charset=UTF-8' /> | |
| <meta http-equiv=\"Cache-control\" content=\"no-cache\"/> | |
| <meta http-equiv=\"Pragma\" content=\"no-cache\"/> | |
| <style>" | |
| uamfile "css" 0 | |
| echo "</style>" | |
| echo "<script>" | |
| uamfile "js" 0 | |
| echo "</script>" | |
| echo "$1</head><body$2>" | |
| echo "<div id=\"popCont\" onclick=\"hidePop();\" title=\"Click sobre la burbuja para cerrar!.\"></div>" | |
| echo "<div class=\"it-divm\">" | |
| } | |
| footer() { | |
| echo "</div>" | |
| echo "<div class='it-footer'> | |
| <i>Powered by</i> | |
| <a href="http://www.itclatam.com"><img src="img/itc.png" width="125" height="21"/></a> | |
| </div>" | |
| } | |
| error() { echo "<div class=\"err\">$1</div>"; } | |
| href() { | |
| echo "<a href=\"$1\">$2</a>" | |
| } | |
| form() { | |
| echo "<div class='it-fmx'><form class="it-frm" name=\"form\" method=\"post\" action=\"$1\"><INPUT TYPE=\"hidden\" NAME=\"userurl\" VALUE=\"$FORM_userurl\">$2</form></div>" | |
| } | |
| loginform() { | |
| case "$AUTHENTICATED" in | |
| 1) | |
| echo "<div class='it-fmx'><h1>SESIÓN ACTIVA</h1><a class='it-buttonx' href='/logoff'>TERMINAR SESIÓN</a></div>" | |
| ;; | |
| *) | |
| [ "$HS_OPENIDAUTH" = "on" ] && { \ | |
| echo "<div id=\"login-label\" style=\"display:none;\"><label><a href=\"javascript:toggleAuth('login')\"><< back</a></label></div>" | |
| form "login.chi" "$(uamfile openid_form 1)" | |
| } | |
| form "login.chi" "$(uamfile login_form 1)" | |
| ;; | |
| esac | |
| echo "<div class='it-opt'> | |
| <br> | |
| <center> | |
| <a class='it-buttonx' href='chpass.chi'>CAMBIAR CONTRASEÑA</a> | |
| <a class='it-buttonx' href='rcpass.chi'>RECUPERAR CONTRASEÑA</a> | |
| </center> | |
| <i>Este servicio se provee de forma libre y bajo su propia responsabilidad.</i> | |
| </div>" | |
| } | |
| local_login_url() { | |
| if [ "$HS_USELOCALUSERS" = "on" ]; then | |
| line=$(head -1 $USERS) | |
| if [ "$line" = "" ]; then | |
| echo "tos:$(echo '$$$(date)'|md5sum|cut -f1)" >> $USERS | |
| line=$(head -1 $USERS) | |
| fi | |
| if [ "$line" != "" ]; then | |
| user=$(echo "$line" | cut -f1 -d:) | |
| pass=$(echo "$line" | cut -f2 -d:) | |
| echo -n $(chi_login_url "$user" "$pass") | |
| fi | |
| else | |
| user=$REMOTE_MAC | |
| pass=$HS_ADMPWD | |
| echo -n $(chi_login_url "$user" "$pass") | |
| fi | |
| } | |
| reply_message() { | |
| case "$AUTHENTICATED" in | |
| 1) | |
| echo "You are now on-line!" | |
| ;; | |
| *) | |
| echo "$FORM_reply" | |
| ;; | |
| esac | |
| } | |
| image() { | |
| ext=$(echo "$1"|awk -v FS=. '{ print tolower($NF) }') | |
| base=$(echo "$1"|awk -v FS=/ '{ gsub(/[^a-zA-Z0-9_\/-]/,""); print tolower($NF) }') | |
| echo -n "img-$base.$ext" | |
| } | |
| registerform() { | |
| form "register.chi" "$(uamfile register_form 1)" | |
| } | |
| contactform() { | |
| form "contact.chi" "$(uamfile contact_form 1)" | |
| } | |
| termsform() { | |
| form "tos.chi" "$(uamfile terms_form 1)" | |
| } | |
| runlogin() { | |
| out=$($CHILLI_QUERY login sessionid "$COOVA_SESSIONID" username "$1" password "$2") | |
| } | |
| chi_login_url() { | |
| case "$HS_RAD_PROTO" in | |
| pap) | |
| response=$($CHILLI_RESPONSE -pap "$CHI_CHALLENGE" "$HS_UAMSECRET" "$2") | |
| echo -n "http://$HS_UAMLISTEN:$HS_UAMPORT/login?username=$1&password=${response}&userurl=${3:-$COOVA_USERURL}" | |
| ;; | |
| mschapv2) | |
| response=$($CHILLI_RESPONSE -nt "$CHI_CHALLENGE" "$HS_UAMSECRET" "$1" "$2") | |
| echo -n "http://$HS_UAMLISTEN:$HS_UAMPORT/login?username=$1&ntresponse=${response}&userurl=${3:-$COOVA_USERURL}" | |
| ;; | |
| *) | |
| response=$($CHILLI_RESPONSE "$CHI_CHALLENGE" "$HS_UAMSECRET" "$2") | |
| echo -n "http://$HS_UAMLISTEN:$HS_UAMPORT/login?username=$1&response=${response}&userurl=${3:-$COOVA_USERURL}" | |
| ;; | |
| esac | |
| } | |
| dologin() { | |
| #============================= ENCRIPTAR PASSWORD ===========================================# | |
| FORM_password=`pyradix "$FORM_password"` | |
| #============================= INYECTAR URL =================================================# | |
| redir_url=`cat /etc/chilli/defaults | grep '@redir_url' | awk '{print substr($0,13)}'` | |
| if [ -n "$redir_url" ] | |
| then | |
| FORM_userurl="$redir_url" | |
| fi | |
| #============================================================================================# | |
| url=$(chi_login_url "$FORM_username" "$FORM_password" "$FORM_userurl") | |
| cat <<ENDHTML | |
| <html><head> | |
| <meta http-equiv="refresh" content="0;url=$url"/> | |
| <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> | |
| </head></html> | |
| ENDHTML | |
| wisprLoginResultsURL "$url" | |
| } | |
| domail() { | |
| from=$1;to=$2;file=$3 | |
| (uamfile "$file" 0 | |
| echo | |
| echo "-------------------------------------------------" | |
| echo "Powered by Coova - http://www.coova.org/" | |
| echo) | /usr/sbin/sendmail -t -f "$from" && return 0 | |
| return 1; | |
| } | |
| FORM_username="${FORM_username:-$FORM_UserName}" | |
| #FORM_username="${FORM_username:-$FORM_Username}" | |
| #FORM_password="${FORM_password:-$FORM_Password}" | |
| # For WISPr 2.0 EAP, bounce back to chilli | |
| [ "$FORM_res" = "wispr" ] && \ | |
| [ "$FORM_WISPrEAPMsg" != "" ] && \ | |
| [ "$FORM_WISPrVersion" = "2.0" ] && { | |
| http_redirect2 "http://$HS_UAMLISTEN:$HS_UAMPORT/login?username=$FORM_username&WISPrEAPMsg=$FORM_WISPrEAPMsg&WISPrVersion=2.0" | |
| } | |
| if [ "$FORM_uamip" != "" ] && [ "$HS_UAMSECRET" != "" ] | |
| then | |
| if [ "$FORM_res" != "wispr" ] | |
| then | |
| QS=$(echo $QUERY_STRING | sed 's/&md=[^&=]*$//') | |
| HTTP="http" | |
| [ "$HTTPS" = "on" ] && HTTP="https" | |
| URL="$HTTP://$SERVER_NAME/$REQUEST_URI?$QS" | |
| CHECK="$URL$HS_UAMSECRET" | |
| CHECK_MD5=$(echo -n "$CHECK" |md5sum|cut -d' ' -f1|tr 'a-z' 'A-Z'); | |
| if [ "$CHECK_MD5" = "$FORM_md" ]; then | |
| COOVA_USERURL=$FORM_userurl | |
| else | |
| http_redirect "/www/error.chi" | |
| fi | |
| fi | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment