martedì 10 maggio 2011

If i use a ldap configuration with

# config/ldap.yml
development:
base: ou=people,dc=test,dc=com
attribute: uid
group_base: ou=groups,dc=test,dc=com
required_groups:
- ["moreMembers", "cn=users,ou=groups,dc=test,dc=com"]

and I have my dn like

uid=gmgp,ou=developpers,ou=people,dc=test,dc=com

in the log the LDAPLogger write

LDAP: LDAP search: uid=gmgp
LDAP: Authorizing user uid=gmgp,ou=developpers,ou=people,dc=test,dc=com
LDAP: LDAP search: uid=gmgp
LDAP: LDAP search: uid=gmgp
LDAP: LDAP search: uid=gmgp
LDAP: User uid=gmgp,ou=people,dc=test,dc=com is not in group: cn=users,ou=groups,dc=test,dc=com

my simple workaround is to create a local attribute


#devise_ldap_authenticatable-0.4.6/lib/devise_ldap_authenticatable/ldap_adapter.rb

27 class LdapConnect
28
29 attr_reader :ldap, :login, :login_dn

54 def dn
55 DeviseLdapAuthenticatable::Logger.send("LDAP search: #{@attribute}=#{@login}")
56 filter = Net::LDAP::Filter.eq(@attribute.to_s, @login.to_s)
57 ldap_entry = nil
58 @ldap.search(:filter => filter) {|entry| ldap_entry = entry}
59 if ldap_entry.nil?
60 @ldap_auth_username_builder.call(@attribute,@login,@ldap)
61 else
62 @login_dn = ldap_entry.dn
63 end
64 end

84 def in_required_groups?
85 return true unless ::Devise.ldap_check_group_membership
86
...
99 admin_ldap.search(:base => group_name, :scope => Net::LDAP::SearchScope_BaseObject) do |entry|
100 unless entry[group_attribute].include? @login_dn
101 DeviseLdapAuthenticatable::Logger.send("User #{@login_dn} is not in group: #{group_name }")
102 return false
103 end
104 end
105 end

This workaround works even if it does not solve the underlying problem
I prepare a commit as it should if I find a moment of time

martedì 3 maggio 2011

Taps per migrazioni tra db (ex: sqlite3 to mysql)

Con la gemma Taps la migrazione dati da un db ad un altro è veramente semplice
Qui la guida base da cui sono partito

1) istallare taps sulle due macchine

$ [sudo] gem install taps

sembra che possa servire in alcuni casi anche

$ [sudo] gem install hoptoad_notifier

2) lanciare il server taps (che sfrutta sinatra) con il comando

$ taps server [OPTIONS] local_database_url login password

per esempio: (utente e password non presenti nel db sono aggiunti posticci in quanto richiesti)

$ taps server sqlite://development.sqlite3 pippo pippo
== Sinatra/1.0 has taken the stage on 5000 for production with backup from Mongrel


3) creare se non esistente il db di destinazione

4) lanciare taps per ricevere i dati

$ taps pull [OPTIONS] local_database_url remote_url

$ taps pull mysql://root@localhost/nome_db_destinazione http://pippo:pippo@localhost:5000

ed è tutto fatto!

venerdì 5 novembre 2010

RVM passo passo

Seguendo le istruzioni qui sono riuscito ad avere diversi ambienti ruby coesistenti

Istallazione

1) $ bash < <( curl http://rvm.beginrescueend.com/releases/rvm-install-head )

Operazioni post installazione

2) Check librerie necessarie come da messaggio presentato

# For RVM
rvm: bash curl git

# For JRuby (if you wish to use it) you will need:
jruby: aptitude install curl sun-java6-bin sun-java6-jre sun-java6-jdk

# For Ruby (MRI & ree) you should install the following OS dependencies:
ruby: aptitude install build-essential bison openssl libreadline5 libreadline5-dev curl git zlib1g zlib1g-dev libssl-dev libsqlite3-0 libsqlite3-dev sqlite3 libxml2-dev

ruby-head: git subversion autoconf

# For IronRuby (if you wish to use it) you will need:
ironruby: aptitude install curl mono-2.0-devel


3) Modifiche .bashrc

a fine file:

[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # This loads RVM into a shell session.

e modificato dove si trovasse la forma '&& return' come da istruzioni modifcanso come
if [...] then ;
code
fi


4) chiusura console

5) prova con
$ type rvm | head -n1
rvm è una funzione


Utilizzo

rvm install 1.9.2
rvm 1.9.2 --default # per rendere definitivo il cambio
rvm info
rvm system --default # per tornare a ruby standard



UPDATE

per alcune librerie può essere che serva una ricompilazione sotto ubuntu per ogni ambiente come riportato qui

venerdì 23 luglio 2010

Rails + Gmail con ruby 1.8.7

Un semplice How-to per fornire un applicazione Rails (2.3.x) del servizio di invio di mail
In particolare si suppone che esistano degli utenti User con attibuto User.username per testare l'interazione con l'applicazione

1) il mailer model "notifier"
Il primo passo è la creazione di un controller per l'invio delle mail

$ script/generate mailer Notifier
exists app/models/
create app/views/notifier
exists test/unit/
create test/fixtures/notifier
create app/models/notifier.rb
create test/unit/notifier_test.rb


crea il model notifier.rb e la cartella nelle viste notifier che conterrà le viste ovvero i modelli dei testi delle mail che manderemo

2)Il metodo"notification"
Bisogna quindi creare il metodo in /models/notifier.rb


class Notifier < user =""> user)
def notification(user)
recipients "myname@gmail.com"#user.email
from "myname@gmail.com"
subject "New account information"
body (:user => user)# "account" => recipient
content_type "text/html"
end
end


:user passato nel body rende disponibile la variabile @user nella vista che andremo a creare per il testo della mail

3) Il testo della mail
creiamo il file /views/notifier/notification.html.erb

Hi <%= @user.username %>,
Thanks for joining our service! Please check back often.


in cui @user è l'utente che abbiamo passato per argomento precedentemente

4) Modifichiamo le impostazioni di invio

modifichiamo il file /config/environments/developments.rb

ActionMailer::Base.smtp_settings = {
:enable_starttls_auto => true,
:address => "smtp.gmail.com",
:port => 587,
:authentication => :plain,
:domain => "myname@gmail.com",
:user_name => "myname@gmail.com",
:password => "mynamepassword",
}
config.action_mailer.raise_delivery_errors = true
config.action_mailer.delivery_method = :smtp


abbiamo completato le modifiche per testarle lanciamo la console con

script/console
Loading development environment (Rails 2.3.5)
>>

Quindi utilizziamo il methodo deliver per inviare la mail

>> Notifier.deliver_notification User.first
>> #TMail::Mail port=#TMail::StringPort:id=0x..fdb3d0cc4>
bodyport= #TMail::StringPort:id=0x..fdb3cf9d2
>>


Mail inviata e ricevuta

martedì 13 luglio 2010

Istallazione CMapTools in Ubuntu

Due dritte per l'installazione di CMapTolls in ubuntu
  • registrarsi con una mail
  • scaricare il file bin
creare la cartella radice in /opt/
  • cd /opt
  • sudo mkdir IHMC_CmapTools
rendere il file bin scaricato eseguibile
  • chmod +x LinuxCmapTools_v5.03_04-07-09.bin
Installare il programma
  • sudo ./LinuxCmapTools_v5.03_04-07-09.bin
    
    Preparing to install...
    Extracting the JRE from the installer archive...
    Unpacking the JRE...
    Extracting the installation resources from the installer archive...
    Configuring the installer for this system's environment...
utilizzando il tool di installazione avanzata è possibile personalizzare le opzioni in particolare specificare come directory radice /opt/IHMC_CmapTools precedentemente creata.

Se si vuole avere il link al programma basta creare un lanciatore che faccia riferimento al file
/opt/IHMC_CmapTools/bin/CmapTools

Una icona adatta la si può trovare a questo indirizzo

Scaricata l'icona per avere il lanciatore basta seguire le semplici istruzioni ipotizzando di trovarsi con il terminale nella cartella dove si è scaricata l'icona:
  • sudo cp CmapTools48px.gif /usr/share/pixmaps/
  • cd /usr/share/pixmaps/
  • sudo chown root:root CmapTools48px.gif
  • sudo chmod u+rw CmapTools48px.gif
  • cd /usr/share/applications/
  • sudo touch cmaptools.desktop
  • sudo gedit cmaptools.desktop
aggiungendo il seguente contenuto

[Desktop Entry]
Version=1.0
Name=CMapTools
Name[it]=CMapTools
Comment=Conceptual maps
Comment[it]=Mappe concettualil
GenericName=CMapTools
GenericName[ca]=CMapTools
Encoding=UTF-8
Exec=/opt/IHMC_CmapTools/CmapTools
Terminal=false
Icon=/usr/share/pixmaps/CmapTools48px.gif
Type=Application
MimeType=application/x-cmaptools
Categories=Application;Office;
Si ha così il lanciatore disponibile all'uso

venerdì 19 giugno 2009

Git in Gedit

Uno stumento veramente comodo ed efficace per il versionamento è l'ormai famoso e diffuso Git.

Utilizzando come IDE Gedit adeguatamente potenziato (qualche plugin qua e là, nulla di che) mi trovo veramente bene e l'unica mancanza finora era la possibilità di una integrazione con Git.
Partendo da questo post ho scelto di crearmi alcuni semplici script da utilizzare con il plugin Tools Extension, già ampiamente sfruttato.

Premessa
tutti questi comandi fanno riferimento al file attivo in gedit al momento del loro invio quindi bisogna prestare attenzione al file aperto al momento del loro utilizzo. L'istallazione del plugin è facilmente recuperabile in rete, per esempio qui, quindi la considero già fatta.
Per quanto riguarda Git presuppongo che sia già istallato e il repository inizializzato.

Questa è l'interfaccia del plugin richiamabile da:

Strumenti>Strumenti esterni...

Creazione procedura
Clicchiamo su New specificando il nome (a volte non lo prende, non preoccupatevi basta tornare successivamente a personalizzarlo)

Aggiungiamo una descrizione che ci aiuti in Description.

In Accelerator indichiamo il tasto scorciatoia (tutti i comandi saranno disponibili nel menu Strumenti)

In Commands incolliamo lo script che ci interessa

In Inputs scegliamo Nothing
In Output scegliamo 'Display in bottom panel'
In Applicability scegliamo 'All Documents'

L'output dell'esecuzione dei comandi viene visualizzato nella finestra inferiore "Output della shell" visualizzabile con Ctrl+F9

SCRIPT

Commit del file nel branch attivo
#!/bin/sh
# Ask message for commit
COMMIT_MESSAGE=`zenity --text-info --editable --width=500 --title="Commit message - gedit" --text="Insert commit message for this file"`
# add current file into repository
git add "$GEDIT_CURRENT_DOCUMENT_NAME"
# Commit current file with previous message
git commit -m "$COMMIT_MESSAGE"
# Print git status
git status

Commit di tutti i file modificati nel branch attivo
#!/bin/sh
# Ask message for commit
COMMIT_MESSAGE=`zenity --text-info --editable --width=500 --title="Commit message - gedit" --text="Insert commit message"`
# add all files into repository
git add .
# Commit current file with previous message
git commit -m "$COMMIT_MESSAGE"
# Print git status
git status


Cambio branch
#!/bin/sh
# Ask name of branch to change
NEW_BRANCH=`zenity --text-info --editable --width=500 --title="New branch - gedit" --text="Insert the name of new current branch"`
# change branch
git checkout "$NEW_BRANCH"
# Print git status
git status

Caricamento branch"sviluppo" sul master
#!/bin/sh
# Ask name of branch to add to master
NEW_BRANCH=`zenity --text-info --editable --width=500 --title="Branch to add - gedit" --text="Insert the name of branch to add"`
# change branch
git checkout master
git merge "$NEW_BRANCH"
# Print git status
git status

Ovviamente ogni script ha bisogno di una sua procedura :-)
Buon versionamento!

venerdì 22 maggio 2009

A rdoc collection auto-updated

Ever more applications hosted by git hub without documentation updated on-line !

http://rdoc.info/

A simple and really useful service that allows you to always have updated the documentation without having to regenerate every time.

Just click on the update button at the top to make sure that the documentation is up to date and a link back to the corresponding page github

doc of ActiveWarehouse

doc of ActiveWarehouse-etl