Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
python-module-privacyidea-pam
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Eugene Omelyanovich
python-module-privacyidea-pam
Commits
8cba124e
Commit
8cba124e
authored
Apr 08, 2015
by
Cornelius Kölbel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add script to display the remaining OTP hashes
for offline authentication
parent
a12ea6c3
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
69 additions
and
0 deletions
+69
-0
privacyidea-pam-remain.py
privacyidea-pam-remain.py
+69
-0
No files found.
privacyidea-pam-remain.py
0 → 100755
View file @
8cba124e
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# 2015-04-08 Cornelius Kölbel <cornelius.koelbel@netknights.it>
# Initial writeup
#
# (c) Cornelius Kölbel
# Info: http://www.privacyidea.org
#
# This code is free software; you can redistribute it and/or
# modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
# License as published by the Free Software Foundation; either
# version 3 of the License, or any later version.
#
# This code is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU AFFERO GENERAL PUBLIC LICENSE for more details.
#
# You should have received a copy of the GNU Affero General Public
# License along with this program. If not, see <http://www.gnu.org/licenses/>.
#
__doc__
=
"""This script is used to display the remaining OTP hashes.
"""
import
sqlite3
import
getpass
SQLFILE
=
"/etc/privacyidea/pam.sqlite"
def
check_remain
(
user
,
sqlfile
):
"""
Check the remaining OTP values for the given user.
:param user: The local user in the sql file
:param sqlfile: The sqlite file
:return: dict of OTP counts
"""
remains
=
{}
conn
=
sqlite3
.
connect
(
sqlfile
)
c
=
conn
.
cursor
()
# get all possible serial/tokens for a user
serials
=
[]
for
row
in
c
.
execute
(
"SELECT serial, user FROM authitems WHERE user='
%
s'"
"GROUP by serial"
%
user
):
serials
.
append
(
row
[
0
])
for
serial
in
serials
:
r
=
c
.
execute
(
"select count(*) from authitems where serial = '
%
s'"
%
serial
)
remains
[
serial
]
=
r
.
fetchone
()[
0
]
conn
.
close
()
return
remains
def
main
():
username
=
getpass
.
getuser
()
remains
=
check_remain
(
username
,
SQLFILE
)
print
"Remaining OTP hashes:"
print
"====================="
for
k
,
v
in
remains
.
iteritems
():
print
(
"
%
s:
%
s"
%
(
k
,
v
))
if
__name__
==
'__main__'
:
main
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment