Redmine.pm-1.2.1.patch

Redmine.pm Patch for version 1.2.1 - Tiemo Vorschuetz, 2011-09-07 09:58

Download (5.79 KB)

View differences:

Redmine.pm Mi Sep 7 09:28:58 2011
51 51
     PerlAuthenHandler Apache::Authn::Redmine::authen_handler
52 52
  
53 53
     ## for mysql
54
     RedmineDSN "DBI:mysql:database=databasename;host=my.db.server"
54
     PerlSetVar RedmineDSN "DBI:mysql:database=databasename;host=my.db.server"
55 55
     ## for postgres
56
     # RedmineDSN "DBI:Pg:dbname=databasename;host=my.db.server"
56
     # PerlSetVar RedmineDSN "DBI:Pg:dbname=databasename;host=my.db.server"
57 57

  
58
     RedmineDbUser "redmine"
59
     RedmineDbPass "password"
58
     PerlSetVar RedmineDbUser "redmine"
59
     PerlSetVar RedmineDbPass "password"
60 60
     ## Optional where clause (fulltext search would be slow and
61 61
     ## database dependant).
62
     # RedmineDbWhereClause "and members.role_id IN (1,2)"
62
     # PerlSetVar RedmineDbWhereClause "and members.role_id IN (1,2)"
63 63
     ## Optional credentials cache size
64
     # RedmineCacheCredsMax 50
64
     # PerlSetVar RedmineCacheCredsMax 50
65 65
  </Location>
66 66

  
67 67
To be able to browse repository inside redmine, you must add something
......
114 114

  
115 115
# use Apache2::Directive qw();
116 116

  
117
my @directives = (
118
  {
119
    name => 'RedmineDSN',
120
    req_override => OR_AUTHCFG,
121
    args_how => TAKE1,
122
    errmsg => 'Dsn in format used by Perl DBI. eg: "DBI:Pg:dbname=databasename;host=my.db.server"',
123
  },
124
  {
125
    name => 'RedmineDbUser',
126
    req_override => OR_AUTHCFG,
127
    args_how => TAKE1,
128
  },
129
  {
130
    name => 'RedmineDbPass',
131
    req_override => OR_AUTHCFG,
132
    args_how => TAKE1,
133
  },
134
  {
135
    name => 'RedmineDbWhereClause',
136
    req_override => OR_AUTHCFG,
137
    args_how => TAKE1,
138
  },
139
  {
140
    name => 'RedmineCacheCredsMax',
141
    req_override => OR_AUTHCFG,
142
    args_how => TAKE1,
143
    errmsg => 'RedmineCacheCredsMax must be decimal number',
144
  },
145
);
117
my $cfg;
146 118

  
147
sub RedmineDSN { 
148
  my ($self, $parms, $arg) = @_;
149
  $self->{RedmineDSN} = $arg;
150
  my $query = "SELECT 
151
                 hashed_password, salt, auth_source_id, permissions
119
sub initialize {
120
  my $r = shift;
121
  my $ret = 1;
122
  
123
  $cfg->{RedmineDSN} = $r->dir_config('RedmineDSN');
124
  $cfg->{RedmineDbUser} = $r->dir_config('RedmineDbUser');
125
  $cfg->{RedmineDbPass} = $r->dir_config('RedmineDbPass'); 
126

  
127
  unless ($cfg->{RedmineDSN) {
128
	$r->log_reason("No DSN has been configured. Maybe PerlSetVar is missing at the beginning of the line");
129
	$ret = 0;
130
  } 
131
  
132
  unless ($cfg->{RedmineDbUser}) {
133
	$r->log_reason("No DSN user has been configured. Maybe PerlSetVar is missing at the beginning of the line");
134
	$ret = 0;
135
  }
136
  
137
  unless ($cfg->{RedmineDbPass}) {
138
	$r->log_reason("No DSN user password has been configured. Maybe PerlSetVar is missing at the beginning of the line");
139
	$ret = 0;
140
  }
141

  
142
  if ($r->dir_config('RedmineCacheCredsMax')) {
143
	  $cfg->{RedmineCachePool} = APR::Pool->new;
144
	  $cfg->{RedmineCacheCreds} = APR::Table::make($cfg->{RedmineCachePool}, $r->dir_config('RedmineCacheCredsMax'));
145
	  $cfg->{RedmineCacheCredsCount} = 0;
146
	  $cfg->{RedmineCacheCredsMax} = $r->dir_config('RedmineCacheCredsMax');
147
  }
148
  
149
  my $query = trim("SELECT 
150
                 hashed_password, auth_source_id, permissions
152 151
              FROM members, projects, users, roles, member_roles
153 152
              WHERE 
154 153
                projects.id=members.project_id
......
157 156
                AND roles.id=member_roles.role_id
158 157
                AND users.status=1 
159 158
                AND login=? 
160
                AND identifier=? ";
161
  $self->{RedmineQuery} = trim($query);
162
}
159
                AND identifier=? ");
163 160

  
164
sub RedmineDbUser { set_val('RedmineDbUser', @_); }
165
sub RedmineDbPass { set_val('RedmineDbPass', @_); }
166
sub RedmineDbWhereClause { 
167
  my ($self, $parms, $arg) = @_;
168
  $self->{RedmineQuery} = trim($self->{RedmineQuery}.($arg ? $arg : "")." ");
169
}
161
  $cfg->{RedmineQuery} = trim($query.($r->dir_config('RedmineDbWhereClause') ? $r->dir_config('RedmineDbWhereClause') : "")." ");
170 162

  
171
sub RedmineCacheCredsMax { 
172
  my ($self, $parms, $arg) = @_;
173
  if ($arg) {
174
    $self->{RedmineCachePool} = APR::Pool->new;
175
    $self->{RedmineCacheCreds} = APR::Table::make($self->{RedmineCachePool}, $arg);
176
    $self->{RedmineCacheCredsCount} = 0;
177
    $self->{RedmineCacheCredsMax} = $arg;
178
  }
163
  return $ret;
179 164
}
180 165

  
166

  
181 167
sub trim {
182 168
  my $string = shift;
183 169
  $string =~ s/\s{2,}/ /g;
184 170
  return $string;
185 171
}
186 172

  
187
sub set_val {
188
  my ($key, $self, $parms, $arg) = @_;
189
  $self->{$key} = $arg;
190
}
191 173

  
192
Apache2::Module::add(__PACKAGE__, \@directives);
193

  
194

  
195 174
my %read_only_methods = map { $_ => 1 } qw/GET PROPFIND REPORT OPTIONS/;
196 175

  
197 176
sub access_handler {
198 177
  my $r = shift;
199 178

  
179
  unless (initialize($r)) {
180
      $r->log_reason("Please check redmine connfiguration");
181
      return FORBIDDEN;
182
  }
183

  
200 184
  unless ($r->some_auth_required) {
201 185
      $r->log_reason("No authentication has been configured");
202 186
      return FORBIDDEN;
......
216 200
sub authen_handler {
217 201
  my $r = shift;
218 202
  
203
  unless (initialize($r)) {
204
      $r->log_reason("Please check redmine connfiguration");
205
      return AUTH_REQUIRED;
206
  }
207

  
219 208
  my ($res, $redmine_pass) =  $r->get_basic_auth_pw();
220 209
  return $res unless $res == OK;
221 210
  
......
305 294

  
306 295
  my $pass_digest = Digest::SHA1::sha1_hex($redmine_pass);
307 296

  
308
  my $cfg = Apache2::Module::get_config(__PACKAGE__, $r->server, $r->per_dir_config);
309 297
  my $usrprojpass;
310 298
  if ($cfg->{RedmineCacheCredsMax}) {
311 299
    $usrprojpass = $cfg->{RedmineCacheCreds}->get($redmine_user.":".$project_id);
......
378 366
}
379 367

  
380 368
sub connect_database {
381
    my $r = shift;
382
    
383
    my $cfg = Apache2::Module::get_config(__PACKAGE__, $r->server, $r->per_dir_config);
384 369
    return DBI->connect($cfg->{RedmineDSN}, $cfg->{RedmineDbUser}, $cfg->{RedmineDbPass});
385 370
}
386 371