PtokaX forum

Archive => Archived 4.0 boards => Finished Lua 4 scripts => Topic started by: Skrollster on 17 April, 2004, 12:16:29

Title: Self registration, passwd sent via email
Post by: Skrollster on 17 April, 2004, 12:16:29
Hi every one, first script i have written for a while...

this script generate a password with 15 chars [0-9,A-z]

and send it to the user typing +regme the@email.address.com

but in order to make it work you need to have a webserver with PHP support...

regme.lua
function main()
sHost = "localhost"
sPahtToPHP = "lua/mail.php"
end

function DataArrival(tUser, sData)
local _,_,sCmd,sArg1 = strfind(sData, "%b<>%s+(%S+)%s+(%S+)%s*.*|" )
if sCmd then
sCmd = strlower(sCmd)
end
if (sCmd=="+regme") then
local userProfile = tUser.iProfile
if userProfile < 0 then
if not sArg1 then
user:SendData("Reg Bot", "You need to enter a email adress.")
return 1
else
regUserViaEmail(tUser, sArg1)
end
else
user:SendData("Reg Bot", "You are already registered on this hub.")
end
end
end

-- tUser ?r anv?ndaren som ska registreras, allts? ett anv?ndar objekt
-- sEmail ?r email adressen som l?senordet ska skickas till
function regUserViaEmail(tUser, sEmail)
local sPasswd = ""
local sHexPasswd = ""
for i = 1, 15 do
sHexPasswd = sHexPasswd .. strchar(37)
local char = 0
if random(1,62) < 10 then
char = random(48,57)
elseif random(1,10) > 5 then
char = random(65,90)
else
char = random(97,122)
end
sHexPasswd = sHexPasswd .. strupper(format("%x", char))
sPasswd = sPasswd .. strchar(char)
end
local sMessage = "You have now been registered with username: "..tUser.sName.."%0A%0DAnd password: "..sHexPasswd
local FullPHPCommand = sPahtToPHP.."?mailTo="..sEmail.."&mailSubject=Registration at "..frmHub:GetHubName().."&mailMessage="..sMessage..""
FullPHPCommand = gsub(FullPHPCommand,"%s", "%%20")
FullPHPCommand = gsub(FullPHPCommand, "?", "%%E5")
FullPHPCommand = gsub(FullPHPCommand, "?", "%%E4")
FullPHPCommand = gsub(FullPHPCommand, "?", "%%F6")
FullPHPCommand = gsub(FullPHPCommand, "?", "%%C5")
FullPHPCommand = gsub(FullPHPCommand, "?", "%%C4")
FullPHPCommand = gsub(FullPHPCommand, "?", "%%D6")
local GETHTML = "GET /"..FullPHPCommand.." HTTP/1.1\r\nHost: "..sHost.."\r\nUser-Agent: Mozilla/4.0 (compatible; LUA 4.0; LUA 4.0)\r\n"
local socket, sErr = connect(sHost, 80)
local sStatus = ""
if not sErr then
socket:timeout(2)
socket:send(GETHTML..strchar(13,10))
local sLine = ""
while not sErr do
if (strsub(sLine, 1, 9) == "Status = ") then
sStatus = sLine
break
end
sLine, sErr = socket:receive("*l")
end
socket:close()
end
socket:close()
if sStatus == "Status = Sent" then
tUser:SendData("Reg Bot", "Email sent to "..sEmail..", with login info")
tUser:SendData("Reg Bot", (adduser(tUser, sPasswd, GetProfileIdx("Reg"))) )
return
else
tUser:SendData("Reg Bot",sStatus)
return sStatus
end
end

function adduser(User, sPasswd, iUserlevel)
local isreg = -1
local sStatus = ""
if type(User) == "string" then
if GetItemByName(User) then
isreg = GetItemByName(User).iProfile or reguserLevel(User.sName)
else
isreg = reguserLevel(User.sName)
end
elseif type(User) == "table" and User.iProfile then
isreg = User.iProfile
end

if isreg == -1 then
AddRegUser(User.sName, sPasswd, iUserlevel)
sStatus = "Registation successful for "..User.sName.." ( "..GetProfileName(iUserlevel).." )."
elseif tonumber(isreg) then
sStatus = "The user is already registered as: "..GetProfileName(isreg).." and nothing is changed"
else
sStatus = "The user is already registered as: "..isreg.." and nothing is changed"
end
return sStatus
end

function reguserLevel(sUserName)
sUserName = strlower(sUserName)
local allprofiles = GetProfiles()
local index, profile, index2, user
for index, profile in allprofiles do
local users = GetUsersByProfile(profile)
for index2, user in users do
if strlower(user) == sUserName then
return GetProfileIdx(profile)
end
end
end
return -1
end


this is the mail.php script that need to be at sHost/sPahtToPHP

$mailTo = $_GET['mailTo'];
$mailSubject = $_GET['mailSubject'];
$mailMessage = $_GET['mailMessage'];
mail($mailTo, $mailSubject, $mailMessage) or die ("Status = Failed to send email to: ".$_GET['mailTo']);
echo("Status = Sent");
?>


you also need to make sure you have some paremeters set in php.ini in your %SYSTEM% folder

[mail function]
; For Win32 only.
SMTP = your.smtp.server

; For Win32 only.
smtp_port = 25

; For Win32 only.
sendmail_from = from@adress.se
Title:
Post by: Stravides on 14 June, 2004, 10:36:44
Any chance of getting this script for ASP (not .net)

I have cdosys and have relevant ASP code for mailing, I just dont understand how to use external html/web pages

many thanks

CDOSYS Version (XP)
<%
htmlBody = "

Thanks for Registering at RPGBooks

"
htmlBody = htmlBody & "

Your password is

"


Set oMail = Server.CreateObject("CDO.Message")
Set iConf = Server.CreateObject("CDO.Configuration")
Set Flds = iConf.Fields
iConf.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing")= 2
iConf.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver")= "mailserver"
iConf.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverpickupdirectory") = "c:\inetpub\mailroot\pickup"
iConf.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 30
iConf.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = smport
iConf.Fields.Update
Set oMail.Configuration = iConf
oMail.To = strREmail
oMail.From = "REGISTRATION@RPGBOOKS-CYMRU.NO-IP.ORG"
oMail.Subject = "User Password"
oMail.HTMLBody = htmlBody
oMail.Send
Set iConf = Nothing
Set Flds = Nothing
%>