#!/usr/fb/bin/lua require 'lua.inc' --[[---------------------------------------------------------------------- Main ----------------------------------------------------------------------]]-- mydump("top.inc") print('') mydump("middle1.inc") mydump("middle2.inc") String=os.getenv("QUERY_STRING") if string.find(String,"x")== 1 then String = nil else String=string.sub(String,1,(string.find(String,"x")-2)) end Send={} Delete={} SendPrint={} DeletePrint={} doubleChecked={} --[[---------------------------------------------------------- Return Name of a File in QUERY_STRING ----------------------------------------------------------]]-- function dataOfQuery(data, position) local nBegin, nEnd if position == nil then nBegin, nEnd = string.find(data, "%d+.%d+%.pdf") return string.sub(data, nBegin, nEnd) else nBegin, nEnd = string.find(data, "%d+.%d+%.pdf", position) return string.sub(data, nBegin, nEnd) end end --[[---------------------------------------------------------- Check if file is marked as delete ----------------------------------------------------------]]-- function isDelete(data, position) local nBegin, nEnd if string.sub(data, position, position) == "D" then return true else return false end end --[[---------------------------------------------------------- Check if file is marked as send ----------------------------------------------------------]]-- function isSend(data, position) local nBegin, nEnd if string.sub(data, position, position) == "S" then return true else return false end end --[[---------------------------------------------------------- Delete files ----------------------------------------------------------]]-- function doDelete(data) if data ~= nil then data2=string.gsub(data,".pdf",".mail") dPDF=os.remove(string.format("%s%s","/data/fax/good/",data)) dMAIL=os.remove(string.format("%s%s","/data/fax/good/",data2)) if dPDF==true and dMAIL==true then return 1 elseif dPDF==true and dMAIL==nil then return 2 elseif dPDF==nil and dMAIL== true then return 3 else return 0 end end end --[[---------------------------------------------------------- Resend file ----------------------------------------------------------]]-- function resend(data) -- execute Befehl fehlt noch if data ~= nil then file=string.sub(data,1,15) file=string.format("%s%s%s",'/sbin/omgfaxdeliver -q /data/fax/good/',file,'.mail') local state = os.execute(file) if tonumber(state or "1")==0 then return true else return false end end end --[[---------------------------------------------------------- Check if a file is double marked and save the name of file ----------------------------------------------------------]]-- function sendAndDelete() for k,v in pairs(Send) do if Delete[k] ~= nil then table.insert(doubleChecked, k) else if resend(k) then table.insert(SendPrint, k) else table.insert(doubleChecked, k) end end end for k,v in pairs(Delete) do if Send[k] ~= nil then else success=doDelete(k) if success==1 then table.insert(DeletePrint, k) elseif success==2 then k=string.format("%s%s",k,' wM') table.insert(DeletePrint,k) k=string.sub(k,1,(string.len(k)-3)) elseif success==3 then k=string.format("%s%s",k,' wP') table.insert(DeletePrint,k) k=string.sub(k,1,(string.len(k)-3)) else table.insert(doubleChecked,k) end end end end function printTable(data) if data ~= nil then print('') for i=1, table.getn(data), 1 do print(data[i]) print('
') end print('') end end --[[---------------------------------------------------------- calculate the step in QUERY_STRING ----------------------------------------------------------]]-- function step(data) if data ~= 0 then nBegin, nEnd = string.find(data, "%d+.%d+%.pdf.%u.") return(string.len(string.sub(data, nBegin, nEnd))) end end if String ~= nil then sneu, anz =string.gsub(String, "&", ":") if anz == 0 then if isSend(String,21) then Send[dataOfQuery(String)]=true elseif isDelete(String,21) then Delete[dataOfQuery(String)]=true end elseif anz > 0 then local i i=0 while i <= anz do if i==0 then if isDelete(String,21) then Delete[dataOfQuery(String)]=true elseif isSend(String,21) then Send[dataOfQuery(String)]=true end i=i+1 elseif i>0 then if isDelete(String,search(String,i*step(String))) then Delete[dataOfQuery(String,i*step(String))]=true elseif isSend(String,search(String,i*step(String))) then Send[dataOfQuery(String,i*step(String))]=true end i=i+1 end end end else print('

Check a file you want to send or delete.

') end print('
') print('') print('') print(' ') print(' ') print(' ') print(' ') print(' ') sendAndDelete() printTable(SendPrint) printTable(DeletePrint) printTable(doubleChecked) print('
 Resended  Deleted  Failed 
') print('') print('
') print('') print('') print('
') mydump("bottom.inc")