Josh,
There really isn't an API for what you want. You have three choices:
1) make your own API2 custom module that we validate the requested action then escalates to root to perform the action.
2) you could utilize a combination of API2 Fileman::listfiles, Fileman::fileop to recursively fetch the filenames and then perform a chmod on them (I assume that is the only "permissions" that your talking about; if you need to chown, this method won't work because Fileman::fileop don't have that option)
3) do the operation via SSH.
I kinda think that a options 3 will be the simplest and most straight forward to maintain.
Regards,
-DavidN
If, by chance, you decide to do method 2, here's a sample in PHP (using the PHP XML-API client class) of how to recursively fetch the file list...just something I whipped up to see how feasible it was
PHP Code:
require "xmlapi.php";
//////////////////////////////////////////////////////////////////
// Extend PHP Class ///////////////////////////////////////////
class CustomXmlapi extends xmlapi
{
private $cpuser;
public function __construct($host = null, $user = null, $pass = null)
{
parent::__construct($host,$user,$pass);
$this->set_output('json');
return $this;
}
public function set_cpuser($user)
{
$this->cpuser = $user;
return $this;
}
public function get_dir_list($listdir)
{
$args = array(
'dir' => $listdir,
'checkleaf' => 1,
'showdotfiles' => 0,
'types' => 'dir|file',
);
$list = $this->api2_query($this->cpuser, 'Fileman', 'listfiles', $args);
$list = $this->_getValidResult($list);
$files = array();
$rdirs = array();
foreach($list as $item) {
if ( $item['type'] == 'file'){
#just a normal file
array_push($files, $item['fullpath']);
} elseif ( $item['type'] == 'dir' && $item['isleaf'] == 1) {
#a directory that contains files;
array_push($rdirs, $item['fullpath']);
}
}
foreach( $rdirs as $dir) {
$tmp_files = $this->get_dir_list($dir);
foreach( $tmp_files as $more ){
array_push($files, $more);
}
}
return $files;
}
private function _getValidResult( $json_str )
{
$arr = json_decode($json_str,1);
if ( $arr === null || !is_array($arr)) {
return null;
} elseif ( !array_key_exists("cpanelresult", $arr)
|| !is_array($arr['cpanelresult'])
|| !array_key_exists("data", $arr['cpanelresult'])
|| !is_array($arr['cpanelresult']['data'])) {
return null;
}
return $arr['cpanelresult']['data'];
}
}
//////////////////////////////////////////////////////////////////
// Main script //////////////////////////////////////////////////
$ip = 'my.server.net';
$loginUser = 'root';
$accessHash = get_file_contents('/stored/root/.accesshash');
$user = 'mycpanel'; //user with permission issues
$xmlapi = new CustomXmlapi($ip);
$xmlapi->set_user($loginUser);
$xmlapi->set_hash($accessHash);
$xmlapi->set_port(2087);
$xmlapi->set_cpuser($user);
//$xmlapi->set_debug(1);
$list = $xmlapi->get_dir_list('public_html');
//var_dump($list);
// Now that we have list we can use Fileman::fileop to perform a chmod on the files.