summaryrefslogtreecommitdiffstats
path: root/modules/vauth/init.php
blob: 96325f35c6693e2baad3b7909d56dd5a2bf8143f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
<?php
/*

 Copyright (c) 2006 Karl Vollmer
 All rights reserved.

 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 2
 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, write to the Free Software
 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

*/
/**
 * init script
 * This script requires all of the additional libraries and does a little error checking to 
 * make sure that we've got the variables we need to make everything work. 
 * Be default you should include this file then call the vauth_init() function
 * passing in an array of the elements we need (see more docs that in theory I'll write)
 */

/**
 * vauth_init
 * This function loads in the extra lib files and checks the data we've got
 * If it doesn't find everything it needs it will return use PHP's Error method
 * to throw an exception and return false
 */
function vauth_init($data) { 

	/* Check for the variables we are going to need first */
	if (isset($data['auth_methods']['mysql'])) { 	
		if (!isset($data['mysql_hostname'])) { 
			vauth_error('No Mysql Hostname Defined [mysql_hostname]');
			$error_status = true;
		}
		if (!isset($data['mysql_db'])) { 
			vauth_error('No Mysql Database Defined [mysql_db]');
			$error_status = true;
		}
		if (!isset($data['mysql_username'])) { 
			vauth_error('No Mysql Username Defined [mysql_username]');
			$error_status = true;
		}
		if (!isset($data['mysql_password'])) { 
			vauth_error('No Mysql Password Defined [mysql_password]');
			$error_status = true;
		}
	} // if we're doing mysql auth

	if (isset($data['auth_methods']['ldap'])) { 
		
		if (!isset($data['ldap_url'])) { 
			vauth_error('No LDAP server defined [ldap_url]');
			$error_status = true;
		}
		if (!isset($data['ldap_name_field'])) { 
			vauth_error('No Name Field defined [ldap_name_field]');
		}
		if (!isset($data['ldap_email_field'])) { 
			vauth_error('No E-mail Field defined [ldap_email_field]');
		}
		if (!isset($data['ldap_username'])) { 
			vauth_error('No Bind Username defined [ldap_username]');
		}
		if (!isset($data['ldap_password'])) { 
			vauth_error('No Bind Password defined [ldap_password]');
		}

	} // if we're doing ldap auth

	if (isset($data['auth_methods']['http'])) { 
	

	} // if we're doing http auth

	if (!isset($data['stop_auth'])) { 
		vauth_error('No Stop File Defined [stop_auth]');
		$error_status = true;
	}

	if (!isset($data['session_length'])) { 
		vauth_error('No Session Length Defined [session_length]');
		$error_status = true;
	}

	if (!isset($data['session_name'])) { 
		vauth_error('No Session Name Defined [session_name]');
		$error_status = true;
	}

	if (!isset($data['cookie_life'])) { 
		vauth_error('No Cookie Life Defined [cookie_life]');
		$error_status = true;
	}

	if (!isset($data['cookie_secure'])) { 
		vauth_error('Cookie Secure Not Defined [cookie_secure]');
		$error_status = true;
	}

	if (!isset($data['cookie_path'])) { 
		vauth_error('Cookie Path Not Defined [cookie_path]');
		$error_status = true;
	}
	
	if (!isset($data['cookie_domain'])) { 
		vauth_error('Cookie Domain Not Defined [cookie_domain]');
		$error_status = true;
	}

	/* For now we won't require it */
	if (!isset($data['remember_length'])) { 
		$data['remember_length'] = '900';
	}
	
	/* If an error has occured then return false */
	if (isset($error_status)) { return false; }

	/* Load the additional libraries that we may or may not need... */
	require_once 'dbh.lib.php';
	require_once 'session.lib.php';
	require_once 'auth.lib.php';

	vauth_conf($data);
	
	return true;

} // vauth_init

/**
 * vauth_error
 * This function throws a PHP error with whatever went wrong. If you don't use a custom
 * Error handler this will get spit out the screen, otherwise well whatever you do with it
 * is what is going to happen to it... amazing huh!
 */
function vauth_error($string) { 

	trigger_error($string,E_USER_WARNING);
	return true;

} // vauth_error


/**
 * vauth_conf
 * This is a function with a static array that we store the configuration variables in
 * So we don't have to worry about globalizing anything
 */
function vauth_conf($param,$clobber=0) { 

        static $params = array();
	
	// We are trying to set variables
	if(is_array($param)) {
                foreach ($param as $key=>$val) {
			if(!$clobber && isset($params[$key])) {
                                vauth_error("Attempting to clobber $key = $val");
                                return false;
                        }
                        $params[$key] = $val;
                }
                return true;
        }
	// We are attempting to retrive a variable
        else {
                if(isset($params[$param])) return $params[$param];
                else return;
        }

} // vauth_conf

?>