QSFit: Automatic analysis of optical AGN spectra