forked from BellevueCollege/wordpress-cas-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcas-client-ui.php
415 lines (330 loc) · 12.7 KB
/
cas-client-ui.php
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
<?php
########
// New
########
##########################
##########################
##########################
##########################
##########################
/*
add_action( 'network_admin_menu', 'casclient_network_menu_settings');
function casclient_network_menu_settings(){
add_submenu_page ('settings.php', 'CAS Client Beta', 'CAS Client Beta', 'manage_network', 'casclient-settings', 'casclient_settings');
}
function casclient_settings($active_tab = '' ) { */
function wpcasldap_options_page($active_tab = '' ) {
// if (is_multisite() && current_user_can('manage_network')) {
?>
<div class="wrap">
<div id="icon-themes" class="icon32"></div>
<h2>CAS Client</h2>
<?php //settings_errors(); ?>
<?php if( isset( $_GET[ 'tab' ] ) ) {
$active_tab = $_GET[ 'tab' ];
} else if( $active_tab == 'role_assignments' ) {
$active_tab = 'role_assignments';
} else if( $active_tab == 'user_mapping' ) {
$active_tab = 'user_mapping';
} else {
$active_tab = 'server_setup';
} // end if/else ?>
<h2 class="nav-tab-wrapper">
<a href="?page=casclient&tab=server_setup" class="nav-tab <?php echo $active_tab == 'server_setup' ? 'nav-tab-active' : ''; ?>">Server Setup</a>
<a href="?page=casclient&tab=role_assignments" class="nav-tab <?php echo $active_tab == 'role_assignments' ? 'nav-tab-active' : ''; ?>">Role Assignments</a>
<a href="?page=casclient&tab=user_mapping" class="nav-tab <?php echo $active_tab == 'user_mapping' ? 'nav-tab-active' : ''; ?>">User Mapping</a>
</h2>
<?php
/*
if (isset($_POST['action']) && $_POST['action'] == 'update_casclientbeta_settings') {
check_admin_referer('save_network_casclientbeta_settings', 'casclientbeta-plugin');
//sample code from Professional WordPress book
//store option values in a variable
$network_casclientbeta_settings = $_POST['network_casclientbeta_settings'];
//use array map function to sanitize option values
$network_casclientbeta_settings = array_map( 'sanitize_text_field', $network_casclientbeta_settings );
//save option values
update_site_option( 'casclient_settings', $network_casclientbeta_settings );
//just assume it all went according to plan
echo '<div id="message" class="updated fade"><p><strong>Globals Settings Updated!</strong></p></div>';
}//if POST
*/
?>
<form method="post" action="">
<input type="hidden" name="action" value="update_casclientbeta_settings" />
<?php
wp_nonce_field('save_network_casclientbeta_settings', 'casclientbeta-plugin');
$optionarray_def = wpcasldap_getoptions();
?>
<?php
if( $active_tab == 'server_setup' ) { ?>
<h4>CAS Server Setup</h4>
<?php settings_fields( 'wpcasldap' ); ?>
<h3><?php _e('Configuration settings for WordPress CAS Client', 'wpcasldap') ?></h3>
<h4><?php _e('Note', 'wpcasldap') ?></h4>
<p>
<?php _e('Now that you’ve activated this plugin, WordPress is attempting to authenticate using CAS, even if it’s not configured or misconfigured.', 'wpcasldap' ) ?><br />
<?php _e('Save yourself some trouble, open up another browser or use another machine to test logins. That way you can preserve this session to adjust the configuration or deactivate the plugin.', 'wpcasldap') ?>"
</p>
<?php if (!isset($wpcasldap_options['include_path'])) : ?>
<h4><?php _e('phpCAS include path', 'wpcasldap') ?></h4>
<p>
<small><em><?php _e('Note: The phpCAS library is required for this plugin to work. We need to know the server path to the CAS.php file.', 'wpcasldap') ?></em></small>
</p>
<table class="form-table">
<tr valign="top">
<th scope="row">
<label>
<?php _e('CAS.php Path', 'wpcasldap') ?>
</label>
</th>
<td>
<?php
$casPath = $optionarray_def['include_path'];
debug_log("cas path :".$casPath);
if(!isset($optionarray_def['include_path']) || empty($optionarray_def['include_path']))
{
if(file_exists( DEFAULT_CASFILE_PATH ))
{
$casPath = DEFAULT_CASFILE_PATH ;
if(is_multisite())
{
update_site_option('wpcasldap_include_path',$casPath);
}
else
{
update_option('wpcasldap_include_path',$casPath);
}
}
}
?>
<input type="text" size="80" name="wpcasldap_include_path" id="include_path_inp" value="<?php echo $casPath; ?>" />
</td>
</tr>
</table>
<?php endif; ?>
<?php if (!isset($wpcasldap_options['cas_version']) ||
//!isset($wpcasldap_options['server_hostname']) ||
//!isset($wpcasldap_options['server_port']) ||
//!isset($wpcasldap_options['server_path'])
!isset($wpcasldap_options['casserver'])) : ?>
<h4><?php _e('CAS Server', 'wpcasldap') ?></h4>
<table class="form-table">
<?php if (!isset($wpcasldap_options['casserver'])) : ?>
<tr valign="top">
<th scope="row">
<label>
<?php _e('CAS Server URI', 'wpcasldap') ?>
</label>
</th>
<td>
<input type="text" name="wpcasldap_casserver" size="50" id="casserver_inp" value="<?php echo $optionarray_def['casserver']; ?>" />
</td>
</tr>
<?php endif; ?>
<?php if (!isset($wpcasldap_options['cas_version'])) : ?>
<tr valign="top">
<th scope="row">
<label>
<?php _e('CAS version', 'wpcasldap') ?>
</label>
</th>
<td>
<select name="wpcasldap_cas_version" id="cas_version_inp">
<option value="2.0" <?php echo ($optionarray_def['cas_version'] == '2.0')?'selected':''; ?>>CAS_VERSION_2_0</option>
<option value="1.0" <?php echo ($optionarray_def['cas_version'] == '1.0')?'selected':''; ?>>CAS_VERSION_1_0</option>
</select>
</td>
</tr>
<?php endif; ?>
</table>
<?php endif; ?>
<?php if (!isset($wpcasldap_options['useradd']) ||
!isset($wpcasldap_options['userrole']) ||
!isset($wpcasldap_options['useldap']) ||
!isset($wpcasldap_options['email_suffix']) ) : ?>
<h4><?php _e('Treatment of Unregistered User','wpcasldap') ?></h4>
<table class="form-table">
<?php if (!isset($wpcasldap_options['useradd'])) : ?>
<tr valign="top">
<th scope="row">
<label>
<?php _e('Add to Database','wpcasldap') ?>
</label>
</th>
<td>
<input type="radio" name="wpcasldap_useradd" id="useradd_yes" value="yes" <?php echo ($optionarray_def['useradd'] == 'yes')?'checked="checked"':''; ?> />
<label for="useradd_yes">Yes </label>
<input type="radio" name="wpcasldap_useradd" id="useradd_no" value="no" <?php echo ($optionarray_def['useradd'] != 'yes')?'checked="checked"':''; ?> />
<label for="useradd_no">No </label>
</td>
</tr>
<?php endif; ?>
<?php if (!isset($wpcasldap_options['userrole'])) : ?>
<tr valign="top">
<th scope="row">
<label>
<?php _e('Default Role','wpcasldap') ?>
</label>
</th>
<td>
<select name="wpcasldap_userrole" id="cas_version_inp">
<option value="subscriber" <?php echo ($optionarray_def['userrole'] == 'subscriber')?'selected':''; ?>>Subscriber</option>
<option value="contributor" <?php echo ($optionarray_def['userrole'] == 'contributor')?'selected':''; ?>>Contributor</option>
<option value="author" <?php echo ($optionarray_def['userrole'] == 'author')?'selected':''; ?>>Author</option>
<option value="editor" <?php echo ($optionarray_def['userrole'] == 'editor')?'selected':''; ?>>Editor</option>
<option value="administrator" <?php echo ($optionarray_def['userrole'] == 'administrator')?'selected':''; ?>>Administrator</option>
</select>
</td>
</tr>
<?php endif; ?>
<?php if (!isset($wpcasldap_options['useldap'])) : ?>
<?php if (function_exists('ldap_connect')) :
//error_log("ldap connect exists");
?>
<tr valign="top">
<th scope="row">
<label>
<?php _e('Use LDAP to get user info','wpcasldap') ?>
</label>
</th>
<td>
<input type="radio" name="wpcasldap_useldap" id="useldap_yes" value="yes" <?php echo ($optionarray_def['useldap'] == 'yes')?'checked="checked"':''; ?> />
<label for="useldap_yes">Yes </label>
<input type="radio" name="wpcasldap_useldap" id="useldap_no" value="no" <?php echo ($optionarray_def['useldap'] != 'yes')?'checked="checked"':''; ?> />
<label for="useldap_no">No </label>
</td>
</tr>
<?php
else :
?>
<input type="hidden" name="wpcasldap_useldap" id="useldap_hidden" value="no" />
<?php
endif;
?>
<?php endif; ?>
<?php if (!isset($wpcasldap_options['email_suffix'])) : ?>
<tr valign="center">
<th scope="row">
<label>
<?php _e('E-mail Suffix','wpcasldap') ?>
</label>
</th>
<td>
<input type="text" size="50" name="wpcasldap_email_suffix" id="email_suffix_inp" value="<?php echo $optionarray_def['email_suffix']; ?>" />
</td>
</tr>
<?php endif; ?>
</table>
<?php endif; ?>
<?php if (function_exists('ldap_connect')) : ?>
<?php if (!isset($wpcasldap_options['ldapbasedn']) ||
//!isset($wpcasldap_options['ldapport']) ||
!isset($wpcasldap_options['ldapuri']) ) : ?>
<h4><?php _e('LDAP parameters','wpcasldap') ?></h4>
<table class="form-table">
<?php if (!isset($wpcasldap_options['ldapuri'])) : ?>
<tr valign="top">
<th scope="row">
<label>
<?php _e('LDAP URI','wpcasldap') ?>
</label>
</th>
<td>
<input type="text" size="50" name="wpcasldap_ldapuri" id="ldap_uri_inp" value="<?php echo $optionarray_def['ldapuri']; ?>" />
</td>
</tr>
<?php endif; ?>
<?php if (!isset($wpcasldap_options['ldapbasedn'])) : ?>
<tr valign="top">
<th scope="row">
<label>
<?php _e('LDAP Base DN','wpcasldap') ?>
</label>
</th>
<td>
<input type="text" size="50" name="wpcasldap_ldapbasedn" id="ldap_basedn_inp" value="<?php echo $optionarray_def['ldapbasedn']; ?>" />
</td>
</tr>
<?php endif; ?>
<?php if (!isset($wpcasldap_options['ldapuser'])) : ?>
<tr valign="top">
<th scope="row">
<label>
<?php _e('LDAP User','wpcasldap') ?>
</label>
</th>
<td>
<input type="text" name="wpcasldap_ldapuser" id="ldap_user_inp" value="<?php echo $optionarray_def['ldapuser']; ?>" />
</td>
</tr>
<?php endif; ?>
<?php if (!isset($wpcasldap_options['ldappassword'])) : ?>
<tr valign="top">
<th scope="row">
<label>
<?php _e('LDAP Password','wpcasldap') ?>
</label>
</th>
<td>
<input type="button" name="reset" id="reset" onclick="showPasswordField()" size="20" value="Reset">
<input type="password" name="wpcasldap_ldappassword" id="ldap_password_inp" style="display:none;" disabled/>
<!-- <input type="password" name="wpcasldap_ldappassword" id="ldap_password_inp" value="<?php echo $optionarray_def['ldappassword']; ?>" /> -->
</td>
</tr>
<?php endif; ?>
</table>
<?php endif; ?>
<?php endif; ?>
<p class="submit">
<input type="submit" class="button-primary" name="wpcasldap_submit" value="Save Settings" />
</p>
<?php
#######################################
// User Mapping Tab
#######################################
?>
<?php } elseif ($active_tab == 'user_mapping' ) { ?>
<h4>User Mapping Rules</h4>
<table class="form-table">
<tr valign="top">
<th scope="row">
<label></label>
</th>
</tr>
</table>
<?php
###############################
// Add User Mapping Rule Modal
###############################
add_thickbox(); ?>
<div id="my-content-id" style="display:none;">
<p>
User Mapping Rules go here.
</p>
</div>
<a href="#TB_inline?width=600&height=550&inlineId=my-content-id" class="thickbox button-secondary">Add rule</a>
<?php } else { ?>
<h4>Role Assignment Rules</h4>
<table class="form-table">
<tr valign="top">
<th scope="row">
<label></label>
</th>
</tr>
</table>
<?php
###############################
// Add Role Assignment Rule Modal
###############################
add_thickbox(); ?>
<div id="add_role_assignments" style="display:none;">
</div>
<a href="#TB_inline?width=600&height=550&inlineId=add_role_assignments" class="thickbox button-secondary">Add rule</a>
</form>
</div>
<?php
}
wp_enqueue_script( 'my_custom_script', plugin_dir_url( __FILE__ ) . '/js/cas-client.js' );
} //settings page function
?>