looking for Lua assistance

You can share your Lua Scripts with everybody here.

looking for Lua assistance

Postby businessclient » Wed Oct 14, 2015 8:02 pm

I am using the send mail feature for OnFileUploaded and it works great but I've been asked "can this email notice only go to the people that are members of the group belonging to the file share that the document was uploaded into?".

All I'm doing today is super simple but global as it sends to a distribution mailbox with an email body of; %Name from %IP uploaded %PathName using %ClientVersion

I'm hoping someone has had this need before me and I'm guessing they would have used Lua to tackle this need.

Can anyone help me with some newbie Lua example code?

Thanks, in advance.
businessclient
 
4
 
Tue Oct 13, 2015 6:56 pm

Re: looking for Lua assistance

Postby FTP » Thu Oct 15, 2015 3:42 am

OK, you can define the user email under "User -> Notes", and then use the following lua script:

Code: Select all
local user = c_GetUser("%Domain","%Name")   
local user_email = user.note_email
if user_email ~= nil and user_email ~= "" then
   c_SendMail(user_email,"a file has been uploaded","%Name uploaded into %PathName","","SMTP_CONFIG")
end



You can add the above Lua script into the event "OnFileUploaded -> Lua script".

And, "SMTP_CONFIG" is the smtp configuration name at the "Servers -> Settings -> SMTP Manager".
FTP
Site Admin
 
1876
 
Tue Sep 29, 2009 6:09 am

Re: looking for Lua assistance

Postby businessclient » Thu Oct 22, 2015 12:38 am

I've been working with the system and think it's great but I ran into a user request I'm having trouble filling.

I have been working a little with Lua, (never used it before), and writing a script in shell and passing it variable valuables through the Execute Program tab that is triggered under HTTP OnFileUploaded.

My issue is the Lua script offered here and anything called from shell work fine but can only notify a single person or list of people if the email is sent to a distribution list on the email server.

What I can't find are groups and members variables. What I'm getting asked to do is this; there are outside clients uploading into wftpserver and a notice is sent to internal staff, this is good. But, the internal staff will upload a file into the folder assigned to the outside clients and they would like an email notice sent to that client to let them know it is ready for download.

The outside clients are all in a common group, i.e. group ABC has members bob, jane and ted sharing a directory /home/abc and group XYZ has members mary, harry, and phil sharing a directory /home/xyz

When the internal staff uploads a file into /home/abc they want an email sent to bob, jane, and ted to let them know to come download the file. If the staff uploads a file into /home/xyz then they want a notice sent to mary, harry and phil to come download it.

I don't see variables to know what groups people are in for using Lua or shell scripts or perl. Is this possible to do with Lua or an external script?

Thanks for any help.
businessclient
 
4
 
Tue Oct 13, 2015 6:56 pm

Re: looking for Lua assistance

Postby FTP » Fri Oct 23, 2015 6:23 am

OK, in WingFTP, the group is not based on the folder name, so maybe you take the following methods:

1. You can use some hard-coded Lua script, specify the group members for each folder.

2. When a user uploads a file, then you can know the groups this user belongs to, then you can send emails to the other members of those groups.
FTP
Site Admin
 
1876
 
Tue Sep 29, 2009 6:09 am

Re: looking for Lua assistance

Postby businessclient » Fri Oct 23, 2015 4:02 pm

ok, Thanks for the help.

I'm wondering... I have had my best luck using shell script or perl and passing vars using the Execute Program feature but that's really because I have never used Lua and I'm getting carried away with a custom email message that would be tough to type inside the little Lua dev window. :-)

I can easily pass the directory it has been uploaded into. I have my users in common groups and those common groups have common shared directories. Is there a group variable I can pass out to an external script? I didn't see one in the manual. If not, can i create one using Lua to pass to an external script?

Thanks again.
businessclient
 
4
 
Tue Oct 13, 2015 6:56 pm

Re: looking for Lua assistance

Postby FTP » Wed Oct 28, 2015 4:00 am

OK, though I am not very clear about what you need, but for your requirements:

1. You can get all the groups with such script:

Code: Select all
local allgroups = ""
local user = c_GetUser("%Domain","%Name")
if (user.usergroups ~= nil) then
  for _,v in pairs(user.usergroups) do
    allgroups = allgroups..","..v.groupname
  end
end


2. You can execute an external program via such script:

Code: Select all
os.execute("/storage/bin/OnFileUploaded --Domain %Domain --Name %Name --PathName \"%PathName\" --IP %IP")
FTP
Site Admin
 
1876
 
Tue Sep 29, 2009 6:09 am


Return to Lua scripts

Who is online

Users browsing this forum: No registered users and 2 guests