Variational Principles for Invariant Tori and Cantori