From patchwork Wed Nov 20 10:45:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Marx X-Patchwork-Id: 2600 Return-Path: Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384 client-signature ECDSA (P-384) client-digest SHA384) (Client CN "mail01.haj.ipfire.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by web04.haj.ipfire.org (Postfix) with ESMTPS id 47HzqX1Wsvz43Sw for ; Wed, 20 Nov 2019 10:45:28 +0000 (UTC) Received: from mail02.haj.ipfire.org (mail02.haj.ipfire.org [172.28.1.201]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384 client-signature ECDSA (P-384) client-digest SHA384) (Client CN "mail02.haj.ipfire.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mail01.ipfire.org (Postfix) with ESMTPS id 47HzqV2TtFz2PD; Wed, 20 Nov 2019 10:45:26 +0000 (UTC) Received: from mail02.haj.ipfire.org (localhost [127.0.0.1]) by mail02.haj.ipfire.org (Postfix) with ESMTP id 47HzqV0qtWz2yNN; Wed, 20 Nov 2019 10:45:26 +0000 (UTC) Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail01.haj.ipfire.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mail02.haj.ipfire.org (Postfix) with ESMTPS id 47HzqS16x0z2xbB for ; Wed, 20 Nov 2019 10:45:24 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (Client did not present a certificate) by mail01.ipfire.org (Postfix) with ESMTPSA id 47HzqR32LNz2PD; Wed, 20 Nov 2019 10:45:23 +0000 (UTC) DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=ipfire.org; s=201909ed25519; t=1574246723; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc; bh=6daB2C63pQQAtEMVb6R8E6jEE4FokHO+uHNS0TJk7vE=; b=sEix7vMpo2PBnIqHmPR2iOtF5kms+8dZ0DeHjp6xMvjJw5TB/9ca4Ka20Fwqd8dF3eRYdE xqdQkCudiK4e5EAQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ipfire.org; s=201909rsa; t=1574246723; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc; bh=6daB2C63pQQAtEMVb6R8E6jEE4FokHO+uHNS0TJk7vE=; b=L5f04HkAjESGGqJkBeZLYrR8CrdA1rmt4FgbYIkQSPA+bOR0b7JbA7G9c/oE73iHifO6so osYV/bVrX3hl2IgcPuaaPW+EHK67BvEBYHbfu8zKUslGwq62qrkuS01a3SbxaY1o0ekkmq 2KU99bDunaf5DXyPJGrAdU0msZNZULSYSZ7sJ4CgNrYahO0QjgFsd07pBI0t3VlwL63/nt h5Nwqz9AErKgGmyQ5PwX8FBmovyQLC0qnI0tVMZ0vlkUF148ItC0i3Pb0YPTbRsgqDeD4T caq29Wht/xf2cPxRmcIeTy3Xk2VsMeTYjz4FyYqKP8NTQLl8GePQ+wCZPqUX8w== From: Alexander Marx To: development@lists.ipfire.org Subject: [PATCH] BUG12245: captive portal - clients are not automatically removed Date: Wed, 20 Nov 2019 11:45:18 +0100 Message-Id: <20191120104518.13156-1-alexander.marx@ipfire.org> Authentication-Results: mail01.ipfire.org; auth=pass smtp.auth=amarx smtp.mailfrom=alexander.marx@ipfire.org X-BeenThere: development@lists.ipfire.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: IPFire development talk List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: development-bounces@lists.ipfire.org Sender: "Development" With this patch the clients are updated and those who are expired get deleted from the hash. In addition the table of active clients is now sorted. --- html/cgi-bin/captive.cgi | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/html/cgi-bin/captive.cgi b/html/cgi-bin/captive.cgi index b33287dd4..8204eb7b3 100755 --- a/html/cgi-bin/captive.cgi +++ b/html/cgi-bin/captive.cgi @@ -514,6 +514,25 @@ END } } +sub cleanup_expired_coupons +{ + my $acttime=time(); + &General::readhasharray($clients, \%clientshash) if (-e $clients); + foreach my $key (keys %clientshash) { + + #calculate endtime from clientshash + my $endtime; + if ($clientshash{$key}[3] > '0'){ + $endtime = $clientshash{$key}[2]+$clientshash{$key}[3]; + if ($acttime > $endtime) { + delete $clientshash{$key}; + } + } + } + #write back hash + &General::writehasharray("$clients", \%clientshash); +} + sub show_coupons() { &General::readhasharray($coupons, \%couponhash) if (-e $coupons); @@ -601,9 +620,9 @@ sub show_clients() { $Lang::tr{'delete'} END - + &cleanup_expired_coupons(); &General::readhasharray($clients, \%clientshash) if (-e $clients); - foreach my $key (keys %clientshash) { + foreach my $key (sort {$clientshash{$a}[2] <=> $clientshash{$b}[2]} keys %clientshash) { #calculate time from clientshash (starttime) my $starttime = sub{sprintf '%02d.%02d.%04d %02d:%02d', $_[3], $_[4]+1, $_[5]+1900, $_[2], $_[1] }->(localtime($clientshash{$key}[2]));