tiki-admin_tokens.php 2.31 KB
Newer Older
1
<?php
changi67's avatar
changi67 committed
2 3 4
/**
 * @package tikiwiki
 */
5
// (c) Copyright 2002-2016 by authors of the Tiki Wiki CMS Groupware Project
6 7 8 9 10 11 12 13
// 
// All Rights Reserved. See copyright.txt for details and a complete list of authors.
// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
// $Id$

require_once('tiki-setup.php');
require_once('lib/auth/tokens.php');

14
$access->check_feature('auth_token_access');
15 16 17 18 19 20
$access->check_permission('tiki_p_admin');

$tokenlib = AuthTokens::build($prefs);

$action = '';
$tokenId = 0;
21
$smarty->assign('tokenCreated', false);
22 23 24 25 26 27 28 29 30 31 32 33 34 35

if (isset($_REQUEST['action'])) {
	$action = $_REQUEST['action'];
}

if (isset($_REQUEST['tokenId']) && is_numeric($_REQUEST['tokenId'])) {
	$tokenId = $_REQUEST['tokenId'];
}

if ($action == 'delete'	&& $tokenId > 0) {
	$tokenlib->deleteToken($_REQUEST['tokenId']);
}

if ($action == 'add') {
36 37
	$url = filter_input(INPUT_POST, 'entry', FILTER_SANITIZE_STRING);
	$entry = parse_url($url, PHP_URL_PATH);
38 39 40 41 42
	
	$groups = filter_input(INPUT_POST, 'groups', FILTER_SANITIZE_STRING);
	$groups = str_replace(' ', '', $groups);
	$groups = explode(',', $groups);
	
43 44 45 46 47 48 49 50 51 52 53 54
	$parameters = array();
	$query = parse_url($url, PHP_URL_QUERY);

	if (!empty($query)) {
		$query = explode('&', $query);
	
		foreach ($query as $element) {
			list($key, $value) = explode('=', $element);
			$parameters[$key] = $value;
		}
	}

55 56 57 58 59
	$arguments = array();
	$arguments['timeout'] = filter_input(INPUT_POST, 'timeout', FILTER_SANITIZE_NUMBER_INT); 
	$arguments['hits'] = filter_input(INPUT_POST, 'maxhits', FILTER_SANITIZE_NUMBER_INT);
	
	if (!empty($entry) && !empty($groups)) {
60
		$token = $tokenlib->createToken($entry, $parameters, $groups, $arguments);
61 62 63 64
		
		if (!empty($token)) {
			$smarty->assign('tokenCreated', true);
		}
65 66 67 68 69
	}
}

$tokens = $tokenlib->getTokens();

70 71
foreach ($tokens as $key => $token) {
	$tokens[$key]['groups'] = join(', ', json_decode($token['groups']));
72
	$tokens[$key]['parameters'] = (array) json_decode($token['parameters']);
73 74 75 76 77 78
	if ($token['timeout'] == -1) {
		$tokens[$key]['expires'] = '';
	} else {
		$tokens[$key]['expires'] = date('c', strtotime($token['creation']) + $token['timeout']);
	}
	$tokens[$key]['entry'] = preg_replace('#^' . preg_quote($tikiroot) . '#', '', $token['entry']);
79 80
}

81 82 83
$smarty->assign('tokens', $tokens);
$smarty->assign('mid', 'tiki-admin_tokens.tpl');
$smarty->display('tiki.tpl');