yubikey/admincp.php
author Dan Fuhry <dan@enanocms.org>
Fri, 30 Jun 2017 17:49:12 -0400
changeset 39 6212d849ab08
permissions -rw-r--r--
Move all files from plugins/ directory to the root
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
39
6212d849ab08 Move all files from plugins/ directory to the root
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
     1
<?php
6212d849ab08 Move all files from plugins/ directory to the root
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
     2
6212d849ab08 Move all files from plugins/ directory to the root
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
     3
$plugins->attachHook('acp_general_users', 'yubikey_admin_cp_ui();');
6212d849ab08 Move all files from plugins/ directory to the root
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
     4
$plugins->attachHook('acp_general_save', 'yubikey_admin_cp_save();');
6212d849ab08 Move all files from plugins/ directory to the root
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
     5
6212d849ab08 Move all files from plugins/ directory to the root
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
     6
function yubikey_admin_cp_ui()
6212d849ab08 Move all files from plugins/ directory to the root
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
     7
{
6212d849ab08 Move all files from plugins/ directory to the root
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
     8
	global $lang;
6212d849ab08 Move all files from plugins/ directory to the root
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
     9
	?>
6212d849ab08 Move all files from plugins/ directory to the root
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    10
		<tr>
6212d849ab08 Move all files from plugins/ directory to the root
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    11
			<th colspan="2" class="subhead">
6212d849ab08 Move all files from plugins/ directory to the root
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    12
				<?php echo $lang->get('yubiacp_th'); ?>
6212d849ab08 Move all files from plugins/ directory to the root
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    13
			</th>
6212d849ab08 Move all files from plugins/ directory to the root
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    14
		</tr>
6212d849ab08 Move all files from plugins/ directory to the root
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    15
		
6212d849ab08 Move all files from plugins/ directory to the root
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    16
		<tr>
6212d849ab08 Move all files from plugins/ directory to the root
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    17
			<td class="row1">
6212d849ab08 Move all files from plugins/ directory to the root
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    18
				<?php echo $lang->get('yubiacp_field_enable_title'); ?>
6212d849ab08 Move all files from plugins/ directory to the root
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    19
			</td>
6212d849ab08 Move all files from plugins/ directory to the root
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    20
			<td class="row1">
6212d849ab08 Move all files from plugins/ directory to the root
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    21
				<label>
6212d849ab08 Move all files from plugins/ directory to the root
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    22
					<input type="checkbox" name="yubikey_enable" <?php if ( getConfig('yubikey_enable', '1') == '1' ) echo 'checked="checked" '; ?>/>
6212d849ab08 Move all files from plugins/ directory to the root
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    23
					<?php echo $lang->get('yubiacp_field_enable'); ?>
6212d849ab08 Move all files from plugins/ directory to the root
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    24
				</label>
6212d849ab08 Move all files from plugins/ directory to the root
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    25
			</td>
6212d849ab08 Move all files from plugins/ directory to the root
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    26
		</tr>
6212d849ab08 Move all files from plugins/ directory to the root
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    27
		
6212d849ab08 Move all files from plugins/ directory to the root
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    28
		<tr>
6212d849ab08 Move all files from plugins/ directory to the root
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    29
			<td class="row2">
6212d849ab08 Move all files from plugins/ directory to the root
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    30
				<?php echo $lang->get('yubiacp_field_api_key'); ?>
6212d849ab08 Move all files from plugins/ directory to the root
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    31
			</td>
6212d849ab08 Move all files from plugins/ directory to the root
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    32
			<td class="row2">
6212d849ab08 Move all files from plugins/ directory to the root
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    33
				<input type="text" name="yubikey_api_key" value="<?php echo htmlspecialchars(getConfig('yubikey_api_key', '')); ?>" size="30" />
6212d849ab08 Move all files from plugins/ directory to the root
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    34
			</td>
6212d849ab08 Move all files from plugins/ directory to the root
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    35
		</tr>
6212d849ab08 Move all files from plugins/ directory to the root
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    36
		
6212d849ab08 Move all files from plugins/ directory to the root
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    37
		<tr>
6212d849ab08 Move all files from plugins/ directory to the root
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    38
			<td class="row1">
6212d849ab08 Move all files from plugins/ directory to the root
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    39
				<?php echo $lang->get('yubiacp_field_api_key_id'); ?>
6212d849ab08 Move all files from plugins/ directory to the root
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    40
			</td>
6212d849ab08 Move all files from plugins/ directory to the root
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    41
			<td class="row1">
6212d849ab08 Move all files from plugins/ directory to the root
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    42
				<input type="text" name="yubikey_api_key_id" value="<?php echo strval(intval(getConfig('yubikey_api_key_id', ''))); ?>" size="5" />
6212d849ab08 Move all files from plugins/ directory to the root
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    43
			</td>
6212d849ab08 Move all files from plugins/ directory to the root
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    44
		</tr>
6212d849ab08 Move all files from plugins/ directory to the root
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    45
		
6212d849ab08 Move all files from plugins/ directory to the root
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    46
		<tr>
6212d849ab08 Move all files from plugins/ directory to the root
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    47
			<td class="row2">
6212d849ab08 Move all files from plugins/ directory to the root
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    48
				<?php echo $lang->get('yubiacp_field_auth_server'); ?>
6212d849ab08 Move all files from plugins/ directory to the root
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    49
			</td>
6212d849ab08 Move all files from plugins/ directory to the root
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    50
			<td class="row2">
6212d849ab08 Move all files from plugins/ directory to the root
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    51
				<input type="text" name="yubikey_auth_server" value="<?php echo htmlspecialchars(getConfig('yubikey_auth_server', YK_DEFAULT_VERIFY_URL)); ?>" size="30" />
6212d849ab08 Move all files from plugins/ directory to the root
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    52
				<?php
6212d849ab08 Move all files from plugins/ directory to the root
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    53
				if ( defined('YMS_INSTALLED') )
6212d849ab08 Move all files from plugins/ directory to the root
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    54
				{
6212d849ab08 Move all files from plugins/ directory to the root
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    55
					echo '<br />';
6212d849ab08 Move all files from plugins/ directory to the root
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    56
					echo $lang->get('yubiacp_field_use_local_pre');
6212d849ab08 Move all files from plugins/ directory to the root
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    57
					?> <label><input type="checkbox" name="yubikey_use_local_yms" <?php echo getConfig('yubikey_use_local_yms', 0) ? 'checked="checked" ' : ''; ?>/><?php
6212d849ab08 Move all files from plugins/ directory to the root
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    58
					echo $lang->get('yubiacp_field_use_local');
6212d849ab08 Move all files from plugins/ directory to the root
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    59
					echo '</label>';
6212d849ab08 Move all files from plugins/ directory to the root
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    60
				}
6212d849ab08 Move all files from plugins/ directory to the root
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    61
				?>
6212d849ab08 Move all files from plugins/ directory to the root
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    62
			</td>
6212d849ab08 Move all files from plugins/ directory to the root
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    63
		</tr>
6212d849ab08 Move all files from plugins/ directory to the root
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    64
		
6212d849ab08 Move all files from plugins/ directory to the root
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    65
		<tr>
6212d849ab08 Move all files from plugins/ directory to the root
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    66
			<td class="row1">
6212d849ab08 Move all files from plugins/ directory to the root
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    67
				<?php echo $lang->get('yubiacp_field_enroll_limit'); ?>
6212d849ab08 Move all files from plugins/ directory to the root
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    68
			</td>
6212d849ab08 Move all files from plugins/ directory to the root
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    69
			<td class="row1">
6212d849ab08 Move all files from plugins/ directory to the root
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    70
				<input type="text" name="yubikey_enroll_limit" value="<?php echo strval(intval(getConfig('yubikey_enroll_limit', '3'))); ?>" size="5" />
6212d849ab08 Move all files from plugins/ directory to the root
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    71
			</td>
6212d849ab08 Move all files from plugins/ directory to the root
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    72
		</tr>
6212d849ab08 Move all files from plugins/ directory to the root
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    73
		
6212d849ab08 Move all files from plugins/ directory to the root
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    74
		<tr>
6212d849ab08 Move all files from plugins/ directory to the root
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    75
			<td class="row2">
6212d849ab08 Move all files from plugins/ directory to the root
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    76
				<?php echo $lang->get('yubiacp_field_reg_require_otp_title'); ?><br />
6212d849ab08 Move all files from plugins/ directory to the root
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    77
				<small><?php echo $lang->get('yubiacp_field_reg_require_otp_hint'); ?></small>
6212d849ab08 Move all files from plugins/ directory to the root
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    78
			</td>
6212d849ab08 Move all files from plugins/ directory to the root
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    79
			<td class="row2">
6212d849ab08 Move all files from plugins/ directory to the root
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    80
				<label>
6212d849ab08 Move all files from plugins/ directory to the root
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    81
					<input type="checkbox" name="yubikey_reg_require_otp" <?php if ( getConfig('yubikey_reg_require_otp', '0') == '1' ) echo 'checked="checked" '; ?>/>
6212d849ab08 Move all files from plugins/ directory to the root
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    82
					<?php echo $lang->get('yubiacp_field_reg_require_otp'); ?>
6212d849ab08 Move all files from plugins/ directory to the root
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    83
				</label>
6212d849ab08 Move all files from plugins/ directory to the root
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    84
			</td>
6212d849ab08 Move all files from plugins/ directory to the root
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    85
		</tr>
6212d849ab08 Move all files from plugins/ directory to the root
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    86
		
6212d849ab08 Move all files from plugins/ directory to the root
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    87
	<?php
6212d849ab08 Move all files from plugins/ directory to the root
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    88
}
6212d849ab08 Move all files from plugins/ directory to the root
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    89
6212d849ab08 Move all files from plugins/ directory to the root
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    90
function yubikey_admin_cp_save()
6212d849ab08 Move all files from plugins/ directory to the root
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    91
{
6212d849ab08 Move all files from plugins/ directory to the root
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    92
	global $lang;
6212d849ab08 Move all files from plugins/ directory to the root
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    93
	
6212d849ab08 Move all files from plugins/ directory to the root
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    94
	// yubikey_enable, yubikey_api_key, yubikey_api_key_id, yubikey_auth_server, yubikey_enroll_limit
6212d849ab08 Move all files from plugins/ directory to the root
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    95
	setConfig('yubikey_enable', isset($_POST['yubikey_enable']) ? '1' : '0');
6212d849ab08 Move all files from plugins/ directory to the root
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    96
	setConfig('yubikey_api_key', $_POST['yubikey_api_key']);
6212d849ab08 Move all files from plugins/ directory to the root
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    97
	setConfig('yubikey_api_key_id', intval($_POST['yubikey_api_key_id']));
6212d849ab08 Move all files from plugins/ directory to the root
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    98
	setConfig('yubikey_enroll_limit', intval($_POST['yubikey_enroll_limit']));
6212d849ab08 Move all files from plugins/ directory to the root
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
    99
	setConfig('yubikey_reg_require_otp', isset($_POST['yubikey_reg_require_otp']) ? '1' : '0');
6212d849ab08 Move all files from plugins/ directory to the root
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   100
	setConfig('yubikey_use_local_yms', isset($_POST['yubikey_use_local_yms']) && defined('YMS_INSTALLED') ? '1' : '0');
6212d849ab08 Move all files from plugins/ directory to the root
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   101
	
6212d849ab08 Move all files from plugins/ directory to the root
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   102
	if ( preg_match('#^(?:https?://)?(\[?[a-z0-9-:]+(?:\.[a-z0-9-:]+\]?)*)(/.*)$#', $_POST['yubikey_auth_server']) )
6212d849ab08 Move all files from plugins/ directory to the root
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   103
		setConfig('yubikey_auth_server', $_POST['yubikey_auth_server']);
6212d849ab08 Move all files from plugins/ directory to the root
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   104
	else
6212d849ab08 Move all files from plugins/ directory to the root
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   105
		echo '<div class="error-box">' . $lang->get('yubiacp_err_invalid_auth_server') . '</div>';
6212d849ab08 Move all files from plugins/ directory to the root
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   106
}
6212d849ab08 Move all files from plugins/ directory to the root
Dan Fuhry <dan@enanocms.org>
parents:
diff changeset
   107