Two-factor ANOVA with Bonferroni

Before I go about hacking the R ANOVA component to handle within and between groups with Bonferroni post-hoc testing, does anyone have experience with scripting this kind of analysis? I don't mind learning, but it would go faster with some guidance or an example.

Thanks,
Chris