File Annotation
Not logged in
dbda8d6ce9 2007-07-21       drh: /*
dbda8d6ce9 2007-07-21       drh: ** Copyright (c) 2007 D. Richard Hipp
dbda8d6ce9 2007-07-21       drh: **
dbda8d6ce9 2007-07-21       drh: ** This program is free software; you can redistribute it and/or
dbda8d6ce9 2007-07-21       drh: ** modify it under the terms of the GNU General Public
dbda8d6ce9 2007-07-21       drh: ** License as published by the Free Software Foundation; either
dbda8d6ce9 2007-07-21       drh: ** version 2 of the License, or (at your option) any later version.
dbda8d6ce9 2007-07-21       drh: **
dbda8d6ce9 2007-07-21       drh: ** This program is distributed in the hope that it will be useful,
dbda8d6ce9 2007-07-21       drh: ** but WITHOUT ANY WARRANTY; without even the implied warranty of
dbda8d6ce9 2007-07-21       drh: ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
dbda8d6ce9 2007-07-21       drh: ** General Public License for more details.
dbda8d6ce9 2007-07-21       drh: **
dbda8d6ce9 2007-07-21       drh: ** You should have received a copy of the GNU General Public
dbda8d6ce9 2007-07-21       drh: ** License along with this library; if not, write to the
dbda8d6ce9 2007-07-21       drh: ** Free Software Foundation, Inc., 59 Temple Place - Suite 330,
dbda8d6ce9 2007-07-21       drh: ** Boston, MA  02111-1307, USA.
dbda8d6ce9 2007-07-21       drh: **
dbda8d6ce9 2007-07-21       drh: ** Author contact information:
dbda8d6ce9 2007-07-21       drh: **   drh@hwaci.com
dbda8d6ce9 2007-07-21       drh: **   http://www.hwaci.com/drh/
dbda8d6ce9 2007-07-21       drh: **
dbda8d6ce9 2007-07-21       drh: *******************************************************************************
dbda8d6ce9 2007-07-21       drh: **
dbda8d6ce9 2007-07-21       drh: ** Implementation of the Setup page
dbda8d6ce9 2007-07-21       drh: */
dbda8d6ce9 2007-07-21       drh: #include <assert.h>
dbda8d6ce9 2007-07-21       drh: #include "config.h"
dbda8d6ce9 2007-07-21       drh: #include "setup.h"
dbda8d6ce9 2007-07-21       drh: 
dbda8d6ce9 2007-07-21       drh: 
dbda8d6ce9 2007-07-21       drh: /*
dbda8d6ce9 2007-07-21       drh: ** Output a single entry for a menu generated using an HTML table.
dbda8d6ce9 2007-07-21       drh: ** If zLink is not NULL or an empty string, then it is the page that
dbda8d6ce9 2007-07-21       drh: ** the menu entry will hyperlink to.  If zLink is NULL or "", then
dbda8d6ce9 2007-07-21       drh: ** the menu entry has no hyperlink - it is disabled.
dbda8d6ce9 2007-07-21       drh: */
dbda8d6ce9 2007-07-21       drh: static void menu_entry(
dbda8d6ce9 2007-07-21       drh:   const char *zTitle,
dbda8d6ce9 2007-07-21       drh:   const char *zLink,
dbda8d6ce9 2007-07-21       drh:   const char *zDesc
dbda8d6ce9 2007-07-21       drh: ){
dbda8d6ce9 2007-07-21       drh:   @ <dt>
dbda8d6ce9 2007-07-21       drh:   if( zLink && zLink[0] ){
dbda8d6ce9 2007-07-21       drh:     @ <a href="%s(zLink)">%h(zTitle)</a>
dbda8d6ce9 2007-07-21       drh:   }else{
dbda8d6ce9 2007-07-21       drh:     @ %h(zTitle)
dbda8d6ce9 2007-07-21       drh:   }
dbda8d6ce9 2007-07-21       drh:   @ </dt>
dbda8d6ce9 2007-07-21       drh:   @ <dd>%h(zDesc)</dd>
dbda8d6ce9 2007-07-21       drh: }
dbda8d6ce9 2007-07-21       drh: 
dbda8d6ce9 2007-07-21       drh: /*
dbda8d6ce9 2007-07-21       drh: ** WEBPAGE: /setup
dbda8d6ce9 2007-07-21       drh: */
dbda8d6ce9 2007-07-21       drh: void setup_page(void){
dbda8d6ce9 2007-07-21       drh:   login_check_credentials();
dbda8d6ce9 2007-07-21       drh:   if( !g.okSetup ){
dbda8d6ce9 2007-07-21       drh:     login_needed();
dbda8d6ce9 2007-07-21       drh:   }
dbda8d6ce9 2007-07-21       drh: 
dbda8d6ce9 2007-07-21       drh:   style_header();
dbda8d6ce9 2007-07-21       drh: 
dbda8d6ce9 2007-07-21       drh:   @ <dl id="setup">
dbda8d6ce9 2007-07-21       drh:   menu_entry("Users", "setup_ulist",
dbda8d6ce9 2007-07-21       drh:     "Grant privileges to individual users.");
dbda8d6ce9 2007-07-21       drh:   menu_entry("Access", "setup_access",
dbda8d6ce9 2007-07-21       drh:     "Control access settings.");
dbda8d6ce9 2007-07-21       drh:   @ </dl>
dbda8d6ce9 2007-07-21       drh: 
dbda8d6ce9 2007-07-21       drh:   style_footer();
dbda8d6ce9 2007-07-21       drh: }
dbda8d6ce9 2007-07-21       drh: 
dbda8d6ce9 2007-07-21       drh: /*
dbda8d6ce9 2007-07-21       drh: ** WEBPAGE: setup_ulist
dbda8d6ce9 2007-07-21       drh: **
dbda8d6ce9 2007-07-21       drh: ** Show a list of users.  Clicking on any user jumps to the edit
dbda8d6ce9 2007-07-21       drh: ** screen for that user.
dbda8d6ce9 2007-07-21       drh: */
dbda8d6ce9 2007-07-21       drh: void setup_ulist(void){
dbda8d6ce9 2007-07-21       drh:   Stmt s;
dbda8d6ce9 2007-07-21       drh:   login_check_credentials();
dbda8d6ce9 2007-07-21       drh:   if( !g.okSetup ){
dbda8d6ce9 2007-07-21       drh:     login_needed();
dbda8d6ce9 2007-07-21       drh:   }
dbda8d6ce9 2007-07-21       drh: 
dbda8d6ce9 2007-07-21       drh:   style_header();
dbda8d6ce9 2007-07-21       drh: 
dbda8d6ce9 2007-07-21       drh:   @ <table border="0" cellpadding="0" cellspacing="0">
dbda8d6ce9 2007-07-21       drh:   db_prepare(&s, "SELECT uid, login, cap FROM repuser ORDER BY login");
dbda8d6ce9 2007-07-21       drh:   while( db_step(&s)==SQLITE_ROW ){
dbda8d6ce9 2007-07-21       drh:     @ <tr><td><a href="%s(g.zBaseURL)/setup_uedit?uid=%d(db_column_int(&s,0))">
dbda8d6ce9 2007-07-21       drh:     @ %h(db_column_text(&s,1))</a></td><td width="10"></td>
dbda8d6ce9 2007-07-21       drh:     @ <td>%h(db_column_text(&s,2))</td></tr>
dbda8d6ce9 2007-07-21       drh:   }
dbda8d6ce9 2007-07-21       drh:   db_finalize(&s);
dbda8d6ce9 2007-07-21       drh:   @ </table>
dbda8d6ce9 2007-07-21       drh: 
dbda8d6ce9 2007-07-21       drh:   style_footer();
dbda8d6ce9 2007-07-21       drh: }
dbda8d6ce9 2007-07-21       drh: 
dbda8d6ce9 2007-07-21       drh: /*
dbda8d6ce9 2007-07-21       drh: ** WEBPAGE: setup_uedit
dbda8d6ce9 2007-07-21       drh: **
dbda8d6ce9 2007-07-21       drh: ** Edit the user with REPUSER.UID equal to the "u" query parameter.
dbda8d6ce9 2007-07-21       drh: */
dbda8d6ce9 2007-07-21       drh: void setup_uedit(void){
dbda8d6ce9 2007-07-21       drh:   int uid;
dbda8d6ce9 2007-07-21       drh: 
dbda8d6ce9 2007-07-21       drh:   login_check_credentials();
dbda8d6ce9 2007-07-21       drh:   if( !g.okSetup ){
dbda8d6ce9 2007-07-21       drh:     login_needed();
dbda8d6ce9 2007-07-21       drh:   }
dbda8d6ce9 2007-07-21       drh:   uid = atoi(PD("u","0"));
dbda8d6ce9 2007-07-21       drh:   if( uid<=0 ){
dbda8d6ce9 2007-07-21       drh:     cgi_redirect("setup_ulist");
dbda8d6ce9 2007-07-21       drh:     assert(0);
dbda8d6ce9 2007-07-21       drh:   }
dbda8d6ce9 2007-07-21       drh:   style_header();
dbda8d6ce9 2007-07-21       drh:   style_footer();
dbda8d6ce9 2007-07-21       drh: }
dbda8d6ce9 2007-07-21       drh: 
dbda8d6ce9 2007-07-21       drh: /*
dbda8d6ce9 2007-07-21       drh: ** Generate a checkbox for an attribute.
dbda8d6ce9 2007-07-21       drh: */
dbda8d6ce9 2007-07-21       drh: static void onoff_attribute(
dbda8d6ce9 2007-07-21       drh:   const char *zLabel,   /* The text label on the checkbox */
dbda8d6ce9 2007-07-21       drh:   const char *zVar,     /* The corresponding row in the VAR table */
dbda8d6ce9 2007-07-21       drh:   const char *zQParm,   /* The query parameter */
dbda8d6ce9 2007-07-21       drh:   int dfltVal           /* Default value if VAR table entry does not exist */
dbda8d6ce9 2007-07-21       drh: ){
dbda8d6ce9 2007-07-21       drh:   const char *zVal = db_get(zVar, 0);
dbda8d6ce9 2007-07-21       drh:   const char *zQ = P(zQParm);
dbda8d6ce9 2007-07-21       drh:   int iVal;
dbda8d6ce9 2007-07-21       drh:   if( zVal ){
dbda8d6ce9 2007-07-21       drh:     iVal = atoi(zVal);
dbda8d6ce9 2007-07-21       drh:   }else{
dbda8d6ce9 2007-07-21       drh:     iVal = dfltVal;
dbda8d6ce9 2007-07-21       drh:   }
dbda8d6ce9 2007-07-21       drh:   if( zQ==0 && P("submit") ){
dbda8d6ce9 2007-07-21       drh:     zQ = "off";
dbda8d6ce9 2007-07-21       drh:   }
dbda8d6ce9 2007-07-21       drh:   if( zQ ){
dbda8d6ce9 2007-07-21       drh:     int iQ = strcmp(zQ,"on")==0 || atoi(zQ);
dbda8d6ce9 2007-07-21       drh:     if( iQ!=iVal ){
dbda8d6ce9 2007-07-21       drh:       db_set(zVar, iQ ? "1" : "0");
dbda8d6ce9 2007-07-21       drh:       iVal = iQ;
dbda8d6ce9 2007-07-21       drh:     }
dbda8d6ce9 2007-07-21       drh:   }
dbda8d6ce9 2007-07-21       drh:   if( iVal ){
dbda8d6ce9 2007-07-21       drh:     @ <input type="checkbox" name="%s(zQParm)" checked>%s(zLabel)</input>
dbda8d6ce9 2007-07-21       drh:   }else{
dbda8d6ce9 2007-07-21       drh:     @ <input type="checkbox" name="%s(zQParm)">%s(zLabel)</input>
dbda8d6ce9 2007-07-21       drh:   }
dbda8d6ce9 2007-07-21       drh: }
dbda8d6ce9 2007-07-21       drh: 
dbda8d6ce9 2007-07-21       drh: /*
dbda8d6ce9 2007-07-21       drh: ** Generate an entry box for an attribute.
dbda8d6ce9 2007-07-21       drh: */
dbda8d6ce9 2007-07-21       drh: static void entry_attribute(
dbda8d6ce9 2007-07-21       drh:   const char *zLabel,   /* The text label on the entry box */
dbda8d6ce9 2007-07-21       drh:   int width,            /* Width of the entry box */
dbda8d6ce9 2007-07-21       drh:   const char *zVar,     /* The corresponding row in the VAR table */
dbda8d6ce9 2007-07-21       drh:   const char *zQParm,   /* The query parameter */
dbda8d6ce9 2007-07-21       drh:   const char *zDflt     /* Default value if VAR table entry does not exist */
dbda8d6ce9 2007-07-21       drh: ){
dbda8d6ce9 2007-07-21       drh:   const char *zVal = db_get(zVar, zDflt);
dbda8d6ce9 2007-07-21       drh:   const char *zQ = P(zQParm);
dbda8d6ce9 2007-07-21       drh:   if( zQ && strcmp(zQ,zVal)!=0 ){
dbda8d6ce9 2007-07-21       drh:     db_set(zVar, zQ);
dbda8d6ce9 2007-07-21       drh:     zVal = zQ;
dbda8d6ce9 2007-07-21       drh:   }
dbda8d6ce9 2007-07-21       drh:   @ <input type="text" name="%s(zQParm)" value="%h(zVal)" size="%d(width)">
dbda8d6ce9 2007-07-21       drh:   @ %s(zLabel)
dbda8d6ce9 2007-07-21       drh: }
dbda8d6ce9 2007-07-21       drh: 
dbda8d6ce9 2007-07-21       drh: 
dbda8d6ce9 2007-07-21       drh: 
dbda8d6ce9 2007-07-21       drh: /*
dbda8d6ce9 2007-07-21       drh: ** WEBPAGE: setup_access
dbda8d6ce9 2007-07-21       drh: */
dbda8d6ce9 2007-07-21       drh: void setup_access(void){
dbda8d6ce9 2007-07-21       drh:   login_check_credentials();
dbda8d6ce9 2007-07-21       drh:   if( !g.okSetup ){
dbda8d6ce9 2007-07-21       drh:     login_needed();
dbda8d6ce9 2007-07-21       drh:   }
dbda8d6ce9 2007-07-21       drh: 
dbda8d6ce9 2007-07-21       drh:   style_header();
dbda8d6ce9 2007-07-21       drh:   db_begin_transaction();
dbda8d6ce9 2007-07-21       drh:   @ <form action="%s(g.zBaseURL)/setup_access" method="GET">
dbda8d6ce9 2007-07-21       drh: 
dbda8d6ce9 2007-07-21       drh:   @ <hr>
dbda8d6ce9 2007-07-21       drh:   onoff_attribute("Require password for local access",
dbda8d6ce9 2007-07-21       drh:      "authenticate-localhost", "localauth", 1);
dbda8d6ce9 2007-07-21       drh:   @ <p>When enabled, the password sign-in is required for
dbda8d6ce9 2007-07-21       drh:   @ web access coming from 127.0.0.1.  When disabled, web access
dbda8d6ce9 2007-07-21       drh:   @ from 127.0.0.1 is allows without any login - the user id is selected
dbda8d6ce9 2007-07-21       drh:   @ from the ~/.fossil database. Password login is always required
dbda8d6ce9 2007-07-21       drh:   @ for incoming web connections on internet addresses other than
dbda8d6ce9 2007-07-21       drh:   @ 127.0.0.1.</p></li>
dbda8d6ce9 2007-07-21       drh: 
dbda8d6ce9 2007-07-21       drh:   @ <hr>
dbda8d6ce9 2007-07-21       drh:   entry_attribute("Login expiration time", 6, "cookie-expire", "cex", "8766");
dbda8d6ce9 2007-07-21       drh:   @ <p>The number of hours for which a login is valid.  This must be a
dbda8d6ce9 2007-07-21       drh:   @ positive number.  The default is 8760 hours which is approximately equal
dbda8d6ce9 2007-07-21       drh:   @ to a year.</p>
dbda8d6ce9 2007-07-21       drh: 
dbda8d6ce9 2007-07-21       drh:   @ <hr>
dbda8d6ce9 2007-07-21       drh:   onoff_attribute("Allow anonymous signup", "anon-signup", "asu", 0);
dbda8d6ce9 2007-07-21       drh:   @ <p>Allow users to create their own accounts</p>
dbda8d6ce9 2007-07-21       drh: 
dbda8d6ce9 2007-07-21       drh:   @ <hr>
dbda8d6ce9 2007-07-21       drh:   @ <p><input type="submit"  name="submit" value="Apply Changes"></p>
dbda8d6ce9 2007-07-21       drh:   @ </form>
dbda8d6ce9 2007-07-21       drh:   db_end_transaction(0);
dbda8d6ce9 2007-07-21       drh:   style_footer();
dbda8d6ce9 2007-07-21       drh: }