PCCS MySQLDatabase Admin Tool version 1.3.4


/ -> mysqldb_create_authscript.php

1  <?php
2  /************************************************************************
3  PCCS MySQLDatabase Admin Tool
4  Copyright (C) Chauncey Thorn
5 
6  This program is free software; you can redistribute it and/or
7  modify it under the terms of the GNU General Public License
8  as published by the Free Software Foundation; either version 2
9  of the License, or (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program; if not, write to the Free Software
18  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA , USA.
19  **************************************************************************/
20 
21  ///////////////////////////////////////////////////////////////////////////////
22  // Create Auth script
23  // Create users table and insert this users data
24  // no need to modify unless you like hacking
25  // bugs report to cthorn
26  //
27  // file inculded from mysqldb_process_webuser.php
28  ///////////////////////////////////////////////////////////////////////////////
29 
30  $authcript_filename="auth-include.php";
31  if(!$authcript = fopen($appfiledir . $authcript_filename,"w")) {
32    print "Couldn'tfile";
33  } else {
34  fputs($authcript,"<?php\n//** Generated by PCCS-MyAppGen\n");
35  fputs($authcript,"//////////////////////////////////////////////////////////////////////////////\n");
36  fputs($authcript,"//\n");
37  fputs($authcript,"require('dbinclude.php');\n");
38  fputs($authcript," function do_login() {\n");
39  fputs($authcript," Header(\"WWW-authenticate: basic realm=\\\"MyAuth System\\\"\");\n");
40  fputs($authcript," Header(\"HTTP/1.0 401 Unauthorized\");\n");
41  fputs($authcript," \$title=\"Invalid Login\";\n");
42  fputs($authcript," print \"ERROR: \" . \$title;\n");
43  fputs($authcript," print \"In order to proceed you will need a valid username/password.\";\n");
44  fputs($authcript,"\n");
45  fputs($authcript," exit;\n");
46  fputs($authcript," }\n");
47  fputs($authcript,"\n");
48  fputs($authcript," if(!isset(\$PHP_AUTH_USER)) {\n");
49  fputs($authcript," do_login();\n");
50  fputs($authcript," } else {\n");
51  // fputs($authcript," mysql_cconnect(\"localhost\",\"nobody\",\"\") or die(\"Unable to connect\");\n");
52  // fputs($authcript," to SQL server\");\n");
53  // fputs($authcript," mysql_select_db(\"rasmus\") or die(\"Unable to select database\");\n");
54  fputs($authcript," \$id=strtolower(\$PHP_AUTH_USER);\n");
55  fputs($authcript," \$query = mysql_query(\"select * from users where id='\$id' and");
56  fputs($authcript," password='\$PHP_AUTH_PW'\");\n");
57  fputs($authcript," if(!mysql_num_rows(\$query)) {\n");
58  fputs($authcript," do_login();\n");
59  fputs($authcript," }\n");
60  fputs($authcript," }\n");
61  fputs($authcript,"//\n");
62  fputs($authcript,"//////////////////////////////////////////////////////////////////////////\n");
63  fputs($authcript,"?>\n");
64  fclose($authcript);
65 
66  // get ready to create table required for this script
67  // define query
68 
69  $create_usertbl_query = "
70  CREATE TABLE users (
71    usernr int(11) DEFAULT '0' NOT NULL auto_increment,
72    login_name varchar(25),
73    first_name varchar(25),
74    last_name varchar(25),
75    password varchar(20),
76    PRIMARY KEY (usernr)
77  )";
78 
79  // execute query
80  if(!mysql_db_query($webdatabase,$create_usertbl_query)) {
81    print "ERROR :" . mysql_error();
82  }
83 
84  // Come back and encrypt password
85  $insert_user_query = "INSERT INTO users VALUES (1,'demo','Firstname','Lastname','password')";
86 
87  if(!mysql_db_query($webdatabase,$insert_user_query)) {
88    print "ERROR :" . mysql_error();
89  }
90 
91  }
92  ?>


Generated: Sat Jan 27 15:40:36 2001 Generated by PHPXref 0.1.2
PCCS-Linux.COM ::ource Advocate Articles catalogue
2000 2002