{"id":793,"date":"2023-10-19T15:04:10","date_gmt":"2023-10-19T13:04:10","guid":{"rendered":"https:\/\/www.tippex.net\/?p=793"},"modified":"2023-10-19T15:04:10","modified_gmt":"2023-10-19T13:04:10","slug":"nextcloudnutzern-einen-2fa-token-zumailen","status":"publish","type":"post","link":"https:\/\/www.tippex.net\/?p=793","title":{"rendered":"Nextcloud:Nutzern einen 2FA Token zumailen"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Gerade stand ich vor der Aufgabe, den Nutzern einer Nextcloud Instanz 2FA aufzuzwingen. Dies l\u00e4sst sich im Nextcloud Admin per Schiebregler konfigurieren. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">2FA ist zur Absicherung eines Kontos nat\u00fcrlich alternativlos. Erzwinge ich 2FA als Admin so, stellt sich f\u00fcr alle User, die diese zus\u00e4tliche Sicherheitsschicht in ihrem Konto nocht nicht aktiviert haben das Problem, dass sie sich an ihrem Konto nicht mehr anmelden k\u00f6nnen.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Aus o.g Grund habe ich ein kleines Bash-Skript erstellt, dass die Userdatenbank nach aktiven Konten durchsucht und dabei diejenigen User anmailt, die 2FA noch nicht aktiviert haben.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Getestet habe ich es unter Ubuntu 22.04. Voraussetzung ist u.A dass PHP installiert ist und der Server Mails versenden kann, z.B. durch einen internen Mailserver, oder via Relay.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#! \/usr\/bin\/env bash\n#Author:todde\n#Version:0.1\n#This script search for users, who do not have 2fa enabled on their account.\n#Then a one time code is generated and mailed to the user for initial login\n##############################################################################\n\nsite=\"https:\/\/www.example.net\"\nmail_from=\"admin@example.net\"\n\n\n#Find all active users\nuser=`sudo -u www-data php \/var\/www\/nextcloud\/occ user:list | cut -c 5- | cut -d : -f 1`\n\n\n\nfor i in $user; do\n\n#Extract email address from each user\n   email=`sudo -u www-data php \/var\/www\/nextcloud\/occ user:info $i | egrep 'email:' | cut -c 5- | cut -d : -f 2`;\n#Compare if totp is already in place\n   status=`sudo -u www-data php \/var\/www\/nextcloud\/occ twofactorauth:state $i | egrep 'totp' | cut -c 3-`;\n\n#Do nothing if totp is enabled    \n     if &#91; \"$status\" = \"totp\" ]; then\n        echo $i  >> \/dev\/null\n#Generate code for initial login and mail code and instructions 2 user\n     else\n        code=`sudo -u www-data php \/var\/www\/nextcloud\/occ twofactorauth:admin:generate-code $i`\n        printf \"Dear $i, please enable 2fa on $site.\\n\\n Your inital code: \\n $code \\n\\n\\n For detailed instructions visit:\\n https:\/\/docs.nextcloud.com\/server\/latest\/user_manual\/en\/user_2fa.html \\n\\n You must complete the above steps from instructions, otherwise you will not be able to log into your account a second time!\\n\\n Regards - Your Site Administrator from $site\" | mail -s \"Urgent notice from $site\" $email -r $mail_from\n\n\n\n     fi\n\ndone<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Das ganze l\u00e4sst sich auch via cron in regelm\u00e4ssigen Abst\u00e4nden automatisch ausf\u00fchren. Der generierte Code is 48 Stunden g\u00fcltig, sodass eine Ausf\u00fchrung in diesem Abstand Sinn ergibt.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Ich hoffe, ihr findet dieses Skript n\u00fctzlich. Bei Fragen\/Problemen oder Anregungen nutzt gerne die Kommentarfunktion weiter unten.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Gerade stand ich vor der Aufgabe, den Nutzern einer Nextcloud Instanz 2FA aufzuzwingen. Dies l\u00e4sst sich im Nextcloud Admin per Schiebregler konfigurieren. 2FA ist zur Absicherung eines Kontos nat\u00fcrlich alternativlos. Erzwinge ich 2FA als Admin so, stellt sich f\u00fcr alle User, die diese zus\u00e4tliche Sicherheitsschicht in ihrem Konto nocht nicht aktiviert haben das Problem, dass [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":795,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1,15,8],"tags":[88,87,89,84,86,85,82],"class_list":["post-793","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-allgemein","category-anleitung","category-linux","tag-2fa","tag-anleitung","tag-mfa","tag-nextcloud","tag-occ","tag-skript","tag-ubuntu","wpbf-post"],"_links":{"self":[{"href":"https:\/\/www.tippex.net\/index.php?rest_route=\/wp\/v2\/posts\/793","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.tippex.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tippex.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tippex.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tippex.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=793"}],"version-history":[{"count":2,"href":"https:\/\/www.tippex.net\/index.php?rest_route=\/wp\/v2\/posts\/793\/revisions"}],"predecessor-version":[{"id":796,"href":"https:\/\/www.tippex.net\/index.php?rest_route=\/wp\/v2\/posts\/793\/revisions\/796"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.tippex.net\/index.php?rest_route=\/wp\/v2\/media\/795"}],"wp:attachment":[{"href":"https:\/\/www.tippex.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=793"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tippex.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=793"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tippex.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=793"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}