Cook's D can be obtained using the formula:
This is essentially the square value of the difference between the predicted value for the full model (one with all of the observations) for observation i, and another one omitting observation i. In the denominator, we have the residual standard deviation for the full model times the number of parameters.
The leverage can be obtained by getting the diagonal elements of the so-called hat matrix. It is obtained by applying the same formula to the design matrix.