This repository has been archived by the owner on Apr 17, 2024. It is now read-only.
/
set_perms.php
100 lines (90 loc) · 2.38 KB
/
set_perms.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?php
declare(strict_types = 1);
require_once __DIR__ . '/../include/bittorrent.php';
require_once BIN_DIR . 'functions.php';
global $site_config, $site_config;
if (empty($BLOCKS)) {
die('BLOCKS are empty');
}
$site_config['cache']['driver'] = 'memory';
$user = get_username();
$group = get_webserver_user();
$paths = [
ROOT_DIR,
];
$styles = get_styles();
$dirs = [];
foreach ($styles as $style) {
$dirs[] = CHAT_DIR . "css/$style/";
$dirs[] = TEMPLATE_DIR . "$style/css/";
}
$exts = [
'php',
'js',
'txt',
'css',
'md',
'json',
'gz',
'example',
'sql',
'cache',
];
$folders = [
BIN_DIR,
CACHE_DIR,
IMDB_CACHE_DIR,
BACKUPS_DIR,
TORRENTS_DIR,
USER_TORRENTS_DIR,
LOGS_DIR,
SQLERROR_LOGS_DIR,
BITBUCKET_DIR,
UPLOADSUB_DIR,
ROOT_DIR . '.git',
ROOT_DIR . 'dir_list/',
ROOT_DIR . 'uploads/',
CHAT_DIR . 'js/',
IMAGES_DIR,
VENDOR_DIR,
NODE_DIR,
];
$folders = array_merge($dirs, $folders);
$excludes = [
ROOT_DIR . 'vendor/',
ROOT_DIR . 'node_modules/',
ROOT_DIR . '.git/',
ROOT_DIR . '.idea/',
];
$chmod_folders = [
VENDOR_DIR,
];
cleanup($group);
chmod(ROOT_DIR, 0774);
$i = 1;
foreach ($paths as $path) {
if (file_exists($path)) {
$objects = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path, RecursiveDirectoryIterator::SKIP_DOTS), RecursiveIteratorIterator::SELF_FIRST);
foreach ($objects as $name => $object) {
if (is_dir($name) && !preg_match('#' . implode('|', $excludes) . '#', realpath($name) . '/')) {
if (preg_match('#' . IMAGES_DIR . '|' . CACHE_DIR . '|' . IMDB_CACHE_DIR . '#', realpath($name) . '/')) {
chown($name, $group);
} else {
chown($name, $user);
}
chgrp($name, $group);
chmod($name, 0774);
$i++;
} elseif (!is_dir($name) && !preg_match('#' . implode('|', $excludes) . '#', realpath($name) . '/')) {
if (preg_match('#' . IMAGES_DIR . '|' . CACHE_DIR . '|' . IMDB_CACHE_DIR . '#', realpath($name) . '/')) {
chown($name, $group);
chmod($name, 0774);
} else {
chmod($name, 0664);
}
$i++;
}
}
}
}
echo "$i files processed\n";