Add files using upload-large-folder tool
Browse files- benchmark/NYU_CTF_Bench/development/2013/CSAW-Finals/web/historypeats/csaw/fuel/packages/auth/classes/auth/acl/driver.php +97 -0
- benchmark/NYU_CTF_Bench/development/2013/CSAW-Finals/web/historypeats/csaw/fuel/packages/auth/classes/auth/acl/ormacl.php +254 -0
- benchmark/NYU_CTF_Bench/development/2013/CSAW-Finals/web/historypeats/csaw/fuel/packages/auth/classes/auth/driver.php +125 -0
- benchmark/NYU_CTF_Bench/development/2013/CSAW-Finals/web/historypeats/csaw/fuel/packages/auth/classes/auth/exceptions.php +20 -0
- benchmark/NYU_CTF_Bench/development/2013/CSAW-Finals/web/historypeats/csaw/fuel/packages/auth/classes/auth/opauth.php +407 -0
- benchmark/NYU_CTF_Bench/development/2013/CSAW-Finals/web/historypeats/csaw/fuel/packages/auth/classes/model/auth/group.php +155 -0
- benchmark/NYU_CTF_Bench/development/2013/CSAW-Finals/web/historypeats/csaw/fuel/packages/auth/classes/model/auth/grouppermission.php +85 -0
- benchmark/NYU_CTF_Bench/development/2013/CSAW-Finals/web/historypeats/csaw/fuel/packages/auth/classes/model/auth/metadata.php +117 -0
- benchmark/NYU_CTF_Bench/development/2013/CSAW-Finals/web/historypeats/csaw/fuel/packages/auth/classes/model/auth/permission.php +162 -0
- benchmark/NYU_CTF_Bench/development/2013/CSAW-Finals/web/historypeats/csaw/fuel/packages/auth/classes/model/auth/role.php +172 -0
- benchmark/NYU_CTF_Bench/development/2013/CSAW-Finals/web/historypeats/csaw/fuel/packages/auth/classes/model/auth/rolepermission.php +85 -0
- benchmark/NYU_CTF_Bench/development/2013/CSAW-Finals/web/historypeats/csaw/fuel/packages/auth/classes/model/auth/user.php +205 -0
- benchmark/NYU_CTF_Bench/development/2013/CSAW-Finals/web/historypeats/csaw/fuel/packages/auth/classes/model/auth/userpermission.php +85 -0
- benchmark/NYU_CTF_Bench/development/2013/CSAW-Finals/web/historypeats/csaw/fuel/packages/auth/lang/en/auth_model_group.php +5 -0
- benchmark/NYU_CTF_Bench/development/2013/CSAW-Finals/web/historypeats/csaw/fuel/packages/auth/lang/en/auth_model_permission.php +7 -0
- benchmark/NYU_CTF_Bench/development/2013/CSAW-Finals/web/historypeats/csaw/fuel/packages/auth/lang/en/auth_model_role.php +13 -0
- benchmark/NYU_CTF_Bench/development/2013/CSAW-Finals/web/historypeats/csaw/fuel/packages/auth/lang/en/auth_model_user.php +8 -0
- benchmark/NYU_CTF_Bench/development/2013/CSAW-Finals/web/historypeats/csaw/fuel/packages/auth/migrations/008_auth_create_providers.php +78 -0
- benchmark/NYU_CTF_Bench/development/2013/CSAW-Finals/web/historypeats/csaw/fuel/packages/auth/migrations/009_auth_create_oauth2tables.php +156 -0
- benchmark/NYU_CTF_Bench/development/2013/CSAW-Finals/web/historypeats/csaw/fuel/packages/auth/tasks/simple2orm.php +444 -0
benchmark/NYU_CTF_Bench/development/2013/CSAW-Finals/web/historypeats/csaw/fuel/packages/auth/classes/auth/acl/driver.php
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/**
|
| 3 |
+
* Fuel
|
| 4 |
+
*
|
| 5 |
+
* Fuel is a fast, lightweight, community driven PHP5 framework.
|
| 6 |
+
*
|
| 7 |
+
* @package Fuel
|
| 8 |
+
* @version 1.7
|
| 9 |
+
* @author Fuel Development Team
|
| 10 |
+
* @license MIT License
|
| 11 |
+
* @copyright 2010 - 2013 Fuel Development Team
|
| 12 |
+
* @link http://fuelphp.com
|
| 13 |
+
*/
|
| 14 |
+
|
| 15 |
+
namespace Auth;
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
abstract class Auth_Acl_Driver extends \Auth_Driver
|
| 19 |
+
{
|
| 20 |
+
|
| 21 |
+
/**
|
| 22 |
+
* @var Auth_Driver default instance
|
| 23 |
+
*/
|
| 24 |
+
protected static $_instance = null;
|
| 25 |
+
|
| 26 |
+
/**
|
| 27 |
+
* @var array contains references if multiple were loaded
|
| 28 |
+
*/
|
| 29 |
+
protected static $_instances = array();
|
| 30 |
+
|
| 31 |
+
public static function forge(array $config = array())
|
| 32 |
+
{
|
| 33 |
+
// default driver id to driver name when not given
|
| 34 |
+
! array_key_exists('id', $config) && $config['id'] = $config['driver'];
|
| 35 |
+
|
| 36 |
+
$class = \Inflector::get_namespace($config['driver']).'Auth_Acl_'.\Str::ucwords(\Inflector::denamespace($config['driver']));
|
| 37 |
+
$driver = new $class($config);
|
| 38 |
+
static::$_instances[$driver->get_id()] = $driver;
|
| 39 |
+
is_null(static::$_instance) and static::$_instance = $driver;
|
| 40 |
+
|
| 41 |
+
foreach ($driver->get_config('drivers', array()) as $type => $drivers)
|
| 42 |
+
{
|
| 43 |
+
foreach ($drivers as $d => $custom)
|
| 44 |
+
{
|
| 45 |
+
$custom = is_int($d)
|
| 46 |
+
? array('driver' => $custom)
|
| 47 |
+
: array_merge($custom, array('driver' => $d));
|
| 48 |
+
$class = 'Auth_'.\Str::ucwords($type).'_Driver';
|
| 49 |
+
$class::forge($custom);
|
| 50 |
+
}
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
return $driver;
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
/**
|
| 57 |
+
* Parses a conditions string into it's array equivalent
|
| 58 |
+
*
|
| 59 |
+
* @rights mixed conditions array or string
|
| 60 |
+
* @return array conditions array formatted as array(area, rights)
|
| 61 |
+
*
|
| 62 |
+
*/
|
| 63 |
+
public static function _parse_conditions($rights)
|
| 64 |
+
{
|
| 65 |
+
if (is_array($rights))
|
| 66 |
+
{
|
| 67 |
+
return $rights;
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
if ( ! is_string($rights) or strpos($rights, '.') === false)
|
| 71 |
+
{
|
| 72 |
+
throw new \InvalidArgumentException('Given rights where not formatted proppery. Formatting should be like area.right or area.[right, other_right]. Received: '.$rights);
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
list($area, $rights) = explode('.', $rights);
|
| 76 |
+
|
| 77 |
+
if (substr($rights, 0, 1) == '[' and substr($rights, -1, 1) == ']')
|
| 78 |
+
{
|
| 79 |
+
$rights = preg_split('#( *)?,( *)?#', trim(substr($rights, 1, -1)));
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
return array($area, $rights);
|
| 83 |
+
}
|
| 84 |
+
|
| 85 |
+
// ------------------------------------------------------------------------
|
| 86 |
+
|
| 87 |
+
/**
|
| 88 |
+
* Check access rights
|
| 89 |
+
*
|
| 90 |
+
* @param mixed condition to check for access
|
| 91 |
+
* @param mixed user or group identifier in the form of array(driver_id, id)
|
| 92 |
+
* @return bool
|
| 93 |
+
*/
|
| 94 |
+
abstract public function has_access($condition, Array $entity);
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
+
/* end of file driver.php */
|
benchmark/NYU_CTF_Bench/development/2013/CSAW-Finals/web/historypeats/csaw/fuel/packages/auth/classes/auth/acl/ormacl.php
ADDED
|
@@ -0,0 +1,254 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/**
|
| 3 |
+
* Fuel is a fast, lightweight, community driven PHP5 framework.
|
| 4 |
+
*
|
| 5 |
+
* @package Fuel
|
| 6 |
+
* @version 1.7
|
| 7 |
+
* @author Fuel Development Team
|
| 8 |
+
* @license MIT License
|
| 9 |
+
* @copyright 2010 - 2013 Fuel Development Team
|
| 10 |
+
* @link http://fuelphp.com
|
| 11 |
+
*/
|
| 12 |
+
|
| 13 |
+
namespace Auth;
|
| 14 |
+
|
| 15 |
+
/**
|
| 16 |
+
* OrmAuth ORM driven acl driver
|
| 17 |
+
*
|
| 18 |
+
* @package Fuel
|
| 19 |
+
* @subpackage Auth
|
| 20 |
+
*/
|
| 21 |
+
class Auth_Acl_Ormacl extends \Auth_Acl_Driver
|
| 22 |
+
{
|
| 23 |
+
/*
|
| 24 |
+
* @var array list of valid roles
|
| 25 |
+
*/
|
| 26 |
+
protected static $_valid_roles = array();
|
| 27 |
+
|
| 28 |
+
/*
|
| 29 |
+
* class init
|
| 30 |
+
*/
|
| 31 |
+
public static function _init()
|
| 32 |
+
{
|
| 33 |
+
// get the list of valid roles
|
| 34 |
+
try
|
| 35 |
+
{
|
| 36 |
+
static::$_valid_roles = \Cache::get(\Config::get('ormauth.cache_prefix', 'auth').'.roles');
|
| 37 |
+
}
|
| 38 |
+
catch (\CacheNotFoundException $e)
|
| 39 |
+
{
|
| 40 |
+
static::$_valid_roles = \Model\Auth_Role::find('all');
|
| 41 |
+
\Cache::set(\Config::get('ormauth.cache_prefix', 'auth').'.roles', static::$_valid_roles);
|
| 42 |
+
}
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
/*
|
| 46 |
+
* Return the list of defined roles
|
| 47 |
+
*/
|
| 48 |
+
public function roles()
|
| 49 |
+
{
|
| 50 |
+
return static::$_valid_roles;
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
/*
|
| 54 |
+
* Check if the user has the required permissions
|
| 55 |
+
*/
|
| 56 |
+
public function has_access($condition, Array $entity)
|
| 57 |
+
{
|
| 58 |
+
// get the group driver instance
|
| 59 |
+
$group_driver = \Auth::group($entity[0]);
|
| 60 |
+
|
| 61 |
+
// parse the requested permissions so we can check them
|
| 62 |
+
$condition = static::_parse_conditions($condition);
|
| 63 |
+
|
| 64 |
+
// if we couldn't parse the conditions, don't have a driver, or the driver doesn't export roles, bail out
|
| 65 |
+
if ( ! is_array($condition) || empty($group_driver) || ! is_callable(array($group_driver, 'get_roles')))
|
| 66 |
+
{
|
| 67 |
+
return false;
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
// get the permission area and the permission rights to be checked
|
| 71 |
+
$area = $condition[0];
|
| 72 |
+
|
| 73 |
+
// any actions defined?
|
| 74 |
+
if ( ! is_array($condition[1]) and preg_match('#(.*)?\[(.*)?\]#', $condition[1], $matches))
|
| 75 |
+
{
|
| 76 |
+
$rights = (array) $matches[1];
|
| 77 |
+
$actions = explode(',', $matches[2]);
|
| 78 |
+
}
|
| 79 |
+
else
|
| 80 |
+
{
|
| 81 |
+
$rights = (array) $condition[1];
|
| 82 |
+
$actions = array();
|
| 83 |
+
}
|
| 84 |
+
|
| 85 |
+
// fetch the current user object
|
| 86 |
+
$user = Auth::get_user();
|
| 87 |
+
|
| 88 |
+
// some storage to collect the current rights and revoked rights, and the global flag
|
| 89 |
+
$current_rights = array();
|
| 90 |
+
$revoked_rights = array();
|
| 91 |
+
$global_access = null;
|
| 92 |
+
|
| 93 |
+
// assemble the current users effective rights
|
| 94 |
+
$cache_key = \Config::get('ormauth.cache_prefix', 'auth').'.permissions.user_'.($user ? $user->id : 0);
|
| 95 |
+
try
|
| 96 |
+
{
|
| 97 |
+
list($current_rights, $revoked_rights, $global_access) = \Cache::get($cache_key);
|
| 98 |
+
}
|
| 99 |
+
catch (\CacheNotFoundException $e)
|
| 100 |
+
{
|
| 101 |
+
// get the role objects assigned to this group
|
| 102 |
+
$current_roles = $entity[1]->roles;
|
| 103 |
+
|
| 104 |
+
// if we have a user, add the roles directly assigned to the user
|
| 105 |
+
if ($user)
|
| 106 |
+
{
|
| 107 |
+
$current_roles = \Arr::merge($current_roles, Auth::get_user()->roles);
|
| 108 |
+
}
|
| 109 |
+
|
| 110 |
+
foreach ($current_roles as $role)
|
| 111 |
+
{
|
| 112 |
+
// role grants all access
|
| 113 |
+
if ($role->filter == 'A')
|
| 114 |
+
{
|
| 115 |
+
$global_access = true;
|
| 116 |
+
}
|
| 117 |
+
|
| 118 |
+
// role denies all access
|
| 119 |
+
elseif ($role->filter == 'D')
|
| 120 |
+
{
|
| 121 |
+
$global_access = false;
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
// role defines a permission revocation
|
| 125 |
+
elseif ($role->filter == 'R')
|
| 126 |
+
{
|
| 127 |
+
// fetch the permissions of this role
|
| 128 |
+
foreach ($role->permissions as $permission)
|
| 129 |
+
{
|
| 130 |
+
isset($revoked_rights[$permission->area][$permission->permission]) or $revoked_rights[$permission->area][$permission->permission] = array();
|
| 131 |
+
$revoked_rights[$permission->area][$permission->permission] = array_merge(
|
| 132 |
+
$revoked_rights[$permission->area][$permission->permission],
|
| 133 |
+
array_intersect_key(
|
| 134 |
+
$role->rolepermission['['.$role->id.']['.$permission->id.']']->permission->actions,
|
| 135 |
+
array_flip($role->rolepermission['['.$role->id.']['.$permission->id.']']->actions)
|
| 136 |
+
)
|
| 137 |
+
);
|
| 138 |
+
}
|
| 139 |
+
}
|
| 140 |
+
|
| 141 |
+
// standard role, add it to the current rights set
|
| 142 |
+
else
|
| 143 |
+
{
|
| 144 |
+
// fetch the permissions of this role
|
| 145 |
+
foreach ($role->permissions as $permission)
|
| 146 |
+
{
|
| 147 |
+
isset($current_rights[$permission->area][$permission->permission]) or $current_rights[$permission->area][$permission->permission] = array();
|
| 148 |
+
$current_rights[$permission->area][$permission->permission] = array_merge(
|
| 149 |
+
$current_rights[$permission->area][$permission->permission],
|
| 150 |
+
array_intersect_key(
|
| 151 |
+
$role->rolepermission['['.$role->id.']['.$permission->id.']']->permission->actions,
|
| 152 |
+
array_flip($role->rolepermission['['.$role->id.']['.$permission->id.']']->actions)
|
| 153 |
+
)
|
| 154 |
+
);
|
| 155 |
+
}
|
| 156 |
+
}
|
| 157 |
+
}
|
| 158 |
+
|
| 159 |
+
// if this user doesn't have a global filter applied...
|
| 160 |
+
if (is_array($current_rights))
|
| 161 |
+
{
|
| 162 |
+
if ($user)
|
| 163 |
+
{
|
| 164 |
+
// add the users group rights
|
| 165 |
+
foreach ($user->group->permissions as $permission)
|
| 166 |
+
{
|
| 167 |
+
isset($current_rights[$permission->area][$permission->permission]) or $current_rights[$permission->area][$permission->permission] = array();
|
| 168 |
+
$current_rights[$permission->area][$permission->permission] = array_merge(
|
| 169 |
+
$current_rights[$permission->area][$permission->permission],
|
| 170 |
+
array_intersect_key(
|
| 171 |
+
$user->group->grouppermission['['.$user->group_id.']['.$permission->id.']']->permission->actions,
|
| 172 |
+
array_flip($user->group->grouppermission['['.$user->group_id.']['.$permission->id.']']->actions)
|
| 173 |
+
)
|
| 174 |
+
);
|
| 175 |
+
}
|
| 176 |
+
|
| 177 |
+
// add the users personal rights
|
| 178 |
+
if ($user)
|
| 179 |
+
{
|
| 180 |
+
foreach ($user->permissions as $permission)
|
| 181 |
+
{
|
| 182 |
+
isset($current_rights[$permission->area][$permission->permission]) or $current_rights[$permission->area][$permission->permission] = array();
|
| 183 |
+
$current_rights[$permission->area][$permission->permission] = array_merge(
|
| 184 |
+
$current_rights[$permission->area][$permission->permission],
|
| 185 |
+
array_intersect_key(
|
| 186 |
+
$user->userpermission['['.$user->id.']['.$permission->id.']']->permission->actions,
|
| 187 |
+
array_flip($user->userpermission['['.$user->id.']['.$permission->id.']']->actions)
|
| 188 |
+
)
|
| 189 |
+
);
|
| 190 |
+
}
|
| 191 |
+
}
|
| 192 |
+
}
|
| 193 |
+
}
|
| 194 |
+
|
| 195 |
+
// save the rights in the cache
|
| 196 |
+
\Cache::set($cache_key, array($current_rights, $revoked_rights, $global_access));
|
| 197 |
+
}
|
| 198 |
+
|
| 199 |
+
// check for a revocation first
|
| 200 |
+
foreach ($rights as $right)
|
| 201 |
+
{
|
| 202 |
+
// check revocation permissions
|
| 203 |
+
if ( isset($revoked_rights[$area]) and array_key_exists($right, $revoked_rights[$area]))
|
| 204 |
+
{
|
| 205 |
+
$revoked = true;
|
| 206 |
+
|
| 207 |
+
// need to check any actions?
|
| 208 |
+
foreach ($actions as $action)
|
| 209 |
+
{
|
| 210 |
+
if ( ! in_array($action, $revoked_rights[$area][$right]))
|
| 211 |
+
{
|
| 212 |
+
$revoked = false;
|
| 213 |
+
break;
|
| 214 |
+
}
|
| 215 |
+
}
|
| 216 |
+
|
| 217 |
+
// right revoked?
|
| 218 |
+
if ($revoked)
|
| 219 |
+
{
|
| 220 |
+
return false;
|
| 221 |
+
}
|
| 222 |
+
}
|
| 223 |
+
}
|
| 224 |
+
|
| 225 |
+
// was a global filter applied?
|
| 226 |
+
if (is_bool($global_access))
|
| 227 |
+
{
|
| 228 |
+
// we're done here
|
| 229 |
+
return $global_access;
|
| 230 |
+
}
|
| 231 |
+
|
| 232 |
+
// start checking rights, terminate false when right not found
|
| 233 |
+
foreach ($rights as $right)
|
| 234 |
+
{
|
| 235 |
+
// check basic permissions
|
| 236 |
+
if ( ! isset($current_rights[$area]) or ! array_key_exists($right, $current_rights[$area]))
|
| 237 |
+
{
|
| 238 |
+
return false;
|
| 239 |
+
}
|
| 240 |
+
|
| 241 |
+
// need to check any actions?
|
| 242 |
+
foreach ($actions as $action)
|
| 243 |
+
{
|
| 244 |
+
if ( ! in_array($action, $current_rights[$area][$right]))
|
| 245 |
+
{
|
| 246 |
+
return false;
|
| 247 |
+
}
|
| 248 |
+
}
|
| 249 |
+
}
|
| 250 |
+
|
| 251 |
+
// all necessary rights were found, return true
|
| 252 |
+
return true;
|
| 253 |
+
}
|
| 254 |
+
}
|
benchmark/NYU_CTF_Bench/development/2013/CSAW-Finals/web/historypeats/csaw/fuel/packages/auth/classes/auth/driver.php
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/**
|
| 3 |
+
* Fuel
|
| 4 |
+
*
|
| 5 |
+
* Fuel is a fast, lightweight, community driven PHP5 framework.
|
| 6 |
+
*
|
| 7 |
+
* @package Fuel
|
| 8 |
+
* @version 1.7
|
| 9 |
+
* @author Fuel Development Team
|
| 10 |
+
* @license MIT License
|
| 11 |
+
* @copyright 2010 - 2013 Fuel Development Team
|
| 12 |
+
* @link http://fuelphp.com
|
| 13 |
+
*/
|
| 14 |
+
|
| 15 |
+
namespace Auth;
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
abstract class Auth_Driver
|
| 19 |
+
{
|
| 20 |
+
|
| 21 |
+
/**
|
| 22 |
+
* @var Auth_Driver
|
| 23 |
+
* THIS MUST BE DEFINED IN THE BASE EXTENSION
|
| 24 |
+
*/
|
| 25 |
+
// protected static $_instance = null;
|
| 26 |
+
|
| 27 |
+
/**
|
| 28 |
+
* @var array contains references if multiple were loaded
|
| 29 |
+
* THIS MUST BE DEFINED IN THE BASE EXTENSION
|
| 30 |
+
*/
|
| 31 |
+
// protected static $_instances = array();
|
| 32 |
+
|
| 33 |
+
public static function forge(array $config = array())
|
| 34 |
+
{
|
| 35 |
+
throw new \AuthException('Driver must have a factory method extension.');
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
/**
|
| 39 |
+
* Return a specific driver, or the default instance
|
| 40 |
+
*
|
| 41 |
+
* @param string driver id
|
| 42 |
+
* @return Auth_Driver
|
| 43 |
+
*/
|
| 44 |
+
public static function instance($instance = null)
|
| 45 |
+
{
|
| 46 |
+
if ($instance === true)
|
| 47 |
+
{
|
| 48 |
+
return static::$_instances;
|
| 49 |
+
}
|
| 50 |
+
elseif ($instance !== null)
|
| 51 |
+
{
|
| 52 |
+
if ( ! array_key_exists($instance, static::$_instances))
|
| 53 |
+
{
|
| 54 |
+
return false;
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
return static::$_instances[$instance];
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
return static::$_instance;
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
// ------------------------------------------------------------------------
|
| 64 |
+
|
| 65 |
+
/**
|
| 66 |
+
* @var string instance identifier
|
| 67 |
+
*/
|
| 68 |
+
protected $id;
|
| 69 |
+
|
| 70 |
+
/**
|
| 71 |
+
* @var array given configuration array
|
| 72 |
+
*/
|
| 73 |
+
protected $config = array();
|
| 74 |
+
|
| 75 |
+
protected function __construct(Array $config)
|
| 76 |
+
{
|
| 77 |
+
$this->id = $config['id'];
|
| 78 |
+
$this->config = array_merge($this->config, $config);
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
/**
|
| 82 |
+
* Get driver instance ID
|
| 83 |
+
*
|
| 84 |
+
* @return string
|
| 85 |
+
*/
|
| 86 |
+
public function get_id()
|
| 87 |
+
{
|
| 88 |
+
return (string) $this->id;
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
/**
|
| 92 |
+
* Create or change config value
|
| 93 |
+
*
|
| 94 |
+
* @param string
|
| 95 |
+
* @param mixed
|
| 96 |
+
*/
|
| 97 |
+
public function set_config($key, $value)
|
| 98 |
+
{
|
| 99 |
+
$this->config[$key] = $value;
|
| 100 |
+
}
|
| 101 |
+
|
| 102 |
+
/**
|
| 103 |
+
* Retrieve config value
|
| 104 |
+
*
|
| 105 |
+
* @param string
|
| 106 |
+
* @param mixed return when key doesn't exist
|
| 107 |
+
* @return mixed
|
| 108 |
+
*/
|
| 109 |
+
public function get_config($key, $default = null)
|
| 110 |
+
{
|
| 111 |
+
return array_key_exists($key, $this->config) ? $this->config[$key] : $default;
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
/**
|
| 115 |
+
* Whether this driver supports guest login
|
| 116 |
+
*
|
| 117 |
+
* @return bool
|
| 118 |
+
*/
|
| 119 |
+
public function guest_login()
|
| 120 |
+
{
|
| 121 |
+
return false;
|
| 122 |
+
}
|
| 123 |
+
}
|
| 124 |
+
|
| 125 |
+
/* end of file driver.php */
|
benchmark/NYU_CTF_Bench/development/2013/CSAW-Finals/web/historypeats/csaw/fuel/packages/auth/classes/auth/exceptions.php
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/**
|
| 3 |
+
* Fuel is a fast, lightweight, community driven PHP5 framework.
|
| 4 |
+
*
|
| 5 |
+
* @package Fuel
|
| 6 |
+
* @version 1.7
|
| 7 |
+
* @author Fuel Development Team
|
| 8 |
+
* @license MIT License
|
| 9 |
+
* @copyright 2010 - 2013 Fuel Development Team
|
| 10 |
+
* @link http://fuelphp.com
|
| 11 |
+
*/
|
| 12 |
+
|
| 13 |
+
namespace Auth;
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
class SimpleUserUpdateException extends \FuelException {}
|
| 17 |
+
|
| 18 |
+
class SimpleUserWrongPassword extends \FuelException {}
|
| 19 |
+
|
| 20 |
+
class OpauthException extends \FuelException {}
|
benchmark/NYU_CTF_Bench/development/2013/CSAW-Finals/web/historypeats/csaw/fuel/packages/auth/classes/auth/opauth.php
ADDED
|
@@ -0,0 +1,407 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/**
|
| 3 |
+
* Fuel
|
| 4 |
+
*
|
| 5 |
+
* Fuel is a fast, lightweight, community driven PHP5 framework.
|
| 6 |
+
*
|
| 7 |
+
* @package Fuel
|
| 8 |
+
* @version 1.7
|
| 9 |
+
* @author Fuel Development Team
|
| 10 |
+
* @license MIT License
|
| 11 |
+
* @copyright 2010 - 2013 Fuel Development Team
|
| 12 |
+
* @link http://fuelphp.com
|
| 13 |
+
*/
|
| 14 |
+
|
| 15 |
+
namespace Auth;
|
| 16 |
+
|
| 17 |
+
class Auth_Opauth
|
| 18 |
+
{
|
| 19 |
+
/**
|
| 20 |
+
* @var string name of the providers table
|
| 21 |
+
*/
|
| 22 |
+
protected static $provider_table = null;
|
| 23 |
+
|
| 24 |
+
/**
|
| 25 |
+
* Class initialisation
|
| 26 |
+
*/
|
| 27 |
+
public static function _init()
|
| 28 |
+
{
|
| 29 |
+
// just checkin', do we have Opauth installed?
|
| 30 |
+
if ( ! class_exists('Opauth'))
|
| 31 |
+
{
|
| 32 |
+
throw new \OpauthException('Opauth composer package not installed. Add "opauth/opauth" to composer.json and run a composer update.');
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
// load the auth and opauth config
|
| 36 |
+
\Config::load('auth', true);
|
| 37 |
+
\Config::load('opauth', true);
|
| 38 |
+
|
| 39 |
+
// determine the auth driver we're going to use
|
| 40 |
+
$drivers = \Config::get('auth.driver', array());
|
| 41 |
+
is_array($drivers) or $drivers = array($drivers);
|
| 42 |
+
|
| 43 |
+
if (in_array('Simpleauth', $drivers))
|
| 44 |
+
{
|
| 45 |
+
// get the tablename
|
| 46 |
+
\Config::load('simpleauth', true);
|
| 47 |
+
static::$provider_table = \Config::get('simpleauth.table_name', 'users').'_providers';
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
elseif (in_array('Ormauth', $drivers))
|
| 51 |
+
{
|
| 52 |
+
// get the tablename
|
| 53 |
+
\Config::load('ormauth', true);
|
| 54 |
+
static::$provider_table = \Config::get('ormauth.table_name', 'users').'_providers';
|
| 55 |
+
}
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
/**
|
| 59 |
+
* Create an OpAuth instance
|
| 60 |
+
*
|
| 61 |
+
* @param array any call-time configuration to be used
|
| 62 |
+
* @param bool whether or not Opauth should run automatically
|
| 63 |
+
*/
|
| 64 |
+
public static function forge($config = array(), $autorun = true)
|
| 65 |
+
{
|
| 66 |
+
// deal with passing only the autorun value
|
| 67 |
+
if (func_num_args() == 1 and is_bool($config))
|
| 68 |
+
{
|
| 69 |
+
$autorun = $config;
|
| 70 |
+
$config = array();
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
// merge the default config with the runtime config
|
| 74 |
+
$config = \Arr::merge(\Config::get('opauth'), $config);
|
| 75 |
+
|
| 76 |
+
// define the transport system we use
|
| 77 |
+
$config['callback_transport'] = 'get';
|
| 78 |
+
|
| 79 |
+
// make sure we have a remotes table
|
| 80 |
+
if ( ! isset($config['table']) and ($config['table'] = static::$provider_table) === null)
|
| 81 |
+
{
|
| 82 |
+
throw new \OpauthException('No providers table configured. At the moment, only SimpleAuth and OrmAuth can be auto-detected.');
|
| 83 |
+
}
|
| 84 |
+
|
| 85 |
+
// and a security salt
|
| 86 |
+
if (empty($config['security_salt']))
|
| 87 |
+
{
|
| 88 |
+
throw new \OpauthException('There is no "security_salt" defined in the opauth.php configuration file.');
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
// set some defaults, just in case
|
| 92 |
+
isset($config['security_iteration']) or $config['security_iteration'] = 300;
|
| 93 |
+
isset($config['security_timeout']) or $config['security_timeout'] = '2 minutes';
|
| 94 |
+
|
| 95 |
+
if (empty($config['path']))
|
| 96 |
+
{
|
| 97 |
+
$parsed_url = parse_url(\Uri::base().\Request::main()->uri->get());
|
| 98 |
+
$path = explode('/', trim($parsed_url['path'], '/'));
|
| 99 |
+
|
| 100 |
+
// construct the path if needed
|
| 101 |
+
// $path = \Request::main()->uri->get_segments();
|
| 102 |
+
$params = count(\Request::active()->route->method_params);
|
| 103 |
+
|
| 104 |
+
while ($params-- > 0)
|
| 105 |
+
{
|
| 106 |
+
array_pop($path);
|
| 107 |
+
}
|
| 108 |
+
$config['path'] = '/'.(implode('/', $path)).'/';
|
| 109 |
+
}
|
| 110 |
+
|
| 111 |
+
// and construct the callback URL if needed
|
| 112 |
+
if (empty($config['callback_url']))
|
| 113 |
+
{
|
| 114 |
+
// pop the method name from the path
|
| 115 |
+
$path = explode('/', trim($config['path'], '/'));
|
| 116 |
+
array_pop($path);
|
| 117 |
+
|
| 118 |
+
// and add 'callback' as the controller callback action
|
| 119 |
+
$config['callback_url'] = '/'.implode('/', $path).'/callback/';
|
| 120 |
+
}
|
| 121 |
+
|
| 122 |
+
// determine the name of the provider we want to call
|
| 123 |
+
if ( ! $autorun)
|
| 124 |
+
{
|
| 125 |
+
// we're processing a callback
|
| 126 |
+
$config['provider'] = 'Callback';
|
| 127 |
+
}
|
| 128 |
+
else
|
| 129 |
+
{
|
| 130 |
+
if (empty($config['provider']))
|
| 131 |
+
{
|
| 132 |
+
$parsed_url = parse_url(\Uri::base().\Request::main()->uri->get());
|
| 133 |
+
$provider = explode('/', substr($parsed_url['path'], strlen($config['path'])));
|
| 134 |
+
$config['provider'] = ucfirst($provider[0]);
|
| 135 |
+
}
|
| 136 |
+
|
| 137 |
+
// check if we have a strategy defined for this provider
|
| 138 |
+
$strategies = \Config::get('opauth.Strategy', array());
|
| 139 |
+
if ( ! array_key_exists(strtolower($config['provider']), array_change_key_case($strategies)))
|
| 140 |
+
{
|
| 141 |
+
throw new \OpauthException('Opauth strategy "'.$config['provider'].'" is not supported');
|
| 142 |
+
}
|
| 143 |
+
}
|
| 144 |
+
|
| 145 |
+
// return the created Auth_Opauth object
|
| 146 |
+
return new static($config, $autorun);
|
| 147 |
+
}
|
| 148 |
+
|
| 149 |
+
// -------------------------------------------------------------------------
|
| 150 |
+
|
| 151 |
+
/**
|
| 152 |
+
* Opauth configuration
|
| 153 |
+
*/
|
| 154 |
+
protected $config = array();
|
| 155 |
+
|
| 156 |
+
/**
|
| 157 |
+
* Opauth instance
|
| 158 |
+
*/
|
| 159 |
+
protected $opauth = null;
|
| 160 |
+
|
| 161 |
+
/**
|
| 162 |
+
* Opauth response
|
| 163 |
+
*/
|
| 164 |
+
protected $response = array();
|
| 165 |
+
|
| 166 |
+
/**
|
| 167 |
+
* Construct the Auth_Opauth object
|
| 168 |
+
*/
|
| 169 |
+
public function __construct(Array $config, $autorun = true)
|
| 170 |
+
{
|
| 171 |
+
// store the config
|
| 172 |
+
$this->config = $config;
|
| 173 |
+
|
| 174 |
+
// construct the Opauth object
|
| 175 |
+
$this->opauth = new \Opauth($config, $autorun);
|
| 176 |
+
}
|
| 177 |
+
|
| 178 |
+
/**
|
| 179 |
+
* New Opauth login. If we know this user, we can perform a login, if
|
| 180 |
+
* not, we need to register the user first
|
| 181 |
+
*/
|
| 182 |
+
public function login_or_register()
|
| 183 |
+
{
|
| 184 |
+
// process the callback data
|
| 185 |
+
$this->callback();
|
| 186 |
+
|
| 187 |
+
// if there is no UID we don't know who this is
|
| 188 |
+
if ($this->get('auth.uid', null) === null)
|
| 189 |
+
{
|
| 190 |
+
throw new \OpauthException('No uid in response from the provider, so we have no idea who you are.');
|
| 191 |
+
}
|
| 192 |
+
|
| 193 |
+
// we have a UID and logged in? Just attach this authentication to a user
|
| 194 |
+
if (\Auth::check())
|
| 195 |
+
{
|
| 196 |
+
list(, $user_id) = \Auth::instance()->get_user_id();
|
| 197 |
+
|
| 198 |
+
$result = \DB::select(\DB::expr('COUNT(*) as count'))->from($this->config['table'])->where('parent_id', '=', $user_id)->execute();
|
| 199 |
+
$num_linked = ($result and $result = $result->current()) ? $result['count'] : 0;
|
| 200 |
+
|
| 201 |
+
// allowed multiple providers, or not authed yet?
|
| 202 |
+
if ($num_linked === 0 or \Config::get('opauth.link_multiple_providers') === true)
|
| 203 |
+
{
|
| 204 |
+
// attach this account to the logged in user
|
| 205 |
+
$this->link_provider(array(
|
| 206 |
+
'parent_id' => $user_id,
|
| 207 |
+
'provider' => $this->get('auth.provider'),
|
| 208 |
+
'uid' => $this->get('auth.uid'),
|
| 209 |
+
'access_token' => $this->get('auth.credentials.token', null),
|
| 210 |
+
'secret' => $this->get('auth.credentials.secret', null),
|
| 211 |
+
'expires' => $this->get('auth.credentials.expires', null),
|
| 212 |
+
'refresh_token' => $this->get('auth.credentials.refresh_token', null),
|
| 213 |
+
'created_at' => time(),
|
| 214 |
+
));
|
| 215 |
+
|
| 216 |
+
// attachment went ok so we'll redirect
|
| 217 |
+
return 'linked';
|
| 218 |
+
}
|
| 219 |
+
|
| 220 |
+
else
|
| 221 |
+
{
|
| 222 |
+
$result = \DB::select()->from($this->config['table'])->where('parent_id', '=', $user_id)->limit(1)->as_object()->execute();
|
| 223 |
+
$auth = $result ? $result->current() : null;
|
| 224 |
+
throw new \OpauthException(sprintf('This user is already linked to "%s" and can\'t be linked to another provider.', $auth->provider));
|
| 225 |
+
}
|
| 226 |
+
}
|
| 227 |
+
|
| 228 |
+
// the user exists, so send him on his merry way as a user
|
| 229 |
+
elseif ($authentication = \DB::select()->from($this->config['table'])->where('uid', '=', $this->get('auth.uid'))->where('provider', '=', $this->get('auth.provider'))->as_object()->execute() and $authentication->count())
|
| 230 |
+
{
|
| 231 |
+
// force a login with this username
|
| 232 |
+
$authentication = $authentication->current();
|
| 233 |
+
if (\Auth::instance()->force_login((int) $authentication->parent_id))
|
| 234 |
+
{
|
| 235 |
+
// credentials ok, go right in
|
| 236 |
+
return 'logged_in';
|
| 237 |
+
}
|
| 238 |
+
|
| 239 |
+
throw new \OpauthException('This user could not be logged in.');
|
| 240 |
+
}
|
| 241 |
+
|
| 242 |
+
// not an existing user of any type, so we need to create a user somehow
|
| 243 |
+
else
|
| 244 |
+
{
|
| 245 |
+
// generate a dummy password if we don't have one, and want auto registration for this user
|
| 246 |
+
if ($this->config['auto_registration'])
|
| 247 |
+
{
|
| 248 |
+
$this->get('auth.info.password') or $this->response['auth']['info']['password'] = \Str::random('sha1');
|
| 249 |
+
}
|
| 250 |
+
|
| 251 |
+
// did the provider return enough information to log the user in?
|
| 252 |
+
if ($this->get('auth.info.nickname') and $this->get('auth.info.email') and $this->get('auth.info.password'))
|
| 253 |
+
{
|
| 254 |
+
// make a user with what we have
|
| 255 |
+
$user_id = $this->create_user($this->response['auth']['info']);
|
| 256 |
+
|
| 257 |
+
// attach this authentication to the new user
|
| 258 |
+
$insert_id = $this->link_provider(array(
|
| 259 |
+
'parent_id' => $user_id,
|
| 260 |
+
'provider' => $this->get('auth.provider'),
|
| 261 |
+
'uid' => $this->get('auth.uid'),
|
| 262 |
+
'access_token' => $this->get('auth.credentials.token', null),
|
| 263 |
+
'secret' => $this->get('auth.credentials.secret', null),
|
| 264 |
+
'expires' => $this->get('auth.credentials.expires', null),
|
| 265 |
+
'refresh_token' => $this->get('auth.credentials.refresh_token', null),
|
| 266 |
+
'created_at' => time(),
|
| 267 |
+
));
|
| 268 |
+
|
| 269 |
+
// force a login with this users id
|
| 270 |
+
if ($insert_id and \Auth::instance()->force_login((int) $user_id))
|
| 271 |
+
{
|
| 272 |
+
// credentials ok, go right in
|
| 273 |
+
return 'registered';
|
| 274 |
+
}
|
| 275 |
+
|
| 276 |
+
throw new \OpauthException('We tried automatically creating a user but that just really did not work. Not sure why...');
|
| 277 |
+
}
|
| 278 |
+
|
| 279 |
+
// they aren't a user and cant be automatically registerd, so redirect to registration page
|
| 280 |
+
else
|
| 281 |
+
{
|
| 282 |
+
\Session::set('auth-strategy', array(
|
| 283 |
+
'user' => $this->get('auth.info'),
|
| 284 |
+
'authentication' => array(
|
| 285 |
+
'provider' => $this->get('auth.provider'),
|
| 286 |
+
'uid' => $this->get('auth.uid'),
|
| 287 |
+
'access_token' => $this->get('auth.credentials.token', null),
|
| 288 |
+
'secret' => $this->get('auth.credentials.secret', null),
|
| 289 |
+
'expires' => $this->get('auth.credentials.expires', null),
|
| 290 |
+
'refresh_token' => $this->get('auth.credentials.refresh_token', null),
|
| 291 |
+
),
|
| 292 |
+
));
|
| 293 |
+
|
| 294 |
+
return 'register';
|
| 295 |
+
}
|
| 296 |
+
}
|
| 297 |
+
}
|
| 298 |
+
|
| 299 |
+
/**
|
| 300 |
+
* create a remote entry for this login
|
| 301 |
+
*/
|
| 302 |
+
public function link_provider(array $data)
|
| 303 |
+
{
|
| 304 |
+
// do some validation
|
| 305 |
+
if ( ! is_numeric($data['expires']))
|
| 306 |
+
{
|
| 307 |
+
if ($date = \DateTime::createFromFormat(\DateTime::ISO8601, $data['expires']))
|
| 308 |
+
{
|
| 309 |
+
$data['expires'] = $date->getTimestamp();
|
| 310 |
+
}
|
| 311 |
+
elseif ($date = \DateTime::createFromFormat('Y-m-d H:i:s', $data['expires']))
|
| 312 |
+
{
|
| 313 |
+
$data['expires'] = $date->getTimestamp();
|
| 314 |
+
}
|
| 315 |
+
else
|
| 316 |
+
{
|
| 317 |
+
$data['expires'] = time();
|
| 318 |
+
}
|
| 319 |
+
}
|
| 320 |
+
|
| 321 |
+
// get rid of old registrations to prevent duplicates
|
| 322 |
+
\DB::delete($this->config['table'])->where('uid', '=', $data['uid'])->where('provider', '=', $data['provider'])->execute();
|
| 323 |
+
|
| 324 |
+
// insert the new provider UID
|
| 325 |
+
list($insert_id, $rows_affected) = \DB::insert($this->config['table'])->set($data)->execute();
|
| 326 |
+
return $rows_affected ? $insert_id : false;
|
| 327 |
+
}
|
| 328 |
+
|
| 329 |
+
/**
|
| 330 |
+
* Get a response value
|
| 331 |
+
*/
|
| 332 |
+
public function get($key, $default = null)
|
| 333 |
+
{
|
| 334 |
+
return is_array($this->response) ? \Arr::get($this->response, $key, $default) : $default;
|
| 335 |
+
}
|
| 336 |
+
|
| 337 |
+
/**
|
| 338 |
+
* fetch the callback response
|
| 339 |
+
*/
|
| 340 |
+
protected function callback()
|
| 341 |
+
{
|
| 342 |
+
// fetch the response and decode it
|
| 343 |
+
$this->response = \Input::get('opauth', false) and $this->response = unserialize(base64_decode($this->response));
|
| 344 |
+
|
| 345 |
+
// did we receive a response at all?
|
| 346 |
+
if ( ! $this->response)
|
| 347 |
+
{
|
| 348 |
+
throw new \OpauthException('no valid response received in the callback');
|
| 349 |
+
}
|
| 350 |
+
|
| 351 |
+
// did we receive one, but was it an error
|
| 352 |
+
if (array_key_exists('error', $this->response))
|
| 353 |
+
{
|
| 354 |
+
throw new \OpauthException('Authentication error: the callback returned an error auth response');
|
| 355 |
+
}
|
| 356 |
+
|
| 357 |
+
// validate the response
|
| 358 |
+
if ($this->get('auth') === null or $this->get('timestamp') === null or
|
| 359 |
+
$this->get('signature') === null or $this->get('auth.provider') === null or $this->get('auth.uid') === null)
|
| 360 |
+
{
|
| 361 |
+
throw new \OpauthException('Invalid auth response: Missing key auth response components');
|
| 362 |
+
}
|
| 363 |
+
elseif ( ! $this->opauth->validate(sha1(print_r($this->get('auth'), true)), $this->get('timestamp'), $this->get('signature'), $reason))
|
| 364 |
+
{
|
| 365 |
+
throw new \OpauthException('Invalid auth response: '.$reason);
|
| 366 |
+
}
|
| 367 |
+
}
|
| 368 |
+
|
| 369 |
+
/**
|
| 370 |
+
* use Auth to create a new user, in case we've received enough information to do so
|
| 371 |
+
*
|
| 372 |
+
* @param array array with the raw Opauth response user fields
|
| 373 |
+
*
|
| 374 |
+
* @return mixed id of the user record created, or false if the create failed
|
| 375 |
+
*/
|
| 376 |
+
protected function create_user(array $user)
|
| 377 |
+
{
|
| 378 |
+
$user_id = \Auth::create_user(
|
| 379 |
+
|
| 380 |
+
// username
|
| 381 |
+
isset($user['nickname']) ? $user['nickname'] : null,
|
| 382 |
+
|
| 383 |
+
// password (random string will do if none provided)
|
| 384 |
+
isset($user['password']) ? $user['password'] : \Str::random(),
|
| 385 |
+
|
| 386 |
+
// email address
|
| 387 |
+
isset($user['email']) ? $user['email'] : null,
|
| 388 |
+
|
| 389 |
+
// which group are they in?
|
| 390 |
+
\Config::get('opauth.default_group', -1),
|
| 391 |
+
|
| 392 |
+
// extra information
|
| 393 |
+
array(
|
| 394 |
+
|
| 395 |
+
// got their name? full name? or first and last to make up a full name?
|
| 396 |
+
'fullname' => isset($user['name']) ? $user['name'] : (
|
| 397 |
+
isset($user['full_name']) ? $user['full_name'] : (
|
| 398 |
+
isset($user['first_name'], $user['last_name']) ? $user['first_name'].' '.$user['last_name'] : null
|
| 399 |
+
)
|
| 400 |
+
),
|
| 401 |
+
)
|
| 402 |
+
);
|
| 403 |
+
|
| 404 |
+
return $user_id ?: false;
|
| 405 |
+
}
|
| 406 |
+
|
| 407 |
+
}
|
benchmark/NYU_CTF_Bench/development/2013/CSAW-Finals/web/historypeats/csaw/fuel/packages/auth/classes/model/auth/group.php
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/**
|
| 3 |
+
* Fuel is a fast, lightweight, community driven PHP5 framework.
|
| 4 |
+
*
|
| 5 |
+
* @package Fuel
|
| 6 |
+
* @version 1.7
|
| 7 |
+
* @author Fuel Development Team
|
| 8 |
+
* @license MIT License
|
| 9 |
+
* @copyright 2010 - 2013 Fuel Development Team
|
| 10 |
+
* @link http://fuelphp.com
|
| 11 |
+
*/
|
| 12 |
+
|
| 13 |
+
namespace Auth\Model;
|
| 14 |
+
|
| 15 |
+
class Auth_Group extends \Orm\Model
|
| 16 |
+
{
|
| 17 |
+
/**
|
| 18 |
+
* @var string connection to use
|
| 19 |
+
*/
|
| 20 |
+
protected static $_connection = null;
|
| 21 |
+
|
| 22 |
+
/**
|
| 23 |
+
* @var string table name to overwrite assumption
|
| 24 |
+
*/
|
| 25 |
+
protected static $_table_name;
|
| 26 |
+
|
| 27 |
+
/**
|
| 28 |
+
* @var array model properties
|
| 29 |
+
*/
|
| 30 |
+
protected static $_properties = array(
|
| 31 |
+
'id',
|
| 32 |
+
'name' => array(
|
| 33 |
+
'label' => 'auth_model_group.name',
|
| 34 |
+
'default' => '',
|
| 35 |
+
'null' => false,
|
| 36 |
+
'validation' => array('required', 'max_length' => array(255))
|
| 37 |
+
),
|
| 38 |
+
'user_id' => array(
|
| 39 |
+
'default' => 0,
|
| 40 |
+
'null' => false,
|
| 41 |
+
'form' => array('type' => false),
|
| 42 |
+
),
|
| 43 |
+
'created_at' => array(
|
| 44 |
+
'default' => 0,
|
| 45 |
+
'null' => false,
|
| 46 |
+
'form' => array('type' => false),
|
| 47 |
+
),
|
| 48 |
+
'updated_at' => array(
|
| 49 |
+
'default' => 0,
|
| 50 |
+
'null' => false,
|
| 51 |
+
'form' => array('type' => false),
|
| 52 |
+
),
|
| 53 |
+
);
|
| 54 |
+
|
| 55 |
+
/**
|
| 56 |
+
* @var array defined observers
|
| 57 |
+
*/
|
| 58 |
+
protected static $_observers = array(
|
| 59 |
+
'Orm\\Observer_CreatedAt' => array(
|
| 60 |
+
'events' => array('before_insert'),
|
| 61 |
+
'property' => 'created_at',
|
| 62 |
+
'mysql_timestamp' => false
|
| 63 |
+
),
|
| 64 |
+
'Orm\\Observer_UpdatedAt' => array(
|
| 65 |
+
'events' => array('before_update'),
|
| 66 |
+
'property' => 'updated_at',
|
| 67 |
+
'mysql_timestamp' => false
|
| 68 |
+
),
|
| 69 |
+
'Orm\\Observer_Typing' => array(
|
| 70 |
+
'events' => array('after_load', 'before_save', 'after_save')
|
| 71 |
+
),
|
| 72 |
+
'Orm\\Observer_Self' => array(
|
| 73 |
+
'events' => array('before_insert', 'before_update'),
|
| 74 |
+
'property' => 'user_id'
|
| 75 |
+
),
|
| 76 |
+
);
|
| 77 |
+
|
| 78 |
+
/**
|
| 79 |
+
* @var array has_many relationships
|
| 80 |
+
*/
|
| 81 |
+
protected static $_has_many = array(
|
| 82 |
+
'users' => array(
|
| 83 |
+
'model_to' => 'Model\\Auth_User',
|
| 84 |
+
'key_from' => 'id',
|
| 85 |
+
'key_to' => 'group_id',
|
| 86 |
+
),
|
| 87 |
+
'grouppermission' => array(
|
| 88 |
+
'model_to' => 'Model\\Auth_Grouppermission',
|
| 89 |
+
'key_from' => 'id',
|
| 90 |
+
'key_to' => 'group_id',
|
| 91 |
+
'cascade_delete' => false,
|
| 92 |
+
),
|
| 93 |
+
);
|
| 94 |
+
|
| 95 |
+
/**
|
| 96 |
+
* @var array many_many relationships
|
| 97 |
+
*/
|
| 98 |
+
protected static $_many_many = array(
|
| 99 |
+
'roles' => array(
|
| 100 |
+
'key_from' => 'id',
|
| 101 |
+
'model_to' => 'Model\\Auth_Role',
|
| 102 |
+
'key_to' => 'id',
|
| 103 |
+
'table_through' => null,
|
| 104 |
+
'key_through_from' => 'group_id',
|
| 105 |
+
'key_through_to' => 'role_id',
|
| 106 |
+
),
|
| 107 |
+
'permissions' => array(
|
| 108 |
+
'key_from' => 'id',
|
| 109 |
+
'model_to' => 'Model\\Auth_Permission',
|
| 110 |
+
'key_to' => 'id',
|
| 111 |
+
'table_through' => null,
|
| 112 |
+
'key_through_from' => 'group_id',
|
| 113 |
+
'key_through_to' => 'perms_id',
|
| 114 |
+
),
|
| 115 |
+
);
|
| 116 |
+
|
| 117 |
+
/**
|
| 118 |
+
* init the class
|
| 119 |
+
*/
|
| 120 |
+
public static function _init()
|
| 121 |
+
{
|
| 122 |
+
// auth config
|
| 123 |
+
\Config::load('ormauth', true);
|
| 124 |
+
|
| 125 |
+
// set the connection this model should use
|
| 126 |
+
static::$_connection = \Config::get('ormauth.db_connection');
|
| 127 |
+
|
| 128 |
+
// set the models table name
|
| 129 |
+
static::$_table_name = \Config::get('ormauth.table_name', 'users').'_groups';
|
| 130 |
+
|
| 131 |
+
// set the relations through table names
|
| 132 |
+
static::$_many_many['roles']['table_through'] = \Config::get('ormauth.table_name', 'users').'_group_roles';
|
| 133 |
+
static::$_many_many['permissions']['table_through'] = \Config::get('ormauth.table_name', 'users').'_group_permissions';
|
| 134 |
+
|
| 135 |
+
// model language file
|
| 136 |
+
\Lang::load('auth_model_group', true);
|
| 137 |
+
}
|
| 138 |
+
|
| 139 |
+
/**
|
| 140 |
+
* before_insert observer event method
|
| 141 |
+
*/
|
| 142 |
+
public function _event_before_insert()
|
| 143 |
+
{
|
| 144 |
+
// assign the user id that lasted updated this record
|
| 145 |
+
$this->user_id = ($this->user_id = \Auth::get_user_id()) ? $this->user_id[1] : 0;
|
| 146 |
+
}
|
| 147 |
+
|
| 148 |
+
/**
|
| 149 |
+
* before_update observer event method
|
| 150 |
+
*/
|
| 151 |
+
public function _event_before_update()
|
| 152 |
+
{
|
| 153 |
+
$this->_event_before_insert();
|
| 154 |
+
}
|
| 155 |
+
}
|
benchmark/NYU_CTF_Bench/development/2013/CSAW-Finals/web/historypeats/csaw/fuel/packages/auth/classes/model/auth/grouppermission.php
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/**
|
| 3 |
+
* Fuel is a fast, lightweight, community driven PHP5 framework.
|
| 4 |
+
*
|
| 5 |
+
* @package Fuel
|
| 6 |
+
* @version 1.7
|
| 7 |
+
* @author Fuel Development Team
|
| 8 |
+
* @license MIT License
|
| 9 |
+
* @copyright 2010 - 2013 Fuel Development Team
|
| 10 |
+
* @link http://fuelphp.com
|
| 11 |
+
*/
|
| 12 |
+
|
| 13 |
+
namespace Auth\Model;
|
| 14 |
+
|
| 15 |
+
class Auth_Grouppermission extends \Orm\Model
|
| 16 |
+
{
|
| 17 |
+
/**
|
| 18 |
+
* @var string connection to use
|
| 19 |
+
*/
|
| 20 |
+
protected static $_connection = null;
|
| 21 |
+
|
| 22 |
+
/**
|
| 23 |
+
* @var string table name to overwrite assumption
|
| 24 |
+
*/
|
| 25 |
+
protected static $_table_name;
|
| 26 |
+
|
| 27 |
+
/**
|
| 28 |
+
* @var array name or names of the primary keys
|
| 29 |
+
*/
|
| 30 |
+
protected static $_primary_key = array('group_id', 'perms_id');
|
| 31 |
+
|
| 32 |
+
/**
|
| 33 |
+
* @var array model properties
|
| 34 |
+
*/
|
| 35 |
+
protected static $_properties = array(
|
| 36 |
+
'group_id',
|
| 37 |
+
'perms_id',
|
| 38 |
+
'actions' => array(
|
| 39 |
+
'data_type' => 'serialize',
|
| 40 |
+
'default' => array(),
|
| 41 |
+
'null' => false,
|
| 42 |
+
'form' => array('type' => false),
|
| 43 |
+
),
|
| 44 |
+
);
|
| 45 |
+
|
| 46 |
+
/**
|
| 47 |
+
* @var array defined observers
|
| 48 |
+
*/
|
| 49 |
+
protected static $_observers = array(
|
| 50 |
+
'Orm\\Observer_Typing' => array(
|
| 51 |
+
'events' => array('after_load', 'before_save', 'after_save')
|
| 52 |
+
),
|
| 53 |
+
);
|
| 54 |
+
|
| 55 |
+
/**
|
| 56 |
+
* @var array belongs_to relationships
|
| 57 |
+
*/
|
| 58 |
+
protected static $_belongs_to = array(
|
| 59 |
+
'group' => array(
|
| 60 |
+
'key_from' => 'group_id',
|
| 61 |
+
'model_to' => 'Model\\Auth_Group',
|
| 62 |
+
'key_to' => 'id',
|
| 63 |
+
),
|
| 64 |
+
'permission' => array(
|
| 65 |
+
'key_from' => 'perms_id',
|
| 66 |
+
'model_to' => 'Model\\Auth_Permission',
|
| 67 |
+
'key_to' => 'id',
|
| 68 |
+
),
|
| 69 |
+
);
|
| 70 |
+
|
| 71 |
+
/**
|
| 72 |
+
* init the class
|
| 73 |
+
*/
|
| 74 |
+
public static function _init()
|
| 75 |
+
{
|
| 76 |
+
// auth config
|
| 77 |
+
\Config::load('ormauth', true);
|
| 78 |
+
|
| 79 |
+
// set the connection this model should use
|
| 80 |
+
static::$_connection = \Config::get('ormauth.db_connection');
|
| 81 |
+
|
| 82 |
+
// set the models table name
|
| 83 |
+
static::$_table_name = \Config::get('ormauth.table_name', 'users').'_group_permissions';
|
| 84 |
+
}
|
| 85 |
+
}
|
benchmark/NYU_CTF_Bench/development/2013/CSAW-Finals/web/historypeats/csaw/fuel/packages/auth/classes/model/auth/metadata.php
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/**
|
| 3 |
+
* Fuel is a fast, lightweight, community driven PHP5 framework.
|
| 4 |
+
*
|
| 5 |
+
* @package Fuel
|
| 6 |
+
* @version 1.7
|
| 7 |
+
* @author Fuel Development Team
|
| 8 |
+
* @license MIT License
|
| 9 |
+
* @copyright 2010 - 2013 Fuel Development Team
|
| 10 |
+
* @link http://fuelphp.com
|
| 11 |
+
*/
|
| 12 |
+
|
| 13 |
+
namespace Auth\Model;
|
| 14 |
+
|
| 15 |
+
class Auth_Metadata extends \Orm\Model
|
| 16 |
+
{
|
| 17 |
+
/**
|
| 18 |
+
* @var string connection to use
|
| 19 |
+
*/
|
| 20 |
+
protected static $_connection = null;
|
| 21 |
+
|
| 22 |
+
/**
|
| 23 |
+
* @var string table name to overwrite assumption
|
| 24 |
+
*/
|
| 25 |
+
protected static $_table_name;
|
| 26 |
+
|
| 27 |
+
/**
|
| 28 |
+
* @var array model properties
|
| 29 |
+
*/
|
| 30 |
+
protected static $_properties = array(
|
| 31 |
+
'id',
|
| 32 |
+
'parent_id',
|
| 33 |
+
'key',
|
| 34 |
+
'value',
|
| 35 |
+
'user_id' => array(
|
| 36 |
+
'default' => 0,
|
| 37 |
+
'null' => false,
|
| 38 |
+
'form' => array('type' => false),
|
| 39 |
+
),
|
| 40 |
+
'created_at' => array(
|
| 41 |
+
'default' => 0,
|
| 42 |
+
'null' => false,
|
| 43 |
+
'form' => array('type' => false),
|
| 44 |
+
),
|
| 45 |
+
'updated_at' => array(
|
| 46 |
+
'default' => 0,
|
| 47 |
+
'null' => false,
|
| 48 |
+
'form' => array('type' => false),
|
| 49 |
+
),
|
| 50 |
+
);
|
| 51 |
+
|
| 52 |
+
/**
|
| 53 |
+
* @var array defined observers
|
| 54 |
+
*/
|
| 55 |
+
protected static $_observers = array(
|
| 56 |
+
'Orm\\Observer_CreatedAt' => array(
|
| 57 |
+
'events' => array('before_insert'),
|
| 58 |
+
'property' => 'created_at',
|
| 59 |
+
'mysql_timestamp' => false
|
| 60 |
+
),
|
| 61 |
+
'Orm\\Observer_UpdatedAt' => array(
|
| 62 |
+
'events' => array('before_update'),
|
| 63 |
+
'property' => 'updated_at',
|
| 64 |
+
'mysql_timestamp' => false
|
| 65 |
+
),
|
| 66 |
+
'Orm\\Observer_Typing' => array(
|
| 67 |
+
'events' => array('after_load', 'before_save', 'after_save')
|
| 68 |
+
),
|
| 69 |
+
'Orm\\Observer_Self' => array(
|
| 70 |
+
'events' => array('before_insert', 'before_update'),
|
| 71 |
+
'property' => 'user_id'
|
| 72 |
+
),
|
| 73 |
+
);
|
| 74 |
+
|
| 75 |
+
/**
|
| 76 |
+
* @var array belongs_to relationships
|
| 77 |
+
*/
|
| 78 |
+
protected static $_belongs_to = array(
|
| 79 |
+
'user' => array(
|
| 80 |
+
'model_to' => 'Model\\Auth_User',
|
| 81 |
+
'key_from' => 'parent_id',
|
| 82 |
+
'key_to' => 'id',
|
| 83 |
+
),
|
| 84 |
+
);
|
| 85 |
+
|
| 86 |
+
/**
|
| 87 |
+
* init the class
|
| 88 |
+
*/
|
| 89 |
+
public static function _init()
|
| 90 |
+
{
|
| 91 |
+
// auth config
|
| 92 |
+
\Config::load('ormauth', true);
|
| 93 |
+
|
| 94 |
+
// set the connection this model should use
|
| 95 |
+
static::$_connection = \Config::get('ormauth.db_connection');
|
| 96 |
+
|
| 97 |
+
// set the models table name
|
| 98 |
+
static::$_table_name = \Config::get('ormauth.table_name', 'users').'_metadata';
|
| 99 |
+
}
|
| 100 |
+
|
| 101 |
+
/**
|
| 102 |
+
* before_insert observer event method
|
| 103 |
+
*/
|
| 104 |
+
public function _event_before_insert()
|
| 105 |
+
{
|
| 106 |
+
// assign the user id that lasted updated this record
|
| 107 |
+
$this->user_id = ($this->user_id = \Auth::get_user_id()) ? $this->user_id[1] : 0;
|
| 108 |
+
}
|
| 109 |
+
|
| 110 |
+
/**
|
| 111 |
+
* before_update observer event method
|
| 112 |
+
*/
|
| 113 |
+
public function _event_before_update()
|
| 114 |
+
{
|
| 115 |
+
$this->_event_before_insert();
|
| 116 |
+
}
|
| 117 |
+
}
|
benchmark/NYU_CTF_Bench/development/2013/CSAW-Finals/web/historypeats/csaw/fuel/packages/auth/classes/model/auth/permission.php
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/**
|
| 3 |
+
* Fuel is a fast, lightweight, community driven PHP5 framework.
|
| 4 |
+
*
|
| 5 |
+
* @package Fuel
|
| 6 |
+
* @version 1.7
|
| 7 |
+
* @author Fuel Development Team
|
| 8 |
+
* @license MIT License
|
| 9 |
+
* @copyright 2010 - 2013 Fuel Development Team
|
| 10 |
+
* @link http://fuelphp.com
|
| 11 |
+
*/
|
| 12 |
+
|
| 13 |
+
namespace Auth\Model;
|
| 14 |
+
|
| 15 |
+
class Auth_Permission extends \Orm\Model
|
| 16 |
+
{
|
| 17 |
+
/**
|
| 18 |
+
* @var string connection to use
|
| 19 |
+
*/
|
| 20 |
+
protected static $_connection = null;
|
| 21 |
+
|
| 22 |
+
/**
|
| 23 |
+
* @var string table name to overwrite assumption
|
| 24 |
+
*/
|
| 25 |
+
protected static $_table_name;
|
| 26 |
+
|
| 27 |
+
/**
|
| 28 |
+
* @var array model properties
|
| 29 |
+
*/
|
| 30 |
+
protected static $_properties = array(
|
| 31 |
+
'id',
|
| 32 |
+
'area' => array(
|
| 33 |
+
'label' => 'auth_model_permission.area',
|
| 34 |
+
'null' => false,
|
| 35 |
+
'validation' => array('required', 'max_length' => array(25))
|
| 36 |
+
),
|
| 37 |
+
'permission' => array(
|
| 38 |
+
'label' => 'auth_model_permission.permission',
|
| 39 |
+
'null' => false,
|
| 40 |
+
'validation' => array('required', 'max_length' => array(25))
|
| 41 |
+
),
|
| 42 |
+
'description' => array(
|
| 43 |
+
'label' => 'auth_model_permission.description',
|
| 44 |
+
'null' => false,
|
| 45 |
+
'validation' => array('required', 'max_length' => array(255))
|
| 46 |
+
),
|
| 47 |
+
'actions' => array(
|
| 48 |
+
'data_type' => 'serialize',
|
| 49 |
+
'default' => array(),
|
| 50 |
+
'null' => false,
|
| 51 |
+
'form' => array('type' => false),
|
| 52 |
+
),
|
| 53 |
+
'user_id' => array(
|
| 54 |
+
'default' => 0,
|
| 55 |
+
'null' => false,
|
| 56 |
+
'form' => array('type' => false),
|
| 57 |
+
),
|
| 58 |
+
'created_at' => array(
|
| 59 |
+
'default' => 0,
|
| 60 |
+
'null' => false,
|
| 61 |
+
'form' => array('type' => false),
|
| 62 |
+
),
|
| 63 |
+
'updated_at' => array(
|
| 64 |
+
'default' => 0,
|
| 65 |
+
'null' => false,
|
| 66 |
+
'form' => array('type' => false),
|
| 67 |
+
),
|
| 68 |
+
);
|
| 69 |
+
|
| 70 |
+
/**
|
| 71 |
+
* @var array defined observers
|
| 72 |
+
*/
|
| 73 |
+
protected static $_observers = array(
|
| 74 |
+
'Orm\\Observer_CreatedAt' => array(
|
| 75 |
+
'events' => array('before_insert'),
|
| 76 |
+
'property' => 'created_at',
|
| 77 |
+
'mysql_timestamp' => false
|
| 78 |
+
),
|
| 79 |
+
'Orm\\Observer_UpdatedAt' => array(
|
| 80 |
+
'events' => array('before_update'),
|
| 81 |
+
'property' => 'updated_at',
|
| 82 |
+
'mysql_timestamp' => false
|
| 83 |
+
),
|
| 84 |
+
'Orm\\Observer_Typing' => array(
|
| 85 |
+
'events' => array('after_load', 'before_save', 'after_save')
|
| 86 |
+
),
|
| 87 |
+
'Orm\\Observer_Self' => array(
|
| 88 |
+
'events' => array('before_insert', 'before_update'),
|
| 89 |
+
'property' => 'user_id'
|
| 90 |
+
),
|
| 91 |
+
);
|
| 92 |
+
|
| 93 |
+
/**
|
| 94 |
+
* @var array many_many relationships
|
| 95 |
+
*/
|
| 96 |
+
protected static $_many_many = array(
|
| 97 |
+
'users' => array(
|
| 98 |
+
'key_from' => 'id',
|
| 99 |
+
'model_to' => 'Model\\Auth_User',
|
| 100 |
+
'key_to' => 'id',
|
| 101 |
+
'table_through' => null,
|
| 102 |
+
'key_through_from' => 'perms_id',
|
| 103 |
+
'key_through_to' => 'user_id',
|
| 104 |
+
),
|
| 105 |
+
'groups' => array(
|
| 106 |
+
'key_from' => 'id',
|
| 107 |
+
'model_to' => 'Model\\Auth_Group',
|
| 108 |
+
'key_to' => 'id',
|
| 109 |
+
'table_through' => null,
|
| 110 |
+
'key_through_from' => 'perms_id',
|
| 111 |
+
'key_through_to' => 'group_id',
|
| 112 |
+
),
|
| 113 |
+
'roles' => array(
|
| 114 |
+
'key_from' => 'id',
|
| 115 |
+
'model_to' => 'Model\\Auth_Role',
|
| 116 |
+
'key_to' => 'id',
|
| 117 |
+
'table_through' => null,
|
| 118 |
+
'key_through_from' => 'perms_id',
|
| 119 |
+
'key_through_to' => 'role_id',
|
| 120 |
+
),
|
| 121 |
+
);
|
| 122 |
+
|
| 123 |
+
/**
|
| 124 |
+
* init the class
|
| 125 |
+
*/
|
| 126 |
+
public static function _init()
|
| 127 |
+
{
|
| 128 |
+
// auth config
|
| 129 |
+
\Config::load('ormauth', true);
|
| 130 |
+
|
| 131 |
+
// set the connection this model should use
|
| 132 |
+
static::$_connection = \Config::get('ormauth.db_connection');
|
| 133 |
+
|
| 134 |
+
// set the models table name
|
| 135 |
+
static::$_table_name = \Config::get('ormauth.table_name', 'users').'_permissions';
|
| 136 |
+
|
| 137 |
+
// set the relations through table names
|
| 138 |
+
static::$_many_many['users']['table_through'] = \Config::get('ormauth.table_name', 'users').'_user_permissions';
|
| 139 |
+
static::$_many_many['groups']['table_through'] = \Config::get('ormauth.table_name', 'users').'_group_permissions';
|
| 140 |
+
static::$_many_many['roles']['table_through'] = \Config::get('ormauth.table_name', 'users').'_role_permissions';
|
| 141 |
+
|
| 142 |
+
// model language file
|
| 143 |
+
\Lang::load('auth_model_permission', true);
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
/**
|
| 147 |
+
* before_insert observer event method
|
| 148 |
+
*/
|
| 149 |
+
public function _event_before_insert()
|
| 150 |
+
{
|
| 151 |
+
// assign the user id that lasted updated this record
|
| 152 |
+
$this->user_id = ($this->user_id = \Auth::get_user_id()) ? $this->user_id[1] : 0;
|
| 153 |
+
}
|
| 154 |
+
|
| 155 |
+
/**
|
| 156 |
+
* before_update observer event method
|
| 157 |
+
*/
|
| 158 |
+
public function _event_before_update()
|
| 159 |
+
{
|
| 160 |
+
$this->_event_before_insert();
|
| 161 |
+
}
|
| 162 |
+
}
|
benchmark/NYU_CTF_Bench/development/2013/CSAW-Finals/web/historypeats/csaw/fuel/packages/auth/classes/model/auth/role.php
ADDED
|
@@ -0,0 +1,172 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/**
|
| 3 |
+
* Fuel is a fast, lightweight, community driven PHP5 framework.
|
| 4 |
+
*
|
| 5 |
+
* @package Fuel
|
| 6 |
+
* @version 1.7
|
| 7 |
+
* @author Fuel Development Team
|
| 8 |
+
* @license MIT License
|
| 9 |
+
* @copyright 2010 - 2013 Fuel Development Team
|
| 10 |
+
* @link http://fuelphp.com
|
| 11 |
+
*/
|
| 12 |
+
|
| 13 |
+
namespace Auth\Model;
|
| 14 |
+
|
| 15 |
+
class Auth_Role extends \Orm\Model
|
| 16 |
+
{
|
| 17 |
+
/**
|
| 18 |
+
* @var string connection to use
|
| 19 |
+
*/
|
| 20 |
+
protected static $_connection = null;
|
| 21 |
+
|
| 22 |
+
/**
|
| 23 |
+
* @var string table name to overwrite assumption
|
| 24 |
+
*/
|
| 25 |
+
protected static $_table_name;
|
| 26 |
+
|
| 27 |
+
/**
|
| 28 |
+
* @var array model properties
|
| 29 |
+
*/
|
| 30 |
+
protected static $_properties = array(
|
| 31 |
+
'id',
|
| 32 |
+
'name' => array(
|
| 33 |
+
'label' => 'auth_model_role.name',
|
| 34 |
+
'default' => 0,
|
| 35 |
+
'null' => false,
|
| 36 |
+
'validation' => array('required', 'max_length' => array(255))
|
| 37 |
+
),
|
| 38 |
+
'filter' => array(
|
| 39 |
+
'label' => 'auth_model_role.filter',
|
| 40 |
+
'data_type' => 'enum',
|
| 41 |
+
'options' => array('', 'A', 'D', 'R'),
|
| 42 |
+
'default' => 0,
|
| 43 |
+
'null' => false,
|
| 44 |
+
'form' => array('type' => 'select'),
|
| 45 |
+
'validation' => array(),
|
| 46 |
+
'default' => '',
|
| 47 |
+
),
|
| 48 |
+
'user_id' => array(
|
| 49 |
+
'default' => 0,
|
| 50 |
+
'null' => false,
|
| 51 |
+
'form' => array('type' => false),
|
| 52 |
+
),
|
| 53 |
+
'created_at' => array(
|
| 54 |
+
'default' => 0,
|
| 55 |
+
'null' => false,
|
| 56 |
+
'form' => array('type' => false),
|
| 57 |
+
),
|
| 58 |
+
'updated_at' => array(
|
| 59 |
+
'default' => 0,
|
| 60 |
+
'null' => false,
|
| 61 |
+
'form' => array('type' => false),
|
| 62 |
+
),
|
| 63 |
+
);
|
| 64 |
+
|
| 65 |
+
/**
|
| 66 |
+
* @var array defined observers
|
| 67 |
+
*/
|
| 68 |
+
protected static $_observers = array(
|
| 69 |
+
'Orm\\Observer_CreatedAt' => array(
|
| 70 |
+
'events' => array('before_insert'),
|
| 71 |
+
'property' => 'created_at',
|
| 72 |
+
'mysql_timestamp' => false
|
| 73 |
+
),
|
| 74 |
+
'Orm\\Observer_UpdatedAt' => array(
|
| 75 |
+
'events' => array('before_update'),
|
| 76 |
+
'property' => 'updated_at',
|
| 77 |
+
'mysql_timestamp' => false
|
| 78 |
+
),
|
| 79 |
+
'Orm\\Observer_Typing' => array(
|
| 80 |
+
'events' => array('after_load', 'before_save', 'after_save')
|
| 81 |
+
),
|
| 82 |
+
'Orm\\Observer_Self' => array(
|
| 83 |
+
'events' => array('before_insert', 'before_update'),
|
| 84 |
+
'property' => 'user_id'
|
| 85 |
+
),
|
| 86 |
+
);
|
| 87 |
+
|
| 88 |
+
/**
|
| 89 |
+
* @var array has_many relationships
|
| 90 |
+
*/
|
| 91 |
+
protected static $_has_many = array(
|
| 92 |
+
'rolepermission' => array(
|
| 93 |
+
'model_to' => 'Model\\Auth_Rolepermission',
|
| 94 |
+
'key_from' => 'id',
|
| 95 |
+
'key_to' => 'role_id',
|
| 96 |
+
'cascade_delete' => false,
|
| 97 |
+
),
|
| 98 |
+
);
|
| 99 |
+
|
| 100 |
+
/**
|
| 101 |
+
* @var array many_many relationships
|
| 102 |
+
*/
|
| 103 |
+
protected static $_many_many = array(
|
| 104 |
+
'users' => array(
|
| 105 |
+
'key_from' => 'id',
|
| 106 |
+
'model_to' => 'Model\\Auth_User',
|
| 107 |
+
'key_to' => 'id',
|
| 108 |
+
'table_through' => null,
|
| 109 |
+
'key_through_from' => 'role_id',
|
| 110 |
+
'key_through_to' => 'user_id',
|
| 111 |
+
),
|
| 112 |
+
'groups' => array(
|
| 113 |
+
'key_from' => 'id',
|
| 114 |
+
'model_to' => 'Model\\Auth_Group',
|
| 115 |
+
'key_to' => 'id',
|
| 116 |
+
'table_through' => null,
|
| 117 |
+
'key_through_from' => 'role_id',
|
| 118 |
+
'key_through_to' => 'group_id',
|
| 119 |
+
),
|
| 120 |
+
'permissions' => array(
|
| 121 |
+
'key_from' => 'id',
|
| 122 |
+
'model_to' => 'Model\\Auth_Permission',
|
| 123 |
+
'key_to' => 'id',
|
| 124 |
+
'table_through' => null,
|
| 125 |
+
'key_through_from' => 'role_id',
|
| 126 |
+
'key_through_to' => 'perms_id',
|
| 127 |
+
),
|
| 128 |
+
);
|
| 129 |
+
|
| 130 |
+
/**
|
| 131 |
+
* init the class
|
| 132 |
+
*/
|
| 133 |
+
public static function _init()
|
| 134 |
+
{
|
| 135 |
+
// auth config
|
| 136 |
+
\Config::load('ormauth', true);
|
| 137 |
+
|
| 138 |
+
// set the connection this model should use
|
| 139 |
+
static::$_connection = \Config::get('ormauth.db_connection');
|
| 140 |
+
|
| 141 |
+
// set the models table name
|
| 142 |
+
static::$_table_name = \Config::get('ormauth.table_name', 'users').'_roles';
|
| 143 |
+
|
| 144 |
+
// set the relations through table names
|
| 145 |
+
static::$_many_many['users']['table_through'] = \Config::get('ormauth.table_name', 'users').'_user_roles';
|
| 146 |
+
static::$_many_many['groups']['table_through'] = \Config::get('ormauth.table_name', 'users').'_group_roles';
|
| 147 |
+
static::$_many_many['permissions']['table_through'] = \Config::get('ormauth.table_name', 'users').'_role_permissions';
|
| 148 |
+
|
| 149 |
+
// model language file
|
| 150 |
+
\Lang::load('auth_model_role', true);
|
| 151 |
+
|
| 152 |
+
// set the filter options from the language file
|
| 153 |
+
static::$_properties['filter']['form']['options'] = \Lang::get('auth_model_role.permissions');
|
| 154 |
+
}
|
| 155 |
+
|
| 156 |
+
/**
|
| 157 |
+
* before_insert observer event method
|
| 158 |
+
*/
|
| 159 |
+
public function _event_before_insert()
|
| 160 |
+
{
|
| 161 |
+
// assign the user id that lasted updated this record
|
| 162 |
+
$this->user_id = ($this->user_id = \Auth::get_user_id()) ? $this->user_id[1] : 0;
|
| 163 |
+
}
|
| 164 |
+
|
| 165 |
+
/**
|
| 166 |
+
* before_update observer event method
|
| 167 |
+
*/
|
| 168 |
+
public function _event_before_update()
|
| 169 |
+
{
|
| 170 |
+
$this->_event_before_insert();
|
| 171 |
+
}
|
| 172 |
+
}
|
benchmark/NYU_CTF_Bench/development/2013/CSAW-Finals/web/historypeats/csaw/fuel/packages/auth/classes/model/auth/rolepermission.php
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/**
|
| 3 |
+
* Fuel is a fast, lightweight, community driven PHP5 framework.
|
| 4 |
+
*
|
| 5 |
+
* @package Fuel
|
| 6 |
+
* @version 1.7
|
| 7 |
+
* @author Fuel Development Team
|
| 8 |
+
* @license MIT License
|
| 9 |
+
* @copyright 2010 - 2013 Fuel Development Team
|
| 10 |
+
* @link http://fuelphp.com
|
| 11 |
+
*/
|
| 12 |
+
|
| 13 |
+
namespace Auth\Model;
|
| 14 |
+
|
| 15 |
+
class Auth_Rolepermission extends \Orm\Model
|
| 16 |
+
{
|
| 17 |
+
/**
|
| 18 |
+
* @var string connection to use
|
| 19 |
+
*/
|
| 20 |
+
protected static $_connection = null;
|
| 21 |
+
|
| 22 |
+
/**
|
| 23 |
+
* @var string table name to overwrite assumption
|
| 24 |
+
*/
|
| 25 |
+
protected static $_table_name;
|
| 26 |
+
|
| 27 |
+
/**
|
| 28 |
+
* @var array name or names of the primary keys
|
| 29 |
+
*/
|
| 30 |
+
protected static $_primary_key = array('role_id', 'perms_id');
|
| 31 |
+
|
| 32 |
+
/**
|
| 33 |
+
* @var array model properties
|
| 34 |
+
*/
|
| 35 |
+
protected static $_properties = array(
|
| 36 |
+
'role_id',
|
| 37 |
+
'perms_id',
|
| 38 |
+
'actions' => array(
|
| 39 |
+
'data_type' => 'serialize',
|
| 40 |
+
'default' => array(),
|
| 41 |
+
'null' => false,
|
| 42 |
+
'form' => array('type' => false),
|
| 43 |
+
),
|
| 44 |
+
);
|
| 45 |
+
|
| 46 |
+
/**
|
| 47 |
+
* @var array defined observers
|
| 48 |
+
*/
|
| 49 |
+
protected static $_observers = array(
|
| 50 |
+
'Orm\\Observer_Typing' => array(
|
| 51 |
+
'events' => array('after_load', 'before_save', 'after_save')
|
| 52 |
+
),
|
| 53 |
+
);
|
| 54 |
+
|
| 55 |
+
/**
|
| 56 |
+
* @var array belongs_to relationships
|
| 57 |
+
*/
|
| 58 |
+
protected static $_belongs_to = array(
|
| 59 |
+
'role' => array(
|
| 60 |
+
'key_from' => 'role_id',
|
| 61 |
+
'model_to' => 'Model\\Auth_Role',
|
| 62 |
+
'key_to' => 'id',
|
| 63 |
+
),
|
| 64 |
+
'permission' => array(
|
| 65 |
+
'key_from' => 'perms_id',
|
| 66 |
+
'model_to' => 'Model\\Auth_Permission',
|
| 67 |
+
'key_to' => 'id',
|
| 68 |
+
),
|
| 69 |
+
);
|
| 70 |
+
|
| 71 |
+
/**
|
| 72 |
+
* init the class
|
| 73 |
+
*/
|
| 74 |
+
public static function _init()
|
| 75 |
+
{
|
| 76 |
+
// auth config
|
| 77 |
+
\Config::load('ormauth', true);
|
| 78 |
+
|
| 79 |
+
// set the connection this model should use
|
| 80 |
+
static::$_connection = \Config::get('ormauth.db_connection');
|
| 81 |
+
|
| 82 |
+
// set the models table name
|
| 83 |
+
static::$_table_name = \Config::get('ormauth.table_name', 'users').'_role_permissions';
|
| 84 |
+
}
|
| 85 |
+
}
|
benchmark/NYU_CTF_Bench/development/2013/CSAW-Finals/web/historypeats/csaw/fuel/packages/auth/classes/model/auth/user.php
ADDED
|
@@ -0,0 +1,205 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/**
|
| 3 |
+
* Fuel is a fast, lightweight, community driven PHP5 framework.
|
| 4 |
+
*
|
| 5 |
+
* @package Fuel
|
| 6 |
+
* @version 1.7
|
| 7 |
+
* @author Fuel Development Team
|
| 8 |
+
* @license MIT License
|
| 9 |
+
* @copyright 2010 - 2013 Fuel Development Team
|
| 10 |
+
* @link http://fuelphp.com
|
| 11 |
+
*/
|
| 12 |
+
|
| 13 |
+
namespace Auth\Model;
|
| 14 |
+
|
| 15 |
+
class Auth_User extends \Orm\Model
|
| 16 |
+
{
|
| 17 |
+
/**
|
| 18 |
+
* @var string connection to use
|
| 19 |
+
*/
|
| 20 |
+
protected static $_connection = null;
|
| 21 |
+
|
| 22 |
+
/**
|
| 23 |
+
* @var string table name to overwrite assumption
|
| 24 |
+
*/
|
| 25 |
+
protected static $_table_name;
|
| 26 |
+
|
| 27 |
+
/**
|
| 28 |
+
* @var array model properties
|
| 29 |
+
*/
|
| 30 |
+
protected static $_properties = array(
|
| 31 |
+
'id',
|
| 32 |
+
'username' => array(
|
| 33 |
+
'label' => 'auth_model_user.name',
|
| 34 |
+
'default' => 0,
|
| 35 |
+
'null' => false,
|
| 36 |
+
'validation' => array('required', 'max_length' => array(255))
|
| 37 |
+
),
|
| 38 |
+
'email' => array(
|
| 39 |
+
'label' => 'auth_model_user.email',
|
| 40 |
+
'default' => 0,
|
| 41 |
+
'null' => false,
|
| 42 |
+
'validation' => array('required', 'valid_email')
|
| 43 |
+
),
|
| 44 |
+
'group_id' => array(
|
| 45 |
+
'label' => 'auth_model_user.group_id',
|
| 46 |
+
'default' => 0,
|
| 47 |
+
'null' => false,
|
| 48 |
+
'form' => array('type' => 'select'),
|
| 49 |
+
'validation' => array('required', 'is_numeric')
|
| 50 |
+
),
|
| 51 |
+
'password' => array(
|
| 52 |
+
'label' => 'auth_model_user.password',
|
| 53 |
+
'default' => 0,
|
| 54 |
+
'null' => false,
|
| 55 |
+
'form' => array('type' => 'password'),
|
| 56 |
+
'validation' => array('min_length' => array(8), 'match_field' => array('confirm'))
|
| 57 |
+
),
|
| 58 |
+
'last_login' => array(
|
| 59 |
+
'form' => array('type' => false),
|
| 60 |
+
),
|
| 61 |
+
'previous_login' => array(
|
| 62 |
+
'form' => array('type' => false),
|
| 63 |
+
),
|
| 64 |
+
'login_hash' => array(
|
| 65 |
+
'form' => array('type' => false),
|
| 66 |
+
),
|
| 67 |
+
'user_id' => array(
|
| 68 |
+
'default' => 0,
|
| 69 |
+
'null' => false,
|
| 70 |
+
'form' => array('type' => false),
|
| 71 |
+
),
|
| 72 |
+
'created_at' => array(
|
| 73 |
+
'default' => 0,
|
| 74 |
+
'null' => false,
|
| 75 |
+
'form' => array('type' => false),
|
| 76 |
+
),
|
| 77 |
+
'updated_at' => array(
|
| 78 |
+
'default' => 0,
|
| 79 |
+
'null' => false,
|
| 80 |
+
'form' => array('type' => false),
|
| 81 |
+
),
|
| 82 |
+
);
|
| 83 |
+
|
| 84 |
+
/**
|
| 85 |
+
* @var array defined observers
|
| 86 |
+
*/
|
| 87 |
+
protected static $_observers = array(
|
| 88 |
+
'Orm\\Observer_CreatedAt' => array(
|
| 89 |
+
'events' => array('before_insert'),
|
| 90 |
+
'property' => 'created_at',
|
| 91 |
+
'mysql_timestamp' => false
|
| 92 |
+
),
|
| 93 |
+
'Orm\\Observer_UpdatedAt' => array(
|
| 94 |
+
'events' => array('before_update'),
|
| 95 |
+
'property' => 'updated_at',
|
| 96 |
+
'mysql_timestamp' => false
|
| 97 |
+
),
|
| 98 |
+
'Orm\\Observer_Typing' => array(
|
| 99 |
+
'events' => array('after_load', 'before_save', 'after_save')
|
| 100 |
+
),
|
| 101 |
+
'Orm\\Observer_Self' => array(
|
| 102 |
+
'events' => array('before_insert', 'before_update'),
|
| 103 |
+
'property' => 'user_id'
|
| 104 |
+
),
|
| 105 |
+
);
|
| 106 |
+
|
| 107 |
+
// EAV container for user metadata
|
| 108 |
+
protected static $_eav = array(
|
| 109 |
+
'metadata' => array(
|
| 110 |
+
'attribute' => 'key',
|
| 111 |
+
'value' => 'value',
|
| 112 |
+
),
|
| 113 |
+
);
|
| 114 |
+
|
| 115 |
+
/**
|
| 116 |
+
* @var array belongs_to relationships
|
| 117 |
+
*/
|
| 118 |
+
protected static $_belongs_to = array(
|
| 119 |
+
'group' => array(
|
| 120 |
+
'model_to' => 'Model\\Auth_Group',
|
| 121 |
+
'key_from' => 'group_id',
|
| 122 |
+
'key_to' => 'id',
|
| 123 |
+
'cascade_delete' => false,
|
| 124 |
+
),
|
| 125 |
+
);
|
| 126 |
+
|
| 127 |
+
/**
|
| 128 |
+
* @var array has_many relationships
|
| 129 |
+
*/
|
| 130 |
+
protected static $_has_many = array(
|
| 131 |
+
'metadata' => array(
|
| 132 |
+
'model_to' => 'Model\\Auth_Metadata',
|
| 133 |
+
'key_from' => 'id',
|
| 134 |
+
'key_to' => 'parent_id',
|
| 135 |
+
'cascade_delete' => true,
|
| 136 |
+
),
|
| 137 |
+
'userpermission' => array(
|
| 138 |
+
'model_to' => 'Model\\Auth_Userpermission',
|
| 139 |
+
'key_from' => 'id',
|
| 140 |
+
'key_to' => 'user_id',
|
| 141 |
+
'cascade_delete' => false,
|
| 142 |
+
),
|
| 143 |
+
);
|
| 144 |
+
|
| 145 |
+
/**
|
| 146 |
+
* @var array many_many relationships
|
| 147 |
+
*/
|
| 148 |
+
protected static $_many_many = array(
|
| 149 |
+
'roles' => array(
|
| 150 |
+
'key_from' => 'id',
|
| 151 |
+
'model_to' => 'Model\\Auth_Role',
|
| 152 |
+
'key_to' => 'id',
|
| 153 |
+
'table_through' => null,
|
| 154 |
+
'key_through_from' => 'user_id',
|
| 155 |
+
'key_through_to' => 'role_id',
|
| 156 |
+
),
|
| 157 |
+
'permissions' => array(
|
| 158 |
+
'key_from' => 'id',
|
| 159 |
+
'model_to' => 'Model\\Auth_Permission',
|
| 160 |
+
'key_to' => 'id',
|
| 161 |
+
'table_through' => null,
|
| 162 |
+
'key_through_from' => 'user_id',
|
| 163 |
+
'key_through_to' => 'perms_id',
|
| 164 |
+
),
|
| 165 |
+
);
|
| 166 |
+
|
| 167 |
+
/**
|
| 168 |
+
* init the class
|
| 169 |
+
*/
|
| 170 |
+
public static function _init()
|
| 171 |
+
{
|
| 172 |
+
// auth config
|
| 173 |
+
\Config::load('ormauth', true);
|
| 174 |
+
|
| 175 |
+
// set the connection this model should use
|
| 176 |
+
static::$_connection = \Config::get('ormauth.db_connection');
|
| 177 |
+
|
| 178 |
+
// set the models table name
|
| 179 |
+
static::$_table_name = \Config::get('ormauth.table_name', 'users');
|
| 180 |
+
|
| 181 |
+
// set the relations through table names
|
| 182 |
+
static::$_many_many['roles']['table_through'] = \Config::get('ormauth.table_name', 'users').'_user_roles';
|
| 183 |
+
static::$_many_many['permissions']['table_through'] = \Config::get('ormauth.table_name', 'users').'_user_permissions';
|
| 184 |
+
|
| 185 |
+
// model language file
|
| 186 |
+
\Lang::load('auth_model_user', true);
|
| 187 |
+
}
|
| 188 |
+
|
| 189 |
+
/**
|
| 190 |
+
* before_insert observer event method
|
| 191 |
+
*/
|
| 192 |
+
public function _event_before_insert()
|
| 193 |
+
{
|
| 194 |
+
// assign the user id that lasted updated this record
|
| 195 |
+
$this->user_id = ($this->user_id = \Auth::get_user_id()) ? $this->user_id[1] : 0;
|
| 196 |
+
}
|
| 197 |
+
|
| 198 |
+
/**
|
| 199 |
+
* before_update observer event method
|
| 200 |
+
*/
|
| 201 |
+
public function _event_before_update()
|
| 202 |
+
{
|
| 203 |
+
$this->_event_before_insert();
|
| 204 |
+
}
|
| 205 |
+
}
|
benchmark/NYU_CTF_Bench/development/2013/CSAW-Finals/web/historypeats/csaw/fuel/packages/auth/classes/model/auth/userpermission.php
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/**
|
| 3 |
+
* Fuel is a fast, lightweight, community driven PHP5 framework.
|
| 4 |
+
*
|
| 5 |
+
* @package Fuel
|
| 6 |
+
* @version 1.7
|
| 7 |
+
* @author Fuel Development Team
|
| 8 |
+
* @license MIT License
|
| 9 |
+
* @copyright 2010 - 2013 Fuel Development Team
|
| 10 |
+
* @link http://fuelphp.com
|
| 11 |
+
*/
|
| 12 |
+
|
| 13 |
+
namespace Auth\Model;
|
| 14 |
+
|
| 15 |
+
class Auth_Userpermission extends \Orm\Model
|
| 16 |
+
{
|
| 17 |
+
/**
|
| 18 |
+
* @var string connection to use
|
| 19 |
+
*/
|
| 20 |
+
protected static $_connection = null;
|
| 21 |
+
|
| 22 |
+
/**
|
| 23 |
+
* @var string table name to overwrite assumption
|
| 24 |
+
*/
|
| 25 |
+
protected static $_table_name;
|
| 26 |
+
|
| 27 |
+
/**
|
| 28 |
+
* @var array name or names of the primary keys
|
| 29 |
+
*/
|
| 30 |
+
protected static $_primary_key = array('user_id', 'perms_id');
|
| 31 |
+
|
| 32 |
+
/**
|
| 33 |
+
* @var array model properties
|
| 34 |
+
*/
|
| 35 |
+
protected static $_properties = array(
|
| 36 |
+
'user_id',
|
| 37 |
+
'perms_id',
|
| 38 |
+
'actions' => array(
|
| 39 |
+
'data_type' => 'serialize',
|
| 40 |
+
'default' => array(),
|
| 41 |
+
'null' => false,
|
| 42 |
+
'form' => array('type' => false),
|
| 43 |
+
),
|
| 44 |
+
);
|
| 45 |
+
|
| 46 |
+
/**
|
| 47 |
+
* @var array defined observers
|
| 48 |
+
*/
|
| 49 |
+
protected static $_observers = array(
|
| 50 |
+
'Orm\\Observer_Typing' => array(
|
| 51 |
+
'events' => array('after_load', 'before_save', 'after_save')
|
| 52 |
+
),
|
| 53 |
+
);
|
| 54 |
+
|
| 55 |
+
/**
|
| 56 |
+
* @var array belongs_to relationships
|
| 57 |
+
*/
|
| 58 |
+
protected static $_belongs_to = array(
|
| 59 |
+
'user' => array(
|
| 60 |
+
'key_from' => 'user_id',
|
| 61 |
+
'model_to' => 'Model\\Auth_User',
|
| 62 |
+
'key_to' => 'id',
|
| 63 |
+
),
|
| 64 |
+
'permission' => array(
|
| 65 |
+
'key_from' => 'perms_id',
|
| 66 |
+
'model_to' => 'Model\\Auth_Permission',
|
| 67 |
+
'key_to' => 'id',
|
| 68 |
+
),
|
| 69 |
+
);
|
| 70 |
+
|
| 71 |
+
/**
|
| 72 |
+
* init the class
|
| 73 |
+
*/
|
| 74 |
+
public static function _init()
|
| 75 |
+
{
|
| 76 |
+
// auth config
|
| 77 |
+
\Config::load('ormauth', true);
|
| 78 |
+
|
| 79 |
+
// set the connection this model should use
|
| 80 |
+
static::$_connection = \Config::get('ormauth.db_connection');
|
| 81 |
+
|
| 82 |
+
// set the models table name
|
| 83 |
+
static::$_table_name = \Config::get('ormauth.table_name', 'users').'_user_permissions';
|
| 84 |
+
}
|
| 85 |
+
}
|
benchmark/NYU_CTF_Bench/development/2013/CSAW-Finals/web/historypeats/csaw/fuel/packages/auth/lang/en/auth_model_group.php
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
|
| 3 |
+
return array(
|
| 4 |
+
'name' => 'Group name',
|
| 5 |
+
);
|
benchmark/NYU_CTF_Bench/development/2013/CSAW-Finals/web/historypeats/csaw/fuel/packages/auth/lang/en/auth_model_permission.php
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
|
| 3 |
+
return array(
|
| 4 |
+
'area' => 'Area name',
|
| 5 |
+
'permission' => 'Permission name',
|
| 6 |
+
'description' => 'Description',
|
| 7 |
+
);
|
benchmark/NYU_CTF_Bench/development/2013/CSAW-Finals/web/historypeats/csaw/fuel/packages/auth/lang/en/auth_model_role.php
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
|
| 3 |
+
return array(
|
| 4 |
+
'name' => 'Role name',
|
| 5 |
+
'filter' => 'Special permissions',
|
| 6 |
+
|
| 7 |
+
'permissions' => array(
|
| 8 |
+
'' => 'None',
|
| 9 |
+
'A' => 'Allow all access',
|
| 10 |
+
'D' => 'Deny all access',
|
| 11 |
+
'R' => 'Revoke assigned permissions',
|
| 12 |
+
),
|
| 13 |
+
);
|
benchmark/NYU_CTF_Bench/development/2013/CSAW-Finals/web/historypeats/csaw/fuel/packages/auth/lang/en/auth_model_user.php
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
|
| 3 |
+
return array(
|
| 4 |
+
'name' => 'User name',
|
| 5 |
+
'email' => 'Email address',
|
| 6 |
+
'password' => 'Password',
|
| 7 |
+
'group_id' => 'Group',
|
| 8 |
+
);
|
benchmark/NYU_CTF_Bench/development/2013/CSAW-Finals/web/historypeats/csaw/fuel/packages/auth/migrations/008_auth_create_providers.php
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
|
| 3 |
+
namespace Fuel\Migrations;
|
| 4 |
+
|
| 5 |
+
class Auth_Create_Providers
|
| 6 |
+
{
|
| 7 |
+
|
| 8 |
+
function up()
|
| 9 |
+
{
|
| 10 |
+
// get the driver used
|
| 11 |
+
\Config::load('auth', true);
|
| 12 |
+
|
| 13 |
+
$drivers = \Config::get('auth.driver', array());
|
| 14 |
+
is_array($drivers) or $drivers = array($drivers);
|
| 15 |
+
|
| 16 |
+
if (in_array('Simpleauth', $drivers))
|
| 17 |
+
{
|
| 18 |
+
// get the tablename
|
| 19 |
+
\Config::load('simpleauth', true);
|
| 20 |
+
$table = \Config::get('simpleauth.table_name', 'users').'_providers';
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
elseif (in_array('Ormauth', $drivers))
|
| 24 |
+
{
|
| 25 |
+
// get the tablename
|
| 26 |
+
\Config::load('ormauth', true);
|
| 27 |
+
$table = \Config::get('ormauth.table_name', 'users').'_providers';
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
if (isset($table))
|
| 31 |
+
{
|
| 32 |
+
\DBUtil::create_table($table, array(
|
| 33 |
+
'id' => array('type' => 'int', 'constraint' => 11, 'auto_increment' => true),
|
| 34 |
+
'parent_id' => array('type' => 'int', 'constraint' => 11, 'default' => 0),
|
| 35 |
+
'provider' => array('type' => 'varchar', 'constraint' => 50),
|
| 36 |
+
'uid' => array('type' => 'varchar', 'constraint' => 255),
|
| 37 |
+
'secret' => array('type' => 'varchar', 'constraint' => 255, 'null' => true),
|
| 38 |
+
'access_token' => array('type' => 'varchar', 'constraint' => 255, 'null' => true),
|
| 39 |
+
'expires' => array( 'type' => 'int', 'constraint' => 12, 'default' => 0, 'null' => true),
|
| 40 |
+
'refresh_token' => array('type' => 'varchar', 'constraint' => 255, 'null' => true),
|
| 41 |
+
'user_id' => array('type' => 'int', 'constraint' => 11, 'default' => 0),
|
| 42 |
+
'created_at' => array('type' => 'int', 'constraint' => 11, 'default' => 0),
|
| 43 |
+
'updated_at' => array('type' => 'int', 'constraint' => 11, 'default' => 0),
|
| 44 |
+
), array('id'));
|
| 45 |
+
|
| 46 |
+
\DBUtil::create_index($table, 'parent_id', 'parent_id');
|
| 47 |
+
}
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
function down()
|
| 51 |
+
{
|
| 52 |
+
// get the driver used
|
| 53 |
+
\Config::load('auth', true);
|
| 54 |
+
|
| 55 |
+
$drivers = \Config::get('auth.driver', array());
|
| 56 |
+
is_array($drivers) or $drivers = array($drivers);
|
| 57 |
+
|
| 58 |
+
if (in_array('Simpleauth', $drivers))
|
| 59 |
+
{
|
| 60 |
+
// get the tablename
|
| 61 |
+
\Config::load('simpleauth', true);
|
| 62 |
+
$table = \Config::get('simpleauth.table_name', 'users').'_providers';
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
elseif (in_array('Ormauth', $drivers))
|
| 66 |
+
{
|
| 67 |
+
// get the tablename
|
| 68 |
+
\Config::load('ormauth', true);
|
| 69 |
+
$table = \Config::get('ormauth.table_name', 'users').'_providers';
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
if (isset($table))
|
| 73 |
+
{
|
| 74 |
+
// drop the users remote table
|
| 75 |
+
\DBUtil::drop_table($table);
|
| 76 |
+
}
|
| 77 |
+
}
|
| 78 |
+
}
|
benchmark/NYU_CTF_Bench/development/2013/CSAW-Finals/web/historypeats/csaw/fuel/packages/auth/migrations/009_auth_create_oauth2tables.php
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
|
| 3 |
+
namespace Fuel\Migrations;
|
| 4 |
+
|
| 5 |
+
class Auth_Create_Oauth2tables
|
| 6 |
+
{
|
| 7 |
+
|
| 8 |
+
function up()
|
| 9 |
+
{
|
| 10 |
+
// get the driver used
|
| 11 |
+
\Config::load('auth', true);
|
| 12 |
+
|
| 13 |
+
$drivers = \Config::get('auth.driver', array());
|
| 14 |
+
is_array($drivers) or $drivers = array($drivers);
|
| 15 |
+
|
| 16 |
+
if (in_array('Simpleauth', $drivers))
|
| 17 |
+
{
|
| 18 |
+
// get the tablename
|
| 19 |
+
\Config::load('simpleauth', true);
|
| 20 |
+
$basetable = \Config::get('simpleauth.table_name', 'users');
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
elseif (in_array('Ormauth', $drivers))
|
| 24 |
+
{
|
| 25 |
+
// get the tablename
|
| 26 |
+
\Config::load('ormauth', true);
|
| 27 |
+
$basetable = \Config::get('ormauth.table_name', 'users');
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
else
|
| 31 |
+
{
|
| 32 |
+
$basetable = 'users';
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
\DBUtil::create_table($basetable.'_clients', array(
|
| 36 |
+
'id' => array('type' => 'int', 'constraint' => 11, 'auto_increment' => true),
|
| 37 |
+
'name' => array('type' => 'varchar', 'constraint' => 32, 'default' => ''),
|
| 38 |
+
'client_id' => array('type' => 'varchar', 'constraint' => 32, 'default' => ''),
|
| 39 |
+
'client_secret' => array('type' => 'varchar', 'constraint' => 32, 'default' => ''),
|
| 40 |
+
'redirect_uri' => array('type' => 'varchar', 'constraint' => 255, 'default' => ''),
|
| 41 |
+
'auto_approve' => array( 'type' => 'tinyint', 'constraint' => 1, 'default' => 0),
|
| 42 |
+
'autonomous' => array( 'type' => 'tinyint', 'constraint' => 1, 'default' => 0),
|
| 43 |
+
'status' => array( 'type' => 'enum', 'constraint' => '"development","pending","approved","rejected"', 'default' => 'development'),
|
| 44 |
+
'suspended' => array( 'type' => 'tinyint', 'constraint' => 1, 'default' => 0),
|
| 45 |
+
'notes' => array('type' => 'tinytext'),
|
| 46 |
+
), array('id'));
|
| 47 |
+
\DBUtil::create_index($basetable.'_clients', 'client_id', 'client_id', 'UNIQUE');
|
| 48 |
+
|
| 49 |
+
\DBUtil::create_table($basetable.'_sessions',
|
| 50 |
+
array(
|
| 51 |
+
'id' => array('type' => 'int', 'constraint' => 11, 'auto_increment' => true),
|
| 52 |
+
'client_id' => array('type' => 'varchar', 'constraint' => 32, 'default' => ''),
|
| 53 |
+
'redirect_uri' => array('type' => 'varchar', 'constraint' => 255, 'default' => ''),
|
| 54 |
+
'type_id' => array('type' => 'varchar', 'constraint' => 64),
|
| 55 |
+
'type' => array( 'type' => 'enum', 'constraint' => '"user","auto"', 'default' => 'user'),
|
| 56 |
+
'code' => array('type' => 'text'),
|
| 57 |
+
'access_token' => array('type' => 'varchar', 'constraint' => 50, 'default' => ''),
|
| 58 |
+
'stage' => array( 'type' => 'enum', 'constraint' => '"request","granted"', 'default' => 'request'),
|
| 59 |
+
'first_requested' => array( 'type' => 'int', 'constraint' => 11),
|
| 60 |
+
'last_updated' => array( 'type' => 'int', 'constraint' => 11),
|
| 61 |
+
'limited_access' => array( 'type' => 'tinyint', 'constraint' => 1, 'default' => 0),
|
| 62 |
+
),
|
| 63 |
+
array('id'),
|
| 64 |
+
true,
|
| 65 |
+
false,
|
| 66 |
+
null,
|
| 67 |
+
array(
|
| 68 |
+
array(
|
| 69 |
+
'constraint' => 'oauth_sessions_ibfk_1',
|
| 70 |
+
'key' => 'client_id',
|
| 71 |
+
'reference' => array(
|
| 72 |
+
'table' => $basetable.'_clients',
|
| 73 |
+
'column' => 'client_id',
|
| 74 |
+
),
|
| 75 |
+
'on_delete' => 'CASCADE',
|
| 76 |
+
),
|
| 77 |
+
)
|
| 78 |
+
);
|
| 79 |
+
|
| 80 |
+
\DBUtil::create_table($basetable.'_scopes', array(
|
| 81 |
+
'id' => array('type' => 'int', 'constraint' => 11, 'auto_increment' => true),
|
| 82 |
+
'scope' => array('type' => 'varchar', 'constraint' => 64, 'default' => ''),
|
| 83 |
+
'name' => array('type' => 'varchar', 'constraint' => 64, 'default' => ''),
|
| 84 |
+
'description' => array('type' => 'varchar', 'constraint' => 255, 'default' => ''),
|
| 85 |
+
), array('id'));
|
| 86 |
+
\DBUtil::create_index($basetable.'_scopes', 'scope', 'scope', 'UNIQUE');
|
| 87 |
+
|
| 88 |
+
\DBUtil::create_table($basetable.'_sessionscopes',
|
| 89 |
+
array(
|
| 90 |
+
'id' => array('type' => 'int', 'constraint' => 11, 'auto_increment' => true),
|
| 91 |
+
'session_id' => array('type' => 'int', 'constraint' => 11),
|
| 92 |
+
'access_token' => array('type' => 'varchar', 'constraint' => 50, 'default' => ''),
|
| 93 |
+
'scope' => array('type' => 'varchar', 'constraint' => 64, 'default' => ''),
|
| 94 |
+
),
|
| 95 |
+
array('id'),
|
| 96 |
+
true,
|
| 97 |
+
false,
|
| 98 |
+
null,
|
| 99 |
+
array(
|
| 100 |
+
array(
|
| 101 |
+
'constraint' => 'oauth_sessionscopes_ibfk_1',
|
| 102 |
+
'key' => 'scope',
|
| 103 |
+
'reference' => array(
|
| 104 |
+
'table' => $basetable.'_scopes',
|
| 105 |
+
'column' => 'scope',
|
| 106 |
+
),
|
| 107 |
+
),
|
| 108 |
+
array(
|
| 109 |
+
'constraint' => 'oauth_sessionscopes_ibfk_2',
|
| 110 |
+
'key' => 'session_id',
|
| 111 |
+
'reference' => array(
|
| 112 |
+
'table' => $basetable.'_sessions',
|
| 113 |
+
'column' => 'id',
|
| 114 |
+
),
|
| 115 |
+
'on_delete' => 'CASCADE',
|
| 116 |
+
),
|
| 117 |
+
)
|
| 118 |
+
);
|
| 119 |
+
\DBUtil::create_index($basetable.'_sessionscopes', 'session_id', 'session_id');
|
| 120 |
+
\DBUtil::create_index($basetable.'_sessionscopes', 'access_token', 'access_token');
|
| 121 |
+
\DBUtil::create_index($basetable.'_sessionscopes', 'scope', 'scope');
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
function down()
|
| 125 |
+
{
|
| 126 |
+
// get the driver used
|
| 127 |
+
\Config::load('auth', true);
|
| 128 |
+
|
| 129 |
+
$drivers = \Config::get('auth.driver', array());
|
| 130 |
+
is_array($drivers) or $drivers = array($drivers);
|
| 131 |
+
|
| 132 |
+
if (in_array('Simpleauth', $drivers))
|
| 133 |
+
{
|
| 134 |
+
// get the tablename
|
| 135 |
+
\Config::load('simpleauth', true);
|
| 136 |
+
$basetable = \Config::get('simpleauth.table_name', 'users');
|
| 137 |
+
}
|
| 138 |
+
|
| 139 |
+
elseif (in_array('Ormauth', $drivers))
|
| 140 |
+
{
|
| 141 |
+
// get the tablename
|
| 142 |
+
\Config::load('ormauth', true);
|
| 143 |
+
$basetable = \Config::get('ormauth.table_name', 'users');
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
else
|
| 147 |
+
{
|
| 148 |
+
$basetable = 'users';
|
| 149 |
+
}
|
| 150 |
+
|
| 151 |
+
\DBUtil::drop_table($basetable.'_sessionscopes');
|
| 152 |
+
\DBUtil::drop_table($basetable.'_sessions');
|
| 153 |
+
\DBUtil::drop_table($basetable.'_scopes');
|
| 154 |
+
\DBUtil::drop_table($basetable.'_clients');
|
| 155 |
+
}
|
| 156 |
+
}
|
benchmark/NYU_CTF_Bench/development/2013/CSAW-Finals/web/historypeats/csaw/fuel/packages/auth/tasks/simple2orm.php
ADDED
|
@@ -0,0 +1,444 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/**
|
| 3 |
+
* Fuel
|
| 4 |
+
*
|
| 5 |
+
* Fuel is a fast, lightweight, community driven PHP5 framework.
|
| 6 |
+
*
|
| 7 |
+
* @package Fuel
|
| 8 |
+
* @version 1.7
|
| 9 |
+
* @author Fuel Development Team
|
| 10 |
+
* @license MIT License
|
| 11 |
+
* @copyright 2010 - 2013 Fuel Development Team
|
| 12 |
+
* @link http://fuelphp.com
|
| 13 |
+
*/
|
| 14 |
+
|
| 15 |
+
namespace Fuel\Tasks;
|
| 16 |
+
|
| 17 |
+
/**
|
| 18 |
+
* Converts a SimpleAuth ruleset to an OrmAuth one
|
| 19 |
+
*/
|
| 20 |
+
class Simple2orm
|
| 21 |
+
{
|
| 22 |
+
/*
|
| 23 |
+
* @var array collected data during validation
|
| 24 |
+
*/
|
| 25 |
+
protected static $data = array();
|
| 26 |
+
|
| 27 |
+
/**
|
| 28 |
+
* Show help.
|
| 29 |
+
*
|
| 30 |
+
* Usage (from command line):
|
| 31 |
+
*
|
| 32 |
+
* php oil refine simple2orm
|
| 33 |
+
*/
|
| 34 |
+
public static function run()
|
| 35 |
+
{
|
| 36 |
+
// fetch the commandline options
|
| 37 |
+
$run_migration = \Cli::option('migrate', \Cli::option('m', false));
|
| 38 |
+
$run_validation = $run_migration ? true : \Cli::option('validate', \Cli::option('v', false));
|
| 39 |
+
|
| 40 |
+
// if no run options are present, show the help
|
| 41 |
+
if ( ! $run_migration and ! $run_validation )
|
| 42 |
+
{
|
| 43 |
+
return static::help();
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
// step 1: run validation
|
| 47 |
+
$validated = true;
|
| 48 |
+
if ($run_validation)
|
| 49 |
+
{
|
| 50 |
+
$validated = static::run_validation();
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
// step 2: run migration
|
| 54 |
+
if ($run_migration)
|
| 55 |
+
{
|
| 56 |
+
if ($validated)
|
| 57 |
+
{
|
| 58 |
+
$migrated = static::run_migration();
|
| 59 |
+
if ($migrated)
|
| 60 |
+
{
|
| 61 |
+
\Cli::write('Migration succesfully finished', 'light_green');
|
| 62 |
+
}
|
| 63 |
+
else
|
| 64 |
+
{
|
| 65 |
+
\Cli::write("\n".'Migration failed. Skipping the remainder of the migration. Please correct the errors and run again.', 'light_red');
|
| 66 |
+
}
|
| 67 |
+
}
|
| 68 |
+
else
|
| 69 |
+
{
|
| 70 |
+
\Cli::write("\n".'Validation failed. Skipping the actual migration. Please correct the errors.', 'light_red');
|
| 71 |
+
}
|
| 72 |
+
}
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
/**
|
| 76 |
+
* Show help.
|
| 77 |
+
*
|
| 78 |
+
* Usage (from command line):
|
| 79 |
+
*
|
| 80 |
+
* php oil refine simple2orm:help
|
| 81 |
+
*/
|
| 82 |
+
public static function help()
|
| 83 |
+
{
|
| 84 |
+
$output = <<<HELP
|
| 85 |
+
|
| 86 |
+
Description:
|
| 87 |
+
The task converts an existing SimpleAuth setup to OrmAuth, migrating
|
| 88 |
+
all configured users, groups, roles and rights.
|
| 89 |
+
|
| 90 |
+
Before using this task, make sure your auth configuration is set to use
|
| 91 |
+
the Ormauth driver, you have an ormauth configuration file, and you have
|
| 92 |
+
run all auth migrations.
|
| 93 |
+
|
| 94 |
+
Runtime options:
|
| 95 |
+
-v, [--validate] # Validate the current installation, do not migrate
|
| 96 |
+
-m, [--migrate] # Run the migration
|
| 97 |
+
|
| 98 |
+
Commands:
|
| 99 |
+
php oil refine simple2orm
|
| 100 |
+
php oil refine simple2orm:help
|
| 101 |
+
php oil refine simple2orm --validate
|
| 102 |
+
php oil refine simple2orm
|
| 103 |
+
|
| 104 |
+
HELP;
|
| 105 |
+
\Cli::write($output);
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
/**
|
| 109 |
+
* Run the environment validation
|
| 110 |
+
*/
|
| 111 |
+
protected static function run_validation()
|
| 112 |
+
{
|
| 113 |
+
// storage for collected errors
|
| 114 |
+
$errors = array();
|
| 115 |
+
|
| 116 |
+
// validate the auth configuration file
|
| 117 |
+
if ( ! is_file($file = APPPATH.'config'.DS.'auth.php'))
|
| 118 |
+
{
|
| 119 |
+
$errors[] = \Fuel::clean_path($file).' does not exist.';
|
| 120 |
+
}
|
| 121 |
+
else
|
| 122 |
+
{
|
| 123 |
+
\Config::load('auth', true);
|
| 124 |
+
if ( ! $driver = \Config::get('auth.driver', false))
|
| 125 |
+
{
|
| 126 |
+
$errors[] = \Fuel::clean_path($file).' does not define an auth driver.';
|
| 127 |
+
}
|
| 128 |
+
elseif ($driver != 'Ormauth')
|
| 129 |
+
{
|
| 130 |
+
$errors[] = \Fuel::clean_path($file).' is not configured to use the Ormauth driver.';
|
| 131 |
+
}
|
| 132 |
+
}
|
| 133 |
+
|
| 134 |
+
// validate the simpleauth configuration file
|
| 135 |
+
if ( ! is_file($file = APPPATH.'config'.DS.'simpleauth.php'))
|
| 136 |
+
{
|
| 137 |
+
$errors[] = \Fuel::clean_path($file).' does not exist.';
|
| 138 |
+
}
|
| 139 |
+
else
|
| 140 |
+
{
|
| 141 |
+
\Config::load('simpleauth', true);
|
| 142 |
+
if ( ! $table = \Config::get('simpleauth.table_name', false))
|
| 143 |
+
{
|
| 144 |
+
$errors[] = \Fuel::clean_path($file).' does not define a user table.';
|
| 145 |
+
}
|
| 146 |
+
elseif ( ! \DBUtil::table_exists($table))
|
| 147 |
+
{
|
| 148 |
+
$errors[] = \Fuel::clean_path($file).' defines a table that does not exist.';
|
| 149 |
+
}
|
| 150 |
+
else
|
| 151 |
+
{
|
| 152 |
+
// store the table name for future use
|
| 153 |
+
static::$data['simpleauth_table'] = $table;
|
| 154 |
+
}
|
| 155 |
+
}
|
| 156 |
+
|
| 157 |
+
// validate the ormauth configuration file
|
| 158 |
+
if ( ! is_file($file = APPPATH.'config'.DS.'ormauth.php'))
|
| 159 |
+
{
|
| 160 |
+
$errors[] = \Fuel::clean_path($file).' does not exist.';
|
| 161 |
+
}
|
| 162 |
+
else
|
| 163 |
+
{
|
| 164 |
+
$config = \Config::load('ormauth', true);
|
| 165 |
+
if ( ! $table = \Config::get('ormauth.table_name', false))
|
| 166 |
+
{
|
| 167 |
+
$errors[] = \Fuel::clean_path($file).' does not define a user table.';
|
| 168 |
+
}
|
| 169 |
+
elseif ( ! \DBUtil::table_exists($table))
|
| 170 |
+
{
|
| 171 |
+
$errors[] = \Fuel::clean_path($file).' defines a table that does not exist.';
|
| 172 |
+
}
|
| 173 |
+
else
|
| 174 |
+
{
|
| 175 |
+
// store the table name for future use
|
| 176 |
+
static::$data['ormauth_table'] = $table;
|
| 177 |
+
}
|
| 178 |
+
|
| 179 |
+
if ( ! $cache_prefix = \Config::get('ormauth.cache_prefix', false) or empty($cache_prefix))
|
| 180 |
+
{
|
| 181 |
+
$errors[] = \Fuel::clean_path($file).' does not define a cache_prefix.';
|
| 182 |
+
}
|
| 183 |
+
else
|
| 184 |
+
{
|
| 185 |
+
// store the cache prefix for future use
|
| 186 |
+
static::$data['cache_prefix'] = $cache_prefix;
|
| 187 |
+
}
|
| 188 |
+
}
|
| 189 |
+
|
| 190 |
+
// check if all migrations have run, and the migration system is consistent
|
| 191 |
+
$migrations = \Config::load('migrations', true);
|
| 192 |
+
if ( ! isset($migrations['version']['package']['auth'][6]))
|
| 193 |
+
{
|
| 194 |
+
$errors[] = 'Auth database migrations haven\'t run (succesfully).';
|
| 195 |
+
}
|
| 196 |
+
else
|
| 197 |
+
{
|
| 198 |
+
$result = \DB::select('*')->from($migrations['table'])->where('type', '=', 'package')->where('name', '=', 'auth')->execute();
|
| 199 |
+
if (count($result) < 7)
|
| 200 |
+
{
|
| 201 |
+
$errors[] = 'Auth database migrations haven\'t run (succesfully).';
|
| 202 |
+
$errors[] = 'There is a discrepancy between your migration configuration file and the migration table.';
|
| 203 |
+
}
|
| 204 |
+
}
|
| 205 |
+
|
| 206 |
+
// check the fields of the users table
|
| 207 |
+
$usertable = array(
|
| 208 |
+
'id' => array('type' => 'int', 'constraint' => 11, 'auto_increment' => true),
|
| 209 |
+
'username' => array('type' => 'varchar', 'constraint' => 50, 'after' => 'id'),
|
| 210 |
+
'password' => array('type' => 'varchar', 'constraint' => 255, 'after' => 'username'),
|
| 211 |
+
'group_id' => array('type' => 'int', 'constraint' => 11, 'default' => 1, 'after' => 'password'),
|
| 212 |
+
'email' => array('type' => 'varchar', 'constraint' => 255, 'after' => 'group_id'),
|
| 213 |
+
'last_login' => array('type' => 'varchar', 'constraint' => 25, 'after' => 'email'),
|
| 214 |
+
'previous_login' => array('type' => 'varchar', 'constraint' => 25, 'default' => 0, 'after' => 'last_login'),
|
| 215 |
+
'login_hash' => array('type' => 'varchar', 'constraint' => 255, 'after' => 'previous_login'),
|
| 216 |
+
'user_id' => array('type' => 'int', 'constraint' => 11, 'default' => 0, 'after' => 'login_hash'),
|
| 217 |
+
'created_at' => array('type' => 'int', 'constraint' => 11, 'default' => 0, 'after' => 'user_id'),
|
| 218 |
+
'updated_at' => array('type' => 'int', 'constraint' => 11, 'default' => 0, 'after' => 'created_at'),
|
| 219 |
+
);
|
| 220 |
+
|
| 221 |
+
foreach ($usertable as $field => $value)
|
| 222 |
+
{
|
| 223 |
+
if (\DBUtil::field_exists(static::$data['ormauth_table'], $field))
|
| 224 |
+
{
|
| 225 |
+
unset($usertable[$field]);
|
| 226 |
+
}
|
| 227 |
+
}
|
| 228 |
+
if ( ! empty($usertable))
|
| 229 |
+
{
|
| 230 |
+
$errors[] = 'User table "'.static::$data['ormauth_table'].'" is missing the field(s): '.implode(', ', array_keys($usertable));
|
| 231 |
+
}
|
| 232 |
+
|
| 233 |
+
// process the results of the validation
|
| 234 |
+
if ($errors)
|
| 235 |
+
{
|
| 236 |
+
// display all errors
|
| 237 |
+
\Cli::write('You environment did not validate:', 'light_red');
|
| 238 |
+
|
| 239 |
+
foreach ($errors as $error)
|
| 240 |
+
{
|
| 241 |
+
\Cli::write('* '.$error);
|
| 242 |
+
}
|
| 243 |
+
|
| 244 |
+
return false;
|
| 245 |
+
}
|
| 246 |
+
|
| 247 |
+
// inform the user we're good to go
|
| 248 |
+
\Cli::write('Environment validated', 'light_green');
|
| 249 |
+
return true;
|
| 250 |
+
}
|
| 251 |
+
|
| 252 |
+
/**
|
| 253 |
+
* Run the actual migration
|
| 254 |
+
*/
|
| 255 |
+
protected static function run_migration()
|
| 256 |
+
{
|
| 257 |
+
// make sure we've got a usertable we can work with
|
| 258 |
+
static::usertable();
|
| 259 |
+
|
| 260 |
+
// get the simpleauth config
|
| 261 |
+
\Config::load('simpleauth', true);
|
| 262 |
+
$simpleauth = \Config::get('simpleauth', array());
|
| 263 |
+
|
| 264 |
+
// process the defined roles
|
| 265 |
+
foreach (\Config::get('simpleauth.roles', array()) as $role => $config)
|
| 266 |
+
{
|
| 267 |
+
// skip all non-standard roles
|
| 268 |
+
if ($role == '#' or ! is_array($config))
|
| 269 |
+
{
|
| 270 |
+
continue;
|
| 271 |
+
}
|
| 272 |
+
|
| 273 |
+
// do we already have this role?
|
| 274 |
+
$result = \DB::select('id')->from(static::$data['ormauth_table'].'_roles')->where('name', '=', $role)->execute();
|
| 275 |
+
if (count($result))
|
| 276 |
+
{
|
| 277 |
+
$role_id = $result[0]['id'];
|
| 278 |
+
}
|
| 279 |
+
|
| 280 |
+
// no, add it
|
| 281 |
+
else
|
| 282 |
+
{
|
| 283 |
+
\Cli::write('- creating role: '.$role, 'light_green');
|
| 284 |
+
list($role_id, $rows_affected) = \DB::insert(static::$data['ormauth_table'].'_roles')->set(array('name' => $role))->execute();
|
| 285 |
+
}
|
| 286 |
+
|
| 287 |
+
// fetch the role as an ORM object, and assign the defined permissions to it
|
| 288 |
+
$role = \Model\Auth_Role::find($role_id);
|
| 289 |
+
if ($role)
|
| 290 |
+
{
|
| 291 |
+
foreach ($config as $area => $permissions)
|
| 292 |
+
{
|
| 293 |
+
foreach ($permissions as $permission)
|
| 294 |
+
{
|
| 295 |
+
$perm = \Model\Auth_Permission::query()->where('area', '=', $area)->where('permission', '=', $permission)->get_one();
|
| 296 |
+
if ( ! $perm)
|
| 297 |
+
{
|
| 298 |
+
\Cli::write('- creating permission: '.$area.'.'.$permission, 'light_green');
|
| 299 |
+
$perm = \Model\Auth_Permission::forge(array('area' => $area, 'permission' => $permission, 'description' => $area.'.'.$permission, 'actions' => serialize(array())));
|
| 300 |
+
}
|
| 301 |
+
$role->permissions[] = $perm;
|
| 302 |
+
}
|
| 303 |
+
}
|
| 304 |
+
|
| 305 |
+
// update the role and save the permissions
|
| 306 |
+
$role->save();
|
| 307 |
+
}
|
| 308 |
+
}
|
| 309 |
+
|
| 310 |
+
// process the defined groups
|
| 311 |
+
foreach (\Config::get('simpleauth.groups', array()) as $group => $config)
|
| 312 |
+
{
|
| 313 |
+
// ignore invalid entries
|
| 314 |
+
if ( ! isset($config['name']) or ! isset($config['roles']))
|
| 315 |
+
{
|
| 316 |
+
continue;
|
| 317 |
+
}
|
| 318 |
+
|
| 319 |
+
// do we already have this group?
|
| 320 |
+
$result = \DB::select('id')->from(static::$data['ormauth_table'].'_groups')->where('name', '=', $config['name'])->execute();
|
| 321 |
+
if (count($result))
|
| 322 |
+
{
|
| 323 |
+
$group_id = $result[0]['id'];
|
| 324 |
+
}
|
| 325 |
+
|
| 326 |
+
// no, add it
|
| 327 |
+
else
|
| 328 |
+
{
|
| 329 |
+
\Cli::write('- creating group: '.$config['name'], 'light_green');
|
| 330 |
+
list($group_id, $rows_affected) = \DB::insert(static::$data['ormauth_table'].'_groups')->set(array('name' => $config['name']))->execute();
|
| 331 |
+
}
|
| 332 |
+
|
| 333 |
+
// update the user group entries
|
| 334 |
+
\DB::update(static::$data['ormauth_table'])->set(array('group_id' => $group_id))->where('group_id', '=', $group)->execute();
|
| 335 |
+
|
| 336 |
+
// fetch the group as an ORM object, and assign the defined roles to it
|
| 337 |
+
$group = \Model\Auth_Group::find($group_id);
|
| 338 |
+
|
| 339 |
+
if ($group)
|
| 340 |
+
{
|
| 341 |
+
foreach ($config['roles'] as $role)
|
| 342 |
+
{
|
| 343 |
+
$role = \Model\Auth_Role::query()->where('name', '=', $role)->get_one();
|
| 344 |
+
if ( ! $role)
|
| 345 |
+
{
|
| 346 |
+
$role = \Model\Auth_Role::forge(array('name' => $role));
|
| 347 |
+
\Cli::write('- creating role: '.$role, 'light_green');
|
| 348 |
+
}
|
| 349 |
+
$group->roles[] = $role;
|
| 350 |
+
}
|
| 351 |
+
|
| 352 |
+
// update the group and save the roles
|
| 353 |
+
$group->save();
|
| 354 |
+
}
|
| 355 |
+
}
|
| 356 |
+
|
| 357 |
+
return true;
|
| 358 |
+
}
|
| 359 |
+
|
| 360 |
+
|
| 361 |
+
/*
|
| 362 |
+
* Deal with potential changes in users table layout between simpleauth and ormauth
|
| 363 |
+
*/
|
| 364 |
+
protected static function usertable()
|
| 365 |
+
{
|
| 366 |
+
if ( ! \DBUtil::table_exists(static::$data['ormauth_table']))
|
| 367 |
+
{
|
| 368 |
+
if ( ! \DBUtil::table_exists(static::$data['simpleauth_table']))
|
| 369 |
+
{
|
| 370 |
+
// table users
|
| 371 |
+
\DBUtil::create_table(static::$data['ormauth_table'], array(
|
| 372 |
+
'id' => array('type' => 'int', 'constraint' => 11, 'auto_increment' => true),
|
| 373 |
+
'username' => array('type' => 'varchar', 'constraint' => 50),
|
| 374 |
+
'password' => array('type' => 'varchar', 'constraint' => 255),
|
| 375 |
+
'group_id' => array('type' => 'int', 'constraint' => 11, 'default' => 1),
|
| 376 |
+
'email' => array('type' => 'varchar', 'constraint' => 255),
|
| 377 |
+
'last_login' => array('type' => 'varchar', 'constraint' => 25),
|
| 378 |
+
'previous_login' => array('type' => 'varchar', 'constraint' => 25, 'default' => 0),
|
| 379 |
+
'login_hash' => array('type' => 'varchar', 'constraint' => 255),
|
| 380 |
+
'user_id' => array('type' => 'int', 'constraint' => 11, 'default' => 0),
|
| 381 |
+
'created_at' => array('type' => 'int', 'constraint' => 11, 'default' => 0),
|
| 382 |
+
'updated_at' => array('type' => 'int', 'constraint' => 11, 'default' => 0),
|
| 383 |
+
), array('id'));
|
| 384 |
+
|
| 385 |
+
// add a unique index on username and email
|
| 386 |
+
\DBUtil::create_index(static::$data['ormauth_table'], array('username', 'email'), 'username', 'UNIQUE');
|
| 387 |
+
}
|
| 388 |
+
else
|
| 389 |
+
{
|
| 390 |
+
\DBUtil::rename_table(static::$data['simpleauth_table'], static::$data['ormauth_table']);
|
| 391 |
+
}
|
| 392 |
+
}
|
| 393 |
+
|
| 394 |
+
// run a check on required fields, and deal with missing ones. we might be migrating from simpleauth
|
| 395 |
+
if (\DBUtil::field_exists(static::$data['ormauth_table'], 'group'))
|
| 396 |
+
{
|
| 397 |
+
\DBUtil::modify_fields(static::$data['ormauth_table'], array(
|
| 398 |
+
'group' => array('name' => 'group_id', 'type' => 'int', 'constraint' => 11),
|
| 399 |
+
));
|
| 400 |
+
}
|
| 401 |
+
if ( ! \DBUtil::field_exists(static::$data['ormauth_table'], 'group_id'))
|
| 402 |
+
{
|
| 403 |
+
\DBUtil::add_fields(static::$data['ormauth_table'], array(
|
| 404 |
+
'group_id' => array('type' => 'int', 'constraint' => 11, 'default' => 1, 'after' => 'password'),
|
| 405 |
+
));
|
| 406 |
+
}
|
| 407 |
+
if ( ! \DBUtil::field_exists(static::$data['ormauth_table'], 'previous_login'))
|
| 408 |
+
{
|
| 409 |
+
\DBUtil::add_fields(static::$data['ormauth_table'], array(
|
| 410 |
+
'previous_login' => array('type' => 'varchar', 'constraint' => 25, 'default' => 0, 'after' => 'last_login'),
|
| 411 |
+
));
|
| 412 |
+
}
|
| 413 |
+
if ( ! \DBUtil::field_exists(static::$data['ormauth_table'], 'user_id'))
|
| 414 |
+
{
|
| 415 |
+
\DBUtil::add_fields(static::$data['ormauth_table'], array(
|
| 416 |
+
'user_id' => array('type' => 'int', 'constraint' => 11, 'default' => 0, 'after' => 'login_hash'),
|
| 417 |
+
));
|
| 418 |
+
}
|
| 419 |
+
if (\DBUtil::field_exists(static::$data['ormauth_table'], 'created'))
|
| 420 |
+
{
|
| 421 |
+
\DBUtil::modify_fields(static::$data['ormauth_table'], array(
|
| 422 |
+
'created' => array('name' => 'created_at', 'type' => 'int', 'constraint' => 11),
|
| 423 |
+
));
|
| 424 |
+
}
|
| 425 |
+
if ( ! \DBUtil::field_exists(static::$data['ormauth_table'], 'created_at'))
|
| 426 |
+
{
|
| 427 |
+
\DBUtil::add_fields(static::$data['ormauth_table'], array(
|
| 428 |
+
'created_at' => array('type' => 'int', 'constraint' => 11, 'default' => 0, 'after' => 'user_id'),
|
| 429 |
+
));
|
| 430 |
+
}
|
| 431 |
+
if (\DBUtil::field_exists(static::$data['ormauth_table'], 'updated'))
|
| 432 |
+
{
|
| 433 |
+
\DBUtil::modify_fields(static::$data['ormauth_table'], array(
|
| 434 |
+
'updated' => array('name' => 'updated_at', 'type' => 'int', 'constraint' => 11),
|
| 435 |
+
));
|
| 436 |
+
}
|
| 437 |
+
if ( ! \DBUtil::field_exists(static::$data['ormauth_table'], 'updated_at'))
|
| 438 |
+
{
|
| 439 |
+
\DBUtil::add_fields(static::$data['ormauth_table'], array(
|
| 440 |
+
'updated_at' => array('type' => 'int', 'constraint' => 11, 'default' => 0, 'after' => 'created_at'),
|
| 441 |
+
));
|
| 442 |
+
}
|
| 443 |
+
}
|
| 444 |
+
}
|