Variational theory for Liouville equations with singularities