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

View file

@ -168,7 +168,7 @@ sub update_operatorsloop {
$bw->log("UPDATE adr from record_primary to operator on loop $sharee_operator",$record_primary->{c_id},"");
$rows = $self->update_record($dbh_operator,$update,$record_primary);
if($rows != 1){
if($rows != 1 && $record_primary->{int04} && $record_primary->{int13} && $record_primary->{int14}){
$bw->log("INSERT adr from record_primary to operator on loop $sharee_operator",$record_primary->{c_id},"");
my $insert = {
%$record_primary,
@ -968,7 +968,7 @@ sub update_record(){
}
}
if($key =~ /(mtime|atime|pay_time|invoice_time|warn_time)$/){
if($value && $value =~ /^\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}$|^\d{2}\.\d{2}\.\d{4}$/){
if($value && $value =~ /^\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}|^\d{2}\.\d{2}\.\d{4}$/){
$set .= " $key='$value',";
}elsif($key =~ /warn_time/ && $value eq "null"){
$set .= " $key=null,";
@ -983,7 +983,7 @@ sub update_record(){
my $sql = "UPDATE $update->{table} set $set $where";
my $sth = $dbh->prepare($sql);
$rows = $sth->execute();
$bw->log("DBtank update_record : $rows",$sql,"") if($debug);
#$bw->log("DBtank update_record : $rows",$sql,"") if($debug);
}
return $rows;
}#update_record

View file

@ -464,7 +464,7 @@ sub save_contenttranspos {
$ctpos = $dbt->collect_post($dbh,$pref);
#print "$R::start_date $s_hh:$s_mi | $R::start_date $e_hh:$e_mi xxxxxxxxx<br>";exit;
($pricing,$counting) = $pri->counting_rental(\%varenv,$ctpos,"calc_price");
($pricing,$counting) = $pri->counting_rental(\%varenv,$ctpos);
$update_pos->{int38} = "$counting->{int38}" if(looks_like_number($counting->{int38}));
$update_pos->{int39} = "$counting->{int39}" if(looks_like_number($counting->{int39}));
$update_pos->{int40} = "$counting->{int40}" if(looks_like_number($counting->{int40}));

View file

@ -331,7 +331,7 @@ sub preinit(){
#again to get setted date-times
$record_pos = $dbt->collect_post($dbh,$pref);
($pricing,$counting) = $pri->counting_rental(\%varenv,$record_pos,"calc_price");
($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}));

View file

@ -15,6 +15,7 @@ use CGI; # only for debugging
use Scalar::Util qw(looks_like_number);
use DateTime;
use DateTime::Format::Pg;
use Date::Calc qw(Add_Delta_YMD);
use Lib::Config;
use Mod::Libenz;
use Mod::DBtank;
@ -43,29 +44,6 @@ sub round(){
return $rounded;
}
sub only_first_free(){
my $self = shift;
my $ctpos = shift;
my %varenv = $cf->envonline();
my $pref = {
table => "contenttrans",
table_pos => "contenttranspos",
fetch => "one",
ca_id => "=::$ctpos->{ca_id}",
ct_id => "=::$ctpos->{ct_id}",
c_id => "!=::$ctpos->{c_id}",
#txt10 => "IN::('available','canceled')",
int10 => "IN::(1,6)",
};
$pref = { %$pref, time_range => "cp.start_time >= '$ctpos->{start_time}' and cp.start_time < '$ctpos->{end_time}' and cp.start_time != cp.end_time" };
my $record = { c_id => 0 };
$record = $dbt->collect_post($dbh,$pref);
return $record;
}
#converts clock-time to minutes
sub clock_minutes {
my $self = shift;
@ -83,12 +61,75 @@ sub clock_minutes {
return $minutes;
}
#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 $ca_id = shift || 0;
my $pos = shift || {};
my $freed_count = 0;
my $dbh = "";
my $today4db = strftime("%Y-%m-%d %H:%M:%S",localtime(time));
my $pricing = {};
my $counting = {};
($pricing, $counting) = $self->counting_rental($varenv,$pos);
my $debug=1;
open(FILE,">>$varenv->{logdir}/count_freedrental.log") if($debug);
print FILE "\n*-->$today4db $varenv->{dbname}\n" if($debug);
print FILE Dumper($q) if($debug);
print FILE "--> c_id:$pos->{c_id} rental_minute_all: $pricing->{rentalog}->{rental_minute_all} > 0\n" if($debug);
#freed mangement will be only dony on accountable rental
if($pricing->{rentalog}->{rental_minute_all} > 0){
my $pref_pos = {
table => "contenttranspos",
fetch => "all",
keyfield => "c_id",
ca_id => "$ca_id",
time02 => ">::00:00",
};
#one freed time by 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;
}#end count_freedrental
#new counting rental time in hours method (last sharee_pricing)
sub counting_rental {
my $self = shift;
my $varenv = shift;
my $ctpos = shift;
my $todo = shift;
my $today4db = strftime("%Y-%m-%d %H:%M:%S",localtime(time));
my $return = {};
my $counting = { c_id => $ctpos->{c_id} };
@ -128,8 +169,6 @@ sub counting_rental {
#freed_time depends on operator and will be set by rental end "count_freedrental"
my $freed_time = "";
if($ctpos->{time02} && $ctpos->{time02} =~ /[1-9]/){
#$ctpos_freed = $self->only_first_free($ctpos);
#if(!$ctpos_freed->{c_id}){
my ($dhh,$dmm) = split(/:/,$ctpos->{time02});
$freed_time = "- $dhh:$dmm" if($dhh || $dmm);
#adding free minutes to start_time
@ -143,7 +182,6 @@ sub counting_rental {
$computed_clock = "$durdd day $durhh:$durmm" if($durdd);
$rental_minute = $self->clock_minutes($computed_clock);
#print "$computed_clock|$rental_minute";
#}
}

View file

@ -227,7 +227,8 @@ td {
my $counting = {};
if($cttpos->{$id}->{int35} && $cttpos->{$id}->{start_time} && $cttpos->{$id}->{end_time}){
($pricing,$counting) = $pri->counting_rental(\%varenv,$cttpos->{$id},"calc_price");
$pri->count_freedrental("Printpreview",\%varenv,$ctt->{int10},$cttpos->{$id});
($pricing,$counting) = $pri->counting_rental(\%varenv,$cttpos->{$id});
$gesamt = $pri->round($pricing->{total_price});
$gesamt = sprintf('%.2f', $gesamt);
}else{
@ -698,7 +699,8 @@ td {
my $rental_feed = {};
if($cttpos->{$id}->{int35} && $cttpos->{$id}->{start_time} && $cttpos->{$id}->{end_time}){
($pricing,$counting) = $pri->counting_rental($varenv,$cttpos->{$id},"calc_price");
$pri->count_freedrental("Printpreview",\%varenv,$ctt->{int10},$cttpos->{$id});
($pricing,$counting) = $pri->counting_rental($varenv,$cttpos->{$id});
$rental_feed = $pri->fetch_rentalfeed($varenv,$cttpos->{$id},$counting);
$rabatt = $pricing->{discount};
$sum_parts19 += $pricing->{total_price};

View file

@ -215,11 +215,11 @@ sub save_account(){
if($_ =~ /^txt04/){
if($valxx eq "xxxxxxxx"){
$pw_dummy = "1";
}elsif($valxx){
my $pwmd5 = md5_hex($valxx);
my $pwsha256=sha256_base64($valxx);
$u_rows = $dbt->update_one($dbh,$update_primary,"txt11='$pwmd5'");
$u_rows = $dbt->update_one($dbh,$update_primary,"txt04='$pwsha256'");
}elsif(length($valxx) >= 8){
my $pwmd5 = md5_hex($valxx) || "";
$u_rows = $dbt->update_one($dbh,$update_primary,"txt11='$pwmd5'") if(length($pwmd5) > 20);
my $pwsha256=sha256_base64($pwmd5) || "";
$u_rows = $dbt->update_one($dbh,$update_primary,"txt04='$pwsha256'") if(length($pwsha256) > 20);
}
}
#operators, only if saved by operator DMS
@ -489,7 +489,6 @@ sub save_account(){
$alphacount = () = $valxx =~ /[a-z]/gi;
$alphafail = length($valxx) - $alphacount;
if(!$valxx || length($valxx) < 8 || $alphafail < 2){
#$ret = "failure::pwlazy_txt04#top";
$ret = "failure::$_#top";
}
}
@ -844,11 +843,11 @@ sub send_password(){
$email =~ s/\s//g;
$bw->log("$varenv{basedir}/src/Mod/newsletter_tink.pl",$email,"");
my $pwmd5 = md5_hex($coo);
my $pwsha256=sha256_base64($coo);#after migration, adjust length test
my $pwmd5 = md5_hex($coo) || "";
if($email && $email =~ /\w\@\w/ && $pwmd5 && length($pwmd5) > 20 && $email !~ /$dbt->{copri_conf}->{test_accounts}/i){
$db->updater("contentadr","1","1","txt11","$pwmd5","$owner","txt08","ilike","$email");
my $pwsha256=sha256_base64($pwmd5) || "";
$db->updater("contentadr","1","1","txt04","$pwsha256","$owner","txt08","ilike","$email");
system(`$varenv{basedir}/src/Mod/newsletter_tink.pl "$varenv{basedir}" "$varenv{wwwhost}" "send_password" "$email" "$coo"`);
}

View file

@ -193,7 +193,7 @@ sub tpl(){
if($cttpos->{int35} && $cttpos->{start_time} && $cttpos->{end_time}){
$cttpos->{end_time} = $now_dt if($cttpos->{int10} == 3 && $cttpos->{int20} == 2);
($pricing,$counting) = $pri->counting_rental(\%varenv,$cttpos,"calc_price");
($pricing,$counting) = $pri->counting_rental(\%varenv,$cttpos);
$rental_feed = $pri->fetch_rentalfeed(\%varenv,$cttpos,$counting);
$gesamt = $pri->round($pricing->{total_price});
$gesamt = sprintf('%.2f', $gesamt);

View file

@ -746,7 +746,7 @@ EOF
if($ct4rel->{$id}->{c_id} == $ct4rel_parts->{$cpid}->{ct_id}){
if($ct4rel_parts->{$cpid}->{int35} && $ct4rel_parts->{$cpid}->{start_time} && $ct4rel_parts->{$cpid}->{end_time}){
($pricing,$counting) = $pri->counting_rental(\%varenv,$ct4rel_parts->{$cpid},"calc_price");
($pricing,$counting) = $pri->counting_rental(\%varenv,$ct4rel_parts->{$cpid});
$sum_pos += $pricing->{total_price}
}elsif((looks_like_number($ct4rel_parts->{$cpid}->{int02}) && $ct4rel_parts->{$cpid}->{int02} != 0) && (looks_like_number($ct4rel_parts->{$cpid}->{int03}) && $ct4rel_parts->{$cpid}->{int03} != 0)){
my ($gesamt,$rabatt) = $pri->price2calc($ct4rel_parts->{$cpid});

View file

@ -176,8 +176,8 @@ EOF
if($cttpos->{$id}->{int35} && $cttpos->{$id}->{start_time} && $cttpos->{$id}->{end_time}){
$cttpos->{$id}->{end_time} = $now_dt if($cttpos->{$id}->{int10} == 3);
($pricing,$counting) = $pri->counting_rental(\%varenv,$cttpos->{$id},"calc_price");
$apif->count_freedrental($q,\%varenv,$ctadr,$pricing->{rentalog}->{rental_minute_all},$cttpos->{$id});
$pri->count_freedrental($q,\%varenv,$ctadr->{c_id},$cttpos->{$id});
($pricing,$counting) = $pri->counting_rental(\%varenv,$cttpos->{$id});
$rental_feed = $pri->fetch_rentalfeed(\%varenv,$cttpos->{$id},$counting);
$sum_parts19 += $pricing->{total_price};
$gesamt = $pri->round($pricing->{total_price});

View file

@ -87,7 +87,7 @@ sub tpl(){
foreach my $id (keys(%$cttpos)){
$cttpos_count++;
if($cttpos->{$id}->{int35} && $cttpos->{$id}->{start_time} && $cttpos->{$id}->{end_time}){
($pricing,$counting) = $pri->counting_rental($varenv,$cttpos->{$id},"calc_price");
($pricing,$counting) = $pri->counting_rental($varenv,$cttpos->{$id});
$sum += $pricing->{total_price};
}else{
my ($gesamt,$rabatt) = $pri->price2calc($cttpos->{$id});

View file

@ -362,7 +362,7 @@ Nach Abschluss der Registrierung erhalten Sie sowohl auf die von Ihnen hinterleg
my $pricing = {};
my $counting = {};
if($cttpos->{$id}->{int35} && $cttpos->{$id}->{start_time} && $cttpos->{$id}->{end_time}){
($pricing,$counting) = $pri->counting_rental($varenv,$cttpos->{$id},"calc_price");
($pricing,$counting) = $pri->counting_rental($varenv,$cttpos->{$id});
}
print $q->Tr(),"\n";