Unified theory of nuclear reactions based on master equations for finite open systems