Commit aa5b152d authored by steven robert's avatar steven robert

Merge branch 'master' of gitlab.com:zourit/zourit-admin

parents 3e60f274 950240b3
......@@ -77,7 +77,7 @@ function SuperAdmin_init() {
jQuery.ajax({ type: "POST",
url: "/users",
dataType: "json",
data: { user: {first_name: $prenom, last_name: $nom, email: $email, admin: true, password: $password, zouritZimbraTask: true, zouritZimbraContact: true, zouritZimbraCalendar: true, zouritZimbraEmail: true, zouritOwncloud: true } },
data: { user: {first_name: $prenom, last_name: $nom, email: $email, admin: true, password: $password, zouritZimbraTask: false, zouritZimbraContact: false, zouritZimbraCalendar: false, zouritZimbraEmail: false, zouritOwncloud: false } },
success: function (data) {
$SuperAdmin_table.bootstrapTable('refresh');
toastr.success("L'administrateur " + $prenom + " " + $nom + " a été créé");
......@@ -626,7 +626,7 @@ function SuperAdmin_init() {
sortable: false,
editable: false,
formatter: function (value) {
return '<a href="#Admin-modal-params" data-toggle="modal" data-id="'+ value +'" class="open-params-modal"><i class="fa fa-cog" aria-hidden="true"></i>';
return '<a href="/domains/' + value + '/infos"><i class="fa fa-cog" aria-hidden="true"></i>';
}
},
{
......@@ -657,67 +657,6 @@ function SuperAdmin_init() {
]
});
$(document).on("click", ".open-params-modal", function () {
var domainId = $(this).data('id');
var str = "<p>Domaine ID: "+ domainId +"</p>";
var myObj = $('#Admin-modal-params .modal-body');
myObj.empty();
jQuery.ajax({type: "GET",
url: "/config_modules/"+domainId+"/infos.json",
dataType: "json",
success: function (datas) {
str += `
<ul class="nav nav-tabs">
`;
var i = 1;
datas.forEach(function(element) {
active = i>1 ? "" : "active";
str += `
<li class="`+active+`"><a data-toggle="tab" href="#tab`+element["id"]+`">`+element["name"]+`</a></li>
`;
i = i+1;
});
str += `
</ul>
<div class="tab-content">
`;
i = 1;
datas.forEach(function(element) {
active = i>1 ? "" : "active in";
str += `
<div id="tab`+element["id"]+`" class="tab-pane fade `+active+`"><br/>
`;
data = element["domain_datas"];
for (var key in data){
value = "";
if (element["value"]) {
value = element["value"][key] ? element["value"][key] : "";
}
str += `
<div class="input-group">
<span class="input-group-addon">`+ data[key] +`</span>
<input type="text" class="form-control" id="userFirstName" placeholder="" value="`+value+`">
</div><br/>
`;
}
str += `
</div>
`;
i = i+1;
});
str += `
</div>
`;
myObj.append(str);
},
error: function (data) {
toastr.error(data.responseText);
}
});
});
$SuperAdmin_table.bootstrapTable('togglePagination'); // Navigation automatique pour changer de page
$cible_input = '.bootstrap-table .search';
......
class CloudController < ApplicationController
include NextcloudHelper
include Core::Nextcloud::Helper
before_action :only_logged_users
# GET /cloud
......
......@@ -4,8 +4,10 @@ class ComptaController < ApplicationController
# GET /compta
def index
configmodule = ConfigModule.where(name: "Garradin").first
if configmodule and configmodule.url
@url_embedded = GarradinHelper.get_login_url(current_user)
domain = Domain.find(current_user.domain_id)
domaininfo = DomainInfo.where(config_module_id: configmodule.id, domain_id: current_user.domain_id).first
if domaininfo && domaininfo.instance
@url_embedded = Core::Garradin::Helper.get_login_url(domain, domaininfo.instance)
else
redirect_to "/services", notice: "Le module garradin n'est pas actif"
end
......
class DomainInfosController < ApplicationController
before_action :set_params
before_action :super_admin_only
# GET /domains/1/infos/2/new
def new
@domainInfo = DomainInfo.new
end
# POST /domains/1/infos/2
def create
unless params[:instance_id]==""
@domainInfo = DomainInfo.new
@domainInfo.domain_id = @domain.id
@domainInfo.config_module_id = @mod.id
@domainInfo.instance_id = params[:instance_id]
respond_to do |format|
if @domainInfo.save
puts "Création du DomainInfo #{@domain.id} - module #{@mod.id}"
format.html { redirect_to "/domains/#{@domain.id}/infos", notice: "L'instance a bien été ajoutée à votre domaine" }
else
puts "Erreur lors de la création du DomainInfo #{@domain.id} - module #{@mod.id}"
format.html { render :new }
end
end
else
redirect_to "/domains/#{@domain.id}/infos", notice: "Impossible de rajouter un serveur à votre domaine"
end
end
private
def set_params
@domain = Domain.find(params[:id])
@mod = ConfigModule.find(params[:mod_id])
end
end
......@@ -19,13 +19,17 @@
class DomainsController < ApplicationController
include DomainsHelper
before_action :set_domain, only: [:show, :edit, :update, :destroy, :administrators]
before_action :set_domain, only: [:show, :edit, :update, :destroy, :administrators, :infos]
before_action :admin_only
before_action :super_admin_only, only: [:infos]
# GET /domains
# GET /domains.json
def index
@domains = list_domains.sort_by { |hsh| hsh.name }
respond_to do |format|
format.html
format.json { @domains = list_domains.sort_by { |domain| domain.name } }
end
end
# GET /domains/1/administrators
......@@ -102,6 +106,12 @@ class DomainsController < ApplicationController
end
end
# GET /domains/1/infos.json
def infos
@infos = DomainInfo.where(domain_id: @domain.id)
@modules = ConfigModule.all
end
private
# Use callbacks to share common setup or constraints between actions.
def set_domain
......
class MailsController < ApplicationController
include ZimbraHelper
include OpenSSL
before_action :only_logged_users
......@@ -8,9 +7,10 @@ class MailsController < ApplicationController
def index
configmodule = ConfigModule.where(name: "Zimbra").first
if configmodule
domain = Domain.find(current_user.domain_id)
domaininfo = DomainInfo.where(config_module_id: configmodule.id, domain_id: current_user.domain_id).first
if domaininfo && domaininfo.instance_id
@url_embedded = get_login_url
@url_embedded = Core::Zimbra::Helper.get_login_url(domain, current_user)
else
redirect_to "/services", notice: "Le module Zimbra n'est pas disponible pour votre domaine"
end
......
class UsersController < ApplicationController
skip_before_filter :verify_authenticity_token
include UsersHelper
include ZimbraHelper
include Core::Zimbra::Helper
before_action :set_user, only: [:show, :edit, :update, :destroy, :alias]
before_action :user_only, only: [:show]
......@@ -141,7 +141,10 @@ class UsersController < ApplicationController
# GET /logout
def logout
@urls = [get_logout_url, GarradinHelper.get_logout_url(current_user)]
domain = Domain.find(current_user.domain_id)
configmodule = ConfigModule.where(name: "Garradin").first
domaininfo = DomainInfo.where(config_module_id: configmodule.id, domain_id: current_user.domain_id).first
@urls = [Core::Zimbra::Helper.get_logout_url(domain), Core::Garradin::Helper.get_logout_url(domain, domaininfo.instance)]
session[:user] = nil
end
......
......@@ -63,10 +63,11 @@ module UsersHelper
:zouritzimbraquota => zouritZimbraQuota.to_s,
:zouritcloudquota => zouritCloudQuota.to_s
}
if $ldap.add( :dn => dn, :attributes => attr )
if $ldap.add( :dn => dn, :attributes => attr )
puts "Utilisateur #{mail} créé dans LDAP"
return true
else
puts "error creation : #{$ldap.get_operation_result.message}"
puts "Erreur de création de l'utilisateur #{mail} dans LDAP"
return false
end
end
......@@ -92,6 +93,7 @@ module UsersHelper
end
def destroy_user dn
puts "Suppression de l'utilisateur #{dn} de LDAP"
return $ldap.delete(dn: dn)
end
......
......@@ -17,8 +17,6 @@
# along with Zourit. If not, see <http://www.gnu.org/licenses/>.
class Alias
include ZimbraHelper
attr_accessor :email, :user_email
def initialize user_email, email
......@@ -27,16 +25,16 @@ class Alias
end
def save
return zimbra_aalias self.user_email, self.email
return Core::Zimbra::Helper.zimbra_aalias self.user_email, self.email
end
def destroy
return zimbra_ralias self.user_email, self.email
return Core::Zimbra::Helper.zimbra_ralias self.user_email, self.email
end
def self.list user_email
aliases = []
brut = ApplicationController.helpers.zimbra_galias user_email
brut = Core::Zimbra::Helper.zimbra_galias user_email
brut.each do |a|
aliases << Alias.new(user_email, a)
end
......@@ -45,7 +43,7 @@ class Alias
def self.create opts
if opts[:user_email] and opts[:email]
return ApplicationController.helpers.zimbra_aalias opts[:user_email], opts[:email]
return Core::Zimbra::Helper.zimbra_aalias opts[:user_email], opts[:email]
else
return false
end
......
......@@ -17,7 +17,7 @@
class Domain
include DomainsHelper
include ZimbraHelper
include Core::Zimbra::Helper
include UsersHelper
include GroupsHelper
......@@ -50,20 +50,10 @@ class Domain
def save
if @id # modification de domaine
opts = { zouritdomainquota: self.zouritDomainQuota }
opts = { zouritdomainquota: self.zouritDomainQuota }
return update_domain self.name, opts
else # create domain
result, message = create_domain self.name, self.zouritDomainQuota
if result
result, message = zimbra_cd self.name
# Si echec de creation dans zimbra alors on supprime dans ldap
if result
result, message = zimbra_cdl_tous self.name
else
p message
destroy_domain self.name
end
end
return result, message
end
end
......@@ -81,7 +71,7 @@ class Domain
end
# puis on supprime le domaine
if destroy_domain self.name
return zimbra_dd self.name
return Core::Zimbra::Helper.destroy_domain self
else
return false
end
......
......@@ -15,7 +15,19 @@
# You should have received a copy of the GNU General Public License
# along with Zourit. If not, see <http://www.gnu.org/licenses/>.
class DomainInfo < ActiveRecord::Base
class DomainInfo < ActiveRecord::Base
belongs_to :config_module
belongs_to :instance
before_save :create_domain_in_modules
private
def create_domain_in_modules
domain = Domain.find(self.domain_id)
mod = ConfigModule.find(self.config_module_id)
if mod.name=="Zimbra"
Core::Zimbra::Helper.create_domain domain
elsif mod.name=="Garradin"
Core::Garradin::Helper.create_domain domain
end
end
end
......@@ -17,7 +17,7 @@
class Group
include GroupsHelper
include ZimbraHelper
include Core::Zimbra::Helper
attr_accessor :member, :name, :domain
attr :dn, :id
......@@ -59,8 +59,8 @@ class Group
if member.count > 0
@dn = "cn=#{self.name},ou=groups,o=#{self.domain.name}"
if create_group(self.dn, self.member)
if zimbra_cdl self.name
return zimbra_adlm self.name, members_to_string
if Core::Zimbra::Helper.zimbra_cdl self.name
return Core::Zimbra::Helper.zimbra_adlm self.name, members_to_string
else
return false
end
......@@ -68,7 +68,7 @@ class Group
return false
end
else
p "Erreur de création : il doit au moins y avoir un utilisateur dans le groupe"
puts "Erreur de création : il doit au moins y avoir un utilisateur dans le groupe"
return false
end
end
......@@ -81,7 +81,7 @@ class Group
self.member << user unless self.is_member?(user)
users_email += "#{user.email} "
end
zimbra_adlm(self.name, users_email) unless self.name.include?("tous@")
Core::Zimbra::Helper.zimbra_adlm(self.name, users_email) unless self.name.include?("tous@")
return self.save
end
......@@ -94,12 +94,12 @@ class Group
self.member.delete(m) if m.id==id
end
end
zimbra_rdlm self.name, users_email unless self.name.include?("tous@")
Core::Zimbra::Helper.zimbra_rdlm self.name, users_email unless self.name.include?("tous@")
return self.save
end
def destroy
zimbra_ddl self.name
Core::Zimbra::Helper.zimbra_ddl self.name
return destroy_group self.dn
end
......
......@@ -16,7 +16,7 @@
# along with Zourit. If not, see <http://www.gnu.org/licenses/>.
class Resource
include ZimbraHelper
include Core::Zimbra::Helper
attr :name, :type
......
......@@ -19,7 +19,7 @@
class User
include UsersHelper
include DomainsHelper
include ZimbraHelper
include Core::Zimbra::Helper
include GroupsHelper
attr_accessor :first_name, :last_name, :email, :admin, :superadmin, :zouritZimbraQuota, :zouritCloudQuota,
......@@ -101,7 +101,6 @@ class User
self.admin = (value.downcase=="true")
when "zouritZimbraQuota"
@reste = value.to_i - self.zouritZimbraQuota.to_i
p "#{value.to_i} - #{self.zouritZimbraQuota.to_i} = #{@reste}"
self.zouritZimbraQuota = value.to_i
req_zimbra += "zimbraMailQuota \"#{self.zouritZimbraQuota.to_i*1024*1024*1024}\" "
when "zouritCloudQuota"
......@@ -114,11 +113,9 @@ class User
@password = Net::LDAP::Password.generate(:sha, value) if key=="password"
end
p "reste : #{@reste} ; resteQuotaDomain: #{@resteQuotadomain}"
if @reste <= @resteQuotadomain
return self.save req_zimbra
else
p "pas ok #{@reste} >= #{@resteQuotadomain}"
return false
end
end
......@@ -137,7 +134,8 @@ class User
# si il n'y a pas de requete pour zimbra ou si zimbra est inactif on ne lance que la mise à jour ldap
zimbraActive = YAML.load_file(Rails.root.join("config", "zimbra.yml"))["active"]
unless req_zimbra.to_s.empty? or !zimbraActive
if (zimbra_ma self, req_zimbra)
#if (Core::Zimbra::Helper.zimbra_ma self, req_zimbra)
if (Core::Zimbra::Helper.update_user self, User.find(self.id))
return update_user self.email, opts
else
return false
......@@ -148,19 +146,22 @@ class User
else # Création d'utilisateur
if create_user(self.email, self.first_name, self.last_name, self.password, objectclass_array, self.admin, self.zouritZimbraQuota, self.zouritCloudQuota)
complete(self.email)
if zimbra_ca(self)
domain = Domain.find(domain_from_mail(self.email))
groupe = Group.find_with_user("tous@#{domain.name}")
if groupe
groupe.add_user [self.id]
if self.zouritZimbraEmail
if Core::Zimbra::Helper.create_user(self)
domain = Domain.find(domain_from_mail(self.email))
groupe = Group.find_with_user("tous@#{domain.name}")
if groupe
groupe.add_user [self.id]
else
groupe = Group.new({name: "tous@#{domain.name}", domain: domain, member: [self]})
groupe.save
end
return true
else
groupe = Group.new({name: "tous@#{domain.name}", domain: domain, member: [self]})
groupe.save
return false
end
return true
else
destroy_user @dn
return false
return true
end
else
return false
......@@ -181,7 +182,11 @@ class User
def destroy
#delete_from_tous_group
if destroy_user @dn
return zimbra_da self
if self.zouritZimbraEmail
return Core::Zimbra::Helper.destroy_user self
else
return true
end
else
return false
end
......
json.array!(@modules) do |mod|
json.extract! mod, :id, :name, :resume, :font
json.datas eval(mod.domain_datas)
json.domain_datas mod.domain_datas ? eval(mod.domain_datas) : nil
end
\ No newline at end of file
<div class="z-index-page">
<div class="container">
<div class="panel panel-warning shadow">
<div class="panel-heading clearfix">
<h1>
<%= "Nouvelle instance pour #{@domain.name} - module #{@mod.name}" %>
</h1>
</div>
<div class="panel-body">
<div class="row">
<%= form_for(@domainInfo, url: "/domains/#{@domain.id}/infos/#{@mod.id}", method: :post) do |f| %>
<% if @domainInfo.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize( @domainInfo.errors.count, "error") %> prohibited this visio from being saved:</h2>
<ul>
<% @domainInfo.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="col-sm-6 col-md-6 col-md-offset-3 text-left">
<div class="field">
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-server" aria-hidden="true"></i></span>
<%= select_tag "instance_id", options_from_collection_for_select(Instance.where(config_module_id: @mod.id), "id", "name", ""), prompt: "Sélectionnez une instance", class: "form-control" %>
</div>
</div>
<div class="actions" align="center">
<%= button_tag(class: "btn btn-primary") do %>
<i></i> Valider
<% end %>
ou <%= link_to "Annuler", "/domains/#{@domain.id}/infos" %>
</div>
</div>
<% end %>
</div>
</div>
</div>
</div>
</div>
\ No newline at end of file
......@@ -119,25 +119,4 @@
</div>
</div>
<!-- Medium modal paramètres du domaine -->
<div id="Admin-modal-params" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title">
<%= "Paramètres du domaine" %>
</h4>
</div>
<div class="modal-body">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>
</div>
<div class="z-index-page">
<div class="container">
<div class="panel panel-warning shadow">
<div class="panel-heading clearfix">
<h1>
<%= I18n.t "terms.parametersdomain"%> <strong><%= @domain.name %></strong></h1>
</h1>
</div>
<div class="panel-body">
<% @modules.each do |mod| %>
<h2><%= mod.name %></h2>
<% info = DomainInfo.where(domain_id: @domain.id, config_module_id: mod.id).first %>
<% if info && info.instance_id %>
<%= "Instance en cours : #{info.instance.name}" %>
<% else %>
<%= link_to "Se relier à un serveur", "/domains/#{@domain.id}/infos/#{mod.id}", class: "btn btn-primary" %>
<% end %>
<% end %>
</div>
</div>
</div>
</div>
json.array!(@infos) do |info|
json.extract! info, :id, :domain_id, :config_module_id, :active, :instance_id
json.instance_name info.instance.name
json.module_name info.config_module.name
json.datas info.data ? eval(info.data) : nil
end
\ No newline at end of file
......@@ -108,7 +108,10 @@ Copyright (c) 2017 Robert Jean Steven <robert.steven.974@gmail.com>
<div id="ConnexionUserModal" class="modal fade z-modal-connexion-user" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel">
<div class="modal-dialog modal-sm">
<div class="modal-content">
<div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button> <h4 class="modal-title" id="mySmallModalLabel"><%= I18n.t "terms.connexion"%></h4> </div>
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="mySmallModalLabel"><%= I18n.t "terms.connexion"%></h4>
</div>
<div class="modal-body">
<form action="login" method="post">
<div class="form-group">
......@@ -116,7 +119,7 @@ Copyright (c) 2017 Robert Jean Steven <robert.steven.974@gmail.com>
<div class="cols-sm-10">
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-envelope fa" aria-hidden="true"></i></span>
<input type="text" class="form-control" name="loginName" placeholder="Adresse email" onFocus="javascript:this.value=''">
<input type="text" class="form-control" name="loginName" placeholder="" onFocus="javascript:this.value=''">
</div>
</div>
</div>
......@@ -125,7 +128,7 @@ Copyright (c) 2017 Robert Jean Steven <robert.steven.974@gmail.com>
<div class="cols-sm-10">
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-lock fa-lg" aria-hidden="true"></i></span>
<input type="password" class="form-control" name="loginPassword" placeholder="Mot de passe" onFocus="javascript:this.value=''">
<input type="password" class="form-control" name="loginPassword" placeholder="" onFocus="javascript:this.value=''">
</div>
</div>
</div>
......
......@@ -25,10 +25,10 @@ module ZouritAdmin
# Do not swallow errors in after_commit/after_rollback callbacks.
config.active_record.raise_in_transactional_callbacks = true
config.autoload_paths += %W(#{config.root}/modules)
config.autoload_paths << Rails.root.join('lib').join('modules')
# application's version
VERSION = '0.5.0 beta2'
VERSION = '0.5.0 beta3'
DEFAULT_THEME = 3
......
# Chargement de tous les modules Core
Dir.foreach(Rails.root.join("modules/core")) do |folder|
file = File.join(Rails.root.join("modules/core", folder), "helper.rb")
require file if File.exist?(file)
end
#Dir.foreach(Rails.root.join("modules/core")) do |folder|
# file = File.join(Rails.root.join("modules/core", folder), "helper.rb")
# require file if File.exist?(file)
#end
# Chargement de tous les modules Others
Dir.foreach(Rails.root.join("modules/others")) do |folder|
file = File.join(Rails.root.join("modules/others", folder), "helper.rb")
require file if File.exist?(file)
end
\ No newline at end of file
#Dir.foreach(Rails.root.join("modules/others")) do |folder|
# file = File.join(Rails.root.join("modules/others", folder), "helper.rb")
# require file if File.exist?(file)
#end
\ No newline at end of file
......@@ -223,6 +223,7 @@ fr:
backdomain: "Retour au domaine"
backdomainlist: "Retour à la liste des domaines"
userdomainmanage: "Gestion des utilisateurs du domaine"
parametersdomain: "Paramètres du domaine"
adduser: "Ajouter un utilisateur"
deluser: "Supprimer utilisateur"
groupmanage: "Gestion des groupes"
......
......@@ -30,6 +30,9 @@ Rails.application.routes.draw do
get 'domains/:id/resources' => 'resources#index'
post 'domains/:id/resources' => 'resources#create'
delete 'domains/:id/resources' => 'resources#destroy'
get 'domains/:id/infos' => 'domains#infos'
get 'domains/:id/infos/:mod_id' => 'domain_infos#new'
post 'domains/:id/infos/:mod_id' => 'domain_infos#create'
get 'visios' => "visios#index"
get 'visios/:id/users' => 'visios#users', :defaults => { :format => :json }
get 'about' => "about#index"
......
......@@ -15,39 +15,27 @@
# You should have received a copy of the GNU General Public License
# along with Zourit. If not, see <http://www.gnu.org/licenses/>.
module GarradinHelper
module Core::Garradin::Helper
# url de login de garradin
def self.get_login_url(user)
return get_domain_module_url(user)
def self.get_login_url(domain, instance)
datas = eval(instance.datas)
url = "https://#{domain.name.gsub('.','-')}.#{datas[:url]}/admin/"
return url
end
# url de logout de garradin
def self.get_logout_url(user)
url = get_domain_module_url(user)
url += "/admin/logout.php" if url
def self.get_logout_url(domain, instance)
url = get_login_url(domain, instance)