Create dir on UNC when member of a specific group

You can share your Lua Scripts with everybody here.

Create dir on UNC when member of a specific group

Postby sis3970 » Wed Feb 22, 2012 11:20 am

Hi all,

I try to create a script that will create a directory on a shared drive, but only when this user is member of a specific group. I want to execute the script on logon.

This is what works

Code: Select all
local newfolder = "//192.168.1.55/nas-000406_ftp/_cims/".."%Name"
c_MkDir(newfolder)
c_AddUserDirectory("%Domain","%Name",newfolder ,'/',true,true,true,true,true,true,true,true,true)


This does not work

Code: Select all
if table.maxn(c_GetUser("%Usergroups")) == "MyGroup"
then
local newfolder = "//192.168.1.55/nas-000406_ftp/_cims/".."%Name"
c_MkDir(newfolder)
c_AddUserDirectory("%Domain","%Name",newfolder ,'/',true,true,true,true,true,true,true,true,true)
end


Any idea what is wrong here?

Thanks in advance!
Sis
sis3970
 
posts 5
 
joined Wed Feb 22, 2012 10:21 am

Re: Create dir on UNC when member of a specific group

Postby FTP » Wed Feb 22, 2012 1:50 pm

Code: Select all
do
   local useruploaded = c_GetUser("%Domain","%Name")
   local grouplist = useruploaded["usergroups"]

   if grouplist ~= nil then
      for _,groupitem in pairs(grouplist) do
         if groupitem.groupname == "MyGroup" then
      local newfolder = "//192.168.1.55/nas-000406_ftp/_cims/".."%Name"
      c_MkDir(newfolder)
      c_AddUserDirectory("%Domain","%Name",newfolder ,'/',true,true,true,true,true,true,true,true,true)
      break
    end
      end
   end
end
FTP
Site Admin
 
posts 1226
 
joined Tue Sep 29, 2009 6:09 am

Re: Create dir on UNC when member of a specific group

Postby sis3970 » Wed Feb 22, 2012 2:53 pm

Thanks! this works fine now.

Additional question, is there a way to add a sub-folder to the user, instead of a normal folder?
I guess I need an alternative for c_AddUserDirectory

Thanks
Sis
sis3970
 
posts 5
 
joined Wed Feb 22, 2012 10:21 am

Re: Create dir on UNC when member of a specific group

Postby FTP » Thu Feb 23, 2012 11:19 am

Do you want to add a virtual folder?

c_AddUserDirectory("%Domain","%Name",newfolder ,'myfolder',false,true,true,true,true,true,true,true,true)
FTP
Site Admin
 
posts 1226
 
joined Tue Sep 29, 2009 6:09 am

Re: Create dir on UNC when member of a specific group

Postby sis3970 » Tue Feb 28, 2012 10:07 am

Actually no, I would need a sub-folder.
We give root access to all users on group level, but only read.

Now I'd like to add a subfolder to give write permissions on a deeper level.

I don't know if this is possible via scripts, but via the Admin it works great...

Best Regards
Sis
sis3970
 
posts 5
 
joined Wed Feb 22, 2012 10:21 am

Re: Create dir on UNC when member of a specific group

Postby FTP » Mon Mar 05, 2012 7:52 am

OK, check out the following script:

Code: Select all
   local strDomain = "mydomain"
   local strUsername = "myuser"
   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

   local subfolder = {}
   subfolder["dir"] = "d:/game"
   subfolder["alias"] = ""
   subfolder["is_home_dir"] = false
   subfolder["fileread"] = true
   subfolder["filewrite"] = true
   subfolder["fileappend"] = false
   subfolder["filedelete"] = false
   subfolder["dirlist"] = true
   subfolder["dirmake"] = true
   subfolder["dirdelete"] = false
   subfolder["dirrename"] = false
   subfolder["filerename"] = false
   subfolder["zipfile"] = false
   subfolder["unzipfile"] = false

   table.insert(tableUser.subdir_perm, subfolder)

   tableUser.oldpassword = tableUser.password

   AddUser(strDomain,tableUser)
FTP
Site Admin
 
posts 1226
 
joined Tue Sep 29, 2009 6:09 am


Return to Lua scripts

Who is online

Users browsing this forum: No registered users and 1 guest

cron