|  | @@ -172,6 +172,73 @@ function remove_user_irc {
 | 
	
		
			
			| 172 | 172 |      fi
 | 
	
		
			
			| 173 | 173 |  }
 | 
	
		
			
			| 174 | 174 |  
 | 
	
		
			
			|  | 175 | +function irc_get_global_password {
 | 
	
		
			
			|  | 176 | +    echo $(cat /etc/ngircd/ngircd.conf | grep "Password =" | head -n 1 | awk -F '=' '{print $2}')
 | 
	
		
			
			|  | 177 | +}
 | 
	
		
			
			|  | 178 | +
 | 
	
		
			
			|  | 179 | +function irc_set_global_password_base {
 | 
	
		
			
			|  | 180 | +    NEW_IRC_PASSWORD="$1"
 | 
	
		
			
			|  | 181 | +    EXISTING_IRC_PASSWORD=$(irc_get_global_password)
 | 
	
		
			
			|  | 182 | +    sed -i "0,/RE/s/Password =.*/Password =$NEW_IRC_PASSWORD/" /etc/ngircd/ngircd.conf
 | 
	
		
			
			|  | 183 | +
 | 
	
		
			
			|  | 184 | +    # replace the password for all users
 | 
	
		
			
			|  | 185 | +    for d in /home/*/ ; do
 | 
	
		
			
			|  | 186 | +        IRC_USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
 | 
	
		
			
			|  | 187 | +        if [[ $(is_valid_user "$IRC_USERNAME") == "1" ]]; then
 | 
	
		
			
			|  | 188 | +            if [ -f /home/${IRC_USERNAME}/.irssi/config ]; then
 | 
	
		
			
			|  | 189 | +                sed -i "s|$EXISTING_IRC_PASSWORD|$NEW_IRC_PASSWORD|g" /home/${IRC_USERNAME}/.irssi/config
 | 
	
		
			
			|  | 190 | +                chown -R ${IRC_USERNAME}:${IRC_USERNAME} /home/${IRC_USERNAME}/.irssi
 | 
	
		
			
			|  | 191 | +            fi
 | 
	
		
			
			|  | 192 | +        fi
 | 
	
		
			
			|  | 193 | +    done
 | 
	
		
			
			|  | 194 | +
 | 
	
		
			
			|  | 195 | +    read_config_param DEFAULT_DOMAIN_NAME
 | 
	
		
			
			|  | 196 | +    read_config_param IRC_PORT
 | 
	
		
			
			|  | 197 | +    read_config_param MY_USERNAME
 | 
	
		
			
			|  | 198 | +
 | 
	
		
			
			|  | 199 | +    stop_irc_bouncer
 | 
	
		
			
			|  | 200 | +    sleep 2
 | 
	
		
			
			|  | 201 | +
 | 
	
		
			
			|  | 202 | +    # change the hashes. There are multiple users, but since we're using a global
 | 
	
		
			
			|  | 203 | +    # password this doesn't matter
 | 
	
		
			
			|  | 204 | +    ZNC_SALT="$(dd if=/dev/urandom bs=16c count=1 | md5sum | awk -F ' ' '{print $1}' | cut -c1-20)"
 | 
	
		
			
			|  | 205 | +    new_user_hash=$(echo -n "${NEW_IRC_PASSWORD}${ZNC_SALT}" | sha256sum | awk -F ' ' '{print $1}')
 | 
	
		
			
			|  | 206 | +    sed -i "s|Hash = .*|Hash = ${new_user_hash}|g" /home/znc/.znc/configs/znc.conf
 | 
	
		
			
			|  | 207 | +    sed -i "s|Salt = .*|Salt = ${ZNC_SALT}|g" /home/znc/.znc/configs/znc.conf
 | 
	
		
			
			|  | 208 | +
 | 
	
		
			
			|  | 209 | +    # change the server password
 | 
	
		
			
			|  | 210 | +    sed -i "s|Server     = 127.0.0.1.*|Server     = 127.0.0.1 ${IRC_PORT} ${NEW_IRC_PASSWORD}|g" /home/znc/.znc/configs/znc.conf
 | 
	
		
			
			|  | 211 | +
 | 
	
		
			
			|  | 212 | +    # Update the password
 | 
	
		
			
			|  | 213 | +    ${PROJECT_NAME}-pass -u $MY_USERNAME -a irc -p "$NEW_IRC_PASSWORD"
 | 
	
		
			
			|  | 214 | +
 | 
	
		
			
			|  | 215 | +    # matrix bridge to irc
 | 
	
		
			
			|  | 216 | +    if [ -f $INSTALL_DIR/matrix_irc_bridge/config.yaml ]; then
 | 
	
		
			
			|  | 217 | +        sed -i "s|password: .*|password: \"$NEW_IRC_PASSWORD\"|g" $INSTALL_DIR/matrix_irc_bridge/config.yaml
 | 
	
		
			
			|  | 218 | +        systemctl restart matrix_irc_bridge
 | 
	
		
			
			|  | 219 | +    fi
 | 
	
		
			
			|  | 220 | +
 | 
	
		
			
			|  | 221 | +    write_config_param "IRC_PASSWORD" "$NEW_IRC_PASSWORD"
 | 
	
		
			
			|  | 222 | +
 | 
	
		
			
			|  | 223 | +    # restart the daemon for the new password to take effect
 | 
	
		
			
			|  | 224 | +    systemctl restart ngircd
 | 
	
		
			
			|  | 225 | +    start_irc_bouncer
 | 
	
		
			
			|  | 226 | +}
 | 
	
		
			
			|  | 227 | +
 | 
	
		
			
			|  | 228 | +function change_password_irc {
 | 
	
		
			
			|  | 229 | +    new_global_password="$2"
 | 
	
		
			
			|  | 230 | +
 | 
	
		
			
			|  | 231 | +    # Change the password for all users
 | 
	
		
			
			|  | 232 | +    for d in /home/*/ ; do
 | 
	
		
			
			|  | 233 | +        USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
 | 
	
		
			
			|  | 234 | +        if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
 | 
	
		
			
			|  | 235 | +            ${PROJECT_NAME}-pass -u "$USERNAME" -a irc -p "$new_global_password"
 | 
	
		
			
			|  | 236 | +        fi
 | 
	
		
			
			|  | 237 | +    done
 | 
	
		
			
			|  | 238 | +
 | 
	
		
			
			|  | 239 | +    irc_set_global_password_base "$new_global_password"
 | 
	
		
			
			|  | 240 | +}
 | 
	
		
			
			|  | 241 | +
 | 
	
		
			
			| 175 | 242 |  function add_user_irc_bouncer {
 | 
	
		
			
			| 176 | 243 |      new_username="$1"
 | 
	
		
			
			| 177 | 244 |      new_user_password="$2"
 | 
	
	
		
			
			|  | @@ -180,12 +247,13 @@ function add_user_irc_bouncer {
 | 
	
		
			
			| 180 | 247 |          is_admin='false'
 | 
	
		
			
			| 181 | 248 |      fi
 | 
	
		
			
			| 182 | 249 |  
 | 
	
		
			
			| 183 |  | -    ${PROJECT_NAME}-pass -u $new_username -a irc -p "$new_user_password"
 | 
	
		
			
			| 184 | 250 |  
 | 
	
		
			
			| 185 | 251 |      if [[ $(is_valid_user "$new_username") == "0" ]]; then
 | 
	
		
			
			| 186 | 252 |          return
 | 
	
		
			
			| 187 | 253 |      fi
 | 
	
		
			
			| 188 | 254 |  
 | 
	
		
			
			|  | 255 | +    ${PROJECT_NAME}-pass -u $new_username -a irc -p "$new_user_password"
 | 
	
		
			
			|  | 256 | +
 | 
	
		
			
			| 189 | 257 |      read_config_param IRC_PORT
 | 
	
		
			
			| 190 | 258 |      read_config_param DEFAULT_DOMAIN_NAME
 | 
	
		
			
			| 191 | 259 |      if [ ! $2 ]; then
 | 
	
	
		
			
			|  | @@ -284,7 +352,7 @@ function add_user_irc {
 | 
	
		
			
			| 284 | 352 |      new_username="$1"
 | 
	
		
			
			| 285 | 353 |      new_user_password="$2"
 | 
	
		
			
			| 286 | 354 |  
 | 
	
		
			
			| 287 |  | -    IRC_PASSWORD=$(cat /etc/ngircd/ngircd.conf | grep "Password =" | head -n 1 | awk -F '=' '{print $2}')
 | 
	
		
			
			|  | 355 | +    IRC_PASSWORD=$(irc_get_global_password)
 | 
	
		
			
			| 288 | 356 |      if [ ${#IRC_PASSWORD} -lt 2 ]; then
 | 
	
		
			
			| 289 | 357 |          IRC_PASSWORD=
 | 
	
		
			
			| 290 | 358 |      fi
 | 
	
	
		
			
			|  | @@ -303,66 +371,22 @@ function run_client_irc {
 | 
	
		
			
			| 303 | 371 |  }
 | 
	
		
			
			| 304 | 372 |  
 | 
	
		
			
			| 305 | 373 |  function irc_show_password {
 | 
	
		
			
			| 306 |  | -    IRC_PASSWORD=$(cat /etc/ngircd/ngircd.conf | grep "Password =" | head -n 1 | awk -F '=' '{print $2}')
 | 
	
		
			
			|  | 374 | +    IRC_PASSWORD=$(irc_get_global_password)
 | 
	
		
			
			| 307 | 375 |      dialog --title $"IRC Password" \
 | 
	
		
			
			| 308 | 376 |             --msgbox "$IRC_PASSWORD" 6 40
 | 
	
		
			
			| 309 | 377 |  }
 | 
	
		
			
			| 310 | 378 |  
 | 
	
		
			
			| 311 | 379 |  function irc_set_global_password {
 | 
	
		
			
			|  | 380 | +    EXISTING_IRC_PASSWORD=$(irc_get_global_password)
 | 
	
		
			
			| 312 | 381 |      dialog --title $"IRC Password" \
 | 
	
		
			
			| 313 | 382 |             --clear \
 | 
	
		
			
			| 314 | 383 |             --backtitle $"Freedombone Control Panel" \
 | 
	
		
			
			| 315 |  | -           --passwordbox $"Password for all IRC users, or press Enter for no password" 10 60 2> $data
 | 
	
		
			
			|  | 384 | +           --passwordbox $"Password for all IRC users, or press Enter for no password" 10 60 "$EXISTING_IRC_PASSWORD" 2> $data
 | 
	
		
			
			| 316 | 385 |      sel=$?
 | 
	
		
			
			| 317 | 386 |      case $sel in
 | 
	
		
			
			| 318 | 387 |          0)
 | 
	
		
			
			| 319 |  | -            EXISTING_IRC_PASSWORD=$(cat /etc/ngircd/ngircd.conf | grep "Password =" | head -n 1 | awk -F '=' '{print $2}')
 | 
	
		
			
			| 320 | 388 |              NEW_IRC_PASSWORD=$(<$data)
 | 
	
		
			
			| 321 |  | -            sed -i "0,/RE/s/Password =.*/Password =$NEW_IRC_PASSWORD/" /etc/ngircd/ngircd.conf
 | 
	
		
			
			| 322 |  | -
 | 
	
		
			
			| 323 |  | -            # replace the password for all users
 | 
	
		
			
			| 324 |  | -            for d in /home/*/ ; do
 | 
	
		
			
			| 325 |  | -                IRC_USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
 | 
	
		
			
			| 326 |  | -                if [[ $(is_valid_user "$IRC_USERNAME") == "1" ]]; then
 | 
	
		
			
			| 327 |  | -                    if [ -f /home/${IRC_USERNAME}/.irssi/config ]; then
 | 
	
		
			
			| 328 |  | -                        sed -i "s|$EXISTING_IRC_PASSWORD|$NEW_IRC_PASSWORD|g" /home/${IRC_USERNAME}/.irssi/config
 | 
	
		
			
			| 329 |  | -                        chown -R ${IRC_USERNAME}:${IRC_USERNAME} /home/${IRC_USERNAME}/.irssi
 | 
	
		
			
			| 330 |  | -                    fi
 | 
	
		
			
			| 331 |  | -                fi
 | 
	
		
			
			| 332 |  | -            done
 | 
	
		
			
			| 333 |  | -
 | 
	
		
			
			| 334 |  | -            read_config_param DEFAULT_DOMAIN_NAME
 | 
	
		
			
			| 335 |  | -            read_config_param IRC_PORT
 | 
	
		
			
			| 336 |  | -            read_config_param MY_USERNAME
 | 
	
		
			
			| 337 |  | -
 | 
	
		
			
			| 338 |  | -            stop_irc_bouncer
 | 
	
		
			
			| 339 |  | -            sleep 2
 | 
	
		
			
			| 340 |  | -
 | 
	
		
			
			| 341 |  | -            # change the hashes. There are multiple users, but since we're using a global
 | 
	
		
			
			| 342 |  | -            # password this doesn't matter
 | 
	
		
			
			| 343 |  | -            ZNC_SALT="$(dd if=/dev/urandom bs=16c count=1 | md5sum | awk -F ' ' '{print $1}' | cut -c1-20)"
 | 
	
		
			
			| 344 |  | -            new_user_hash=$(echo -n "${NEW_IRC_PASSWORD}${ZNC_SALT}" | sha256sum | awk -F ' ' '{print $1}')
 | 
	
		
			
			| 345 |  | -            sed -i "s|Hash = .*|Hash = ${new_user_hash}|g" /home/znc/.znc/configs/znc.conf
 | 
	
		
			
			| 346 |  | -            sed -i "s|Salt = .*|Salt = ${ZNC_SALT}|g" /home/znc/.znc/configs/znc.conf
 | 
	
		
			
			| 347 |  | -
 | 
	
		
			
			| 348 |  | -            # change the server password
 | 
	
		
			
			| 349 |  | -            sed -i "s|Server     = 127.0.0.1.*|Server     = 127.0.0.1 ${IRC_PORT} ${NEW_IRC_PASSWORD}|g" /home/znc/.znc/configs/znc.conf
 | 
	
		
			
			| 350 |  | -
 | 
	
		
			
			| 351 |  | -            # Update the password
 | 
	
		
			
			| 352 |  | -            ${PROJECT_NAME}-pass -u $MY_USERNAME -a irc -p "$NEW_IRC_PASSWORD"
 | 
	
		
			
			| 353 |  | -
 | 
	
		
			
			| 354 |  | -
 | 
	
		
			
			| 355 |  | -            if [ -f $INSTALL_DIR/matrix_irc_bridge/config.yaml ]; then
 | 
	
		
			
			| 356 |  | -                sed -i "s|password: .*|password: \"$NEW_IRC_PASSWORD\"|g" $INSTALL_DIR/matrix_irc_bridge/config.yaml
 | 
	
		
			
			| 357 |  | -                systemctl restart matrix_irc_bridge
 | 
	
		
			
			| 358 |  | -            fi
 | 
	
		
			
			| 359 |  | -
 | 
	
		
			
			| 360 |  | -            write_config_param "IRC_PASSWORD" "$NEW_IRC_PASSWORD"
 | 
	
		
			
			| 361 |  | -
 | 
	
		
			
			| 362 |  | -            # restart the daemon for the new password to take effect
 | 
	
		
			
			| 363 |  | -            systemctl restart ngircd
 | 
	
		
			
			| 364 |  | -            start_irc_bouncer
 | 
	
		
			
			| 365 |  | -
 | 
	
		
			
			|  | 389 | +            irc_set_global_password_base "$NEW_IRC_PASSWORD"
 | 
	
		
			
			| 366 | 390 |              dialog --title $"IRC Password" \
 | 
	
		
			
			| 367 | 391 |                     --msgbox $"The IRC password was changed" 6 40
 | 
	
		
			
			| 368 | 392 |              ;;
 |