noosfero | 2 new commits pushed to repository

Antonio Terceiro gitlab at gitlab.com
Fri Feb 27 18:56:09 BRT 2015


Antonio Terceiro pushed to refs/heads/master at <a href="https://gitlab.com/noosfero/noosfero">Noosfero / noosfero</a>

Commits:
<a href="https://gitlab.com/noosfero/noosfero/commit/efe67a46d7980e93f2fd1eef076d820ab0dff448">efe67a46</a> by Antonio Terceiro
move "is noosfero running?" test to script/production

- - - - -
<a href="https://gitlab.com/noosfero/noosfero/commit/b17c0a2482266dc055264779b284c70217357176">b17c0a24</a> by Antonio Terceiro
stoa: add independent authentication server

To install:

$ sudo ln -s $NOOSFERO/plugins/stoa/script/stoa-auth-server /etc/init.d/
$ sudo update-rc.d stoa-auth-server defaults
$ sudo service stoa-auth-server start

Of course, the stoa plugin must be enabled and properly configure foo
any of this to work.

It will run on port 4000, and requests must be made to /, e.g.

$ curl -d 'login=USER&password=PASSWORD' http://server:4000/

- - - - -


Changes:

=====================================
etc/init.d/noosfero
=====================================
--- a/etc/init.d/noosfero
+++ b/etc/init.d/noosfero
@@ -123,7 +123,7 @@ do_restart() {
 }
 
 running(){
-  pgrep -u noosfero -f 'thin server' > /dev/null
+  main_script running
 }
 
 case "$1" in

=====================================
plugins/stoa/Gemfile
=====================================
--- /dev/null
+++ b/plugins/stoa/Gemfile
@@ -0,0 +1 @@
+gem 'sinatra'

=====================================
plugins/stoa/config.ru
=====================================
--- /dev/null
+++ b/plugins/stoa/config.ru
@@ -0,0 +1,5 @@
+require ::File.expand_path('../../../config/environment',  __FILE__)
+require 'stoa_plugin'
+require 'stoa_plugin/auth'
+
+run StoaPlugin::Auth

=====================================
plugins/stoa/lib/stoa_plugin/auth.rb
=====================================
--- /dev/null
+++ b/plugins/stoa/lib/stoa_plugin/auth.rb
@@ -0,0 +1,36 @@
+require 'sinatra'
+require 'stoa_plugin/person_fields'
+
+class StoaPlugin::Auth < Sinatra::Base
+
+  include StoaPlugin::PersonFields
+
+  post '/' do
+    headers['Content-Type'] = 'application/json'
+    if params[:login].blank?
+      person = Person.find_by_usp_id(params[:usp_id])
+      login = person ? person.user.login : nil
+    else
+      login = params[:login]
+    end
+
+    domain = Domain.find_by_name(request.host)
+    environment = domain && domain.environment
+    environment ||= Environment.default
+
+    user = User.authenticate(login, params[:password], environment)
+    if user
+      result = StoaPlugin::PersonApi.new(user.person, self).fields(selected_fields(params[:fields], user))
+      result.merge!(:ok => true)
+    else
+      result = { :error => _('Incorrect user/password pair.'), :ok => false }
+    end
+    result.to_json
+  end
+
+  get '/' do
+    headers['Content-Type'] = 'application/json'
+    { :error => _('Conection requires post method.'), :ok => false }.to_json
+  end
+
+end

=====================================
plugins/stoa/script/stoa-auth-server
=====================================
--- /dev/null
+++ b/plugins/stoa/script/stoa-auth-server
@@ -0,0 +1,123 @@
+#! /bin/sh
+### BEGIN INIT INFO
+# Provides:          noosfero
+# Required-Start:    $remote_fs
+# Required-Stop:     $remote_fs
+# Should-Start:      postgresql
+# Should-Stop:       postgresql
+# Default-Start:     2 3 4 5
+# Default-Stop:      0 1 6
+# Short-Description: Stoa authentication daemon
+# Description:       This file should be symlinked or copied into /etc/init.d.
+### END INIT INFO
+
+# Sample init.d script for noosfero.
+#
+# This script was based on the skeleton init.d script present in a Debian
+# GNU/Linux system (sid), on Sat Feb 16 11:12:03 BRT 2008. It must be placed
+# in /etc/init.d/ (or whatever place your system uses for startup scripts),
+# and you must create a file /etc/default/noosfero defining the variable
+#
+# Author: Antonio Terceiro <terceiro at colivre.coop.br>
+
+# Do NOT "set -e"
+
+# PATH should only include /usr/* if it runs after the mountnfs.sh script
+PATH=/sbin:/usr/sbin:/bin:/usr/bin
+DESC="Stoa authentication deamon"
+NAME=stoa-auth-daemon
+SCRIPTNAME=/etc/init.d/$NAME
+
+# default values
+NOOSFERO_DIR=/var/lib/noosfero/current
+NOOSFERO_USER=noosfero
+
+# Read configuration variable file if it is present
+if [ -r /etc/default/$NAME ]; then
+  . /etc/default/$NAME
+else
+  # for running from development setup, or from git with the script symlinked
+  script=$(readlink -f $0)
+  NOOSFERO_DIR=$(readlink -f $(dirname $script)/../../..)
+  NOOSFERO_USER=$(stat --format %U $NOOSFERO_DIR/tmp/pids)
+fi
+
+# Load the VERBOSE setting and other rcS variables
+. /lib/init/vars.sh
+
+. /lib/lsb/init-functions
+
+if [ -z "$NOOSFERO_DIR" ] || [ -z "$NOOSFERO_USER" ]; then
+  echo "NOOSFERO_DIR or NOOSFERO_USER not defined, noosfero not being started."
+  echo "Both variables must be defined in /etc/default/noosfero"
+  exit 0
+fi
+
+if test -x /usr/sbin/noosfero-check-dbconfig ; then
+  if ! /usr/sbin/noosfero-check-dbconfig; then
+    echo "Noosfero database access not configured, service disabled."
+    exit 0
+  fi
+fi
+
+######################
+
+THIN_PID_FILE='--pid tmp/pids/stoa-auth-server.pid'
+THIN_START_OPTIONS="--port 4000 --environment production --chdir $NOOSFERO_DIR --rackup plugins/stoa/config.ru --log log/stoa-auth-server.log --daemonize"
+
+as_noosfero_user() {
+  cmd="$@"
+  if [ "$NOOSFERO_USER" != "$USER" ]; then
+    su $NOOSFERO_USER -l -c "cd $NOOSFERO_DIR && $cmd"
+  else
+    cd $NOOSFERO_DIR
+    $cmd
+  fi
+}
+
+run_thin() {
+  action="$1"
+  shift
+  log_daemon_msg "$action $DESC" "$NAME"
+  if as_noosfero_user thin $THIN_PID_FILE $@; then
+    log_success_msg
+  else
+    log_failure_msg
+  fi
+}
+
+running() {
+  kill -0 $(cat $NOOSFERO_DIR/tmp/pids/stoa-auth-server.pid 2>/dev/null || true) 2>/dev/null
+}
+
+do_start() {
+  if ! running; then
+    run_thin "Starting" $THIN_START_OPTIONS start
+  fi
+}
+
+do_stop() {
+  if running; then
+    run_thin "Stopping" stop
+  fi
+}
+
+do_restart() {
+  if running; then
+    do_stop
+  fi
+  do_start
+}
+
+case "$1" in
+  start|stop|restart)
+    do_$1
+    ;;
+  force-reload)
+    do_restart
+    ;;
+  *)
+    echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload|setup}" >&2
+    exit 3
+    ;;
+esac

=====================================
script/production
=====================================
--- a/script/production
+++ b/script/production
@@ -84,6 +84,12 @@ environments_loop() {
   fi
 }
 
+do_running() {
+  pids=$(cat tmp/pids/thin.*.pid 2>/dev/null || true)
+  # passes if any of $pids exist, fails otherwise
+  kill -0 $pids > /dev/null 2>&1
+}
+
 case "$ACTION" in
   start|stop)
     do_$ACTION
@@ -100,6 +106,10 @@ case "$ACTION" in
     do_restart
     ;;
 
+  running)
+    do_running
+    ;;
+
   *)
     echo "usage: $0 start|stop|restart|run"
     exit 1

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20150227/20dd34e5/attachment-0001.html>


More information about the Noosfero-dev mailing list