Delete user directory through REST service

You can share your Lua Scripts with everybody here.
Post Reply
jvillavi2
Posts: 3
Joined: Fri Feb 26, 2016 11:12 am

Delete user directory through REST service

Post by jvillavi2 »

Hi everybody,

I was wondering if exist any function to delete user directories through the REST service.
I can see in the documentation that exist the c_AddUserDirectory function wich allows me to manually add folders with proper permits but doesn't exist a delete user directory function.
How can I do that?

Thanks
FTP
Site Admin
Posts: 2072
Joined: Tue Sep 29, 2009 6:09 am

Re: Delete user directory through REST service

Post by FTP »

OK, you can do it like the below code, here we use PHP for calling the RESTful web service:

Code: Select all

<?php

$strUrl = "http://127.0.0.1:5466/admin_webservice.html";
$strUrlParam = "?admin=demo&pass=demo123&cmd=";
$strLuaScript = <<<EOT
   local strDomain = "domain1"
   local strUsername = "test"
   local tableUser = c_GetUser(strDomain,strUsername)

   for k,v in pairs(tableUser) do
      if type(v) == "boolean" then
         if v == true then
            tableUser[k] = 1
         else
            tableUser[k] = 0
         end
      end
   end

   tableUser.oldpassword = tableUser.password
   tableUser.directories = {}
   AddUser(strDomain,tableUser)
EOT;

$strResult = file_get_contents($strUrl.$strUrlParam.rawurlencode($strLuaScript));
print($strResult);

?>
jvillavi2
Posts: 3
Joined: Fri Feb 26, 2016 11:12 am

Re: Delete user directory through REST service

Post by jvillavi2 »

Hi FTP,

Thanks for your fast answer!!

Excuse me but I'm not an expert in Lua language and I have a doubt about the script.
What is "<<<EOT" and "EOT"?
Maybe they could be the quotation marks?

Something like this:

$strLuaScript = '
local strDomain = "domain1"
local strUsername = "test"
...
AddUser(strDomain,tableUser)
';
FTP
Site Admin
Posts: 2072
Joined: Tue Sep 29, 2009 6:09 am

Re: Delete user directory through REST service

Post by FTP »

Yes, you are right, see this help document:
http://php.net/manual/en/language.types ... ax.heredoc" rel="nofollow
jvillavi2
Posts: 3
Joined: Fri Feb 26, 2016 11:12 am

Re: Delete user directory through REST service

Post by jvillavi2 »

Hi FTP,

Thank you very much!!
The script is working fine except one thing:

when the script is executed, the user modified can't establish a ftp connection with the wing server. Seems like the password had been changed.

Could this be possible?
FTP
Site Admin
Posts: 2072
Joined: Tue Sep 29, 2009 6:09 am

Re: Delete user directory through REST service

Post by FTP »

Just modified the above Lua script, please try it again.
Post Reply