GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — develop ( f6fa23...df8a48 )
by Lonnie
06:13
created
myth/Auth/AuthenticateInterface.php 1 patch
Indentation   +191 added lines, -191 removed lines patch added patch discarded remove patch
@@ -42,196 +42,196 @@
 block discarded – undo
42 42
  */
43 43
 interface AuthenticateInterface {
44 44
 
45
-    /**
46
-     * Attempt to log a user into the system.
47
-     *
48
-     * $credentials is an array of key/value pairs needed to log the user in.
49
-     * This is often email/password, or username/password.
50
-     *
51
-     * @param $credentials
52
-     * @param bool $remember
53
-     */
54
-    public function login($credentials, $remember=false);
55
-
56
-    //--------------------------------------------------------------------
57
-
58
-    /**
59
-     * Validates user login information without logging them in.
60
-     *
61
-     * $credentials is an array of key/value pairs needed to log the user in.
62
-     * This is often email/password, or username/password.
63
-     *
64
-     * @param $credentials
65
-     * @param bool $return_user
66
-     * @return mixed
67
-     */
68
-    public function validate($credentials, $return_user=false);
69
-
70
-    //--------------------------------------------------------------------
71
-
72
-    /**
73
-     * Logs a user out and removes all session information.
74
-     *
75
-     * @return mixed
76
-     */
77
-    public function logout();
78
-
79
-    //--------------------------------------------------------------------
80
-
81
-    /**
82
-     * Checks whether a user is logged in or not.
83
-     *
84
-     * @return bool
85
-     */
86
-    public function isLoggedIn();
87
-
88
-    //--------------------------------------------------------------------
89
-
90
-    /**
91
-     * Attempts to log a user in based on the "remember me" cookie.
92
-     *
93
-     * @return bool
94
-     */
95
-    public function viaRemember();
96
-
97
-    //--------------------------------------------------------------------
98
-
99
-    /**
100
-     * Registers a new user and handles activation method.
101
-     *
102
-     * @param $user_data
103
-     * @return bool
104
-     */
105
-    public function registerUser($user_data);
106
-
107
-    //--------------------------------------------------------------------
108
-
109
-    /**
110
-     * Used to verify the user values and activate a user so they can
111
-     * visit the site.
112
-     *
113
-     * @param $data
114
-     * @return bool
115
-     */
116
-    public function activateUser($data);
117
-
118
-    //--------------------------------------------------------------------
119
-
120
-    /**
121
-     * Used to allow manual activation of a user with a known ID.
122
-     *
123
-     * @param $id
124
-     * @return bool
125
-     */
126
-    public function activateUserById($id);
127
-
128
-    //--------------------------------------------------------------------
129
-
130
-    /**
131
-     * Grabs the current user object. Returns NULL if nothing found.
132
-     *
133
-     * @return array|null
134
-     */
135
-    public function user();
136
-
137
-    //--------------------------------------------------------------------
138
-
139
-    /**
140
-     * A convenience method to grab the current user's ID.
141
-     *
142
-     * @return int|null
143
-     */
144
-    public function id();
145
-
146
-    //--------------------------------------------------------------------
147
-
148
-    /**
149
-     * Tells the system to start throttling a user. This may vary by implementation,
150
-     * but will often add additional time before another login is allowed.
151
-     *
152
-     * @param $email
153
-     * @return mixed
154
-     */
155
-    public function isThrottled($email);
156
-
157
-    //--------------------------------------------------------------------
158
-
159
-    /**
160
-     * Sends a password reminder email to the user associated with
161
-     * the passed in $email.
162
-     *
163
-     * @param $email
164
-     * @return mixed
165
-     */
166
-    public function remindUser($email);
167
-
168
-    //--------------------------------------------------------------------
169
-
170
-    /**
171
-     * Validates the credentials provided and, if valid, resets the password.
172
-     *
173
-     * @param $credentials
174
-     * @param $password
175
-     * @param $passConfirm
176
-     * @return mixed
177
-     */
178
-    public function resetPassword($credentials, $password, $passConfirm);
179
-
180
-    //--------------------------------------------------------------------
181
-
182
-    /**
183
-     * Provides a way for implementations to allow new statuses to be set
184
-     * on the user. The details will vary based upon implementation, but
185
-     * will often allow for banning or suspending users.
186
-     *
187
-     * @param $newStatus
188
-     * @param null $message
189
-     * @return mixed
190
-     */
191
-    public function changeStatus($newStatus, $message=null);
192
-
193
-    //--------------------------------------------------------------------
194
-
195
-    /**
196
-     * Allows the consuming application to pass in a reference to the
197
-     * model that should be used.
198
-     *
199
-     * The model MUST extend Myth\Models\CIDbModel.
200
-     *
201
-     * @param $model
202
-     * @return mixed
203
-     */
204
-    public function useModel($model);
205
-
206
-    //--------------------------------------------------------------------
207
-
208
-    /**
209
-     * Returns the current error string.
210
-     *
211
-     * @return mixed
212
-     */
213
-    public function error();
214
-
215
-    //--------------------------------------------------------------------
216
-
217
-    /**
218
-     * Purges all login attempt records from the database.
219
-     *
220
-     * @param $email
221
-     */
222
-    public function purgeLoginAttempts($email);
223
-
224
-    //--------------------------------------------------------------------
225
-
226
-    /**
227
-     * Purges all remember tokens for a single user. Effectively logs
228
-     * a user out of all devices. Intended to allow users to log themselves
229
-     * out of all devices as a security measure.
230
-     *
231
-     * @param $email
232
-     */
233
-    public function purgeRememberTokens($email);
234
-
235
-    //--------------------------------------------------------------------
45
+	/**
46
+	 * Attempt to log a user into the system.
47
+	 *
48
+	 * $credentials is an array of key/value pairs needed to log the user in.
49
+	 * This is often email/password, or username/password.
50
+	 *
51
+	 * @param $credentials
52
+	 * @param bool $remember
53
+	 */
54
+	public function login($credentials, $remember=false);
55
+
56
+	//--------------------------------------------------------------------
57
+
58
+	/**
59
+	 * Validates user login information without logging them in.
60
+	 *
61
+	 * $credentials is an array of key/value pairs needed to log the user in.
62
+	 * This is often email/password, or username/password.
63
+	 *
64
+	 * @param $credentials
65
+	 * @param bool $return_user
66
+	 * @return mixed
67
+	 */
68
+	public function validate($credentials, $return_user=false);
69
+
70
+	//--------------------------------------------------------------------
71
+
72
+	/**
73
+	 * Logs a user out and removes all session information.
74
+	 *
75
+	 * @return mixed
76
+	 */
77
+	public function logout();
78
+
79
+	//--------------------------------------------------------------------
80
+
81
+	/**
82
+	 * Checks whether a user is logged in or not.
83
+	 *
84
+	 * @return bool
85
+	 */
86
+	public function isLoggedIn();
87
+
88
+	//--------------------------------------------------------------------
89
+
90
+	/**
91
+	 * Attempts to log a user in based on the "remember me" cookie.
92
+	 *
93
+	 * @return bool
94
+	 */
95
+	public function viaRemember();
96
+
97
+	//--------------------------------------------------------------------
98
+
99
+	/**
100
+	 * Registers a new user and handles activation method.
101
+	 *
102
+	 * @param $user_data
103
+	 * @return bool
104
+	 */
105
+	public function registerUser($user_data);
106
+
107
+	//--------------------------------------------------------------------
108
+
109
+	/**
110
+	 * Used to verify the user values and activate a user so they can
111
+	 * visit the site.
112
+	 *
113
+	 * @param $data
114
+	 * @return bool
115
+	 */
116
+	public function activateUser($data);
117
+
118
+	//--------------------------------------------------------------------
119
+
120
+	/**
121
+	 * Used to allow manual activation of a user with a known ID.
122
+	 *
123
+	 * @param $id
124
+	 * @return bool
125
+	 */
126
+	public function activateUserById($id);
127
+
128
+	//--------------------------------------------------------------------
129
+
130
+	/**
131
+	 * Grabs the current user object. Returns NULL if nothing found.
132
+	 *
133
+	 * @return array|null
134
+	 */
135
+	public function user();
136
+
137
+	//--------------------------------------------------------------------
138
+
139
+	/**
140
+	 * A convenience method to grab the current user's ID.
141
+	 *
142
+	 * @return int|null
143
+	 */
144
+	public function id();
145
+
146
+	//--------------------------------------------------------------------
147
+
148
+	/**
149
+	 * Tells the system to start throttling a user. This may vary by implementation,
150
+	 * but will often add additional time before another login is allowed.
151
+	 *
152
+	 * @param $email
153
+	 * @return mixed
154
+	 */
155
+	public function isThrottled($email);
156
+
157
+	//--------------------------------------------------------------------
158
+
159
+	/**
160
+	 * Sends a password reminder email to the user associated with
161
+	 * the passed in $email.
162
+	 *
163
+	 * @param $email
164
+	 * @return mixed
165
+	 */
166
+	public function remindUser($email);
167
+
168
+	//--------------------------------------------------------------------
169
+
170
+	/**
171
+	 * Validates the credentials provided and, if valid, resets the password.
172
+	 *
173
+	 * @param $credentials
174
+	 * @param $password
175
+	 * @param $passConfirm
176
+	 * @return mixed
177
+	 */
178
+	public function resetPassword($credentials, $password, $passConfirm);
179
+
180
+	//--------------------------------------------------------------------
181
+
182
+	/**
183
+	 * Provides a way for implementations to allow new statuses to be set
184
+	 * on the user. The details will vary based upon implementation, but
185
+	 * will often allow for banning or suspending users.
186
+	 *
187
+	 * @param $newStatus
188
+	 * @param null $message
189
+	 * @return mixed
190
+	 */
191
+	public function changeStatus($newStatus, $message=null);
192
+
193
+	//--------------------------------------------------------------------
194
+
195
+	/**
196
+	 * Allows the consuming application to pass in a reference to the
197
+	 * model that should be used.
198
+	 *
199
+	 * The model MUST extend Myth\Models\CIDbModel.
200
+	 *
201
+	 * @param $model
202
+	 * @return mixed
203
+	 */
204
+	public function useModel($model);
205
+
206
+	//--------------------------------------------------------------------
207
+
208
+	/**
209
+	 * Returns the current error string.
210
+	 *
211
+	 * @return mixed
212
+	 */
213
+	public function error();
214
+
215
+	//--------------------------------------------------------------------
216
+
217
+	/**
218
+	 * Purges all login attempt records from the database.
219
+	 *
220
+	 * @param $email
221
+	 */
222
+	public function purgeLoginAttempts($email);
223
+
224
+	//--------------------------------------------------------------------
225
+
226
+	/**
227
+	 * Purges all remember tokens for a single user. Effectively logs
228
+	 * a user out of all devices. Intended to allow users to log themselves
229
+	 * out of all devices as a security measure.
230
+	 *
231
+	 * @param $email
232
+	 */
233
+	public function purgeRememberTokens($email);
234
+
235
+	//--------------------------------------------------------------------
236 236
 
237 237
 }
Please login to merge, or discard this patch.
myth/Auth/Flat/FlatGroupsModel.php 1 patch
Indentation   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -85,10 +85,10 @@  discard block
 block discarded – undo
85 85
 	 */
86 86
 	public function addUserToGroup($user_id, $group_id)
87 87
 	{
88
-	    $data = [
89
-		    'user_id'   => (int)$user_id,
90
-		    'group_id'  => (int)$group_id
91
-	    ];
88
+		$data = [
89
+			'user_id'   => (int)$user_id,
90
+			'group_id'  => (int)$group_id
91
+		];
92 92
 
93 93
 		return $this->db->insert('auth_groups_users', $data);
94 94
 	}
@@ -105,10 +105,10 @@  discard block
 block discarded – undo
105 105
 	 */
106 106
 	public function removeUserFromGroup($user_id, $group_id)
107 107
 	{
108
-	    return $this->where([
109
-		    'user_id' => (int)$user_id,
110
-		    'group_id' => (int)$group_id
111
-	    ])->delete('auth_groups_users');
108
+		return $this->where([
109
+			'user_id' => (int)$user_id,
110
+			'group_id' => (int)$group_id
111
+		])->delete('auth_groups_users');
112 112
 	}
113 113
 
114 114
 	//--------------------------------------------------------------------
@@ -122,8 +122,8 @@  discard block
 block discarded – undo
122 122
 	 */
123 123
 	public function removeUserFromAllGroups($user_id)
124 124
 	{
125
-	    return $this->db->where('user_id', (int)$user_id)
126
-		                ->delete('auth_groups_users');
125
+		return $this->db->where('user_id', (int)$user_id)
126
+						->delete('auth_groups_users');
127 127
 	}
128 128
 
129 129
 	//--------------------------------------------------------------------
@@ -137,11 +137,11 @@  discard block
 block discarded – undo
137 137
 	 */
138 138
 	public function getGroupsForUser($user_id)
139 139
 	{
140
-	    return $this->select('auth_groups_users.*, auth_groups.name, auth_groups.description')
141
-		            ->join('auth_groups_users', 'auth_groups_users.group_id = auth_groups.id', 'left')
142
-		            ->where('user_id', $user_id)
143
-		            ->as_array()
144
-		            ->find_all();
140
+		return $this->select('auth_groups_users.*, auth_groups.name, auth_groups.description')
141
+					->join('auth_groups_users', 'auth_groups_users.group_id = auth_groups.id', 'left')
142
+					->where('user_id', $user_id)
143
+					->as_array()
144
+					->find_all();
145 145
 	}
146 146
 
147 147
 	//--------------------------------------------------------------------
@@ -160,7 +160,7 @@  discard block
 block discarded – undo
160 160
 			'group_id'      => (int)$group_id
161 161
 		];
162 162
 
163
-	    return $this->db->insert('auth_groups_permissions', $data);
163
+		return $this->db->insert('auth_groups_permissions', $data);
164 164
 	}
165 165
 
166 166
 	//--------------------------------------------------------------------
@@ -176,10 +176,10 @@  discard block
 block discarded – undo
176 176
 	 */
177 177
 	public function removePermissionFromGroup($permission_id, $group_id)
178 178
 	{
179
-	    return $this->db->where([
180
-		    'permission_id' => $permission_id,
181
-		    'group_id'      => $group_id
182
-	    ])->delete('auth_groups_permissions');
179
+		return $this->db->where([
180
+			'permission_id' => $permission_id,
181
+			'group_id'      => $group_id
182
+		])->delete('auth_groups_permissions');
183 183
 	}
184 184
 
185 185
 	//--------------------------------------------------------------------
@@ -193,8 +193,8 @@  discard block
 block discarded – undo
193 193
 	 */
194 194
 	public function removePermissionFromAllGroups($permission_id)
195 195
 	{
196
-	    return $this->db->where('permission_id', $permission_id)
197
-		                ->delete('auth_groups_permissions');
196
+		return $this->db->where('permission_id', $permission_id)
197
+						->delete('auth_groups_permissions');
198 198
 	}
199 199
 
200 200
 	//--------------------------------------------------------------------
Please login to merge, or discard this patch.
myth/Auth/Password.php 1 patch
Indentation   +321 added lines, -321 removed lines patch added patch discarded remove patch
@@ -51,325 +51,325 @@
 block discarded – undo
51 51
  */
52 52
 class Password {
53 53
 
54
-    /**
55
-     * A standardized method for hasing a password before storing
56
-     * in the database.
57
-     *
58
-     * @param $password
59
-     * @return bool|mixed|string
60
-     */
61
-    public static function hashPassword($password)
62
-    {
63
-        if (! config_item('auth.hash_cost'))
64
-        {
65
-            get_instance()->load->config('auth');
66
-        }
67
-
68
-        return password_hash($password, PASSWORD_DEFAULT, ['cost' => config_item('auth.hash_cost')]);
69
-    }
70
-
71
-    //--------------------------------------------------------------------
72
-
73
-    /**
74
-     * Determines the number of entropy bits a password has based on
75
-     *
76
-     *
77
-     * @param $password
78
-     * @param bool $repeatcalc
79
-     * @return int
80
-     */
81
-    public static function getNISTNumBits($password, $repeatcalc = false)
82
-    {
83
-        $y = strlen($password);
84
-        if ($repeatcalc)
85
-        {
86
-            // Variant on NIST rules to reduce long sequences of repeated characters.
87
-            $result = 0;
88
-            $charmult = array_fill(0, 256, 1);
89
-            for ($x = 0; $x < $y; $x++)
90
-            {
91
-                $tempchr = ord(substr($password, $x, 1));
92
-                if ($x > 19)  $result += $charmult[$tempchr];
93
-                else if ($x > 7)  $result += $charmult[$tempchr] * 1.5;
94
-                else if ($x > 0)  $result += $charmult[$tempchr] * 2;
95
-                else  $result += 4;
96
-
97
-                $charmult[$tempchr] *= 0.75;
98
-            }
99
-
100
-            return $result;
101
-        }
102
-        else
103
-        {
104
-            if ($y > 20)  return 4 + (7 * 2) + (12 * 1.5) + $y - 20;
105
-            if ($y > 8)  return 4 + (7 * 2) + (($y - 8) * 1.5);
106
-            if ($y > 1)  return 4 + (($y - 1) * 2);
107
-
108
-            return ($y == 1 ? 4 : 0);
109
-        }
110
-    }
111
-
112
-    //--------------------------------------------------------------------
113
-
114
-    /**
115
-     * Determines whether a password is strong enough to use. You should check
116
-     * the password against this method and reject it if the password is not
117
-     * strong enough.
118
-     *
119
-     * The following guidelines come from the author's tests against 10.4 million actual passwords
120
-     * ( see post: http://cubicspot.blogspot.com/2012/01/how-to-calculate-password-strength-part.html )
121
-     * and represents the suggested minimum entropy bits for different types of sites:
122
-     *
123
-     *      - 18 bits of entropy = minimum for ANY website.
124
-     *      - 25 bits of entropy = minimum for a general purpose web service used relatively widely (e.g. Hotmail).
125
-     *      - 30 bits of entropy = minimum for a web service with business critical applications (e.g. SAAS).
126
-     *      - 40 bits of entropy = minimum for a bank or other financial service.
127
-     *
128
-     * The algorithm is based upon a modified version of the NIST rules which suggest the following:
129
-     *
130
-     *      - The first byte counts as 4 bits.
131
-     *      - The next 7 bytes count as 2 bits each.
132
-     *      - The next 12 bytes count as 1.5 bits each.
133
-     *      - Anything beyond that counts as 1 bit each.
134
-     *      - Mixed case + non-alphanumeric = up to 6 extra bits.
135
-     *
136
-     * @param string    $password   - The password to check
137
-     * @param int       $minbits    - Minimum "entropy bits" that is allowed
138
-     * @param bool      $usedict    - Should we check the password against a 300,000 word English dictionary?
139
-     * @param int       $minwordlen -
140
-     * @return bool
141
-     */
142
-    public static function isStrongPassword($password, $minbits = 18, $usedict = false, $minwordlen = 4)
143
-    {
144
-        // NIST password strength rules allow up to 6 extra bits for mixed case and non-alphabetic.
145
-        $upper = false;
146
-        $lower = false;
147
-        $numeric = false;
148
-        $other = false;
149
-        $space = false;
150
-        $y = strlen($password);
151
-        for ($x = 0; $x < $y; $x++)
152
-        {
153
-            $tempchr = ord(substr($password, $x, 1));
154
-            if ($tempchr >= ord("A") && $tempchr <= ord("Z"))  $upper = true;
155
-            else if ($tempchr >= ord("a") && $tempchr <= ord("z"))  $lower = true;
156
-            else if ($tempchr >= ord("0") && $tempchr <= ord("9"))  $numeric = true;
157
-            else if ($tempchr == ord(" "))  $space = true;
158
-            else  $other = true;
159
-        }
160
-        $extrabits = ($upper && $lower && $other ? ($numeric ? 6 : 5) : ($numeric && !$upper && !$lower ? ($other ? -2 : -6) : 0));
161
-        if (!$space)  $extrabits -= 2;
162
-        else if (count(explode(" ", preg_replace('/\s+/', " ", $password))) > 3)  $extrabits++;
163
-        $result = self::getNISTNumBits($password, true) + $extrabits;
164
-
165
-        $password = strtolower($password);
166
-        $revpassword = strrev($password);
167
-        $numbits = self::getNISTNumBits($password) + $extrabits;
168
-        if ($result > $numbits)  $result = $numbits;
169
-
170
-        // Remove QWERTY strings.
171
-        $qwertystrs = array(
172
-            "1234567890-qwertyuiopasdfghjkl;zxcvbnm,./",
173
-            "1qaz2wsx3edc4rfv5tgb6yhn7ujm8ik,9ol.0p;/-['=]:?_{\"+}",
174
-            "1qaz2wsx3edc4rfv5tgb6yhn7ujm8ik9ol0p",
175
-            "qazwsxedcrfvtgbyhnujmik,ol.p;/-['=]:?_{\"+}",
176
-            "qazwsxedcrfvtgbyhnujmikolp",
177
-            "]\"/=[;.-pl,0okm9ijn8uhb7ygv6tfc5rdx4esz3wa2q1",
178
-            "pl0okm9ijn8uhb7ygv6tfc5rdx4esz3wa2q1",
179
-            "]\"/[;.pl,okmijnuhbygvtfcrdxeszwaq",
180
-            "plokmijnuhbygvtfcrdxeszwaq",
181
-            "014725836914702583697894561230258/369*+-*/",
182
-            "abcdefghijklmnopqrstuvwxyz"
183
-        );
184
-        foreach ($qwertystrs as $qwertystr)
185
-        {
186
-            $qpassword = $password;
187
-            $qrevpassword = $revpassword;
188
-            $z = 6;
189
-            do
190
-            {
191
-                $y = strlen($qwertystr) - $z;
192
-                for ($x = 0; $x < $y; $x++)
193
-                {
194
-                    $str = substr($qwertystr, $x, $z);
195
-                    $qpassword = str_replace($str, "*", $qpassword);
196
-                    $qrevpassword = str_replace($str, "*", $qrevpassword);
197
-                }
198
-
199
-                $z--;
200
-            } while ($z > 2);
201
-
202
-            $numbits = self::getNISTNumBits($qpassword) + $extrabits;
203
-            if ($result > $numbits)  $result = $numbits;
204
-            $numbits = self::getNISTNumBits($qrevpassword) + $extrabits;
205
-            if ($result > $numbits)  $result = $numbits;
206
-
207
-            if ($result < $minbits)  return false;
208
-        }
209
-
210
-        if ($usedict && $result >= $minbits)
211
-        {
212
-            $passwords = array();
213
-
214
-            // Add keyboard shifting password variants.
215
-            $keyboardmap_down_noshift = array(
216
-                "z" => "", "x" => "", "c" => "", "v" => "", "b" => "", "n" => "", "m" => "", "," => "", "." => "", "/" => "", "<" => "", ">" => "", "?" => ""
217
-            );
218
-            if ($password == str_replace(array_keys($keyboardmap_down_noshift), array_values($keyboardmap_down_noshift), $password))
219
-            {
220
-                $keyboardmap_downright = array(
221
-                    "a" => "z",
222
-                    "q" => "a",
223
-                    "1" => "q",
224
-                    "s" => "x",
225
-                    "w" => "s",
226
-                    "2" => "w",
227
-                    "d" => "c",
228
-                    "e" => "d",
229
-                    "3" => "e",
230
-                    "f" => "v",
231
-                    "r" => "f",
232
-                    "4" => "r",
233
-                    "g" => "b",
234
-                    "t" => "g",
235
-                    "5" => "t",
236
-                    "h" => "n",
237
-                    "y" => "h",
238
-                    "6" => "y",
239
-                    "j" => "m",
240
-                    "u" => "j",
241
-                    "7" => "u",
242
-                    "i" => "k",
243
-                    "8" => "i",
244
-                    "o" => "l",
245
-                    "9" => "o",
246
-                    "0" => "p",
247
-                );
248
-
249
-                $keyboardmap_downleft = array(
250
-                    "2" => "q",
251
-                    "w" => "a",
252
-                    "3" => "w",
253
-                    "s" => "z",
254
-                    "e" => "s",
255
-                    "4" => "e",
256
-                    "d" => "x",
257
-                    "r" => "d",
258
-                    "5" => "r",
259
-                    "f" => "c",
260
-                    "t" => "f",
261
-                    "6" => "t",
262
-                    "g" => "v",
263
-                    "y" => "g",
264
-                    "7" => "y",
265
-                    "h" => "b",
266
-                    "u" => "h",
267
-                    "8" => "u",
268
-                    "j" => "n",
269
-                    "i" => "j",
270
-                    "9" => "i",
271
-                    "k" => "m",
272
-                    "o" => "k",
273
-                    "0" => "o",
274
-                    "p" => "l",
275
-                    "-" => "p",
276
-                );
277
-
278
-                $password2 = str_replace(array_keys($keyboardmap_downright), array_values($keyboardmap_downright), $password);
279
-                $passwords[] = $password2;
280
-                $passwords[] = strrev($password2);
281
-
282
-                $password2 = str_replace(array_keys($keyboardmap_downleft), array_values($keyboardmap_downleft), $password);
283
-                $passwords[] = $password2;
284
-                $passwords[] = strrev($password2);
285
-            }
286
-
287
-            // Deal with LEET-Speak substitutions.
288
-            $leetspeakmap = array(
289
-                "@" => "a",
290
-                "!" => "i",
291
-                "$" => "s",
292
-                "1" => "i",
293
-                "2" => "z",
294
-                "3" => "e",
295
-                "4" => "a",
296
-                "5" => "s",
297
-                "6" => "g",
298
-                "7" => "t",
299
-                "8" => "b",
300
-                "9" => "g",
301
-                "0" => "o"
302
-            );
303
-
304
-            $password2 = str_replace(array_keys($leetspeakmap), array_values($leetspeakmap), $password);
305
-            $passwords[] = $password2;
306
-            $passwords[] = strrev($password2);
307
-
308
-            $leetspeakmap["1"] = "l";
309
-            $password3 = str_replace(array_keys($leetspeakmap), array_values($leetspeakmap), $password);
310
-            if ($password3 != $password2)
311
-            {
312
-                $passwords[] = $password3;
313
-                $passwords[] = strrev($password3);
314
-            }
315
-
316
-            // Process the password, while looking for words in the dictionary.
317
-            $a = ord("a");
318
-            $z = ord("z");
319
-            $data = file_get_contents(DICTIONARY_PATH);
320
-            foreach ($passwords as $num => $password)
321
-            {
322
-                $y = strlen($password);
323
-                for ($x = 0; $x < $y; $x++)
324
-                {
325
-                    $tempchr = ord(substr($password, $x, 1));
326
-                    if ($tempchr >= $a && $tempchr <= $z)
327
-                    {
328
-                        for ($x2 = $x + 1; $x2 < $y; $x2++)
329
-                        {
330
-                            $tempchr = ord(substr($password, $x2, 1));
331
-                            if ($tempchr < $a || $tempchr > $z)  break;
332
-                        }
333
-
334
-                        $found = false;
335
-                        while (!$found && $x2 - $x >= $minwordlen)
336
-                        {
337
-                            $word = "/\\n" . substr($password, $x, $minwordlen);
338
-                            for ($x3 = $x + $minwordlen; $x3 < $x2; $x3++)  $word .= "(" . $password{$x3};
339
-                            for ($x3 = $x + $minwordlen; $x3 < $x2; $x3++)  $word .= ")?";
340
-                            $word .= "\\n/";
341
-
342
-                            preg_match_all($word, $data, $matches);
343
-                            if (!count($matches[0]))
344
-                            {
345
-                                $password{$x} = "*";
346
-                                $x++;
347
-                                $numbits = self::getNISTNumBits(substr($password, 0, $x)) + $extrabits;
348
-                                if ($numbits >= $minbits)  $found = true;
349
-                            }
350
-                            else
351
-                            {
352
-                                foreach ($matches[0] as $match)
353
-                                {
354
-                                    $password2 = str_replace(trim($match), "*", $password);
355
-                                    $numbits = self::getNISTNumBits($password2) + $extrabits;
356
-                                    if ($result > $numbits)  $result = $numbits;
357
-
358
-                                    if ($result < $minbits)  return false;
359
-                                }
360
-
361
-                                $found = true;
362
-                            }
363
-                        }
364
-
365
-                        if ($found)  break;
366
-
367
-                        $x = $x2 - 1;
368
-                    }
369
-                }
370
-            }
371
-        }
372
-
373
-        return $result >= $minbits;
374
-    }
54
+	/**
55
+	 * A standardized method for hasing a password before storing
56
+	 * in the database.
57
+	 *
58
+	 * @param $password
59
+	 * @return bool|mixed|string
60
+	 */
61
+	public static function hashPassword($password)
62
+	{
63
+		if (! config_item('auth.hash_cost'))
64
+		{
65
+			get_instance()->load->config('auth');
66
+		}
67
+
68
+		return password_hash($password, PASSWORD_DEFAULT, ['cost' => config_item('auth.hash_cost')]);
69
+	}
70
+
71
+	//--------------------------------------------------------------------
72
+
73
+	/**
74
+	 * Determines the number of entropy bits a password has based on
75
+	 *
76
+	 *
77
+	 * @param $password
78
+	 * @param bool $repeatcalc
79
+	 * @return int
80
+	 */
81
+	public static function getNISTNumBits($password, $repeatcalc = false)
82
+	{
83
+		$y = strlen($password);
84
+		if ($repeatcalc)
85
+		{
86
+			// Variant on NIST rules to reduce long sequences of repeated characters.
87
+			$result = 0;
88
+			$charmult = array_fill(0, 256, 1);
89
+			for ($x = 0; $x < $y; $x++)
90
+			{
91
+				$tempchr = ord(substr($password, $x, 1));
92
+				if ($x > 19)  $result += $charmult[$tempchr];
93
+				else if ($x > 7)  $result += $charmult[$tempchr] * 1.5;
94
+				else if ($x > 0)  $result += $charmult[$tempchr] * 2;
95
+				else  $result += 4;
96
+
97
+				$charmult[$tempchr] *= 0.75;
98
+			}
99
+
100
+			return $result;
101
+		}
102
+		else
103
+		{
104
+			if ($y > 20)  return 4 + (7 * 2) + (12 * 1.5) + $y - 20;
105
+			if ($y > 8)  return 4 + (7 * 2) + (($y - 8) * 1.5);
106
+			if ($y > 1)  return 4 + (($y - 1) * 2);
107
+
108
+			return ($y == 1 ? 4 : 0);
109
+		}
110
+	}
111
+
112
+	//--------------------------------------------------------------------
113
+
114
+	/**
115
+	 * Determines whether a password is strong enough to use. You should check
116
+	 * the password against this method and reject it if the password is not
117
+	 * strong enough.
118
+	 *
119
+	 * The following guidelines come from the author's tests against 10.4 million actual passwords
120
+	 * ( see post: http://cubicspot.blogspot.com/2012/01/how-to-calculate-password-strength-part.html )
121
+	 * and represents the suggested minimum entropy bits for different types of sites:
122
+	 *
123
+	 *      - 18 bits of entropy = minimum for ANY website.
124
+	 *      - 25 bits of entropy = minimum for a general purpose web service used relatively widely (e.g. Hotmail).
125
+	 *      - 30 bits of entropy = minimum for a web service with business critical applications (e.g. SAAS).
126
+	 *      - 40 bits of entropy = minimum for a bank or other financial service.
127
+	 *
128
+	 * The algorithm is based upon a modified version of the NIST rules which suggest the following:
129
+	 *
130
+	 *      - The first byte counts as 4 bits.
131
+	 *      - The next 7 bytes count as 2 bits each.
132
+	 *      - The next 12 bytes count as 1.5 bits each.
133
+	 *      - Anything beyond that counts as 1 bit each.
134
+	 *      - Mixed case + non-alphanumeric = up to 6 extra bits.
135
+	 *
136
+	 * @param string    $password   - The password to check
137
+	 * @param int       $minbits    - Minimum "entropy bits" that is allowed
138
+	 * @param bool      $usedict    - Should we check the password against a 300,000 word English dictionary?
139
+	 * @param int       $minwordlen -
140
+	 * @return bool
141
+	 */
142
+	public static function isStrongPassword($password, $minbits = 18, $usedict = false, $minwordlen = 4)
143
+	{
144
+		// NIST password strength rules allow up to 6 extra bits for mixed case and non-alphabetic.
145
+		$upper = false;
146
+		$lower = false;
147
+		$numeric = false;
148
+		$other = false;
149
+		$space = false;
150
+		$y = strlen($password);
151
+		for ($x = 0; $x < $y; $x++)
152
+		{
153
+			$tempchr = ord(substr($password, $x, 1));
154
+			if ($tempchr >= ord("A") && $tempchr <= ord("Z"))  $upper = true;
155
+			else if ($tempchr >= ord("a") && $tempchr <= ord("z"))  $lower = true;
156
+			else if ($tempchr >= ord("0") && $tempchr <= ord("9"))  $numeric = true;
157
+			else if ($tempchr == ord(" "))  $space = true;
158
+			else  $other = true;
159
+		}
160
+		$extrabits = ($upper && $lower && $other ? ($numeric ? 6 : 5) : ($numeric && !$upper && !$lower ? ($other ? -2 : -6) : 0));
161
+		if (!$space)  $extrabits -= 2;
162
+		else if (count(explode(" ", preg_replace('/\s+/', " ", $password))) > 3)  $extrabits++;
163
+		$result = self::getNISTNumBits($password, true) + $extrabits;
164
+
165
+		$password = strtolower($password);
166
+		$revpassword = strrev($password);
167
+		$numbits = self::getNISTNumBits($password) + $extrabits;
168
+		if ($result > $numbits)  $result = $numbits;
169
+
170
+		// Remove QWERTY strings.
171
+		$qwertystrs = array(
172
+			"1234567890-qwertyuiopasdfghjkl;zxcvbnm,./",
173
+			"1qaz2wsx3edc4rfv5tgb6yhn7ujm8ik,9ol.0p;/-['=]:?_{\"+}",
174
+			"1qaz2wsx3edc4rfv5tgb6yhn7ujm8ik9ol0p",
175
+			"qazwsxedcrfvtgbyhnujmik,ol.p;/-['=]:?_{\"+}",
176
+			"qazwsxedcrfvtgbyhnujmikolp",
177
+			"]\"/=[;.-pl,0okm9ijn8uhb7ygv6tfc5rdx4esz3wa2q1",
178
+			"pl0okm9ijn8uhb7ygv6tfc5rdx4esz3wa2q1",
179
+			"]\"/[;.pl,okmijnuhbygvtfcrdxeszwaq",
180
+			"plokmijnuhbygvtfcrdxeszwaq",
181
+			"014725836914702583697894561230258/369*+-*/",
182
+			"abcdefghijklmnopqrstuvwxyz"
183
+		);
184
+		foreach ($qwertystrs as $qwertystr)
185
+		{
186
+			$qpassword = $password;
187
+			$qrevpassword = $revpassword;
188
+			$z = 6;
189
+			do
190
+			{
191
+				$y = strlen($qwertystr) - $z;
192
+				for ($x = 0; $x < $y; $x++)
193
+				{
194
+					$str = substr($qwertystr, $x, $z);
195
+					$qpassword = str_replace($str, "*", $qpassword);
196
+					$qrevpassword = str_replace($str, "*", $qrevpassword);
197
+				}
198
+
199
+				$z--;
200
+			} while ($z > 2);
201
+
202
+			$numbits = self::getNISTNumBits($qpassword) + $extrabits;
203
+			if ($result > $numbits)  $result = $numbits;
204
+			$numbits = self::getNISTNumBits($qrevpassword) + $extrabits;
205
+			if ($result > $numbits)  $result = $numbits;
206
+
207
+			if ($result < $minbits)  return false;
208
+		}
209
+
210
+		if ($usedict && $result >= $minbits)
211
+		{
212
+			$passwords = array();
213
+
214
+			// Add keyboard shifting password variants.
215
+			$keyboardmap_down_noshift = array(
216
+				"z" => "", "x" => "", "c" => "", "v" => "", "b" => "", "n" => "", "m" => "", "," => "", "." => "", "/" => "", "<" => "", ">" => "", "?" => ""
217
+			);
218
+			if ($password == str_replace(array_keys($keyboardmap_down_noshift), array_values($keyboardmap_down_noshift), $password))
219
+			{
220
+				$keyboardmap_downright = array(
221
+					"a" => "z",
222
+					"q" => "a",
223
+					"1" => "q",
224
+					"s" => "x",
225
+					"w" => "s",
226
+					"2" => "w",
227
+					"d" => "c",
228
+					"e" => "d",
229
+					"3" => "e",
230
+					"f" => "v",
231
+					"r" => "f",
232
+					"4" => "r",
233
+					"g" => "b",
234
+					"t" => "g",
235
+					"5" => "t",
236
+					"h" => "n",
237
+					"y" => "h",
238
+					"6" => "y",
239
+					"j" => "m",
240
+					"u" => "j",
241
+					"7" => "u",
242
+					"i" => "k",
243
+					"8" => "i",
244
+					"o" => "l",
245
+					"9" => "o",
246
+					"0" => "p",
247
+				);
248
+
249
+				$keyboardmap_downleft = array(
250
+					"2" => "q",
251
+					"w" => "a",
252
+					"3" => "w",
253
+					"s" => "z",
254
+					"e" => "s",
255
+					"4" => "e",
256
+					"d" => "x",
257
+					"r" => "d",
258
+					"5" => "r",
259
+					"f" => "c",
260
+					"t" => "f",
261
+					"6" => "t",
262
+					"g" => "v",
263
+					"y" => "g",
264
+					"7" => "y",
265
+					"h" => "b",
266
+					"u" => "h",
267
+					"8" => "u",
268
+					"j" => "n",
269
+					"i" => "j",
270
+					"9" => "i",
271
+					"k" => "m",
272
+					"o" => "k",
273
+					"0" => "o",
274
+					"p" => "l",
275
+					"-" => "p",
276
+				);
277
+
278
+				$password2 = str_replace(array_keys($keyboardmap_downright), array_values($keyboardmap_downright), $password);
279
+				$passwords[] = $password2;
280
+				$passwords[] = strrev($password2);
281
+
282
+				$password2 = str_replace(array_keys($keyboardmap_downleft), array_values($keyboardmap_downleft), $password);
283
+				$passwords[] = $password2;
284
+				$passwords[] = strrev($password2);
285
+			}
286
+
287
+			// Deal with LEET-Speak substitutions.
288
+			$leetspeakmap = array(
289
+				"@" => "a",
290
+				"!" => "i",
291
+				"$" => "s",
292
+				"1" => "i",
293
+				"2" => "z",
294
+				"3" => "e",
295
+				"4" => "a",
296
+				"5" => "s",
297
+				"6" => "g",
298
+				"7" => "t",
299
+				"8" => "b",
300
+				"9" => "g",
301
+				"0" => "o"
302
+			);
303
+
304
+			$password2 = str_replace(array_keys($leetspeakmap), array_values($leetspeakmap), $password);
305
+			$passwords[] = $password2;
306
+			$passwords[] = strrev($password2);
307
+
308
+			$leetspeakmap["1"] = "l";
309
+			$password3 = str_replace(array_keys($leetspeakmap), array_values($leetspeakmap), $password);
310
+			if ($password3 != $password2)
311
+			{
312
+				$passwords[] = $password3;
313
+				$passwords[] = strrev($password3);
314
+			}
315
+
316
+			// Process the password, while looking for words in the dictionary.
317
+			$a = ord("a");
318
+			$z = ord("z");
319
+			$data = file_get_contents(DICTIONARY_PATH);
320
+			foreach ($passwords as $num => $password)
321
+			{
322
+				$y = strlen($password);
323
+				for ($x = 0; $x < $y; $x++)
324
+				{
325
+					$tempchr = ord(substr($password, $x, 1));
326
+					if ($tempchr >= $a && $tempchr <= $z)
327
+					{
328
+						for ($x2 = $x + 1; $x2 < $y; $x2++)
329
+						{
330
+							$tempchr = ord(substr($password, $x2, 1));
331
+							if ($tempchr < $a || $tempchr > $z)  break;
332
+						}
333
+
334
+						$found = false;
335
+						while (!$found && $x2 - $x >= $minwordlen)
336
+						{
337
+							$word = "/\\n" . substr($password, $x, $minwordlen);
338
+							for ($x3 = $x + $minwordlen; $x3 < $x2; $x3++)  $word .= "(" . $password{$x3};
339
+							for ($x3 = $x + $minwordlen; $x3 < $x2; $x3++)  $word .= ")?";
340
+							$word .= "\\n/";
341
+
342
+							preg_match_all($word, $data, $matches);
343
+							if (!count($matches[0]))
344
+							{
345
+								$password{$x} = "*";
346
+								$x++;
347
+								$numbits = self::getNISTNumBits(substr($password, 0, $x)) + $extrabits;
348
+								if ($numbits >= $minbits)  $found = true;
349
+							}
350
+							else
351
+							{
352
+								foreach ($matches[0] as $match)
353
+								{
354
+									$password2 = str_replace(trim($match), "*", $password);
355
+									$numbits = self::getNISTNumBits($password2) + $extrabits;
356
+									if ($result > $numbits)  $result = $numbits;
357
+
358
+									if ($result < $minbits)  return false;
359
+								}
360
+
361
+								$found = true;
362
+							}
363
+						}
364
+
365
+						if ($found)  break;
366
+
367
+						$x = $x2 - 1;
368
+					}
369
+				}
370
+			}
371
+		}
372
+
373
+		return $result >= $minbits;
374
+	}
375 375
 }
Please login to merge, or discard this patch.
myth/CIModules/auth/helpers/password_helper.php 1 patch
Indentation   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -32,28 +32,28 @@
 block discarded – undo
32 32
 
33 33
 if (! function_exists('isStrongPassword'))
34 34
 {
35
-    /**
36
-     * Works with Myth\Auth\Password to enforce a strong password.
37
-     * Uses settings from the auth config file.
38
-     *
39
-     * @param $password
40
-     */
41
-    function isStrongPassword($password)
42
-    {
43
-        $min_strength = config_item('auth.min_password_strength');
44
-        $use_dict = config_item('auth.use_dictionary');
35
+	/**
36
+	 * Works with Myth\Auth\Password to enforce a strong password.
37
+	 * Uses settings from the auth config file.
38
+	 *
39
+	 * @param $password
40
+	 */
41
+	function isStrongPassword($password)
42
+	{
43
+		$min_strength = config_item('auth.min_password_strength');
44
+		$use_dict = config_item('auth.use_dictionary');
45 45
 
46
-        $strong = \Myth\Auth\Password::isStrongPassword($password, $min_strength, $use_dict);
46
+		$strong = \Myth\Auth\Password::isStrongPassword($password, $min_strength, $use_dict);
47 47
 
48
-        if (! $strong)
49
-        {
50
-            if (isset(get_instance()->form_validation))
51
-            {
52
-                get_instance()->form_validation->set_message('isStrongPassword', lang('auth.pass_not_strong'));
53
-            }
54
-            return false;
55
-        }
48
+		if (! $strong)
49
+		{
50
+			if (isset(get_instance()->form_validation))
51
+			{
52
+				get_instance()->form_validation->set_message('isStrongPassword', lang('auth.pass_not_strong'));
53
+			}
54
+			return false;
55
+		}
56 56
 
57
-        return true;
58
-    }
57
+		return true;
58
+	}
59 59
 }
Please login to merge, or discard this patch.
myth/CIModules/auth/models/Login_model.php 1 patch
Indentation   +269 added lines, -269 removed lines patch added patch discarded remove patch
@@ -41,274 +41,274 @@
 block discarded – undo
41 41
  */
42 42
 class Login_model extends \Myth\Models\CIDbModel {
43 43
 
44
-    protected $table_name = 'auth_logins';
45
-
46
-    protected $set_created = false;
47
-    protected $set_modified = false;
48
-
49
-    //--------------------------------------------------------------------
50
-
51
-    //--------------------------------------------------------------------
52
-    // Login Attempts
53
-    //--------------------------------------------------------------------
54
-
55
-    /**
56
-     * Records a login attempt. This is used to implement
57
-     * throttling of user login attempts.
58
-     *
59
-     * @param $email
60
-     * @return object
61
-     */
62
-    public function recordLoginAttempt($email)
63
-    {
64
-        $data = [
65
-            'email' => $email,
66
-            'datetime' => date('Y-m-d H:i:s')
67
-        ];
68
-
69
-        return $this->db->insert('auth_login_attempts', $data);
70
-    }
71
-
72
-    //--------------------------------------------------------------------
73
-
74
-    /**
75
-     * Purges all login attempt records from the database.
76
-     *
77
-     * @param $email
78
-     * @return mixed
79
-     */
80
-    public function purgeLoginAttempts($email)
81
-    {
82
-        return $this->db->where('email', $email)
83
-                        ->delete('auth_login_attempts');
84
-    }
85
-
86
-    //--------------------------------------------------------------------
87
-
88
-    /**
89
-     * Checks to see if how many login attempts have been attempted in the
90
-     * last 60 seconds. If over 100, it is considered to be under a
91
-     * brute force attempt.
92
-     *
93
-     * @param $email
94
-     * @return bool
95
-     */
96
-    public function isBruteForced($email)
97
-    {
98
-        $start_time = date('Y-m-d H:i:s', time() - 60);
99
-
100
-        $attempts = $this->db->where('email', $email)
101
-                             ->where('datetime >=', $start_time)
102
-                             ->count_all_results('auth_login_attempts');
103
-
104
-        return $attempts > 100;
105
-    }
106
-
107
-    //--------------------------------------------------------------------
108
-
109
-    /**
110
-     * Attempts to determine if the system is under a distributed
111
-     * brute force attack.
112
-     *
113
-     * To determine if we are in under a brute force attack, we first
114
-     * find the average number of bad logins per day that never converted to
115
-     * successful logins over the last 3 months. Then we compare
116
-     * that to the the average number of logins in the past 24 hours.
117
-     *
118
-     * If the number of attempts in the last 24 hours is more than X (see config)
119
-     * times the average, then institute additional throttling.
120
-     *
121
-     * @return int The time to add to any throttling.
122
-     */
123
-    public function distributedBruteForceTime()
124
-    {
125
-        if (! $time = $this->cache->get('dbrutetime'))
126
-        {
127
-            $time = 0;
128
-
129
-            // Compute our daily average over the last 3 months.
130
-            $avg_start_time = date('Y-m-d 00:00:00', strtotime('-3 months'));
131
-
132
-            $query = $this->db->query("SELECT COUNT(*) / COUNT(DISTINCT DATE(`datetime`)) as num_rows FROM `auth_login_attempts` WHERE `datetime` >= ?", $avg_start_time);
133
-
134
-            if (! $query->num_rows())
135
-            {
136
-                $average = 0;
137
-            }
138
-            else
139
-            {
140
-                $average = $query->row()->num_rows;
141
-            }
142
-
143
-            // Get the total in the last 24 hours
144
-            $today_start_time = date('Y-m-d H:i:s', strtotime('-24 hours'));
145
-
146
-            $attempts = $this->db->where('datetime >=', $today_start_time)
147
-                                 ->count_all_results('auth_login_attempts');
148
-
149
-            if ($attempts > (config_item('auth.dbrute_multiplier') * $average))
150
-            {
151
-                $time = config_item('auth.distributed_brute_add_time');
152
-            }
153
-
154
-            // Cache it for 3 hours.
155
-            $this->cache->save('dbrutetime', $time, 60*60*3);
156
-        }
157
-
158
-        return $time;
159
-    }
160
-
161
-    //--------------------------------------------------------------------
162
-
163
-    //--------------------------------------------------------------------
164
-    // Logins
165
-    //--------------------------------------------------------------------
166
-
167
-    /**
168
-     * Records a successful login. This stores in a table so that a
169
-     * history can be pulled up later if needed for security analyses.
170
-     *
171
-     * @param $user
172
-     */
173
-    public function recordLogin($user)
174
-    {
175
-        $data = [
176
-            'user_id'    => (int)$user['id'],
177
-            'datetime'   => date('Y-m-d H:i:s'),
178
-            'ip_address' => $this->input->ip_address()
179
-        ];
180
-
181
-        return $this->db->insert('auth_logins', $data);
182
-    }
183
-
184
-    //--------------------------------------------------------------------
185
-
186
-    //--------------------------------------------------------------------
187
-    // Tokens
188
-    //--------------------------------------------------------------------
189
-
190
-    /**
191
-     * Generates a new token for the rememberme cookie.
192
-     *
193
-     * The token is based on the user's email address (since everyone will have one)
194
-     * with the '@' turned to a '.', followed by a pipe (|) and a random 128-character
195
-     * string with letters and numbers.
196
-     *
197
-     * @param $user
198
-     * @return mixed
199
-     */
200
-    public function generateRememberToken($user)
201
-    {
202
-        $this->load->helper('string');
203
-
204
-        return str_replace('@', '.', $user['email']) .'|' . random_string('alnum', 128);
205
-    }
206
-
207
-    //--------------------------------------------------------------------
208
-
209
-    /**
210
-     * Hashes the token for the Remember Me Functionality.
211
-     *
212
-     * @param $token
213
-     * @return string
214
-     */
215
-    public function hashRememberToken($token)
216
-    {
217
-        return sha1(config_item('auth.salt') . $token);
218
-    }
219
-
220
-    //--------------------------------------------------------------------
221
-
222
-    /**
223
-     * Deletes a single token that matches the email/token combo.
224
-     *
225
-     * @param $email
226
-     * @param $token
227
-     * @return mixed
228
-     */
229
-    public function deleteRememberToken($email, $token)
230
-    {
231
-        $where = [
232
-            'email' => $email,
233
-            'hash'  => $this->hashRememberToken($token)
234
-        ];
235
-
236
-        $this->db->delete('auth_tokens', $where);
237
-    }
238
-
239
-    //--------------------------------------------------------------------
240
-
241
-    /**
242
-     * Removes all persistent login tokens (RememberMe) for a single user
243
-     * across all devices they may have logged in with.
244
-     *
245
-     * @param $email
246
-     * @return mixed
247
-     */
248
-    public function purgeRememberTokens($email)
249
-    {
250
-        return $this->db->delete('auth_tokens', ['email' => $email]);
251
-    }
252
-
253
-    //--------------------------------------------------------------------
254
-
255
-
256
-    /**
257
-     * Purges the 'auth_tokens' table of any records that are too old
258
-     * to be of any use anymore. This equates to 1 week older than
259
-     * the remember_length set in the config file.
260
-     */
261
-    public function purgeOldRememberTokens()
262
-    {
263
-        if (! config_item('auth.allow_remembering'))
264
-        {
265
-            return;
266
-        }
267
-
268
-        $date = time() - config_item('auth.remember_length') - 604800; // 1 week
269
-        $date = date('Y-m-d 00:00:00', $date);
270
-
271
-        $this->db->where('created <=', $date)
272
-                 ->delete('auth_tokens');
273
-    }
274
-
275
-    //--------------------------------------------------------------------
276
-
277
-    /**
278
-     * Gets the timestamp of the last attempted login for this user.
279
-     *
280
-     * @param $email
281
-     * @return int|null
282
-     */
283
-    public function lastLoginAttemptTime($email)
284
-    {
285
-        $query = $this->db->where('email', $email)
286
-                          ->order_by('datetime', 'desc')
287
-                          ->limit(1)
288
-                          ->get('auth_login_attempts');
289
-
290
-        if (! $query->num_rows())
291
-        {
292
-            return 0;
293
-        }
294
-
295
-        return strtotime($query->row()->datetime);
296
-    }
297
-
298
-    //--------------------------------------------------------------------
299
-
300
-    /**
301
-     * Returns the number of failed login attempts for a single email.
302
-     *
303
-     * @param $email
304
-     * @return int
305
-     */
306
-    public function countLoginAttempts($email)
307
-    {
308
-        return $this->db->where('email', $email)
309
-                        ->count_all_results('auth_login_attempts');
310
-    }
311
-
312
-    //--------------------------------------------------------------------
44
+	protected $table_name = 'auth_logins';
45
+
46
+	protected $set_created = false;
47
+	protected $set_modified = false;
48
+
49
+	//--------------------------------------------------------------------
50
+
51
+	//--------------------------------------------------------------------
52
+	// Login Attempts
53
+	//--------------------------------------------------------------------
54
+
55
+	/**
56
+	 * Records a login attempt. This is used to implement
57
+	 * throttling of user login attempts.
58
+	 *
59
+	 * @param $email
60
+	 * @return object
61
+	 */
62
+	public function recordLoginAttempt($email)
63
+	{
64
+		$data = [
65
+			'email' => $email,
66
+			'datetime' => date('Y-m-d H:i:s')
67
+		];
68
+
69
+		return $this->db->insert('auth_login_attempts', $data);
70
+	}
71
+
72
+	//--------------------------------------------------------------------
73
+
74
+	/**
75
+	 * Purges all login attempt records from the database.
76
+	 *
77
+	 * @param $email
78
+	 * @return mixed
79
+	 */
80
+	public function purgeLoginAttempts($email)
81
+	{
82
+		return $this->db->where('email', $email)
83
+						->delete('auth_login_attempts');
84
+	}
85
+
86
+	//--------------------------------------------------------------------
87
+
88
+	/**
89
+	 * Checks to see if how many login attempts have been attempted in the
90
+	 * last 60 seconds. If over 100, it is considered to be under a
91
+	 * brute force attempt.
92
+	 *
93
+	 * @param $email
94
+	 * @return bool
95
+	 */
96
+	public function isBruteForced($email)
97
+	{
98
+		$start_time = date('Y-m-d H:i:s', time() - 60);
99
+
100
+		$attempts = $this->db->where('email', $email)
101
+							 ->where('datetime >=', $start_time)
102
+							 ->count_all_results('auth_login_attempts');
103
+
104
+		return $attempts > 100;
105
+	}
106
+
107
+	//--------------------------------------------------------------------
108
+
109
+	/**
110
+	 * Attempts to determine if the system is under a distributed
111
+	 * brute force attack.
112
+	 *
113
+	 * To determine if we are in under a brute force attack, we first
114
+	 * find the average number of bad logins per day that never converted to
115
+	 * successful logins over the last 3 months. Then we compare
116
+	 * that to the the average number of logins in the past 24 hours.
117
+	 *
118
+	 * If the number of attempts in the last 24 hours is more than X (see config)
119
+	 * times the average, then institute additional throttling.
120
+	 *
121
+	 * @return int The time to add to any throttling.
122
+	 */
123
+	public function distributedBruteForceTime()
124
+	{
125
+		if (! $time = $this->cache->get('dbrutetime'))
126
+		{
127
+			$time = 0;
128
+
129
+			// Compute our daily average over the last 3 months.
130
+			$avg_start_time = date('Y-m-d 00:00:00', strtotime('-3 months'));
131
+
132
+			$query = $this->db->query("SELECT COUNT(*) / COUNT(DISTINCT DATE(`datetime`)) as num_rows FROM `auth_login_attempts` WHERE `datetime` >= ?", $avg_start_time);
133
+
134
+			if (! $query->num_rows())
135
+			{
136
+				$average = 0;
137
+			}
138
+			else
139
+			{
140
+				$average = $query->row()->num_rows;
141
+			}
142
+
143
+			// Get the total in the last 24 hours
144
+			$today_start_time = date('Y-m-d H:i:s', strtotime('-24 hours'));
145
+
146
+			$attempts = $this->db->where('datetime >=', $today_start_time)
147
+								 ->count_all_results('auth_login_attempts');
148
+
149
+			if ($attempts > (config_item('auth.dbrute_multiplier') * $average))
150
+			{
151
+				$time = config_item('auth.distributed_brute_add_time');
152
+			}
153
+
154
+			// Cache it for 3 hours.
155
+			$this->cache->save('dbrutetime', $time, 60*60*3);
156
+		}
157
+
158
+		return $time;
159
+	}
160
+
161
+	//--------------------------------------------------------------------
162
+
163
+	//--------------------------------------------------------------------
164
+	// Logins
165
+	//--------------------------------------------------------------------
166
+
167
+	/**
168
+	 * Records a successful login. This stores in a table so that a
169
+	 * history can be pulled up later if needed for security analyses.
170
+	 *
171
+	 * @param $user
172
+	 */
173
+	public function recordLogin($user)
174
+	{
175
+		$data = [
176
+			'user_id'    => (int)$user['id'],
177
+			'datetime'   => date('Y-m-d H:i:s'),
178
+			'ip_address' => $this->input->ip_address()
179
+		];
180
+
181
+		return $this->db->insert('auth_logins', $data);
182
+	}
183
+
184
+	//--------------------------------------------------------------------
185
+
186
+	//--------------------------------------------------------------------
187
+	// Tokens
188
+	//--------------------------------------------------------------------
189
+
190
+	/**
191
+	 * Generates a new token for the rememberme cookie.
192
+	 *
193
+	 * The token is based on the user's email address (since everyone will have one)
194
+	 * with the '@' turned to a '.', followed by a pipe (|) and a random 128-character
195
+	 * string with letters and numbers.
196
+	 *
197
+	 * @param $user
198
+	 * @return mixed
199
+	 */
200
+	public function generateRememberToken($user)
201
+	{
202
+		$this->load->helper('string');
203
+
204
+		return str_replace('@', '.', $user['email']) .'|' . random_string('alnum', 128);
205
+	}
206
+
207
+	//--------------------------------------------------------------------
208
+
209
+	/**
210
+	 * Hashes the token for the Remember Me Functionality.
211
+	 *
212
+	 * @param $token
213
+	 * @return string
214
+	 */
215
+	public function hashRememberToken($token)
216
+	{
217
+		return sha1(config_item('auth.salt') . $token);
218
+	}
219
+
220
+	//--------------------------------------------------------------------
221
+
222
+	/**
223
+	 * Deletes a single token that matches the email/token combo.
224
+	 *
225
+	 * @param $email
226
+	 * @param $token
227
+	 * @return mixed
228
+	 */
229
+	public function deleteRememberToken($email, $token)
230
+	{
231
+		$where = [
232
+			'email' => $email,
233
+			'hash'  => $this->hashRememberToken($token)
234
+		];
235
+
236
+		$this->db->delete('auth_tokens', $where);
237
+	}
238
+
239
+	//--------------------------------------------------------------------
240
+
241
+	/**
242
+	 * Removes all persistent login tokens (RememberMe) for a single user
243
+	 * across all devices they may have logged in with.
244
+	 *
245
+	 * @param $email
246
+	 * @return mixed
247
+	 */
248
+	public function purgeRememberTokens($email)
249
+	{
250
+		return $this->db->delete('auth_tokens', ['email' => $email]);
251
+	}
252
+
253
+	//--------------------------------------------------------------------
254
+
255
+
256
+	/**
257
+	 * Purges the 'auth_tokens' table of any records that are too old
258
+	 * to be of any use anymore. This equates to 1 week older than
259
+	 * the remember_length set in the config file.
260
+	 */
261
+	public function purgeOldRememberTokens()
262
+	{
263
+		if (! config_item('auth.allow_remembering'))
264
+		{
265
+			return;
266
+		}
267
+
268
+		$date = time() - config_item('auth.remember_length') - 604800; // 1 week
269
+		$date = date('Y-m-d 00:00:00', $date);
270
+
271
+		$this->db->where('created <=', $date)
272
+				 ->delete('auth_tokens');
273
+	}
274
+
275
+	//--------------------------------------------------------------------
276
+
277
+	/**
278
+	 * Gets the timestamp of the last attempted login for this user.
279
+	 *
280
+	 * @param $email
281
+	 * @return int|null
282
+	 */
283
+	public function lastLoginAttemptTime($email)
284
+	{
285
+		$query = $this->db->where('email', $email)
286
+						  ->order_by('datetime', 'desc')
287
+						  ->limit(1)
288
+						  ->get('auth_login_attempts');
289
+
290
+		if (! $query->num_rows())
291
+		{
292
+			return 0;
293
+		}
294
+
295
+		return strtotime($query->row()->datetime);
296
+	}
297
+
298
+	//--------------------------------------------------------------------
299
+
300
+	/**
301
+	 * Returns the number of failed login attempts for a single email.
302
+	 *
303
+	 * @param $email
304
+	 * @return int
305
+	 */
306
+	public function countLoginAttempts($email)
307
+	{
308
+		return $this->db->where('email', $email)
309
+						->count_all_results('auth_login_attempts');
310
+	}
311
+
312
+	//--------------------------------------------------------------------
313 313
 
314 314
 }
Please login to merge, or discard this patch.
myth/CIModules/cron/controllers/Cron.php 1 patch
Indentation   +304 added lines, -304 removed lines patch added patch discarded remove patch
@@ -37,325 +37,325 @@
 block discarded – undo
37 37
 // todo Add ability to log actual cron jobs to database to verify when they ran for sure.
38 38
 class Cron extends \Myth\Controllers\CLIController {
39 39
 
40
-    protected $descriptions = [
41
-        'show'  => ['show [all/<task>]', 'Lists the names one or more tasks, with run times.'],
42
-        'run'   => ['run [<task>]', 'Runs all scheduled tasks. If <task> is present only runs that task.'],
43
-        'disable'   => ['disable', 'Disables the cron system and will not run any tasks.'],
44
-        'enable'    => ['enable', 'Enables the cron system and will run tasks again.'],
45
-        'suspend'   => ['suspend <task>', 'Stops a single task from running until resumed.'],
46
-        'resume'    => ['resume <task>', 'Resumes execution of a single suspended task.']
47
-    ];
48
-
49
-    protected $long_descriptions = [
50
-        'show'  => '',
51
-        'run'   => '',
52
-        'disable'   => '',
53
-        'enable'    => '',
54
-        'suspend'   => '',
55
-        'resume'    => ''
56
-    ];
57
-
58
-    //--------------------------------------------------------------------
59
-
60
-    public function __construct()
61
-    {
62
-        parent::__construct();
63
-
64
-        // Load our tasks into the sytem.
65
-        require APPPATH .'config/cron.php';
66
-    }
67
-
68
-    //--------------------------------------------------------------------
69
-
70
-    /**
71
-     * Runs all of the tasks (after checking their time, of course...)
72
-     *
73
-     * @param string $alias
74
-     * @return mixed
75
-     */
76
-    public function run($alias=null)
77
-    {
78
-        // Has the system been disabled?
79
-        if (Settings::get('is_disabled', 'cron') == 'y')
80
-        {
81
-            return CLI::error('The cron system has been disabled. No tasks were run.');
82
-        }
83
-
84
-        $force_run = false;
85
-
86
-        // Run one task or all?
87
-        if (! empty($alias))
88
-        {
89
-            $tasks = \Myth\Cron\CronManager::task($alias);
90
-
91
-            if (is_null($tasks))
92
-            {
93
-                return CLI::error("Unable to find the task: '{$alias}'.");
94
-            }
95
-
96
-            $tasks = [ $alias => $tasks];
97
-            $force_run = true;
98
-        }
99
-        else
100
-        {
101
-            $tasks = \Myth\Cron\CronManager::tasks();
102
-        }
103
-
104
-        if (empty($tasks))
105
-        {
106
-            return CLI::write("There are no tasks to run at this time.");
107
-        }
108
-
109
-        // We need to be able to check against suspended tasks.
110
-        $suspended = Settings::get('suspended_tasks', 'cron');
111
-
112
-        if (! is_array($suspended))
113
-        {
114
-            $suspended = array($suspended);
115
-        }
116
-
117
-        // Loop over all of our tasks, checking them against the
118
-        // suspended tasks to see if they're okay to run.
119
-
120
-        // Collect the output of the actions so that we can make
121
-        // it available to the event (for sending emails and the like)
122
-        $output = '';
123
-
124
-        echo CLI::write('Starting Tasks...');
125
-
126
-        foreach ($tasks as $alias => $task)
127
-        {
128
-            if (in_array($alias, $suspended))
129
-            {
130
-                echo CLI::write("\t[Suspended] {$alias} will not run until resumed.", 'yellow');
131
-                $output .= "[Suspended] {$alias} will not run until resumed.";
132
-                continue;
133
-            }
134
-
135
-            echo CLI::write("\tRunning task: {$alias}...");
136
-            $output .= \Myth\Cron\CronManager::run($alias, $force_run);
137
-        }
138
-
139
-        // Give other people a chance to respond.
140
-        echo CLI::write('Done. Firing the event so others can play too...');
141
-
142
-        Events::trigger('afterCron', [$output]);
143
-
144
-        // And we're out of here boys and girls!
145
-        echo CLI::write('Done');
146
-    }
147
-
148
-    //--------------------------------------------------------------------
149
-
150
-
151
-    /**
152
-     * Lists one or more tasks with their scheduled run times.
153
-     *
154
-     * @param null $task
155
-     * @return mixed
156
-     */
157
-    public function show($task=null)
158
-    {
159
-        if (empty($task))
160
-        {
161
-            return $this->listTaskNames();
162
-        }
163
-
164
-        if (trim(strtolower($task)) == 'all')
165
-        {
166
-            $tasks = \Myth\Cron\CronManager::listAll();
167
-        }
168
-        else
169
-        {
170
-            $tasks = \Myth\Cron\CronManager::task($task);
171
-        }
172
-
173
-        if (! is_array($tasks))
174
-        {
175
-            $tasks = [ $task => [
176
-                'next_run'  => $tasks->nextRunDate(),
177
-                'prev_run'  => $tasks->previousRunDate()
178
-            ]];
179
-        }
180
-
181
-        if (! count($tasks))
182
-        {
183
-            return CLI::found('No tasks found.', 'red');
184
-        }
185
-
186
-        $suspended = Settings::get('suspended_tasks', 'cron');
187
-
188
-        if (empty($suspended))
189
-        {
190
-            $suspended = [];
191
-        }
192
-        /*
40
+	protected $descriptions = [
41
+		'show'  => ['show [all/<task>]', 'Lists the names one or more tasks, with run times.'],
42
+		'run'   => ['run [<task>]', 'Runs all scheduled tasks. If <task> is present only runs that task.'],
43
+		'disable'   => ['disable', 'Disables the cron system and will not run any tasks.'],
44
+		'enable'    => ['enable', 'Enables the cron system and will run tasks again.'],
45
+		'suspend'   => ['suspend <task>', 'Stops a single task from running until resumed.'],
46
+		'resume'    => ['resume <task>', 'Resumes execution of a single suspended task.']
47
+	];
48
+
49
+	protected $long_descriptions = [
50
+		'show'  => '',
51
+		'run'   => '',
52
+		'disable'   => '',
53
+		'enable'    => '',
54
+		'suspend'   => '',
55
+		'resume'    => ''
56
+	];
57
+
58
+	//--------------------------------------------------------------------
59
+
60
+	public function __construct()
61
+	{
62
+		parent::__construct();
63
+
64
+		// Load our tasks into the sytem.
65
+		require APPPATH .'config/cron.php';
66
+	}
67
+
68
+	//--------------------------------------------------------------------
69
+
70
+	/**
71
+	 * Runs all of the tasks (after checking their time, of course...)
72
+	 *
73
+	 * @param string $alias
74
+	 * @return mixed
75
+	 */
76
+	public function run($alias=null)
77
+	{
78
+		// Has the system been disabled?
79
+		if (Settings::get('is_disabled', 'cron') == 'y')
80
+		{
81
+			return CLI::error('The cron system has been disabled. No tasks were run.');
82
+		}
83
+
84
+		$force_run = false;
85
+
86
+		// Run one task or all?
87
+		if (! empty($alias))
88
+		{
89
+			$tasks = \Myth\Cron\CronManager::task($alias);
90
+
91
+			if (is_null($tasks))
92
+			{
93
+				return CLI::error("Unable to find the task: '{$alias}'.");
94
+			}
95
+
96
+			$tasks = [ $alias => $tasks];
97
+			$force_run = true;
98
+		}
99
+		else
100
+		{
101
+			$tasks = \Myth\Cron\CronManager::tasks();
102
+		}
103
+
104
+		if (empty($tasks))
105
+		{
106
+			return CLI::write("There are no tasks to run at this time.");
107
+		}
108
+
109
+		// We need to be able to check against suspended tasks.
110
+		$suspended = Settings::get('suspended_tasks', 'cron');
111
+
112
+		if (! is_array($suspended))
113
+		{
114
+			$suspended = array($suspended);
115
+		}
116
+
117
+		// Loop over all of our tasks, checking them against the
118
+		// suspended tasks to see if they're okay to run.
119
+
120
+		// Collect the output of the actions so that we can make
121
+		// it available to the event (for sending emails and the like)
122
+		$output = '';
123
+
124
+		echo CLI::write('Starting Tasks...');
125
+
126
+		foreach ($tasks as $alias => $task)
127
+		{
128
+			if (in_array($alias, $suspended))
129
+			{
130
+				echo CLI::write("\t[Suspended] {$alias} will not run until resumed.", 'yellow');
131
+				$output .= "[Suspended] {$alias} will not run until resumed.";
132
+				continue;
133
+			}
134
+
135
+			echo CLI::write("\tRunning task: {$alias}...");
136
+			$output .= \Myth\Cron\CronManager::run($alias, $force_run);
137
+		}
138
+
139
+		// Give other people a chance to respond.
140
+		echo CLI::write('Done. Firing the event so others can play too...');
141
+
142
+		Events::trigger('afterCron', [$output]);
143
+
144
+		// And we're out of here boys and girls!
145
+		echo CLI::write('Done');
146
+	}
147
+
148
+	//--------------------------------------------------------------------
149
+
150
+
151
+	/**
152
+	 * Lists one or more tasks with their scheduled run times.
153
+	 *
154
+	 * @param null $task
155
+	 * @return mixed
156
+	 */
157
+	public function show($task=null)
158
+	{
159
+		if (empty($task))
160
+		{
161
+			return $this->listTaskNames();
162
+		}
163
+
164
+		if (trim(strtolower($task)) == 'all')
165
+		{
166
+			$tasks = \Myth\Cron\CronManager::listAll();
167
+		}
168
+		else
169
+		{
170
+			$tasks = \Myth\Cron\CronManager::task($task);
171
+		}
172
+
173
+		if (! is_array($tasks))
174
+		{
175
+			$tasks = [ $task => [
176
+				'next_run'  => $tasks->nextRunDate(),
177
+				'prev_run'  => $tasks->previousRunDate()
178
+			]];
179
+		}
180
+
181
+		if (! count($tasks))
182
+		{
183
+			return CLI::found('No tasks found.', 'red');
184
+		}
185
+
186
+		$suspended = Settings::get('suspended_tasks', 'cron');
187
+
188
+		if (empty($suspended))
189
+		{
190
+			$suspended = [];
191
+		}
192
+		/*
193 193
          * Headers
194 194
          */
195
-        echo CLI::write("Task\t\t\t\tNext Run\t\tPrevious Run");
196
-        echo CLI::write( str_repeat('-', 80) );
197
-
198
-        foreach ($tasks as $alias => $task)
199
-        {
200
-            // Suspended?
201
-            $color = 'yellow';
202
-            $extra = '';
203
-
204
-            if (in_array($alias, $suspended) )
205
-            {
206
-                $color = 'blue';
207
-                $extra = "\t[Suspended]";
208
-            }
209
-
210
-            // Alias can only be 24 chars long.
211
-            $alias = strlen($alias) >= 32 ? substr($alias, 0, 28) .'... ' : $alias . str_repeat(" ", 32 - strlen($alias));
212
-
213
-            $next = date('D Y-m-d H:i', $task['next_run']);
214
-            $prev = date('D Y-m-d H:i', $task['prev_run']);
215
-
216
-            echo CLI::write("{$alias}{$next}\t{$prev}{$extra}", $color);
217
-        }
218
-    }
219
-
220
-    //--------------------------------------------------------------------
221
-
222
-    /**
223
-     * Stops a task from being executed during the normal cron runs.
224
-     *
225
-     * @param $alias
226
-     */
227
-    public function suspend($alias)
228
-    {
229
-        // Verify the task actually exists.
230
-        $task = \Myth\Cron\CronManager::task($alias);
231
-
232
-        if (is_null($task))
233
-        {
234
-            return CLI::error("Unable to find the task: {$alias}.");
235
-        }
236
-
237
-        // Update the existing setting.
238
-        $suspended = Settings::get('suspended_tasks', 'cron');
239
-
240
-        if (empty($suspended))
241
-        {
242
-            $suspended = [];
243
-        }
244
-
245
-        $suspended[] = $alias;
246
-
247
-        if (Settings::save('suspended_tasks', $suspended, 'cron') )
248
-        {
249
-            return CLI::write('Done');
250
-        }
251
-
252
-        echo CLI::error('Unkown problem saving the settings.');
253
-    }
254
-
255
-    //--------------------------------------------------------------------
256
-
257
-    /**
258
-     * Allows the execution of a suspended task to continue again
259
-     * during normal cron execution.
260
-     *
261
-     * @param $alias
262
-     */
263
-    public function resume($alias)
264
-    {
265
-        // Verify the task actually exists.
266
-        $task = \Myth\Cron\CronManager::task($alias);
267
-
268
-        if (is_null($task))
269
-        {
270
-            return CLI::error("Unable to find the task: {$alias}.");
271
-        }
272
-
273
-        // Update the existing setting.
274
-        $suspended = Settings::get('suspended_tasks', 'cron');
275
-
276
-        if (! empty($suspended))
277
-        {
278
-            unset($suspended[ array_search($alias, $suspended) ]);
279
-
280
-            if (! Settings::save('suspended_tasks', $suspended, 'cron') )
281
-            {
282
-                return CLI::error('Unkown problem saving the settings.');
283
-            }
284
-        }
285
-
286
-        return CLI::write('Done');
287
-    }
288
-
289
-    //--------------------------------------------------------------------
290
-
291
-    /**
292
-     * Disables the cron tasks and stops the system from running any tasks.
293
-     * To start the system allowing it to run again, use the `enable` command.
294
-     */
295
-    public function disable()
296
-    {
297
-        if (! Settings::save('is_disabled', 'y', 'cron'))
298
-        {
299
-            return CLI::error('Unknown problem saving the setting. '. CLI::color('Cron jobs will still run!', 'yellow'));
300
-        }
301
-
302
-        CLI::write('Done');
303
-    }
195
+		echo CLI::write("Task\t\t\t\tNext Run\t\tPrevious Run");
196
+		echo CLI::write( str_repeat('-', 80) );
197
+
198
+		foreach ($tasks as $alias => $task)
199
+		{
200
+			// Suspended?
201
+			$color = 'yellow';
202
+			$extra = '';
203
+
204
+			if (in_array($alias, $suspended) )
205
+			{
206
+				$color = 'blue';
207
+				$extra = "\t[Suspended]";
208
+			}
209
+
210
+			// Alias can only be 24 chars long.
211
+			$alias = strlen($alias) >= 32 ? substr($alias, 0, 28) .'... ' : $alias . str_repeat(" ", 32 - strlen($alias));
212
+
213
+			$next = date('D Y-m-d H:i', $task['next_run']);
214
+			$prev = date('D Y-m-d H:i', $task['prev_run']);
215
+
216
+			echo CLI::write("{$alias}{$next}\t{$prev}{$extra}", $color);
217
+		}
218
+	}
219
+
220
+	//--------------------------------------------------------------------
221
+
222
+	/**
223
+	 * Stops a task from being executed during the normal cron runs.
224
+	 *
225
+	 * @param $alias
226
+	 */
227
+	public function suspend($alias)
228
+	{
229
+		// Verify the task actually exists.
230
+		$task = \Myth\Cron\CronManager::task($alias);
231
+
232
+		if (is_null($task))
233
+		{
234
+			return CLI::error("Unable to find the task: {$alias}.");
235
+		}
236
+
237
+		// Update the existing setting.
238
+		$suspended = Settings::get('suspended_tasks', 'cron');
239
+
240
+		if (empty($suspended))
241
+		{
242
+			$suspended = [];
243
+		}
244
+
245
+		$suspended[] = $alias;
246
+
247
+		if (Settings::save('suspended_tasks', $suspended, 'cron') )
248
+		{
249
+			return CLI::write('Done');
250
+		}
251
+
252
+		echo CLI::error('Unkown problem saving the settings.');
253
+	}
254
+
255
+	//--------------------------------------------------------------------
256
+
257
+	/**
258
+	 * Allows the execution of a suspended task to continue again
259
+	 * during normal cron execution.
260
+	 *
261
+	 * @param $alias
262
+	 */
263
+	public function resume($alias)
264
+	{
265
+		// Verify the task actually exists.
266
+		$task = \Myth\Cron\CronManager::task($alias);
267
+
268
+		if (is_null($task))
269
+		{
270
+			return CLI::error("Unable to find the task: {$alias}.");
271
+		}
272
+
273
+		// Update the existing setting.
274
+		$suspended = Settings::get('suspended_tasks', 'cron');
275
+
276
+		if (! empty($suspended))
277
+		{
278
+			unset($suspended[ array_search($alias, $suspended) ]);
279
+
280
+			if (! Settings::save('suspended_tasks', $suspended, 'cron') )
281
+			{
282
+				return CLI::error('Unkown problem saving the settings.');
283
+			}
284
+		}
285
+
286
+		return CLI::write('Done');
287
+	}
288
+
289
+	//--------------------------------------------------------------------
290
+
291
+	/**
292
+	 * Disables the cron tasks and stops the system from running any tasks.
293
+	 * To start the system allowing it to run again, use the `enable` command.
294
+	 */
295
+	public function disable()
296
+	{
297
+		if (! Settings::save('is_disabled', 'y', 'cron'))
298
+		{
299
+			return CLI::error('Unknown problem saving the setting. '. CLI::color('Cron jobs will still run!', 'yellow'));
300
+		}
301
+
302
+		CLI::write('Done');
303
+	}
304 304
     
305
-    //--------------------------------------------------------------------
305
+	//--------------------------------------------------------------------
306 306
 
307
-    /**
308
-     * Resumes the running of tasks after the system has been disabled
309
-     * with the `disable` command.
310
-     */
311
-    public function enable()
312
-    {
313
-        if (! Settings::save('is_disabled', 'n', 'cron'))
314
-        {
315
-            return CLI::error('Unknown problem saving the setting. '. CLI::color('Cron jobs will NOT run!', 'yellow'));
316
-        }
307
+	/**
308
+	 * Resumes the running of tasks after the system has been disabled
309
+	 * with the `disable` command.
310
+	 */
311
+	public function enable()
312
+	{
313
+		if (! Settings::save('is_disabled', 'n', 'cron'))
314
+		{
315
+			return CLI::error('Unknown problem saving the setting. '. CLI::color('Cron jobs will NOT run!', 'yellow'));
316
+		}
317 317
 
318
-        CLI::write('Done');
319
-    }
318
+		CLI::write('Done');
319
+	}
320 320
 
321
-    //--------------------------------------------------------------------
321
+	//--------------------------------------------------------------------
322 322
 
323 323
 
324
-    //--------------------------------------------------------------------
325
-    // Private Methods
326
-    //--------------------------------------------------------------------
324
+	//--------------------------------------------------------------------
325
+	// Private Methods
326
+	//--------------------------------------------------------------------
327 327
 
328
-    /**
329
-     * Lists out all available tasks, names only.
330
-     */
331
-    private function listTaskNames()
332
-    {
333
-        $suspended = Settings::get('suspended_tasks', 'cron');
328
+	/**
329
+	 * Lists out all available tasks, names only.
330
+	 */
331
+	private function listTaskNames()
332
+	{
333
+		$suspended = Settings::get('suspended_tasks', 'cron');
334 334
 
335
-        if (empty($suspended))
336
-        {
337
-            $suspended = [];
338
-        }
335
+		if (empty($suspended))
336
+		{
337
+			$suspended = [];
338
+		}
339 339
 
340
-        $tasks = \Myth\Cron\CronManager::listAll();
340
+		$tasks = \Myth\Cron\CronManager::listAll();
341 341
 
342
-        echo CLI::write("\nAvailable Tasks:");
342
+		echo CLI::write("\nAvailable Tasks:");
343 343
 
344
-        foreach ($tasks as $alias => $task)
345
-        {
346
-            $color = 'yellow';
347
-            $extra = '';
344
+		foreach ($tasks as $alias => $task)
345
+		{
346
+			$color = 'yellow';
347
+			$extra = '';
348 348
 
349
-            if (in_array($alias, $suspended) )
350
-            {
351
-                $color = 'blue';
352
-                $extra = "[Suspended]";
353
-            }
349
+			if (in_array($alias, $suspended) )
350
+			{
351
+				$color = 'blue';
352
+				$extra = "[Suspended]";
353
+			}
354 354
 
355
-            echo CLI::write("\t{$extra} {$alias}", $color);
356
-        }
357
-    }
355
+			echo CLI::write("\t{$extra} {$alias}", $color);
356
+		}
357
+	}
358 358
 
359
-    //--------------------------------------------------------------------
359
+	//--------------------------------------------------------------------
360 360
 
361 361
 }
Please login to merge, or discard this patch.
myth/CIModules/database/controllers/Database.php 1 patch
Indentation   +224 added lines, -224 removed lines patch added patch discarded remove patch
@@ -35,207 +35,207 @@  discard block
 block discarded – undo
35 35
 class Database extends \Myth\Controllers\CLIController
36 36
 {
37 37
 
38
-    protected $descriptions = [
39
-        'migrate'       => ['migrate [$to]',        'Runs the migrations up or down until schema at version \$to'],
40
-        'quietMigrate'  => ['quiteMigrate [$to]',   'Same as migrate but without any feedback.'],
41
-        'refresh'       => ['refresh',              'Runs migrations back to version 0 (uninstall) and then back to the most recent migration.'],
42
-        'newMigration'  => ['newMigration [$name]', 'Creates a new migration file.'],
43
-        'seed'          => ['seed [$name]',         'Runs the named database seeder.']
44
-    ];
45
-
46
-    protected $long_descriptions = [
47
-        'migrate'       => '',
48
-        'quietMigrate'  => '',
49
-        'refresh'       => '',
50
-        'newMigration'  => '',
51
-        'seed'          => ''
52
-    ];
53
-
54
-    //-------------------------------------------------------------------
55
-
56
-    //--------------------------------------------------------------------
57
-    // Migration Methods
58
-    //--------------------------------------------------------------------
59
-
60
-    /**
61
-     * Provides a command-line interface to the migration scripts.
62
-     * If no $to is provided, will migrate to the latest version.
63
-     *
64
-     * Example:
65
-     *      > php index.php database migrate
66
-     *
67
-     * @param string $type 'app', 'myth', 'all' or {module_name}
68
-     * @param null $to
69
-     * @param bool $silent If TRUE, will NOT display any prompts for verification.
70
-     * @return bool|void
71
-     */
72
-    public function migrate($type=null, $to = null, $silent = false)
73
-    {
74
-        $this->load->library('migration');
75
-
76
-        if (empty($type))
77
-        {
78
-            $type = CLI::prompt("Migration group to refresh?", $this->migration->default_migration_path());
79
-
80
-            if (empty($type))
81
-            {
82
-                return $silent ? false : CLI::error("\tYou must supply a group to refresh.");
83
-            }
84
-        }
85
-
86
-        // We need to append 'mod:' to properly handle modules, if
87
-        // the $type is not one of the recognized migration groups.
88
-        $this->config->load('migration');
89
-        $groups = config_item('migration_paths');
90
-        $groups = array_keys($groups);
91
-
92
-        // If it's not in the groups list, then assume it's a module.
93
-        if (! in_array($type, $groups))
94
-        {
95
-            if (strpos($type, 'mod:') !== 0)
96
-            {
97
-                $type = 'mod:'. $type;
98
-            }
99
-        }
100
-
101
-        unset($groups);
102
-
103
-        // Get our stats on the migrations
104
-        $latest = $this->migration->get_latest($type);
105
-        $latest = empty($latest) ? 0 : substr($latest, 0, strpos($latest, '_'));
106
-
107
-        if (empty($latest)) {
108
-            return CLI::write("\tNo migrations found.", 'yellow');
109
-        }
110
-
111
-        $current = $this->migration->get_version($type);
112
-
113
-        // Already at the desired version?
114
-        if ((! is_null($to) && $current == $to) OR (is_null($to) && $current == $latest))
115
-        {
116
-            return $silent ? true : CLI::write("\tDatabase is already at the desired version ({$current})", 'yellow');
117
-        }
118
-
119
-        $target = is_null($to) ? $latest : $to;
120
-
121
-        // Just to be safe, verify with the user they want to migrate
122
-        // to the latest version.
123
-        if (is_null($to)) {
124
-            // If we're in silent mode, don't prompt, just go to the latest...
125
-            if (! $silent) {
126
-                $go_ahead = CLI::prompt('Migrate to the latest available version?', array('y', 'n'));
127
-
128
-                if ($go_ahead == 'n') {
129
-                    return CLI::write('Bailing...', 'yellow');
130
-                }
131
-            }
132
-
133
-            if (! $this->migration->latest($type)) {
134
-                return CLI::error("\n\tERROR: " . $this->migration->error_string() . "\n");
135
-            }
136
-        } else {
137
-            if ($this->migration->version($type, $to) === false) {
138
-                return CLI::error("\n\tERROR: " . $this->migration->error_string() . "\n");
139
-            }
140
-        }
141
-
142
-        return $silent ? true :
143
-            CLI::write("\n\tSuccessfully migrated database from version {$current} to {$target}.\n", 'green');
144
-    }
145
-
146
-    //--------------------------------------------------------------------
147
-
148
-    /**
149
-     * Performs a migration that does not prompt for any information.
150
-     * Suitable for use within automated scripts that can't be
151
-     * bothered with answering questions.
152
-     *
153
-     * @param string $type 'app', 'myth', 'all' or {module_name}
154
-     * @param null $to
155
-     * @return bool|void
156
-     */
157
-    public function quietMigrate($type='app', $to = null)
158
-    {
159
-        return $this->migrate($type, $to, true);
160
-    }
161
-
162
-    //--------------------------------------------------------------------
163
-
164
-
165
-    /**
166
-     * Migrates the database back to 0, then back up to the latest version.
167
-     *
168
-     * @param string $type  The group or module to refresh.
169
-     * @return mixed
170
-     */
171
-    public function refresh($type=null)
172
-    {
173
-        $this->load->library('migration');
174
-
175
-        if (empty($type))
176
-        {
177
-            $type = CLI::prompt("Migration group to refresh?", $this->migration->default_migration_path());
178
-
179
-            if (empty($type))
180
-            {
181
-                return CLI::error("\tYou must supply a group to refresh.");
182
-            }
183
-        }
184
-
185
-        if ($this->migration->version($type, 0) === false) {
186
-            return CLI::error("\tERROR: " . $this->migration->error_string());
187
-        }
188
-
189
-        CLI::write(CLI::color("\tCleared the database.", 'green'));
190
-
191
-        if ($this->migration->latest($type) === false) {
192
-            return CLI::error("\tERROR: " . $this->migration->error_string());
193
-        }
194
-
195
-        CLI::write("\tRe-installed the database to the latest migration.", 'green');
196
-    }
197
-
198
-    //--------------------------------------------------------------------
199
-
200
-    /**
201
-     * Creates a new migration file ready to be used.
202
-     *
203
-     * @param $name
204
-     */
205
-    public function newMigration($name = null, $type = 'app')
206
-    {
207
-        if (empty($name)) {
208
-            $name = CLI::prompt('Migration name? ');
209
-
210
-            if (empty($name)) {
211
-                return CLI::error("\tYou must provide a migration name.", 'red');
212
-            }
213
-        }
214
-
215
-        $this->load->library('migration');
216
-
217
-        $path = $this->migration->determine_migration_path($type);
218
-
219
-        // Does the alias path exist in our config?
220
-        if (! $path) {
221
-            return CLI::error("\tThe migration path for '{$type}' does not exist.'");
222
-        }
223
-
224
-        // Does the path really exist?
225
-        if (! is_dir($path)) {
226
-            return CLI::error("\tThe path for '{$type}' is not a directory.");
227
-        }
228
-
229
-        // Is the folder writeable?
230
-        if (! is_writeable($path)) {
231
-            return CLI::error("\tThe folder for '{$type}' migrations is not writeable.");
232
-        }
233
-
234
-        $file = $this->migration->make_name($name);
235
-
236
-        $path = rtrim($path, '/') .'/'. $file;
237
-
238
-        $contents = <<<EOT
38
+	protected $descriptions = [
39
+		'migrate'       => ['migrate [$to]',        'Runs the migrations up or down until schema at version \$to'],
40
+		'quietMigrate'  => ['quiteMigrate [$to]',   'Same as migrate but without any feedback.'],
41
+		'refresh'       => ['refresh',              'Runs migrations back to version 0 (uninstall) and then back to the most recent migration.'],
42
+		'newMigration'  => ['newMigration [$name]', 'Creates a new migration file.'],
43
+		'seed'          => ['seed [$name]',         'Runs the named database seeder.']
44
+	];
45
+
46
+	protected $long_descriptions = [
47
+		'migrate'       => '',
48
+		'quietMigrate'  => '',
49
+		'refresh'       => '',
50
+		'newMigration'  => '',
51
+		'seed'          => ''
52
+	];
53
+
54
+	//-------------------------------------------------------------------
55
+
56
+	//--------------------------------------------------------------------
57
+	// Migration Methods
58
+	//--------------------------------------------------------------------
59
+
60
+	/**
61
+	 * Provides a command-line interface to the migration scripts.
62
+	 * If no $to is provided, will migrate to the latest version.
63
+	 *
64
+	 * Example:
65
+	 *      > php index.php database migrate
66
+	 *
67
+	 * @param string $type 'app', 'myth', 'all' or {module_name}
68
+	 * @param null $to
69
+	 * @param bool $silent If TRUE, will NOT display any prompts for verification.
70
+	 * @return bool|void
71
+	 */
72
+	public function migrate($type=null, $to = null, $silent = false)
73
+	{
74
+		$this->load->library('migration');
75
+
76
+		if (empty($type))
77
+		{
78
+			$type = CLI::prompt("Migration group to refresh?", $this->migration->default_migration_path());
79
+
80
+			if (empty($type))
81
+			{
82
+				return $silent ? false : CLI::error("\tYou must supply a group to refresh.");
83
+			}
84
+		}
85
+
86
+		// We need to append 'mod:' to properly handle modules, if
87
+		// the $type is not one of the recognized migration groups.
88
+		$this->config->load('migration');
89
+		$groups = config_item('migration_paths');
90
+		$groups = array_keys($groups);
91
+
92
+		// If it's not in the groups list, then assume it's a module.
93
+		if (! in_array($type, $groups))
94
+		{
95
+			if (strpos($type, 'mod:') !== 0)
96
+			{
97
+				$type = 'mod:'. $type;
98
+			}
99
+		}
100
+
101
+		unset($groups);
102
+
103
+		// Get our stats on the migrations
104
+		$latest = $this->migration->get_latest($type);
105
+		$latest = empty($latest) ? 0 : substr($latest, 0, strpos($latest, '_'));
106
+
107
+		if (empty($latest)) {
108
+			return CLI::write("\tNo migrations found.", 'yellow');
109
+		}
110
+
111
+		$current = $this->migration->get_version($type);
112
+
113
+		// Already at the desired version?
114
+		if ((! is_null($to) && $current == $to) OR (is_null($to) && $current == $latest))
115
+		{
116
+			return $silent ? true : CLI::write("\tDatabase is already at the desired version ({$current})", 'yellow');
117
+		}
118
+
119
+		$target = is_null($to) ? $latest : $to;
120
+
121
+		// Just to be safe, verify with the user they want to migrate
122
+		// to the latest version.
123
+		if (is_null($to)) {
124
+			// If we're in silent mode, don't prompt, just go to the latest...
125
+			if (! $silent) {
126
+				$go_ahead = CLI::prompt('Migrate to the latest available version?', array('y', 'n'));
127
+
128
+				if ($go_ahead == 'n') {
129
+					return CLI::write('Bailing...', 'yellow');
130
+				}
131
+			}
132
+
133
+			if (! $this->migration->latest($type)) {
134
+				return CLI::error("\n\tERROR: " . $this->migration->error_string() . "\n");
135
+			}
136
+		} else {
137
+			if ($this->migration->version($type, $to) === false) {
138
+				return CLI::error("\n\tERROR: " . $this->migration->error_string() . "\n");
139
+			}
140
+		}
141
+
142
+		return $silent ? true :
143
+			CLI::write("\n\tSuccessfully migrated database from version {$current} to {$target}.\n", 'green');
144
+	}
145
+
146
+	//--------------------------------------------------------------------
147
+
148
+	/**
149
+	 * Performs a migration that does not prompt for any information.
150
+	 * Suitable for use within automated scripts that can't be
151
+	 * bothered with answering questions.
152
+	 *
153
+	 * @param string $type 'app', 'myth', 'all' or {module_name}
154
+	 * @param null $to
155
+	 * @return bool|void
156
+	 */
157
+	public function quietMigrate($type='app', $to = null)
158
+	{
159
+		return $this->migrate($type, $to, true);
160
+	}
161
+
162
+	//--------------------------------------------------------------------
163
+
164
+
165
+	/**
166
+	 * Migrates the database back to 0, then back up to the latest version.
167
+	 *
168
+	 * @param string $type  The group or module to refresh.
169
+	 * @return mixed
170
+	 */
171
+	public function refresh($type=null)
172
+	{
173
+		$this->load->library('migration');
174
+
175
+		if (empty($type))
176
+		{
177
+			$type = CLI::prompt("Migration group to refresh?", $this->migration->default_migration_path());
178
+
179
+			if (empty($type))
180
+			{
181
+				return CLI::error("\tYou must supply a group to refresh.");
182
+			}
183
+		}
184
+
185
+		if ($this->migration->version($type, 0) === false) {
186
+			return CLI::error("\tERROR: " . $this->migration->error_string());
187
+		}
188
+
189
+		CLI::write(CLI::color("\tCleared the database.", 'green'));
190
+
191
+		if ($this->migration->latest($type) === false) {
192
+			return CLI::error("\tERROR: " . $this->migration->error_string());
193
+		}
194
+
195
+		CLI::write("\tRe-installed the database to the latest migration.", 'green');
196
+	}
197
+
198
+	//--------------------------------------------------------------------
199
+
200
+	/**
201
+	 * Creates a new migration file ready to be used.
202
+	 *
203
+	 * @param $name
204
+	 */
205
+	public function newMigration($name = null, $type = 'app')
206
+	{
207
+		if (empty($name)) {
208
+			$name = CLI::prompt('Migration name? ');
209
+
210
+			if (empty($name)) {
211
+				return CLI::error("\tYou must provide a migration name.", 'red');
212
+			}
213
+		}
214
+
215
+		$this->load->library('migration');
216
+
217
+		$path = $this->migration->determine_migration_path($type);
218
+
219
+		// Does the alias path exist in our config?
220
+		if (! $path) {
221
+			return CLI::error("\tThe migration path for '{$type}' does not exist.'");
222
+		}
223
+
224
+		// Does the path really exist?
225
+		if (! is_dir($path)) {
226
+			return CLI::error("\tThe path for '{$type}' is not a directory.");
227
+		}
228
+
229
+		// Is the folder writeable?
230
+		if (! is_writeable($path)) {
231
+			return CLI::error("\tThe folder for '{$type}' migrations is not writeable.");
232
+		}
233
+
234
+		$file = $this->migration->make_name($name);
235
+
236
+		$path = rtrim($path, '/') .'/'. $file;
237
+
238
+		$contents = <<<EOT
239 239
 <?php
240 240
 
241 241
 /**
@@ -262,36 +262,36 @@  discard block
 block discarded – undo
262 262
 
263 263
 }
264 264
 EOT;
265
-        $contents = str_replace('{name}', $name, $contents);
266
-        $contents = str_replace('{date}', date('Y-m-d H:i:s a'), $contents);
267
-        $contents = str_replace('{clean_name}', ucwords(str_replace('_', ' ', $name)), $contents);
265
+		$contents = str_replace('{name}', $name, $contents);
266
+		$contents = str_replace('{date}', date('Y-m-d H:i:s a'), $contents);
267
+		$contents = str_replace('{clean_name}', ucwords(str_replace('_', ' ', $name)), $contents);
268 268
 
269
-        $this->load->helper('file');
269
+		$this->load->helper('file');
270 270
 
271
-        if (write_file($path, $contents)) {
272
-            return CLI::write("\tNew migration created: " . CLI::color($file, 'yellow'), 'green');
273
-        }
271
+		if (write_file($path, $contents)) {
272
+			return CLI::write("\tNew migration created: " . CLI::color($file, 'yellow'), 'green');
273
+		}
274 274
 
275
-        return CLI::error("\tUnkown error trying to create migration: {$file}", 'red');
276
-    }
275
+		return CLI::error("\tUnkown error trying to create migration: {$file}", 'red');
276
+	}
277 277
 
278
-    //--------------------------------------------------------------------
278
+	//--------------------------------------------------------------------
279 279
 
280
-    //--------------------------------------------------------------------
281
-    // Seeding Methods
282
-    //--------------------------------------------------------------------
280
+	//--------------------------------------------------------------------
281
+	// Seeding Methods
282
+	//--------------------------------------------------------------------
283 283
 
284
-    /**
285
-     * Installs any database seeds stored in database/seeds. Seeds just need to
286
-     * extend the Seeder class and have a method named run.
287
-     */
288
-    public function seed($name = null)
289
-    {
290
-        $this->load->library('seeder');
284
+	/**
285
+	 * Installs any database seeds stored in database/seeds. Seeds just need to
286
+	 * extend the Seeder class and have a method named run.
287
+	 */
288
+	public function seed($name = null)
289
+	{
290
+		$this->load->library('seeder');
291 291
 
292
-        $this->seeder->call($name);
293
-    }
292
+		$this->seeder->call($name);
293
+	}
294 294
 
295
-    //--------------------------------------------------------------------
295
+	//--------------------------------------------------------------------
296 296
 
297 297
 }
Please login to merge, or discard this patch.
myth/CIModules/database/libraries/Seeder.php 1 patch
Indentation   +63 added lines, -63 removed lines patch added patch discarded remove patch
@@ -39,92 +39,92 @@
 block discarded – undo
39 39
  */
40 40
 class Seeder {
41 41
 
42
-    public $error_string    = '';
42
+	public $error_string    = '';
43 43
 
44
-    protected $ci;
44
+	protected $ci;
45 45
 
46
-    protected $is_cli = false;
46
+	protected $is_cli = false;
47 47
 
48
-    protected $db;
49
-    protected $dbforge;
48
+	protected $db;
49
+	protected $dbforge;
50 50
 
51
-    //--------------------------------------------------------------------
51
+	//--------------------------------------------------------------------
52 52
 
53
-    public function __construct ()
54
-    {
55
-        $this->ci =& get_instance();
53
+	public function __construct ()
54
+	{
55
+		$this->ci =& get_instance();
56 56
 
57
-        $this->is_cli = $this->ci->input->is_cli_request();
57
+		$this->is_cli = $this->ci->input->is_cli_request();
58 58
 
59
-        if ($this->is_cli)
60
-        {
61
-            $cli = new CLI();
62
-            $cli::_init();
63
-        }
59
+		if ($this->is_cli)
60
+		{
61
+			$cli = new CLI();
62
+			$cli::_init();
63
+		}
64 64
 
65
-        $this->ci->load->dbforge();
65
+		$this->ci->load->dbforge();
66 66
 
67
-        // Setup some convenience vars.
68
-        $this->db       =& $this->ci->db;
69
-        $this->dbforge  =& $this->ci->dbforge;
70
-    }
67
+		// Setup some convenience vars.
68
+		$this->db       =& $this->ci->db;
69
+		$this->dbforge  =& $this->ci->dbforge;
70
+	}
71 71
 
72
-    //--------------------------------------------------------------------
72
+	//--------------------------------------------------------------------
73 73
 
74 74
 
75
-    /**
76
-     * Run the database seeds. It's where the magic happens.
77
-     * This method MUST be overridden by child classes.
78
-     */
79
-    public function run ()
80
-    {
75
+	/**
76
+	 * Run the database seeds. It's where the magic happens.
77
+	 * This method MUST be overridden by child classes.
78
+	 */
79
+	public function run ()
80
+	{
81 81
 
82
-    }
82
+	}
83 83
 
84
-    //--------------------------------------------------------------------
84
+	//--------------------------------------------------------------------
85 85
 
86
-    /**
87
-     * Loads the class file and calls the run() method
88
-     * on the class.
89
-     *
90
-     * @param $class
91
-     */
92
-    public function call ($class)
93
-    {
94
-        if (empty($class))
95
-        {
96
-            // Ask the user...
97
-            $class = trim( CLI::prompt("Seeder name") );
86
+	/**
87
+	 * Loads the class file and calls the run() method
88
+	 * on the class.
89
+	 *
90
+	 * @param $class
91
+	 */
92
+	public function call ($class)
93
+	{
94
+		if (empty($class))
95
+		{
96
+			// Ask the user...
97
+			$class = trim( CLI::prompt("Seeder name") );
98 98
 
99
-            if (empty($class)) {
100
-                return CLI::error("\tNo Seeder was specified.");
101
-            }
102
-        }
99
+			if (empty($class)) {
100
+				return CLI::error("\tNo Seeder was specified.");
101
+			}
102
+		}
103 103
 
104
-        $path = APPPATH .'database/seeds/'. str_replace('.php', '', $class) .'.php';
104
+		$path = APPPATH .'database/seeds/'. str_replace('.php', '', $class) .'.php';
105 105
 
106
-        if ( ! is_file($path))
107
-        {
108
-            return CLI::error("\tUnable to find seed class: ". $class);
109
-        }
106
+		if ( ! is_file($path))
107
+		{
108
+			return CLI::error("\tUnable to find seed class: ". $class);
109
+		}
110 110
 
111
-        try {
112
-            require $path;
111
+		try {
112
+			require $path;
113 113
 
114
-            $seeder = new $class();
114
+			$seeder = new $class();
115 115
 
116
-            $seeder->run();
116
+			$seeder->run();
117 117
 
118
-            unset($seeder);
119
-        }
120
-        catch (\Exception $e)
121
-        {
122
-            show_error($e->getMessage(), $e->getCode());
123
-        }
118
+			unset($seeder);
119
+		}
120
+		catch (\Exception $e)
121
+		{
122
+			show_error($e->getMessage(), $e->getCode());
123
+		}
124 124
 
125
-        return Cli::write("\tSeeded: $class", 'green');
126
-    }
125
+		return Cli::write("\tSeeded: $class", 'green');
126
+	}
127 127
 
128
-    //--------------------------------------------------------------------
128
+	//--------------------------------------------------------------------
129 129
 
130 130
 }
Please login to merge, or discard this patch.
myth/CIModules/docs/config/docs.php 1 patch
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -57,8 +57,8 @@
 block discarded – undo
57 57
 | if realpath cannot find/read the folder.
58 58
 */
59 59
 $config['docs.folders'] = [
60
-    'application'   => APPPATH .'docs',
61
-    'developer'     => APPPATH .'../myth/_docs_src'
60
+	'application'   => APPPATH .'docs',
61
+	'developer'     => APPPATH .'../myth/_docs_src'
62 62
 ];
63 63
 
64 64
 /*
Please login to merge, or discard this patch.