Microscopic hamiltonian for Zn- or Ni-substituted high-temperature cuprate superconductors