6f05b4292a 2008-02-05 stephan: /* 6f05b4292a 2008-02-05 stephan: ** Copyright (c) 2007 D. Richard Hipp 6f05b4292a 2008-02-05 stephan: ** Copyright (c) 2008 Stephan Beal 6f05b4292a 2008-02-05 stephan: ** 6f05b4292a 2008-02-05 stephan: ** This program is free software; you can redistribute it and/or 6f05b4292a 2008-02-05 stephan: ** modify it under the terms of the GNU General Public 6f05b4292a 2008-02-05 stephan: ** License as published by the Free Software Foundation; either 6f05b4292a 2008-02-05 stephan: ** version 2 of the License, or (at your option) any later version. 6f05b4292a 2008-02-05 stephan: ** 6f05b4292a 2008-02-05 stephan: ** This program is distributed in the hope that it will be useful, 6f05b4292a 2008-02-05 stephan: ** but WITHOUT ANY WARRANTY; without even the implied warranty of 6f05b4292a 2008-02-05 stephan: ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 6f05b4292a 2008-02-05 stephan: ** General Public License for more details. 6f05b4292a 2008-02-05 stephan: ** 6f05b4292a 2008-02-05 stephan: ** You should have received a copy of the GNU General Public 6f05b4292a 2008-02-05 stephan: ** License along with this library; if not, write to the 6f05b4292a 2008-02-05 stephan: ** Free Software Foundation, Inc., 59 Temple Place - Suite 330, 6f05b4292a 2008-02-05 stephan: ** Boston, MA 02111-1307, USA. 6f05b4292a 2008-02-05 stephan: ** 6f05b4292a 2008-02-05 stephan: ** Author contact information: 6f05b4292a 2008-02-05 stephan: ** drh@hwaci.com 6f05b4292a 2008-02-05 stephan: ** http://www.hwaci.com/drh/ 6f05b4292a 2008-02-05 stephan: ** 6f05b4292a 2008-02-05 stephan: ******************************************************************************* 6f05b4292a 2008-02-05 stephan: ** 6f05b4292a 2008-02-05 stephan: ** Implementation of the Admin SQL 6f05b4292a 2008-02-05 stephan: */ 6f05b4292a 2008-02-05 stephan: #include <assert.h> 6f05b4292a 2008-02-05 stephan: #include "config.h" 6f05b4292a 2008-02-05 stephan: #include "admin_sql_page.h" 6f05b4292a 2008-02-05 stephan: 6f05b4292a 2008-02-05 stephan: 6f05b4292a 2008-02-05 stephan: static void admin_sql_page_form() 6f05b4292a 2008-02-05 stephan: { 6f05b4292a 2008-02-05 stephan: char const * sql = P("sql"); 6f05b4292a 2008-02-05 stephan: @ <hr/><h2>SQL:</h2> 6f05b4292a 2008-02-05 stephan: @ <span class='achtung'>You can enter arbitrary SQL here, to execute 6f05b4292a 2008-02-05 stephan: @ against the repo database. 6f05b4292a 2008-02-05 stephan: @ With great power comes great responsibility...</span><br/> 6f05b4292a 2008-02-05 stephan: @ <form action='' method='post'> 6f05b4292a 2008-02-05 stephan: @ <textarea style='border:2px solid black' name='sql' cols='80' rows='5'>%s(sql?sql:"")</textarea> 6f05b4292a 2008-02-05 stephan: @ <br/><input type='submit' name='sql_submit'/> <input type='reset'/> 6f05b4292a 2008-02-05 stephan: @ </form> 6f05b4292a 2008-02-05 stephan: } 6f05b4292a 2008-02-05 stephan: 6f05b4292a 2008-02-05 stephan: /* 6f05b4292a 2008-02-05 stephan: ** WEBPAGE: /admin/sql 6f05b4292a 2008-02-05 stephan: */ 6f05b4292a 2008-02-05 stephan: void admin_sql_page(void){ 6f05b4292a 2008-02-05 stephan: /** 6f05b4292a 2008-02-05 stephan: TODOs: refactor db_generic_query_view() to use sqlite3 directly, 6f05b4292a 2008-02-05 stephan: instead of the db_prepare()/db_step() API, so we can do our own 6f05b4292a 2008-02-05 stephan: handling. Currently SQL-level failures will cause the page to 6f05b4292a 2008-02-05 stephan: immediately stop (e.g. page footer won't get a chance to render). 6f05b4292a 2008-02-05 stephan: */ 6f05b4292a 2008-02-05 stephan: login_check_credentials(); 6f05b4292a 2008-02-05 stephan: style_header("Admin SQL"); 6f05b4292a 2008-02-05 stephan: if( !g.okAdmin ){ 6f05b4292a 2008-02-05 stephan: @ <strong>Access Denied!</strong> You must be an Admin to use this tool. 6f05b4292a 2008-02-05 stephan: style_footer(); 6f05b4292a 2008-02-05 stephan: return; 6f05b4292a 2008-02-05 stephan: } 6f05b4292a 2008-02-05 stephan: admin_sql_page_form(); 6f05b4292a 2008-02-05 stephan: char const * sql = P("sql"); 6f05b4292a 2008-02-05 stephan: if( sql ) 6f05b4292a 2008-02-05 stephan: { 6f05b4292a 2008-02-05 stephan: db_generic_query_view( sql, 0, 0 ); 6f05b4292a 2008-02-05 stephan: } 6f05b4292a 2008-02-05 stephan: style_footer(); 6f05b4292a 2008-02-05 stephan: }