Project

General

Profile

Download (1.64 KB) Statistics
| Branch: | Tag: | Revision:
1
#!/usr/local/bin/php-cgi -f
2
<?php
3
/*
4
 * rc.expireaccounts
5
 *
6
 * part of pfSense (https://www.pfsense.org)
7
 * Copyright (c) 2009 Shrew Soft Inc.
8
 * Copyright (c) 2016 Electric Sheep Fencing
9
 * Copyright (c) 2016-2025 Rubicon Communications, LLC (Netgate)
10
 * All rights reserved.
11
 *
12
 * Licensed under the Apache License, Version 2.0 (the "License");
13
 * you may not use this file except in compliance with the License.
14
 * You may obtain a copy of the License at
15
 *
16
 * http://www.apache.org/licenses/LICENSE-2.0
17
 *
18
 * Unless required by applicable law or agreed to in writing, software
19
 * distributed under the License is distributed on an "AS IS" BASIS,
20
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21
 * See the License for the specific language governing permissions and
22
 * limitations under the License.
23
 */
24

    
25
	require_once("config.inc");
26
	require_once("functions.inc");
27

    
28
	$removed = 0;
29
	$user_config = config_get_path('system/user');
30
	if (!is_array($user_config)) {
31
		return;
32
	}
33

    
34
	$count = count($user_config);
35
	$index = 0;
36
	for (; $index < $count; $index++) {
37
		$user = &$user_config[$index];
38
		if ($user['scope'] == "system") {
39
			continue;
40
		}
41
		echo "1\n";
42
		echo "User {$user['name']} expires {$user['expires']}\n";
43
		if (!$user['expires'] || isset($user['disabled'])) {
44
			continue;
45
		}
46
		echo "1\n";
47
		if (strtotime("-1 day") > strtotime($user['expires'])) {
48
			echo "Disabling user {$user['name']} at index #{$index}\n";
49
			$user['disabled'] = true;
50
			$removed++;
51
			$count--;
52
			$index--;
53
		}
54
	}
55
	config_set_path("system/user", $user_config);
56

    
57
	if ($removed > 0) {
58
		write_config("Expired {$removed} user accounts");
59
	}
60

    
61
	//print_r($config);
62

    
63
?>
(32-32/84)