* Mohit Sindhwani <[EMAIL PROTECTED]> [2007-12-20 00:33:42 +0800]:

> Saji N Hameed wrote:
> > Hi Mohit,
> >
> > We control our own server, and it is easy to do stuff like this.
> > Here is a script that I use to update or add certain parts of our
> > website (currently offline).
> >
> > Hope it is helpful.
> >  
> > saji
> >   
> 
> Looking at this answers the fundamental question I had!!  I was 
> concerned about how the authentication is handled to get past the 
> admin.  But, of course, when we use script/runner, we're usually 
> accessing the models directly rather than through the controllers - and 
> the controllers are where the before_filters for authentication will 
> usually be!
> 
> That said, I guess this means that it's best for the script to be local 
> to the site - so, I can't get it to submit from my desktop to the server 
> machine.  The script should ideally be on the server where the site is 
> running.
> 
> Is this how you're using it, Saji?
> 

 Well, the web-server is a different machine, but we have
full access to it. We run a drb server on the
web-server and installed clients on other machines. Users upload
stuff from their desktops to the webserver through this mechanism.

I remember Sean's advise that you may be able to use Capistrano
for this purpose. That may be worth checking out.

Anyway, I am attaching scripts for the client and servers
we use.

best wishes,
saji


# --- this is the drb server that sits at the web-server

#!/usr/bin/env ruby

require 'drb'
require 'drb/acl'

@baseDir=ENV['RadiantHOME']+"/customScripts"
# this order is important, so do not move the
# the require statement below

require  File.join(File.dirname(__FILE__), 'server_methods')

puts "Will Exit if not executed in right Directory"
exit unless `pwd`.chomp == @baseDir

if __FILE__ == $0
  acl = ACL.new(%w( deny all allow 190.1.1.121 allow 220.84.94.58  allow 
localhost ) )
  DRb.install_acl(acl)
  DRb.start_service("druby://:7777", OurClass.new)
  puts "Drb server running at #{DRb.uri}"
  trap("INT") {DRb.stop_service }
  DRb.thread.join
end

# --- some methods used by the DRb object

require 'net/ftp'


class OurClass

  def chDir(wDir,year,month)
    wDir="/home/saji/MyTestServer/public/Reports/"+wDir+"/"+year+"/"+month
    `mkdir -p #{wDir}`
    @wDir=wDir
  end

  def ftpFiles(ftpsite,login,password,wDir,txt,img)
      "Opening new ftp session for #{ftpsite}"
      ftp=Net::FTP.new(ftpsite)
      ftp.login(user=login,passwd=password)
      ftp.chdir(wDir)
      "Retrieving Image files"
      ftp.getbinaryfile(img,@wDir+"/"+img)
      "Retrieving Text files"
      ftp.gettextfile(txt,@wDir+"/"+txt)
      ftp.close
      "ftp over"
  end
  
  def updateWeb(service,year,month)
      # run an update
      retVal=[]
      ENV['RAILS_ENV']="production"
      ls = IO.popen("../script/runner updateWeb #{year} #{month} 
#{service}","r")
      while line = ls.gets
        retVal << line
        puts line
      end
      ls.close
      return(retVal)
  end

end

# --- The ncurses based client that is used to upload information to the
#      web-page via DRb server

#!/usr/bin/env ruby
require "rdialog" 
require 'drb'


@months=%w(JAN FEB MAR APR MAY JUN JUL AUG SEP OCT NOV DEC)
dialog = RDialog.new
dialog.nocancel = true
@[EMAIL PROTECTED] - 1]
@thisYear=Time.today.year.to_s

def updateWebPage
  meSg = @webServer.updateWeb(@product,@year,@month)
  dialog = RDialog.new
  dialog.nocancel = true
  dialog.shadow = false
  tst=dialog.infobox(meSg, height=0, width=0)   
end

def interactWithRemoteServer
  @webServer = DRbObject.new nil, 'druby://190.1.1.24:7777'
  @webServer.chDir(@product,@year,@month)
  [EMAIL PROTECTED]"/"[EMAIL PROTECTED]"/"[EMAIL PROTECTED]
  [EMAIL PROTECTED](@ftpsite,@login,@password,wDir,@txt,@img)
  dialog = RDialog.new
  dialog.nocancel = true
  dialog.shadow = false
  tst=dialog.msgbox(meSg, height=0, width=0)   
  updateWebPage
end

def findLoginDetails
  dialog = RDialog.new
  dialog.nocancel = true
  dialog.shadow = false
  @ftpsite = dialog.inputbox(text="IP address of your machine", 
height=20,width=60, init="190.1.1.121")
  defLogin=`whoami`.chomp
  @login = dialog.inputbox(text="Your login", height=0,width=0, init=defLogin)
  @password = dialog.passwordbox(text="Enter your password", 
height=0,width=0,init="")
end

def checkFiles
  dialog = RDialog.new
  dialog.nocancel = true
  dialog.shadow = false
  allFiles=`ls`.split
  txtFiles=[]
  allFiles.each { |a| txtFiles.push([a]) unless File.extname(a)==".png"}
  exit if txtFiles.size==0
  myText = dialog.radiolist(text="Chose Text Files", items=txtFiles)
  imgFiles=[]
  allFiles.each { |a| imgFiles.push([a]) if File.extname(a)==".png"}
  exit if imgFiles.size==0
  myImgs = dialog.checklist(text="Chose Image Files", items=imgFiles)
  @txt = myText
  @img = myImgs[0]

  findLoginDetails
  interactWithRemoteServer
end

def prepareForTransport
  dialog1 = RDialog.new
  dialog1.nocancel = true
  dialog1.shadow = false
  Dir.chdir(@wDir)
  myDate =  dialog1.calendar(text="Select a Date", height=0, width=0, day=-1, 
month=Date.today.mon(), year=Date.today.year())   
  myMonth = myDate.mon()
  myYear  = myDate.year
  @month  = @months[myMonth - 1]
  @year   = myYear.to_s
  Dir.chdir(@year)
  Dir.chdir(@month)
  checkFiles
end

prod_type = Array.new
prod_type.push(["Monitoring Highlights"])
prod_type.push(["Prediction Outlook"])
prod_type.push(["ISV Highlights"])
prod_type.push(["Drought Highlights"])

services = dialog.checklist("Chose a Service",prod_type)

for service in services
  prefix = service.split[0]
  workDir=ENV["CIS_#{prefix.upcase}"]
  exit if workDir==nil
  exit unless File.exist?(workDir)
  @wDir=workDir
  @product=prefix
  prepareForTransport
end

> 
> _______________________________________________
> Radiant mailing list
> Post:   [email protected]
> Search: http://radiantcms.org/mailing-list/search/
> Site:   http://lists.radiantcms.org/mailman/listinfo/radiant

-- 
Saji N. Hameed

APEC Climate Center                                     +82 51 668 7470
National Pension Corporation Busan Building 12F         
Yeonsan 2-dong, Yeonje-gu, BUSAN 611705                 [EMAIL PROTECTED]
KOREA
_______________________________________________
Radiant mailing list
Post:   [email protected]
Search: http://radiantcms.org/mailing-list/search/
Site:   http://lists.radiantcms.org/mailman/listinfo/radiant

Reply via email to