1 # ===================================================================== 2 # logIn: grant authentication credentials. 3 # 4 # Copyright (c) 2005,2009 Carlo Strozzi 5 # 6 # This program is free software; you can redistribute it and/or modify 7 # it under the terms of the GNU General Public License as published by 8 # the Free Software Foundation; version 2 dated June, 1991. 9 # 10 # This program is distributed in the hope that it will be useful, 11 # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 # GNU General Public License for more details. 14 # 15 # You should have received a copy of the GNU General Public License 16 # along with this program; if not, write to the Free Software 17 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 18 # 19 # ===================================================================== 20 21 # ===================================================================== 22 # Local variables and functions 23 # ===================================================================== 24 25 TNS_GROUP_HOME = () 26 27 cgi.group = () 28 cgi.group.literal = () 29 30 tmp1 = /dev/null 31 32 # ===================================================================== 33 # Main program 34 # ===================================================================== 35 36 HTTP_AUTHORIZATION = () # *Always* clear any old auth. 37 38 # We are "appending" a session, and anyway we are sending authentication 39 # data across the wire so using GET is out of question. 40 41 csaGetArgs POST 42 43 . $CSA_ROOT/lib/group-stuff.rc 44 45 #~ $REMOTE_ADDR 192.168.1.2 && csaExit.env 46 47 ~ $#TNS_GROUP_HOME 1 2 || csaExit.fault 0041 TNS_GROUP_HOME # required 48 49 # Follow the specs. 50 ~ $TNS_GROUP_HOME(2) () && 51 TNS_GROUP_HOME = ($TNS_GROUP_HOME(1) $TNS_GROUP_HOME(1)) 52 53 # The authCheck function is application-specific, and must be provided 54 # by the application programmer. We need to pass it the authentication 55 # data posted by the user, which was not known when 'authCheck' was 56 # called by 'weblib.rc', so we must call it again after 'csaGetArgs'. 57 58 #~ $REMOTE_ADDR 192.168.1.2 && csaExit.env 59 60 # Display login failures in a custom template if available. 61 62 authCheck --return || { 63 if (!~ $TNS_SELFREG_AUTH *[a-z]* || !csaTrue $TNS_SELFREG_AUTOASK) { 64 CSA_EXIT_SCRIPT = ($CSA_EXIT_SCRIPT back) 65 csaExit.needauth 66 } 67 68 # Show self-registration form if appropriate. 69 csaExit.location $CSA_RPC_URI'?0=showStatic&x-csa-lang='$CSA_LANG^'&1='$'cgi.group'^'&2=tw-reg-form' 70 } 71 72 # Set new auth, after passing the authorization check. 73 74 HTTP_AUTHORIZATION='Basic '^`{ 75 echo -n $CSA_AUTH_USER:$CSA_AUTH_PW | swu-encdec -e -b 76 } 77 78 csaPrintMsg 0014 # Log the event. 79 80 # The proper (i.e. RESTful) way of displaying the successful 81 # authentication page is through PRG. 82 83 #~ $REMOTE_ADDR 192.168.1.2 && csaExit.env 84 85 # Take the user to the last failed authentication if applicable. 86 if (~ $CSA_SESSION(18) http://* https://* /*) { 87 csaSession.set - 18 88 if (csaIsInteractive) { 89 if (~ $CSA_SESSION(18) /$CSA_ID/*) { 90 csaExit.location $CSA_CGI_STEM$CSA_SESSION(18) 91 } else csaExit.location $CSA_SESSION(18) 92 } 93 } 94 95 # Else take the user to the welcome page. 96 csaExit.location \ 97 $CSA_RPC_URI/$CSA_LANG/$'cgi.group'/$TNS_GROUP_HOME(2) 98 99 # End of program.