{"id":936,"date":"2025-01-02T07:14:31","date_gmt":"2025-01-02T04:14:31","guid":{"rendered":"https:\/\/itgen.itbumper.com\/?page_id=936"},"modified":"2025-01-02T07:14:32","modified_gmt":"2025-01-02T04:14:32","slug":"0036_bash-vcfwifi-qr-gen","status":"publish","type":"page","link":"https:\/\/itgen.itbumper.com\/?page_id=936","title":{"rendered":"0036_Bash: VCF&amp;WiFi QR-Gen"},"content":{"rendered":"<div>The script allows you to:<\/div>\n<ol>\n<li>\u00a0Generate a QR code for a Wi-Fi wireless network;<\/li>\n<li>\u00a0Generate a QR code and a VCF file (Business Card);<\/li>\n<li>\u00a0Send the received files by email.<\/li>\n<\/ol>\n<div>The script uses dialog.<\/div>\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"590\" src=\"https:\/\/itgen.itbumper.com\/wp-content\/uploads\/2025\/01\/qr-bash_01-1024x590.png\" alt=\"\" class=\"wp-image-938\" srcset=\"https:\/\/itgen.itbumper.com\/wp-content\/uploads\/2025\/01\/qr-bash_01-1024x590.png 1024w, https:\/\/itgen.itbumper.com\/wp-content\/uploads\/2025\/01\/qr-bash_01-300x173.png 300w, https:\/\/itgen.itbumper.com\/wp-content\/uploads\/2025\/01\/qr-bash_01-768x442.png 768w, https:\/\/itgen.itbumper.com\/wp-content\/uploads\/2025\/01\/qr-bash_01-1200x691.png 1200w, https:\/\/itgen.itbumper.com\/wp-content\/uploads\/2025\/01\/qr-bash_01.png 1361w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px\" \/><\/figure>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n#!\/bin\/bash\n\n# Enable debug mode\n# set -x\n# set +x\n\nCHARSET=&quot;utf-8&quot;\n# Temporary files for dialog\nWIFI_TMP=$(mktemp)\nVCF_TMP=$(mktemp)\nSEND_TMP=$(mktemp)\nCHOICE_TMP=$(mktemp)\nGENERATED_FILES=()\n\n# Function to collect Wi-Fi details\nget_wifi_details() {\n    while true; do\n        dialog --title &quot;Wi-Fi QR Generator&quot; \\\n               --form &quot;Enter Wi-Fi connection details:&quot; \\\n               15 50 0 \\\n               &quot;SSID:&quot; 1 1 &quot;&quot; 1 10 30 0 \\\n               &quot;Password:&quot; 2 1 &quot;&quot; 2 10 30 0 \\\n               &quot;Encryption (WPA\/WEP\/NONE):&quot; 3 1 &quot;WPA&quot; 3 10 30 0 \\\n               2&gt;$WIFI_TMP\n\n        if &#x5B; $? -ne 0 ]; then\n            return 0  # Back\n        fi\n\n        SSID=$(sed -n '1p' $WIFI_TMP)\n        PASSWORD=$(sed -n '2p' $WIFI_TMP)\n        ENCRYPTION=$(sed -n '3p' $WIFI_TMP)\n\n        if &#x5B; -z &quot;$SSID&quot; ] || &#x5B; -z &quot;$PASSWORD&quot; ] || &#x5B; -z &quot;$ENCRYPTION&quot; ]; then\n            dialog --msgbox &quot;SSID, password, and encryption type cannot be empty.&quot; 6 40\n        else\n            WIFI_STRING=&quot;WIFI:T:$ENCRYPTION;S:$SSID;P:$PASSWORD;;&quot;\n            qrencode -o wifi_qr.png &quot;$WIFI_STRING&quot;\n            GENERATED_FILES+=(wifi_qr.png)\n            dialog --msgbox &quot;Wi-Fi QR code saved as wifi_qr.png&quot; 6 40\n            return 0\n        fi\n    done\n}\n\n# Function to collect VCF details\nget_vcf_details() {\n    while true; do\n        dialog --title &quot;VCF QR Generator&quot; \\\n               --form &quot;Enter contact details for the business card:&quot; \\\n               20 70 0 \\\n               &quot;Full Name (FN):&quot; 1 1 &quot;&quot; 1 25 40 0 \\\n               &quot;Name (N):&quot; 2 1 &quot;&quot; 2 25 40 0 \\\n               &quot;Phone (TEL):&quot; 3 1 &quot;&quot; 3 25 40 0 \\\n               &quot;Email (EMAIL):&quot; 4 1 &quot;&quot; 4 25 40 0 \\\n               &quot;Address (ADR):&quot; 5 1 &quot;&quot; 5 25 40 0 \\\n               &quot;Organization (ORG):&quot; 6 1 &quot;&quot; 6 25 40 0 \\\n               &quot;Title (TITLE):&quot; 7 1 &quot;&quot; 7 25 40 0 \\\n               &quot;Website (URL):&quot; 8 1 &quot;&quot; 8 25 40 0 \\\n               &quot;Birthday (BDAY):&quot; 9 1 &quot;&quot; 9 25 40 0 \\\n               &quot;Notes (NOTE):&quot; 10 1 &quot;&quot; 10 25 40 0 \\\n               2&gt;$VCF_TMP\n\n        if &#x5B; $? -ne 0 ]; then\n            return 0  # Back\n        fi\n\n        FN=$(sed -n '1p' $VCF_TMP)\n        N=$(sed -n '2p' $VCF_TMP)\n        TEL=$(sed -n '3p' $VCF_TMP)\n        EMAIL=$(sed -n '4p' $VCF_TMP)\n        ADR=$(sed -n '5p' $VCF_TMP)\n        ORG=$(sed -n '6p' $VCF_TMP)\n        TITLE=$(sed -n '7p' $VCF_TMP)\n        URL=$(sed -n '8p' $VCF_TMP)\n        BDAY=$(sed -n '9p' $VCF_TMP)\n        NOTE=$(sed -n '10p' $VCF_TMP)\n\n        if &#x5B; -z &quot;$FN&quot; ] || &#x5B; -z &quot;$TEL&quot; ] || &#x5B; -z &quot;$EMAIL&quot; ]; then\n            dialog --msgbox &quot;Full Name, Phone, and Email fields are mandatory.&quot; 6 50\n        else\n            VCF_CONTENT=$(cat &lt;&lt;-END\nBEGIN:VCARD\nVERSION:3.0\nFN:$FN\nN:$N;;;\nTEL;TYPE=CELL:$TEL\nEMAIL;TYPE=INTERNET:$EMAIL\nADR;TYPE=WORK:;;$ADR;;;;\nORG:$ORG\nTITLE:$TITLE\nURL:$URL\nBDAY:$BDAY\nNOTE:$NOTE\nEND:VCARD\nEND\n)\n            echo &quot;$VCF_CONTENT&quot; &gt; contact.vcf\n            qrencode -o vcf_qr.png &quot;$VCF_CONTENT&quot;\n            GENERATED_FILES+=(contact.vcf vcf_qr.png)\n            dialog --msgbox &quot;VCF and QR code saved as contact.vcf and vcf_qr.png&quot; 6 50\n            return 0\n        fi\n    done\n}\n\n# Function to send email\nsend_email() {\n    while true; do\n        dialog --title &quot;Send Email&quot; \\\n               --inputbox &quot;Enter email address to send files to:&quot; 8 50 \\\n               2&gt;$SEND_TMP\n\n        if &#x5B; $? -ne 0 ]; then\n            return 0  # Back\n        fi\n\n        EMAIL=$(cat $SEND_TMP)\n\n        if &#x5B; -z &quot;$EMAIL&quot; ]; then\n            dialog --msgbox &quot;Email address cannot be empty.&quot; 6 40\n        else\n            sendemail -f &lt;sender email&gt; -t &quot;$EMAIL&quot; -u &quot;Your QR Code&quot; -m &quot;Your files&quot; -s &lt;your an email server&gt; -a ${GENERATED_FILES&#x5B;@]} -o message-charset=$CHARSET\n            if &#x5B; $? -eq 0 ]; then\n                dialog --msgbox &quot;Files successfully sent to $EMAIL&quot; 6 40\n                rm -f ${GENERATED_FILES&#x5B;@]}\n            else\n                dialog --msgbox &quot;Error sending files.&quot; 6 40\n                rm -f ${GENERATED_FILES&#x5B;@]}\n            fi\n            return 0\n        fi\n    done\n}\n\n# Main menu\nmain_menu() {\n    while true; do\n        dialog --title &quot;Operation Selection&quot; \\\n               --menu &quot;What would you like to do?&quot; 15 50 4 \\\n               1 &quot;QR Code for Wi-Fi&quot; \\\n               2 &quot;QR Code and VCF for a Business Card&quot; \\\n               3 &quot;Send Files via Email&quot; \\\n               4 &quot;Exit&quot; \\\n               2&gt;$CHOICE_TMP\n\n        CHOICE=$(cat $CHOICE_TMP)\n\n        case $CHOICE in\n            1) get_wifi_details ;;\n            2) get_vcf_details ;;\n            3)\n                if &#x5B; ${#GENERATED_FILES&#x5B;@]} -eq 0 ]; then\n                    dialog --msgbox &quot;No files to send.&quot; 6 40\n                else\n                    send_email\n                fi\n                ;;\n            4) break ;;\n            *) dialog --msgbox &quot;Invalid choice.&quot; 6 40 ;;\n        esac\n    done\n}\n\nmain_menu\n\n# Remove temporary files\nrm -f $WIFI_TMP $VCF_TMP $CHOICE_TMP $SEND_TMP\n\n### hint ###\n#sudo apt install sendemail libio-socket-ssl-perl libnet-ssleay-perl\n#sendemail -f &quot;Sender Name &lt;sender@example.com&gt;&quot; \\\n#          -t recipient@example.com \\\n#          -u &quot;Personalized Email&quot; \\\n#          -m &quot;This email has a custom sender name.&quot; \\\n#          -s smtp.example.com:587 \\\n#          -xu sender@example.com \\\n#          -xp &quot;password&quot;\n\n#sendemail -f sender@example.com -t recipient@example.com \\ -u &quot;Log Test&quot; -m &quot;This email will be logged.&quot; \\ -s smtp.yourserver.com:25 -l \/path\/to\/logfile.log\n\n<\/pre><\/div>","protected":false},"excerpt":{"rendered":"<p>The script allows you to: \u00a0Generate a QR code for a Wi-Fi wireless network; \u00a0Generate a QR code and a VCF file (Business Card); \u00a0Send the received files by email. The script uses dialog.<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"categories":[],"tags":[],"_links":{"self":[{"href":"https:\/\/itgen.itbumper.com\/index.php?rest_route=\/wp\/v2\/pages\/936"}],"collection":[{"href":"https:\/\/itgen.itbumper.com\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/itgen.itbumper.com\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/itgen.itbumper.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/itgen.itbumper.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=936"}],"version-history":[{"count":2,"href":"https:\/\/itgen.itbumper.com\/index.php?rest_route=\/wp\/v2\/pages\/936\/revisions"}],"predecessor-version":[{"id":939,"href":"https:\/\/itgen.itbumper.com\/index.php?rest_route=\/wp\/v2\/pages\/936\/revisions\/939"}],"wp:attachment":[{"href":"https:\/\/itgen.itbumper.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=936"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itgen.itbumper.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=936"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itgen.itbumper.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=936"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}