pw encryption extended with sha. Minor freed-time changes

This commit is contained in:
ragu 2023-04-17 15:30:19 +02:00
parent 9b05eed19b
commit d6292aa09d
12 changed files with 104 additions and 128 deletions

View file

@ -18,7 +18,6 @@ use Digest::SHA qw(sha256_base64);
use Scalar::Util qw(looks_like_number);
use DateTime;
use DateTime::Format::Pg;
use Date::Calc qw(Add_Delta_YMD);
use URI::Encode;
use Config::General;
@ -1003,66 +1002,6 @@ sub booking_request(){
return $return;
}
#for one freed rental
#depends on operator, only 1 rental get freed_time
sub count_freedrental {
my $self = shift;
my $q = shift || "";
my $varenv = shift;
my $auth = shift;
my $rental_minute_all = shift || 0;
my $pos = shift || {};
my $freed_count = 0;
my $dbh = "";
my $debug=1;
open(FILE,">>$varenv->{logdir}/count_freedrental.log") if($debug);
print FILE "\n*-->$now_dt $varenv->{dbname}\n" if($debug);
print FILE Dumper($q) if($debug);
print FILE "--> c_id:$pos->{c_id} rental_minute_all: $rental_minute_all > 0\n" if($debug);
#freed mangement will be only dony on accountable rental
if($rental_minute_all > 0){
my $pref_pos = {
table => "contenttranspos",
fetch => "all",
keyfield => "c_id",
ca_id => "$auth->{c_id}",
time02 => ">::00:00",
};
#one freed time with three parallel rentals
if($dbt->{operator}->{$varenv->{dbname}}->{project} eq "Konstanz"){
$pref_pos->{int10} = "3";
}
#one freed time per day
else{
my $day = strftime "%d", localtime;
my $mon = strftime "%m", localtime;
my $year = strftime "%Y", localtime;
my ($nyear,$nmon,$nday) = Add_Delta_YMD($year,$mon,$day, 0,0,1);
$pref_pos->{time_range} = "((start_time >= '$year-$mon-$day' and start_time < '$nyear-$nmon-$nday' and start_time != end_time) OR int10=3)";
}
my $record_pos = $dbt->fetch_tablerecord($dbh,$pref_pos);
foreach my $pid (sort { $record_pos->{$a}->{c_id} <=> $record_pos->{$b}->{c_id} } keys (%$record_pos)){
$freed_count++;
print FILE "if($freed_count > 1 && $pos->{c_id} != $record_pos->{$pid}->{c_id})\n" if($debug);
if($freed_count > 1 && $pos->{c_id} != $record_pos->{$pid}->{c_id}){
my $pos_ref = {
table => "contenttranspos",
c_id => $record_pos->{$pid}->{c_id},
};
$dbt->update_one($dbh,$pos_ref,"time02='00:00'");
print FILE "--> delete freed_time on c_id=$record_pos->{$pid}->{c_id} to time02=00:00\n" if($debug);
}
}
}
close(FILE) if($debug);
return;
}
#int03=1 if sepa, 2=CC
#int04==1 if email Ack
#int13==1 if sms Ack
@ -1317,7 +1256,7 @@ sub booking_update(){
$update_cc->{txt13} = "$dbt->{operator}->{$varenv{dbname}}->{oprefix}";
#return after booking_update
my ($pricing,$counting) = $pri->counting_rental(\%varenv,$record_pos,"");
my ($pricing,$counting) = $pri->counting_rental(\%varenv,$record_pos);
#int03 only used for tarif counting backwards compatibility
$update_pos->{int03} = "$pricing->{computed_hours}" if(looks_like_number($pricing->{computed_hours}));
$update_pos->{int38} = "$counting->{int38}" if(looks_like_number($counting->{int38}));
@ -1325,8 +1264,8 @@ sub booking_update(){
$update_pos->{int40} = "$counting->{int40}" if(looks_like_number($counting->{int40}));
$update_pos->{int41} = "$counting->{int41}" if(looks_like_number($counting->{int41}));
#in real, we can get only freed accountable rentals only on rental end's
$self->count_freedrental($q,$varenv,$auth,$pricing->{rentalog}->{rental_minute_all},$update_pos);
#in real, we know freed accountable rentals only on rental end's
$pri->count_freedrental($q,$varenv,$auth->{c_id},$update_pos);
$rows_end = $dbt->update_record($dbh,$update_pos,$record_pos);
if($rows_end > 0){
@ -1353,7 +1292,7 @@ sub booking_update(){
$update_cc->{txt13} = "$dbt->{operator}->{$varenv{dbname}}->{oprefix}";
#return after booking_update
my ($pricing,$counting) = $pri->counting_rental(\%varenv,$record_pos,"");
my ($pricing,$counting) = $pri->counting_rental(\%varenv,$record_pos);
#int03 only used for tarif counting backwards compatibility
$update_pos->{int03} = "$pricing->{computed_hours}" if(looks_like_number($pricing->{computed_hours}));
$update_pos->{int38} = "$counting->{int38}" if(looks_like_number($counting->{int38}));
@ -1809,18 +1748,16 @@ sub rentals(){
my $return = {};
foreach my $id (sort { $record->{$a}->{end_time} cmp $record->{$b}->{end_time} } keys (%$record)){
my $pricing->{$id} = {};
my $counting = {};
#adjusting freed time rental by called bikes_occupied
$pri->count_freedrental("rentals by user_bikes_occupied",\%varenv,$auth->{c_id},$record->{$id});
($pricing->{$id}, $counting) = $pri->counting_rental(\%varenv,$record->{$id});
#$pricing
(my $return_counting->{$id}, my $counting) = $pri->counting_rental(\%varenv,$record->{$id},"");
#adjusting freed time rental by often called bikes_occupied
$self->count_freedrental("rentals by user_bikes_occupied",\%varenv,$auth,$return_counting->{$id}->{rentalog}->{rental_minute_all},$record->{$id});
#yes once again to get the counted freedrental
(my $return_counting->{$id}, my $counting) = $pri->counting_rental(\%varenv,$record->{$id},"");
#$bw->log("rentals-rentalog",$return_counting->{$id}->{rentalog},"");
$return_counting->{$id}->{rentalog} = "";#just for debuggiog, removed to reduce data in json
my $return_feed->{$id} = $pri->fetch_rentalfeed(\%varenv,$record->{$id},$return_counting->{$id});
$return->{$id} = { %{ $return_counting->{$id} }, %{ $return_feed->{$id} } };
#$bw->log("rentals-rentalog",$pricing->{$id}->{rentalog},"");
$pricing->{$id}->{rentalog} = "";#just for debuggiog, removed to reduce data in json
my $return_feed->{$id} = $pri->fetch_rentalfeed(\%varenv,$record->{$id},$pricing->{$id});
$return->{$id} = { %{ $pricing->{$id} }, %{ $return_feed->{$id} } };
my $bike_id = $return->{$id}->{bike};
$bike_id = $1 if($bike_id =~ /(\d+)/);
@ -3126,10 +3063,10 @@ sub authorization(){
my $pass_name = $q->escapeHTML($user_pw);
$pass_name =~ s/\s//g;
my $pwmd5=md5_hex($pass_name);
my $pwsha256=sha256_base64($pass_name);
$authref->{txt11} = "$pwmd5";
#$authref->{txt04} = "$pwsha256";#enable after migration
my $pwmd5=md5_hex($pass_name) || "";
my $pwsha256=sha256_base64($pwmd5) || "";
#$authref->{txt11} = "$pwmd5";
$authref->{txt04} = "$pwsha256";
#Servicetool, only users with users.int09=1
#shareetool