Read file and add it into part of file

Hello
let me explain senario.
there is a file which name is config and it store main software variable:

file main.conf contents:

update="1"
log_login="0"
allow_ports=""
deny_ports="21,22,23"

and there is a file which name is ports.txt
file ports.txt contents:

25,26,27

i want to write script, when it run, import all data from ports.txt into main.conf but between "" in allow_ports and save this new file as finall.conf
so finall.conf should be like this:

update="1"
log_login="0"
allow_ports="25,26,27"
deny_ports="21,22,23"

ive test several ways like use source cat ports.txt and more.

one way:

awk -v qq='"' 'FNR==NR {f2=$0;next} /^allow_ports=/{sub(qq qq, qq f2 qq)}1' ports.txt main.conf

Try also

sed '1 {h; d; n; }; /allow_ports/ { G; s/""\|$/"/g; s/\n//g; }' ports.txt main.conf
update="1"
log_login="0"
allow_ports="25,26,27"
deny_ports="21,22,23"
allow_ports=$(< ports.txt)

while read line
do
   echo "$line" | grep -q "^allow_ports=" && line="allow_ports=\"$allow_ports\""
   echo "$line"
done < main.conf > finall.conf