└── bitrix24-account-avoid-inactivity-deletion.sh /bitrix24-account-avoid-inactivity-deletion.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #=================================================================== 4 | # Use this script to avoid deletion of the account due to inactivity. 5 | # It creates a directory with a random name on Bitrix24.Drive and deletes it immediately. 6 | # 7 | # VERSION: 01.02.00 8 | # 9 | # BACKGROUND: 10 | # If an instance of Bitrix24 on a free plan (either converted to a free plan or originally on a free plan) is completely inactive over the course of 30 days, 11 | # it is 'archived', and it can be retrieved only by an administrator account (yourself or a user in the instance with administrator rights). 12 | # To retrieve the account, an administrator simply needs to log in. If no administrator logs in for another 15 days after the instance has been 'archived', 13 | # the Bitrix24 instance will be deleted. Please note – this does not affect Bitrix24 paid plans subscribers. 14 | # 15 | # REQUIREMENTS: 16 | # curl / base64 / uuidgen 17 | # 18 | # RUN: 19 | # chmod +x ./bitrix24-account-avoid-inactivity-deletion.sh 20 | # ./bitrix24-account-avoid-inactivity-deletion.sh 21 | # 22 | # 23 | # ::::::::::::::: www.blogging-it.com ::::::::::::::: 24 | # 25 | # Copyright (C) 2020 Markus Eschenbach. All rights reserved. 26 | # 27 | # 28 | # This software is provided on an "as-is" basis, without any express or implied warranty. 29 | # In no event shall the author be held liable for any damages arising from the 30 | # use of this software. 31 | # 32 | # Permission is granted to anyone to use this software for any purpose, 33 | # including commercial applications, and to alter and redistribute it, 34 | # provided that the following conditions are met: 35 | # 36 | # 1. All redistributions of source code files must retain all copyright 37 | # notices that are currently in place, and this list of conditions without 38 | # modification. 39 | # 40 | # 2. All redistributions in binary form must retain all occurrences of the 41 | # above copyright notice and web site addresses that are currently in 42 | # place (for example, in the About boxes). 43 | # 44 | # 3. The origin of this software must not be misrepresented; you must not 45 | # claim that you wrote the original software. If you use this software to 46 | # distribute a product, an acknowledgment in the product documentation 47 | # would be appreciated but is not required. 48 | # 49 | # 4. Modified versions in source or binary form must be plainly marked as 50 | # such, and must not be misrepresented as being the original software. 51 | # 52 | # ::::::::::::::: www.blogging-it.com ::::::::::::::: 53 | # 54 | #=================================================================== 55 | 56 | 57 | #=================================================================== 58 | # SETTINGS 59 | #=================================================================== 60 | users='somebody@example.com;somebody2@example.com' # Bitrix24 account - user/email with administrator rights - separated by semicolon (s1@ex.com;s2@ex.com;.....) 61 | passwords='1234567;987654' # Bitrix24 account - password - separated by semicolon (1234567;987654;.....) 62 | accounts='b24-1xxxxx;b24-2xxxxx' # default names or custom bitrix24 - separated by semicolon (b24-xxxxxx;b24-xxxxxx;.....) 63 | domain='bitrix24.de' # domain with zone 64 | dirName="tmp_webdav-check-$(uuidgen)" # name of the directory 65 | 66 | 67 | #=================================================================== 68 | # PREPARE 69 | #=================================================================== 70 | exitCode=0 # the default exit code, if no error occurs 71 | #basicAuth=$(echo -ne "${user}:${password}" | base64) # convert auth string to base64 string 72 | declare -a accountsArr= # define variable 73 | declare -a usersArr= # define variable 74 | declare -a passwordsArr= # define variable 75 | IFS=';' read -ra accountsArr <<< "${accounts}" # parse string to array 76 | IFS=';' read -ra usersArr <<< "${users}" # parse string to array 77 | IFS=';' read -ra passwordsArr <<< "${passwords}" # parse string to array 78 | 79 | 80 | #=================================================================== 81 | # EXECUTE CURL 82 | #=================================================================== 83 | function execCurl() { 84 | echo "Run request: ${1} - ${2}" 85 | local statusCode=$(curl -k --write-out '%{http_code}' --silent --output /dev/null --header "Authorization: Basic ${3}" -X "${1}" "${2}") 86 | echo "Response - Status-Code: ${statusCode}" 87 | if [[ "${statusCode}" -ne "${4}" ]] ; then 88 | echo "ERROR: Wrong Status-Code - Expected: ${4}" 89 | exitCode=1 90 | fi 91 | } 92 | 93 | function processBitrix() { 94 | local idx=${1} 95 | local account=${accountsArr[idx]} 96 | local user=${usersArr[idx]} 97 | local pass=${passwordsArr[idx]} 98 | 99 | if [[ "${idx}" -ge "${#usersArr[@]}" ]] ; then 100 | user=${usersArr[0]} 101 | fi 102 | 103 | if [[ "${idx}" -ge "${#passwordsArr[@]}" ]] ; then 104 | pass=${passwordsArr[0]} 105 | fi 106 | 107 | local basicAuth=$(echo -ne "${user}:${pass}" | base64) # convert auth string to base64 string 108 | local webDavURL="https://${account}.${domain}/company/personal/user/1/disk/path/${dirName}" 109 | 110 | echo "Process Bitrix24 - ${idx} - ${account} - ${user}" 111 | 112 | echo "Step 1/2: create folder - ${dirName}" 113 | execCurl "MKCOL" "${webDavURL}" "${basicAuth}" 201 114 | 115 | echo "Step 2/2: delete folder - ${dirName}" 116 | execCurl "DELETE" "${webDavURL}" "${basicAuth}" 204 117 | } 118 | 119 | 120 | #=================================================================== 121 | # MAIN 122 | #=================================================================== 123 | for i in "${!accountsArr[@]}"; do 124 | processBitrix "${i}" 125 | done 126 | 127 | exit ${exitCode} 128 | --------------------------------------------------------------------------------