home *** CD-ROM | disk | FTP | other *** search
- <%
- // command.fts
- // PURPOSE:
- // This script implements some of the functionality of the FTGate command processor.
- //
- // USE:
- // to use this you need to create a mailbox called command and add the following to the
- // script command box
- // command.fts
- //
- // WARNING:
- // This script is supplied for reference only, it should be considered untested
- // with no warranty either written or implied. Use is strictly at you own risk.
- //
-
- #include <systemconst.fts>
- var log=new server.log
- log.write(3,"Executing command processor.fts")
- log.write(3,"Message from \""+message.header.fromname+"\"<"+message.header.fromaddress+">");
-
- var outmsg=new server.newmessage;
- outmsg.new()
- outmsg.write.sender(mailbox.address)
- outmsg.write.recipient(message.header.fromaddress)
- outmsg.write("From: "+mailbox.description+" <"+mailbox.address+">\n");
- outmsg.write("To: "+message.header.fromname+" <"+message.header.fromaddress+">\n");
- outmsg.write("Subject: RE:"+message.header.subject+"\n\n");
-
- //
- // declare any variables needed in the system
- //
- const AdminPassword="password"
- var AdministratorMode=false;
- var IsMime=false;
- var CurrentDomain
- var CurrentMailbox
-
- //
- // now we declare the functions that we will need for the command processor
- //
-
-
- function write(msg)
- {
- outmsg.write(msg+"\n");
- log.write(3,msg);
- }
-
- function IsAdministrator(password)
- {
- // write("Checking "+password+"=="+AdminPassword)
- AdministratorMode=(password==AdminPassword);
- return AdministratorMode;
- }
-
- function NextText()
- {
- var Text;
- if (IsMime)
- {
- if (!message.mime.nexttext())
- Text=false;
- else
- Text=message.mime.text
- }
- else
- {
- if (!message.nexttext())
- Text=false;
- else
- Text=message.text
- }
- return Text;
- }
-
- function ProcessMailbox(inname,password)
- {
- CurrentDomain="";
- CurrentMailbox="";
- // first open the mailbox
- var ok=false
- var d=new server.domain
- var mailboxname=string(inname)
- var i=mailboxname.indexof("@",1)
- var domainname=mailbox.domain
- if (i!=-1)
- {
- domainname=mailboxname.slice(i+1,mailbox.length)
- mailboxname=mailboxname.slice(0,i)
- }
- if (d.domainname=domainname)
- {
- var mbx=new d.mailbox
- if (mbx.name=mailboxname)
- {
- if (AdministratorMode || mbx.verifypassword(password))
- {
- write("opened mailbox \""+mailboxname+"\"")
- CurrentMailbox=mbx.name
- CurrentDomain=d.domainname
- ok=true
- }
- else
- {
- write("failed to open mailbox \""+mailboxname+"\" - password error")
- ok=false;
- }
- }
- else
- {
- write("failed to open mailbox \""+mailboxname+"\"")
- ok=false;
- }
- }
- else
- {
- write("failed to open domain \""+domainname+"\"")
- ok=false;
- }
-
- return ok;
- }
-
-
- function ProcessMessage()
- {
- var Text;
- while (1)
- {
- Text=NextText();
- if (!Text)
- break;
- // write("Text=\""+Text+"\"");
- // now decide what we want to do
- // look for comments
- if (Text.Slice(0,2)=="\\")
- continue;
- if (Text.slice(0,13)=="administrator")
- {
- write("Administrator Access Requested ");
- if (IsAdministrator(Text.slice(14,Text.length-1)))
- write("admin mode granted")
- else
- {
- write("admin mode DENIED")
- break;
- }
- continue
- }
- // now look at the other commands
- if (Text.slice(0,12)=="open mailbox")
- {
- // first parameter is mailbox
- // with an optional password
- var mailbox=Text.slice(13,text.length-1)
- var s=mailbox.indexof(",",1)
- if (s!=-1)
- {
- write(text.slice(0,13+s))
- // they added a password
- // so split it and access the mailbox
- var password=mailbox.slice(s+1,mailbox.length)
- mailbox=mailbox.slice(0,s)
- if (!ProcessMailbox(mailbox,password))
- break;
- }
- else
- {
- write(text)
- // no password
- if (!AdministratorMode)
- {
- write("access DENIED")
- break;
- }
- if (!ProcessMailbox(mailbox,""))
- break;
- }
- continue
- }
- if (Text.slice(0,9)=="subscribe")
- {
- if (CurrentMailbox!="" && CurrentDomain!="")
- {
- var d=new server.domain
- d.domainname=CurrentDomain
- var mbx=new d.mailbox
- mbx.name=CurrentMailbox
- if (mbx.type==mbxTypeList)
- {
- // we can subscribe the named person
- // format = subscribe address,[name]
- var address=Text.slice(10,Text.length-1)
- var s=address.indexof(",",1)
- var name=""
- if (s!=-1)
- {
- name=address.slice(s+1,address.length)
- address=address.slice(0,s)
- }
- if (mbx.member.new(address,name))
- write("Subscribed <"+address+"> \""+Name+"\"")
- else
- write("Subscribe failed <"+address+"> \""+Name+"\"")
-
- }
- else
- {
- write("Mailbox is not a list mailbox");
- }
- continue;
- }
- else
- {
- write("No open mailbox");
- break;
- }
- }
- if (Text.slice(0,11)=="unsubscribe")
- {
- if (CurrentMailbox!="" && CurrentDomain!="")
- {
- var d=new server.domain
- d.domainname=CurrentDomain
- var mbx=new d.mailbox
- mbx.name=CurrentMailbox
- if (mbx.type==mbxTypeList)
- {
- // we can subscribe the named person
- // format = subscribe address,[name]
- var address=Text.slice(12,Text.length-1)
- if (mbx.member.delete(address))
- write("Unsubscribed <"+address+">")
- else
- write("Unsubscribe failed <"+address+">")
-
- }
- else
- {
- write("Mailbox is not a list mailbox");
- }
- continue;
- }
- else
- {
- write("No open mailbox");
- break;
- }
- }
-
- }
- return 0
- }
-
- //
- // this is the main section
- // we read the message and process the lines in it
- // align the message with the start of the instructions
- // and then process it
- //
-
- // is it mime or not
- if (message.header.ismime)
- {
- // yes - look for a plain text section
- // and process it
- if (message.mime.firstsection())
- {
- while (1)
- {
- if (message.mime.contenttype=="text/plain")
- {
- // this is the bit to process
- IsMime=true
- ProcessMessage();
- break;
- }
- if (!message.mime.nextsection())
- break;
- }
- }
- }
- else
- {
- // this is plain text
- // skip the header and then process it
- var InHeader=true;
-
- message.firsttext()
- while (message.text)
- {
- if (InHeader && message.text=="\n")
- {
- IsMime=false;
- ProcessMessage()
- break;
- }
- message.nexttext()
- }
- }
- outmsg.close()
- %>