summaryrefslogtreecommitdiff
path: root/app/controllers
diff options
context:
space:
mode:
authorNicolas Braud-Santoni <nicoo@ffgraz.net>2016-08-07 16:39:42 +0200
committerNicolas Braud-Santoni <nicoo@ffgraz.net>2016-08-07 16:39:42 +0200
commitb6ca062670b342344df08b53fb216db619ef42bc (patch)
tree7680ac6b407239f6b7272c937e42f688b8de542c /app/controllers
Import legacy manman source
Copied from www.ffgraz.net
Diffstat (limited to 'app/controllers')
-rw-r--r--app/controllers/application.rb16
-rw-r--r--app/controllers/export_controller.rb38
-rw-r--r--app/controllers/location_controller.rb109
-rw-r--r--app/controllers/net_controller.rb3
-rw-r--r--app/controllers/node_controller.rb69
-rw-r--r--app/controllers/person_controller.rb177
6 files changed, 412 insertions, 0 deletions
diff --git a/app/controllers/application.rb b/app/controllers/application.rb
new file mode 100644
index 0000000..30f98da
--- /dev/null
+++ b/app/controllers/application.rb
@@ -0,0 +1,16 @@
+# Filters added to this controller will be run for all controllers in the application.
+# Likewise, all the methods added will be available for all controllers.
+class ApplicationController < ActionController::Base
+ before_filter :authenticate, :except => [ :login, :sign_on, :register, :create, :revoke_pass, :do_revoke, :smokeping, :all ]
+
+
+protected
+ def authenticate
+ #session[:url] = url_for
+ session[:url] = request.env["REQUEST_URI"]
+ unless session[:person]
+ redirect_to :controller => 'person',
+ :action => 'login'
+ end
+ end
+end
diff --git a/app/controllers/export_controller.rb b/app/controllers/export_controller.rb
new file mode 100644
index 0000000..5d2ef85
--- /dev/null
+++ b/app/controllers/export_controller.rb
@@ -0,0 +1,38 @@
+class ExportController < ApplicationController
+ def smokeping
+ @locations = Location.find(:all, :order => "name")
+ if @locations != nil
+ text = ""
+ @locations.each do |location|
+ @nodes = Node.find(:all, :conditions => { :location_id => location.id, :smokeping => true } )
+ if @nodes != nil and not @nodes.empty?
+ text += "++ #{location.name}\n"
+ text += "menu = #{location.name}\n"
+ text += "title = #{location.name} connectivity\n"
+ @nodes.each do |node|
+ text += "+++ #{node.name}\n"
+ text += "menu = #{node.name}\n"
+ text += "title = #{node.name} connectivity\n"
+ # prefer interfaces named wifi, even if they are not the first in the list
+ ip = Ip.find(:first, :conditions => ["node_id = ? AND name like ?", node.id, 'wifi%'])
+ if ip != nil
+ text += "host = #{ip.ip}\n"
+ else
+ # no 'wifi' interface found, use any old interface...
+ ip = Ip.find(:first, :conditions => ["node_id = ?", node.id])
+ if ip != nil
+ text += "host = #{ip.ip}\n"
+ end
+ end
+ end
+ end
+ end
+ render_text text
+ end
+ end
+
+ def all
+ @locations = Location.find(:all, :order => "name")
+ render :layout => false
+ end
+end
diff --git a/app/controllers/location_controller.rb b/app/controllers/location_controller.rb
new file mode 100644
index 0000000..0d2a64c
--- /dev/null
+++ b/app/controllers/location_controller.rb
@@ -0,0 +1,109 @@
+class LocationController < ApplicationController
+# model :person, :location
+
+ def index
+ redirect_to :action => "list"
+ end
+
+ def list
+ @person = @params[:person]
+ if @person != nil
+ @locations = Location.find(:all,
+ :conditions => ["person_id = ?", Person.find(:first,
+ :conditions => { :email => @person }).id],
+ :order => "name" )
+ else
+ @locations = Location.find(:all, :order => 'name' )
+ end
+ end
+
+
+ def edit
+ @location = Location.find(params[:id])
+ @persons = Person.find(:all)
+ if ( session[:person] != @location.person ) and ( session[:person].email != 'nine@wirdorange.org' )
+ flash[:notice] = 'Sie haben nicht die Berechtigung hierfür.'
+ redirect_to :back
+ end
+ end
+
+ def update
+ @location = Location.find(params[:id])
+ values = params[:location]
+ values[:time] = DateTime.now
+ if @location.update_attributes(params[:location])
+ flash[:notice] = 'Location wurde erfolgreich upgedatet.'
+ redirect_to :action => 'show', :id => @location
+ else
+ flash[:notice] = 'Keine Änderung möglich.'
+ redirect_to :action => 'edit', :id => @location
+ end
+ end
+
+ def destroy
+ render_text 'aktion nicht verfügbar'
+ end
+
+ # show inforomation of location
+ # parameters:
+ # id = location_id
+ def show
+ begin
+
+ @location = Location.find(params[:id])
+ @person = @location.person
+ @nodes = Node.find(:all, :conditions => ["location_id=?", params[:id]] )
+ @nets = Nets.find(:all, :conditions => ["location_id=?", params[:id]] )
+ @googlemap = 'https://karte.graz.funkfeuer.at/?'
+ @googlemap += "lng=#{@location.lon}"
+ @googlemap += "&lat=#{@location.lat}"
+ @googlemap += "&res=17"
+ @googlemap += "&marker=all"
+
+ rescue ActiveRecord::RecordNotFound
+ flash[:notice] = "Error, Location with ID #{params[:id]} not found!"
+ redirect_to :action => 'list'
+ end
+ end
+
+ # display 'new location' form
+ def new
+ begin
+ if params[:c] == nil or params[:r] == nil or params[:z_x] == nil or params[:z_y] == nil
+ @location = Location.new(:pixel_x => params[:x], :pixel_y => params[:y] )
+ else
+ x = params[:c].to_i * 100 + params[:z_x].to_i;
+ if x < 0
+ x += 100;
+ end
+ @location = Location.new(:pixel_x => x ,
+ :pixel_y => params[:r].to_i * 100 + params[:z_y].to_i )
+ end
+ end
+ end
+
+
+ # create new location
+ def create
+ begin
+ values = params[:location]
+ values[:time] = DateTime.now
+ values[:creator_ip] = @request.env["REMOTE_ADDR"]
+
+
+ values[:person_id] = session[:person].id
+
+ @location = Location.new(values)
+ if @location.save
+ flash[:notice] = 'Location gespeichert'
+ redirect_to :action => 'show', :id => @location
+ else
+ flash[:notice] = 'Location nicht gespeichert, bitte ueberpruefen Sie Ihre Eingabe'
+ redirect_to :back
+ end
+ end
+ end
+end
+
+
+
diff --git a/app/controllers/net_controller.rb b/app/controllers/net_controller.rb
new file mode 100644
index 0000000..a65e7c1
--- /dev/null
+++ b/app/controllers/net_controller.rb
@@ -0,0 +1,3 @@
+class NetController < ApplicationController
+ model :person
+end
diff --git a/app/controllers/node_controller.rb b/app/controllers/node_controller.rb
new file mode 100644
index 0000000..6f827e3
--- /dev/null
+++ b/app/controllers/node_controller.rb
@@ -0,0 +1,69 @@
+class NodeController < ApplicationController
+ model :person
+
+ def index
+ redirect_to :action => "list"
+ end
+
+ def list
+ @location = @params[:location]
+ if @location != nil
+ @nodes = Node.find(:all,
+ :conditions => ["location_id = ?", Location.find_by_name(@params[:location]).id],
+ :order => 'location_id')
+ else
+ @nodes = Node.find(:all, :order => 'location_id')
+ end
+ end
+
+ def destroy
+ end
+
+ def edit
+ @persons = Person.find(:all)
+ @node = Node.find(params[:id])
+ end
+
+ def update
+ @node = Node.find(params[:id])
+ values = params[:node]
+ if ( session[:person] != @node.location.person ) and ( session[:person].email != 'nine@wirdorange.org' )
+ flash[:notice] = 'Sie sind nicht berechtigt.'
+ redirect_to :back
+ else if @node.update_attributes(params[:node])
+ flash[:notice] = 'Node erfolgreich geaendert'
+ redirect_to :action => 'show', :controller => 'location', :id => @node.location
+ else
+ flash[:notice] = 'Änderung fehlgeschlagen'
+ redirect_to :action => 'show', :controller => 'location', :id => @node.location
+ end
+ end
+ end
+
+ def new
+ @persons = Person.find(:all)
+ @location = Location.find(params[:location])
+ @node = Node.new( :location_id => @location.id )
+ end
+
+ def do_new
+ node_values = params[:node]
+ node_values[:time] = DateTime.now
+ node_values[:creator_ip] = @request.env["REMOTE_ADDR"]
+
+# Nets.find(:first, :conditions =>
+
+ location = Location.find(node_values[:location_id])
+ if ( session[:person] != location.person ) and ( session[:person].email != 'nine@wirdorange.org' )
+ flash[:notice] = 'Sie sind nicht berechtigt.'
+ redirect_to :action => 'show', :controller => 'person', :id => session[:person].id
+ elsif Node.create_node(node_values)
+ flash[:notice] = 'Node erfolgreich erzeugt'
+ redirect_to :action => "show", :controller => "location", :id => node_values[:location_id]
+ else
+ flash[:notice] = 'error'
+ render_text 'error'
+ end
+ end
+end
+
diff --git a/app/controllers/person_controller.rb b/app/controllers/person_controller.rb
new file mode 100644
index 0000000..43cecb9
--- /dev/null
+++ b/app/controllers/person_controller.rb
@@ -0,0 +1,177 @@
+
+
+class PersonController < ApplicationController
+# model :location, :person
+
+# before_filter :validate_person, :only => [:edit, :update, :do_change_pass]
+
+ @person = ''
+
+ def login
+ if session[:person]
+ reset_session
+ end
+ end
+
+ def sign_on
+ person = Person.authenticate( params[:person][:email],
+ params[:person][:password])
+
+ if person
+ session[:person] = person
+ if session[:url]
+ redirect_to session[:url]
+ else
+ redirect_to :controller => "person", :action => "show", :id => session[:person].id
+ end
+ session[:url] = nil
+ else
+ flash[:notice] = "Login fehlgeschlagen."
+ redirect_to :action => "login"
+ end
+ end
+
+ def logout
+ reset_session
+ redirect_to :action => "login"
+ end
+ def login
+ end
+
+ def index
+ redirect_to :action => "list"
+ end
+
+ # list all persons
+ def list
+ @persons = Person.find(:all, :order => :email )
+ end
+
+ # show information about a person
+ def show
+ begin
+ @person = Person.find(params[:id])
+
+ @locations = Location.find(:all,
+ :conditions => ["person_id = ?", params[:id]] )
+
+ rescue ActiveRecord::RecordNotFound
+ render_text "Error, Person not found"
+ end
+ end
+
+ # edit a specific person identified by param person id
+ def edit
+ @person = Person.find(params[:id])
+ if session[:person] != @person and session[:person].email != 'nine@wirdorange.org'
+ flash[:notice] = 'Sie haben nicht die Berechtigung hierfür.'
+ redirect_to :back
+ end
+ end
+
+ # update the information about a person identified by person id
+ def update
+ @person = Person.find(params[:id])
+ if session[:person] != @person and session[:person].email != 'nine@wirdorange.org'
+ flash[:notice] = 'Sie haben nicht die Berechtigung hierfür.'
+ redirect_to :back
+ else
+ if @person.update_attributes(params[:person])
+ flash[:notice] = 'Person wurde erfolgreich upgedatet.'
+ redirect_to :action => 'show', :id => @person
+ else
+ flash[:notice] = 'Person wurde NICHT verändert.'
+ redirect_to :action => 'edit', :id => @person
+ end
+ end
+ end
+
+ def register
+ end
+
+ # create new person record
+ def create
+ if params[:password] == params[:password2]
+ values = params[:person]
+ values[:password] = params[:password]
+ @person = Person.new(values)
+ @person.password = params[:person][:password]
+ if @person.save
+ flash[:notice] = 'Person erfolgreich registriert'
+ redirect_to :action => 'show', :id => @person
+ else
+ params[:person][:password2] = "";
+ params[:person][:password] = "";
+ render :action => 'register', :person => params[:person]
+ end
+ else
+ flash[:notice] = 'Bitte überprüfen Sie ihre Eingabe'
+ render :action => 'register', :person => params[:person]
+ end
+ end
+
+ # revoke password form
+ def revoke_pass
+ reset_session
+ end
+
+ # generate new password and mail to the poor guy
+ def do_revoke
+ password = newpass( 8 )
+ @person = Person.find( :first,
+ :conditions => [ "email = ?", params[:person][:email] ] )
+ if @person == nil
+ flash[:notice] = 'Die angegebene Email Adresse ist nicht registriert.'
+ redirect_to :action => 'revoke_pass'
+ elsif @person.update_attribute( 'password', password )
+ mail = PasswordMailer.deliver_password( @person, password )
+ flash[:notice] = 'Ihr neues Passwort wird Ihnen via email zugesendet.'
+ redirect_to :action => 'login'
+ else
+ render :action => 'revoke_pass'
+ end
+ end
+
+ def change_pass
+ @person = Person.find(params[:id])
+ if session[:person] != @person
+ flash[:notice] = 'Sie haben nicht die Berechtigung hierfür.'
+ redirect_to :back
+ end
+ end
+
+ def do_change_pass
+ person = Person.find( :first, :conditions =>
+ [ "email = BINARY ? AND password = BINARY ?",
+ session[:person][:email],
+ Digest::MD5.hexdigest(params[:oldpassword]) ] )
+ if person and params[:password] == params[:password2]
+ person.update_attribute( 'password', params[:password] )
+ flash[:notice] = 'Ihr Passwort wurde geaendert.'
+ redirect_to :action => 'show', :id => session[:person][:id]
+ else
+ flash[:notice] = 'Ihr altes Passwort wurde falsch eingegeben.'
+ redirect_to :back
+ end
+ end
+
+
+protected
+ # validate rights of person
+ def validate_person
+ if session[:person] != @person
+ flash[:notice] = 'Sie sind leider nicht berechtigt!'
+ redirect_to :back
+ end
+ end
+
+private
+ # generate alphanumeric password
+ def newpass( len )
+ chars = ("a".."z").to_a + ("A".."Z").to_a + ("1".."9").to_a
+ newpass = ""
+ 1.upto(len) { |i| newpass << chars[rand(chars.size-1)] }
+ return newpass
+ end
+
+end