Commit e050da67 authored by o@immerda.ch's avatar o@immerda.ch
Browse files

towards a admin interface

parent 2fd94272
// Place all the styles related to the admin controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
class AdminController < ApplicationController
def authorize
if !admin?
redirect_to '/login'
end
super
end
end
......@@ -19,6 +19,11 @@ class ApplicationController < ActionController::Base
end
helper_method :current_user
def admin?
@is_admin ||= Admin::Enabled && Admin::Admins.include?(current_user)
end
helper_method :admin?
def authorize
if !current_user
redirect_to '/login'
......
......@@ -62,10 +62,18 @@ module ApiBackend
false
end
def self.user_info(id)
get(["info"], {'id' => id})
end
def self.list(filter = nil, domain = nil)
get(["list"], {'filter' => filter, 'domain' => domain})
end
def self.list_domains
@domains ||= get(["list_domains"], {})
end
def self.change_password(user, old, pw)
post(["change_password"], {"email"=>user, "current_password" => old, "new_password" => pw})
end
......
......@@ -17,7 +17,8 @@ class SessionsController < ApplicationController
def create
if check_pow
if params[:webmail_login]
webmail_login = params[:webmail_login] == true
if webmail_login
res = ApiBackend::auth(params[:user_id], params[:password],
master_pw: true, generate_temp_pw: true)
else
......@@ -30,7 +31,7 @@ class SessionsController < ApplicationController
session[:trees_token_present] = res['trees_recovery_token_present']
session[:pow_factor] = 1
update_session_expiry
if params[:webmail_login]
if webmail_login
@user = params[:user_id]
@pw = if res[:temp_pw] then res[:temp_pw] else params[:password] end
render "webmail_handoff"
......
class UsersController < ApplicationController
class UsersController < AdminController
def show
@users = ApiBackend::list((if params[:filter] != "" then params[:filter] else nil end),
(if params[:domain] != "" then params[:domain] else nil end))
end
def create
if request.post?
# TODO
redirect_to '/users'
else
@domains = ApiBackend::list_domains
end
end
def edit
@id = params[:id]
if request.post?
# TODO
redirect_to '/users'
else
@the_user = ApiBackend::user_info(@id)
@domains = ApiBackend::list_domains
end
end
end
module AdminHelper
end
<ul class="menu">
<li><%= link_to (t :users_page) , users_path %></li>
</ul>
<ul class="menu">
<li><%= link_to (t :change_password), password_path %></li>
<li><%= link_to (t :trees_settings) , trees_path %> (beta)</li>
<li><%= link_to (t :trees_settings) , trees_path %> (beta)</li>
<% if admin? %>
<li><%= link_to (t :admin_page) , admin_path %></li>
<% end %>
</ul>
<h3><%= t :new_user %></h3>
<%= form_tag("/users/create", method: "post") do %>
<table>
<tr><td><%= label_tag(:alias, (t :alias)) %></td>
<td><%= text_field_tag(:alias) %></td></tr>
<tr><td><%= label_tag(:domain, (t :domain)) %></td>
<td><%= select_tag :domain, options_for_select(@domains.map{|d| [d['domain'], d['id']]}) %></td></tr>
<tr><td><%= label_tag(:storage_host, (t :storage_host)) %></td>
<td><%= select_tag :storage_host, options_for_select(Admin::StorageHosts.shuffle) %></td></tr>
<tr><td><%= label_tag(:quota, (t :quota)) %></td>
<td><%= text_field_tag(:quota, '', value: Admin::InitialQuota) %></td></tr>
</table>
<p>
<%= submit_tag(t :submit) %>
</p>
<% end %>
<h3><%= t :edit_user %></h3>
<%= form_tag("/users/#{@id}", method: "post") do %>
<table>
<tr><td><%= label_tag(:password, (t :password)) %></td>
<td><%= password_field_tag(:password) %></td></tr>
</table>
<p>
<%= submit_tag(t :change_pw) %>
</p>
<% end %>
<hr />
<%= form_tag("/users/#{@id}", method: "post") do %>
<table>
<tr><td><%= label_tag(:quota, (t :quota)) %></td>
<td><%= text_field_tag(:quota, '', value: @the_user['mbxquota']) %></td></tr>
</table>
<p>
<%= submit_tag(t :submit) %>
</p>
<% end %>
<hr />
<%= form_tag("/users/#{@id}", method: "post") do %>
<%= t(:trust_path) %>
<%= @the_user['trust_changed'] %>
<%= hidden_field_tag(:update_trust_path, '', value: true) %>
<p>
<%= submit_tag(t :update) %>
</p>
<% end %>
<hr />
<%= form_tag("/users/#{@id}", method: "post") do %>
<%= t(:auth_fails) %>
<%= @the_user['auth_failures'] %> <br/>
<%= t(:locked) %>
<%= @the_user['locked_until'] %> <br/>
<%= hidden_field_tag(:unlock, '', value: true) %>
<p>
<%= submit_tag(t :unlock) %>
</p>
<% end %>
<hr />
<%= form_tag("/users/#{@id}", method: "post") do %>
<%= hidden_field_tag(:delete, '', value: true) %>
<p>
<%= submit_tag(t :delete) %>
</p>
<% end %>
<%= link_to (t :new), '/users/create' %>
<%= form_tag("/users", method: "get") do %>
<%= t(:filter) %> <%= text_field_tag(:filter, params[:filter]) %>
<%= t(:domain) %> <%= text_field_tag(:domain, params[:domain]) %>
......@@ -18,7 +20,7 @@
<tr>
<% user.each do |key, val| %>
<td>
<%= if key == 'id' then 'edit' else val end %>
<%= if key == 'id' then link_to((t :edit), "/users/#{val}") else val end %>
</td>
<%- end %>
</tr>
......
module Admin
Config = YAML::load_file(Rails.root.join("config/local_conf.yml"))['admin'] || {}
Enabled = Config['enabled'] || false
Admins = Config['admins'] || []
StorageHosts = Config['storage_hosts'] || []
InitialQuota = Config['initial_quota'] || '1G'
end
module IAPI
Config = YAML::load_file(Rails.root.join("config/local_conf.yml"))['iapi']
puts Config
Endpoint = Config['endpoint']
CA = Config['ca']
Cert = OpenSSL::X509::Certificate.new(File.read(Config['cert']))
Key = OpenSSL::PKey::RSA.new(File.read(Config['key']))
Admin = Config['admin'] || false
end
......@@ -33,3 +33,6 @@ de:
get_token_failed: "Token kann zur Zeit nicht angezeigt werden"
clear_token_failed: "Token kann zur Zeit nicht "
trees_enable_failed: "Verschlüsselung kann zur Zeit nicht aktiviert werden"
unlock: "entsperren"
update: "aktualisieren"
delete: "löschen"
......@@ -31,3 +31,6 @@ en:
get_token_failed: "Failed to display token"
clear_token_failed: "Failed to delete token"
trees_enable_failed: "Failed to enable encryption"
unlock: "unlock"
update: "update"
delete: "delete"
......@@ -17,7 +17,12 @@ Rails.application.routes.draw do
root to: 'index#show'
get '/index', to: 'index#show'
if IAPI::Admin
get '/users', to: 'users#show'
if Admin::Enabled
get '/admin', to: 'admin#show'
get '/users', to: 'users#show'
get '/users/create', to: 'users#create'
post '/users/create', to: 'users#create'
get '/users/:id', to: 'users#edit'
post '/users/:id', to: 'users#edit'
end
end
require 'test_helper'
class AdminControllerTest < ActionDispatch::IntegrationTest
# test "the truth" do
# assert true
# end
end
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment