public function toolsSetChmod()
 {
     $return = array();
     $return['status'] = 'error';
     $return['msg'] = '';
     $return['perms'] = '';
     $post = $this->input->post();
     if (empty($post['folder']) || empty($post['type'])) {
         $return['msg'] = 'Data not specified';
         $this->_json($return);
     }
     if (!is_numeric($post['type'])) {
         $return['msg'] = 'Chmod type is wrong!';
         $this->_json($return);
     }
     $type = $post['type'];
     $folder = $post['folder'];
     $chmod = $type == 1 ? 755 : 777;
     $found = false;
     foreach ($this->chmod_folders as $cfolder) {
         if ($folder == $cfolder['path']) {
             $found = true;
             break;
         }
     }
     if (!$found) {
         $return['msg'] = 'Chmod folder ' . $folder . ' not allowed!';
         $this->_json($return);
     }
     $stat = @chmod($folder, $chmod);
     if ($stat) {
         $status = 1;
     } else {
         @exec('sudo chmod ' . $chmod . ' ' . $folder, $output, $res);
         if (!$res) {
             $status = 1;
         } else {
             $return['msg'] = 'Chmod folder ' . $folder . ' not allowed!';
             $this->_json($return);
         }
     }
     clearstatcache();
     $perms = PathHelper::getPermissions($folder, true);
     $return['perms'] = $perms['int'] . ' (' . $perms['str'] . ')';
     $return['msg'] = 'Successfully chmoded folder ' . $folder . ' to ' . $chmod;
     $return['status'] = $status ? 'ok' : 'error';
     $this->_json($return);
 }