I've done this before with Asterisk and a quad-port T1 card.

T1/PRI from carrier goes in one port, T1/Pri/Whatever comes out one port to customer's PBX/etc, third port comes out and goes into a FXS/FXO channel bank.

It all works best if there is a PRI coming from the carrier as it's easy to do call routing based upon DID/CID/Etc.