/
chown.php
136 lines (129 loc) · 5.67 KB
/
chown.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
<?php
/*
* Pharinix Copyright (C) 2015 Pedro Pelaez <aaaaa976@gmail.com>
* Sources https://github.com/PSF1/pharinix
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
if (!defined("CMS_VERSION")) { header("HTTP/1.0 404 Not Found"); die(""); }
if (!class_exists("commandChown")) {
class commandChown extends driverCommand {
public static function runMe(&$params, $debug = true) {
$params = array_merge(array(
"cmd" => "",
"owner" => null, // To detect defaults
"group" => null,
), $params);
$cmd = $params["cmd"];
$owner = null;
$group = null;
// Detect wrong values
if ($params["owner"] != null) {
if (!is_numeric($params["owner"])) {
// Owner is a mail
$resp = driverUser::getUserIDByMail($params["owner"]);
if ($resp === false) {
return array("ok" => false, "msg" => __("Bad user id."));
} else {
$owner = $resp;
}
} else {
// Owner is a ID
$resp = driverUser::getUserName($params["owner"]);
if ($resp == "unknown") {
return array("ok" => false, "msg" => __("Bad user id."));
}
$owner = $params["owner"];
}
}
if ($params["group"] != null) {
if (!is_numeric($params["group"])) {
// group is a title
$resp = driverUser::getGroupID($params["group"]);
if ($resp === false) {
return array("ok" => false, "msg" => __("Bad group id."));
} else {
$group = $resp;
}
} else {
// group is a ID
$resp = driverUser::getGroupName($params["group"]);
if ($resp == "unknown") {
return array("ok" => false, "msg" => __("Bad group id."));
}
$group = $params["group"];
}
}
//Change
foreach (driverCommand::$paths as $path) {
if (is_file($path . $cmd . ".php")) {
$object = include($path . $cmd . ".php");
$can = $object->getAccessData($path . $cmd . ".php");
if (driverUser::getID() == 0 || driverUser::getID() == $can["owner"]) {
// Calculate the new ownership
if ($params["owner"] != null) {
$can["owner"] = $owner;
}
if ($params["group"] != null) {
$can["group"] = $group;
}
// Change ownership
driverUser::secFileSetAccess(
$path . $cmd . ".php",
$can["flags"], $can["owner"], $can["group"]
);
$resp = array("ok" => true);
} else {
$resp = array("ok" => false, "msg" => __("You need ownership."));
}
return $resp;
}
}
}
public static function getHelp() {
return array(
"package" => 'core',
"description" => __("To change owner, and/or group, of the command."),
"parameters" => array(
"cmd" => __("Command that you need change ownership."),
"owner" => __("Mail of the user or ID of the new owner. If it's null, or it is not set, command don't change it, to set to root you must value how 0, zero."),
"group" => __("Title or ID of the group. If it's null, or it is not set, command don't change it, to set to root you must value how 0, zero."),
),
"response" => array(
"ok" => __("TRUE if changed.")
),
"type" => array(
"parameters" => array(
"cmd" => "string",
"owner" => "string",
"group" => "string",
),
"response" => array(
"ok" => "boolean"
),
),
"echo" => false
);
}
public static function getAccess($ignore = "") {
$me = __FILE__;
return parent::getAccess($me);
}
public static function getAccessFlags() {
return driverUser::PERMISSION_FILE_ALL_EXECUTE;
}
}
}
return new commandChown();