view · edit · sidebar · attach · print · history

20101130-update-bbmb-ch

<< Masa.20101201-update-bbmb-ch-update-spreadsheet | 2010 | Masa.20101129-install-win7-update-bbmb >>


  1. Confirm pure-ftpd working locally
  2. Set up login process bbmb.ch
  3. Check login process
  4. Check registration process
  5. Check SubAdmin registration
  6. Check how to show customer information

Goal
  • Update bbmb.ch / 80%
Milestones
  1. Set up pure-ftpd 8:30
  2. Check login process 10:15
  3. Check subadmin process 14:30
  4. Customer list 16:45
  5. Set up bbmb.ch
  6. Debug 'run_statistics'

Memo

masa@masa ~/ywesee/bbmb.ch $ grep -r hwyss *|grep -v user-stories|grep -v test|grep -v bbmb
Summary
Commits
ToDo Tomorrow
  • Update customer's top page
Keep in Mind
  1. Testcase of 'Object Stream' parser (for rpdf2txt/lib/rpdf2txt/parser.rb#rebuild_object_catalogue method) 20101126-update-rpdf2txt
  2. Testcases of lib/oddb/html/state/global.rb#grant_download, lib/oddb/html/view/download.rb#to_html
  3. Debug testcases in test/export/test_server.rb de.oddb.org
  4. A bug import_gkv Tue Nov 16 02:00:10 2010: de.oddb.org Zubef (PDF)
  5. Compression (refer to lib/oddb/export/server.rb), Test cases (grant_download, Logging, Reporting)
  6. Log Error: on production server, de.oddb.org/log/import_dimdi, import_pharmnet
  7. On Ice
  8. emerge --sync

Confirm pure-ftpd working locally

Setting pure-ftpd

masa@masa ~ $ sudo groupadd ftp_group
masa@masa ~ $ sudo chgrp ftp_group ftp_share
masa@masa ~ $ ls -l
drwxr-xr-x  2 masa ftp_group     1 30. Nov 07:45 ftp_share
masa@masa ~ $ sudo useradd -g ftp_group -d /home/masa/ftp_share ftp_user
masa@masa ~ $ sudo pure-pw useradd ftp_user1 -u ftp_user -g ftp_group -d /home/masa/ftp_share -m
Password: 
Enter it again: 
masa@masa ~ $ sudo /etc/init.d/pure-ftpd restart
* You need to setup /etc/conf.d/pure-ftpd first!
* ERROR: pure-ftpd failed to start

Note

  • Failed

Reference

masa@masa ~ $ vim /etc/conf.d/pure-ftpd

IS_CONFIGURED="yes"
SERVER="-S 21"
MAX_CONN="-c 30"
MAX_CONN_IP="-C 10"
DAEMON="-B"
DISK_FULL="-k 90%"
AUTH="-lpuredb:/etc/pureftpd.pdb"
MISC_OTHER="-A -E -X -U 177:077 -d -4 -L100:5 -I 15"

Set up again

masa@masa ~ $ sudo userdel ftp_user
masa@masa ~ $ sudo useradd -g ftp_group -d /dev/null -s /etc ftp_user
masa@masa ~ $ vim /etc/passwd
ftp_user:x:1001:1008::/dev/null:/etc
masa@masa ~ $ vim /etc/group
ftp_group:x:1008:
masa@masa ~ $ sudo pure-pw userdel ftp_user1
masa@masa ~ $ sudo pure-pw useradd ftp_user1 -u ftp_user -d /home/masa/ftp_share -m
Password: 
Enter it again: 
masa@masa ~ $ sudo pure-pw show ftp_user1
masa@masa ~ $ sudo /etc/init.d/pure-ftpd restart
* Caching service dependencies...                                                                                                                                  [ok]
* Starting Pure-FTPd...            

Note

  • Works!

Check login

masa@masa ~ $ lftp ftp_user1@localhost
Passwort: 
lftp ftp_user1@localhost:~> ls       
-rw-r--r--    1 1000       1003                6 Nov 30 08:31 hello.dat
lftp ftp_user1@localhost:/> exit
masa@masa ~ $ ls ftp_share/ -l
insgesamt 4
-rw-r--r-- 1 masa masa 6 30. Nov 08:31 hello.dat
masa@masa ~ $ ps aux|grep ftp
root      3787  0.0  0.0  25956   756 ?        Ss   08:28   0:00 pure-ftpd (SERVER)    

Set up login process bbmb.ch

Set up bbmb.ch (for local) again (Review yesterday)

1. git clone

2. src/testenvironment.rb

#!/usr/bin/env ruby

puts 'loading testenvironment'
class BbmbApp < SBSM::DRbServer
    puts "disabling UPDATER"
    remove_const :RUN_UPDATER
    RUN_UPDATER = false
end 
module BBMB
  class CustomBehaviorGag < CustomBehavior
    remove_const :MAIL_RECIPIENTS, :MAIL_RECIPIENTS_CC, :MAIL_INJECT_RECIPIENTS,
                 :MAIL_PDF_RECIPIENTS, :MAIL_PDF_RECIPIENTS_CC, :MAIL_PDF_FROM
    MAIL_RECIPIENTS = ['mhatakeyama@ywesee.com']
    MAIL_RECIPIENTS_CC = []
    MAIL_INJECT_RECIPIENTS = ['mhatakeyama@ywesee.com']
    MAIL_PDF_RECIPIENTS = ['mhatakeyama@ywesee.com']
    MAIL_PDF_RECIPIENTS_CC = []
    MAIL_PDF_FROM = 'mhatakeyama@ywesee.com'

  end

end

3. src/custom/lookandfeelgag.rb (updated))

#!/usr/bin/env ruby
# LookandfeelGag -- bbmb -- hwyss@ywesee.com

require "sbsm/lookandfeelwrapper"

module BBMB
    class LookandfeelGag < SBSM::LookandfeelWrapper
        DICTIONARIES = {
            "de"    =>  {
                :new_customer_mail  =>  "mailto:mhatakeyama@ywesee.com?subject=Neukunde BBMB - bitte Passwort generieren&amp;",
                :partner    =>  "Masapharm AG",
                :welcome    =>  "Willkommen bei Masapharm",
            }
        }
        ENABLED = [
            :bcreader_usb,
        ]
    end
end

4. src/util/bbmbconfig.rb

#!/usr/bin/env ruby
# BbmbConfig -- bbmb -- 09.04.2003 -- hwyss@ywesee.com 

module BBMB
    DEFAULT_FLAVOR = 'gag'
    #SERVER_URI = ["druby://localhost:9999", "druby://192.168.0.35:9876"]
    SERVER_URI = ["druby://localhost:9999", "druby://localhost:9876"]
    def primary_uri
        if(SERVER_URI.is_a? Array)
            SERVER_URI.first
        else
            SERVER_URI.to_s
        end
    end
    module_function :primary_uri
    YAML_ODDB_URI = "druby://localhost:10004"
end                       

5. replace doc/resources/gag/logo.gif

6. src/util/session.rb#http_protocol

        def http_protocol
            #'https'
            'http'
        end

7. /etc/apache2/vhosts.d/05_bbmbch_vhost.conf

<Directory /home/masa/ywesee/bbmb.ch/doc>
Options ExecCGI
AllowOverride None
Order allow,deny
Allow from all
</Directory>

<VirtualHost *:80>
DocumentRoot /home/masa/ywesee/bbmb.ch/doc
ServerName masapharm.bbmb.ch
DirectoryIndex index.rbx
RubyAddPath /home/masa/ywesee/bbmb.ch/src
RubyRequire 'sbsm/trans_handler'
SetHandler ruby-object
RubyTransHandler SBSM::FlavoredTransHandler.instance
</VirtualHost>

8. Start bbmb.ch/bin/bbmbd

Access to http://masapharm.bbmb.ch

Result

  • Confirmed the top (login) site

Set up login process

1. bbmb.ch/etc/accessgag.rb

#!/usr/bin/env ruby
# CustomBehavior -- bbmb -- hwyss@ywesee.com

module BBMB
    class CustomBehaviorGag < CustomBehavior
        REMOTE_ACCESS = 'ftp://ftp_user1:passwd@localhost'
    end
end

Note

  • It seems that this is not used for login process

Check login process

Root user is defined in the code

src/model/root.rb

        INITIAL_VALUES = {
            :email      => "aa@bb.cc",
            :pass_hash  => "47bce5c74f589f4867dbd57e9ca9f808",
        }

Note

        def recognizes? session
            #puts "#{session[:email].inspect} <=> #{@attributes[:email].inspect}"
            #puts "#{session[:pass].inspect} <=> #{@attributes[:pass_hash].inspect}"
      return false unless session[:email] && session[:pass]
print "session[:pass]="
p session[:pass]
print "@attributes[:pass_hash]="
print @attributes[:pass_hash]
print "session[:email]="
p session[:email]
print "@attributes[:email]="
p @attributes[:email]
            rec = (session[:pass] == @attributes[:pass_hash]) && (@attributes[:email] == session[:email])
            if(rec)
                @attributes[:last_login] = Time.now
            end
            rec
        end

Reboot bbmb.ch/bin/bbmbd

Login by root user

Result

  • Success

Quesion

  • Where is the setting regarding the other users (admin user, normal user)?

Experiment (add Admin user from browser)

  • The registration process does not work

Check registration process

grep search

masa@masa ~/ywesee/bbmb.ch $ grep -r admin *
src/custom/lookandfeelbase.rb:                          :new_admin                                                      =>      "Neuer Administrator",
src/custom/lookandfeelbase.rb:                          :new_subadmin                                           =>      "Neuer Administrator",

Notes

  • It seems that two 'admin', admin and subadmin, exist

Debugging

src/state/admin.rb

module BBMB
    class AdminState < GlobalState
        DIRECT_EVENT = :show_admin
        VIEW = AdminView
        def init
            @model = @session.user.show_admin(@session)
        end
        def save
p "getin AdminState#save"
            begin
                mandatory = [
                    :address,
                    :email,
                    :location,
                    :plz,
                    :reseller_name,
                    :reseller_short,
                ]
                keys = mandatory + [
                    :uid,
                ]
                input = user_input(keys, mandatory)
print "input="
p input
print "error?="
p error?
                unless(error?)
p "passin error?"
                    if(input[:uid].to_s == 'new')
                        @session.create_admin(@session)
                    else
                        @session.save_admin(@session)
                    end
                    trigger(:admins)
                end
            rescue BBMB::IllegalActionException => e
                puts e
            end
        end

Result

  • 'Speichern' worked but error comes

Note

  • PLZ/Ort also must be entered

Debugging

src/state/admin.rb

#!/usr/bin/env ruby
# AdminState -- bbmb -- 16.04.2004 -- hwyss@ywesee.com

require 'state/global'
require 'view/admin'

module BBMB
    class AdminState < GlobalState
        DIRECT_EVENT = :show_admin
        VIEW = AdminView
        def init
            @model = @session.user.show_admin(@session)
        end
        def save
p "getin AdminState#save"
            begin
                mandatory = [
                    :address,
                    :email,
                    :location,
                    :plz,
                    :reseller_name,
                    :reseller_short,
                ]
                keys = mandatory + [
                    :uid,
                ]
                input = user_input(keys, mandatory)
print "input="
p input
print "error?="
p error?
                unless(error?)
p "passin error?"
                    if(input[:uid].to_s == 'new')
                        @session.create_admin(@session)
                    else
                        @session.save_admin(@session)
                    end
                    trigger(:admins)
                end
            rescue BBMB::IllegalActionException => e
p "BBMB::IllegalActionExcepion"
                puts e
            end
        end
        def change_pass
            self
        end
    end
end

src/util/bbmbapp.rb

    def create_admin session
p "getin create_admin"
        unless session.user.instance_of?(BBMB::RootUser)
            raise BBMB::IllegalActionException.new(:create_admin)
        end
        create_user(BBMB::AdminUser, session, session.user)
    end
    def create_hospital(session)
        unless session.user.allowed?(:create, 'hospital')
            raise BBMB::IllegalActionException.new(:create_hospital)
        end
        create_user(BBMB::HospitalUser, session, session.user)
    end
    def create_user(klass, session, creator)
p "getin create_user"
        values = klass.prepare(session)
        command = BBMB::Transaction.new(AddUserCommand.new(klass, values, creator))
        @prevalence.executeTransaction(command)
    end
    def create_subadmin(session)
p "getin create_subadmin"
        create_user(BBMB::SubAdminUser, session, session.user)
    end
    def create_supplier_user(session)
p "getin create_supplier_user"
        create_user(BBMB::SupplierUser, session, session.user)
    end

Reboot bbmb.ch/bin/bbmbd

Register admin user again

Result

"getin AdminState#save"
input={:address=>"mmm", :reseller_short=>"gag", :plz=>"1111", :uid=>"new", :reseller_name=>"mhatakeyama@ywesee.com", :location=>"mmm", :email=>"mhatakeyama@ywesee.com"}
error?="getin error?"
@errors={}
false
"getin error?"
@errors={}
"passin error?"
"getin create_admin"
"getin create_user"
:email
"mhatakeyama@ywesee.com"
:e_duplicate_email

Question

  • Where is the admin user information saved?

git status check

masa@masa ~/ywesee/bbmb.ch $ git status
# On branch master
# Changed but not updated:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#       modified:   doc/resources/gag/logo.gif
#       modified:   src/custom/lookandfeelgag.rb
#       modified:   src/model/root.rb
#       modified:   src/model/user.rb
#       modified:   src/state/admin.rb
#       modified:   src/util/bbmbapp.rb
#       modified:   src/util/bbmbconfig.rb
#       modified:   src/util/session.rb
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       log/
#       src/testenvironment.rb
no changes added to commit (use "git add" and/or "git commit -a")

Experiment

masa@masa ~/ywesee/bbmb.ch $ rm -rf log

Register admin user again

Result

  • Success

Notes

  • log file is used for the user authentification!!
  • And probably bbmb.ch (ver. 1.0) does not use ODBA (database)

But

  • Rebooting bbmbd does not work after the admin registration
masa@masa ~/ywesee/bbmb.ch $ bin/bbmbd 
/usr/lib64/ruby/1.8/net/protocol.rb:206:in `initialize': Connection refused - connect(2) (Errno::ECONNREFUSED)
        from /usr/lib64/ruby/1.8/net/protocol.rb:206:in `new'
        from /usr/lib64/ruby/1.8/net/protocol.rb:206:in `old_open'
        from /usr/lib64/ruby/1.8/timeout.rb:62:in `timeout'
        from /usr/lib64/ruby/1.8/timeout.rb:93:in `timeout'
        from /usr/lib64/ruby/1.8/net/protocol.rb:206:in `old_open'
        from /usr/lib64/ruby/1.8/net/smtp.rb:392:in `do_start'
        from /usr/lib64/ruby/1.8/net/smtp.rb:377:in `start'
        from /home/masa/ywesee/bbmb.ch/src/custom/behavior.rb:350:in `mail_send'
         ... 12 levels...
        from /home/masa/ywesee/bbmb.ch/src/util/bbmbapp.rb:520:in `run_statistics'
        from /home/masa/ywesee/bbmb.ch/src/util/bbmbapp.rb:302:in `initialize'
        from bin/bbmbd:9:in `new'
        from bin/bbmbd:9

Note

  • Stop the 'updater' and 'statistics' temporarily

src/util/bbmbapp.rb

#       @statistics = run_statistics if RUN_STATISTICS

Check SubAdmin registration

1. Login as superuser (aa@bb.cc)

2. Click an admin user (mhatakeyama@ywesee.com)

3. Click 'Administratoren 0'

4. Click 'Neuer Administrator'

5. Input items

Result

  • I confirmed it is possible to login as 'aaa@bbb.ccc'

Next

  • How to show the customer list when a subadmin login

Check how to show customer information

Question

  • Where is the customer information?

There are 5 types of users defined

  1. RootUser
  2. AdminUser
  3. SubAdminUser
  4. HopitalUser
  5. SupplierUser

src/state/login.rb

        def login
            @session.login
            case @session.user
            when RootUser
                state = AdminsState.new(@session, nil)
                state.extend(RootState)
                state
            when AdminUser
                state = HospitalsState.new(@session, nil)
                state.extend(AdminUserState)
                state
            when SubAdminUser
                state = HospitalsState.new(@session, nil)
                state.extend(SubAdminUserState)
                state
            when HospitalUser
                state = CurrentOrderState.new(@session, nil)
                state.extend(HospitalUserState)
                state
            when SupplierUser
                state = BackordersState.new(@session, nil)
                state.extend(SupplierUserState)
                state
            else
                self
            end
        end

Question

  • When is 'HospitalUser' created?

Note

  • @users are created in 'update' method through accessing to ftp server

src/util/bbmbapp.rb

    def run_updater
        puts "running updater thread"
        Thread.new {
            Thread.current.priority=-10
            Thread.current.abort_on_exception = true
            today = (UPDATE_HOUR > Time.now.hour) ? Date.today : Date.today.next
            loop {
                next_run = Time.local(today.year, today.month, today.day, UPDATE_HOUR)
                sleep(next_run - Time.now)
                update()
                today = Date.today.next
            }
        }
    end

Note

  • The 'run_updater' runs once a day (1:00 am)
  • This means that @users is updated once a day
  • For example, the reflection of the data takes about one day, even if the customer file on the ftp server is updated

Experiment

1. put a cosutomer file (ywskund) in the ftp directory

masa@masa ~ $ ls ftp_share/ywesee/Out/
ywskund
masa@masa ~ $ cat ftp_share/ywesee/Out/ywskund 
584674;584674;22;ywesee;;Hatapharm AG;;hoge hoge 11;;CH;8000;hogehoge;011 / 111 22 33;;;011 / 111 22 44;hatapharm@ywesee.com;

2. Set REMOTE_ACCESS constant

src/custom/behavior.rb

        REMOTE_ACCESS = 'ftp://ftp_user1:passwd@localhost'

3. Modify in order to run 'update_users' quickly

src/util/bbmbapp.rb

    def run_updater
        puts "running updater thread"
        Thread.new {
            Thread.current.priority=-10
            Thread.current.abort_on_exception = true
            #today = (UPDATE_HOUR > Time.now.hour) ? Date.today : Date.today.next
            today = Date.today
            loop {
                #next_run = Time.local(today.year, today.month, today.day, UPDATE_HOUR)
                next_run = Time.local(today.year, today.month, today.day, Time.now.hour, Time.now.min+1)
print "now="
p Time.now
print "next_run="
p next_run
                sleep(next_run - Time.now)
                update()
                today = Date.today.next
            }
        }
    end

Reboot bbmbd

Login as a superuser (aa@bb.cc)

Result

  • Customer registration succeeded

Test login as a customer

  • Success
  • But there is no data for a customer
  • Because the other updaters than 'update_users' did not run

Note

  • src/testenvironment.rb file does not work if REMOTE_ACCESS is set in that file

Important

  • Superuser account information is in the source code (hard-coded)
  • Admin and SubAdmin accounts information is in log file
  • Customer (HospitalUser) account information is on ftp server (ywskund)
    • After the update_user runs, the account information is also save in log file
  • I did not check 'SupplierUser' information
view · edit · sidebar · attach · print · history
Page last modified on July 13, 2011, at 11:53 AM