#
# @copyright Copyright (c) 2024, Pietro Marini (pmarini@rcasys.com)
#
# @license GNU AGPL version 3 or any later version
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program 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/>.
#
import json
def get_param(params_file,param_name):
return json.load(open(params_file,"r"))[param_name]
def get_norm_user_agent(s):
## EDGE
# Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36 Edg/110.0.1587.57
## Chrome
# Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36
## Firefox
# Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:110.0) Gecko/20100101 Firefox/110.0
## Safari
# Mozilla/5.0 (Macintosh; Intel Mac OS X 13_2_1) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.3 Safari/605.1.15
s = s.lower()
## Nextcloud Talk App
if "nextcloud-talk" in s:
if "android" in s:
return "nextcloud_talk_android"
elif "ios" in s:
return "nextcloud_talk_ios"
else:
return "nextcloud_talk_unknown"
## Nextcloud Files App
if "nextcloud-android" in s:
return "nextcloud_android"
## Browser
if "chrome" in s:
if "edg" in s:
return "edge_browser"
else:
return "chrome_browser"
if "firefox" in s:
return "firefox_browser"
if "macintosh" in s and "applewebkit" in s:
return "safari_browser"
## Desktop Client
if "mirall" in s:
if "linux" in s:
return "desktop_client_linux"
elif "macintosh" in s:
return "desktop_client_mac"
elif "windows" in s:
return "desktop_client_windows"
else:
return "desktop_client_unknown"
## DavX5, CardDAV / CalDAV sync agent on Android
if "davx5" in s:
return "davx5"
## Thunderbird, CardDAV / CalDAV sync agent on Desktop
if "thunderbird" in s:
return "thunderbird"
## Python scripting
if "python" in s:
return "python"
return "other"