diff options
author | Paul W. Frields <stickster@gmail.com> | 2010-07-11 11:23:56 -0400 |
---|---|---|
committer | Paul W. Frields <stickster@gmail.com> | 2010-07-11 11:23:56 -0400 |
commit | fae003306d2267624f9f70300883e6adfe8f2074 (patch) | |
tree | 8e32c8aac008e70d548651173403ef4b736af851 | |
parent | f8315920bc020f5b0ab783ff815063df5f487f52 (diff) | |
download | drupal-authfas-6x-fae003306d2267624f9f70300883e6adfe8f2074.tar.gz drupal-authfas-6x-fae003306d2267624f9f70300883e6adfe8f2074.tar.xz drupal-authfas-6x-fae003306d2267624f9f70300883e6adfe8f2074.zip |
Add validation function via JSON
-rw-r--r-- | authfas.module | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/authfas.module b/authfas.module index e0f869e..390dd7e 100644 --- a/authfas.module +++ b/authfas.module @@ -101,9 +101,29 @@ function authfas_menu() { /** * Validate settings entered in AuthFAS settings menu */ - function authfas_admin_validate($form, &$form_state) { +function authfas_admin_validate($form, &$form_state) { // This is where we would validate the menu settings above // http://drupal.org/node/206761 + + $ch = curl_init(); + $fasurl = $form_state['values']['authfas_fasurl']; + // Expect a JSON interface to be present + curl_setopt($ch, CURLOPT_URL, 'https://' . $fasurl . '/json'); + curl_setopt($ch, CURLOPT_POST, 1); + curl_setopt($ch, CURLOPT_USERAGENT, "Auth_FAS 0.9"); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + // The following two lines need to be enabled when using a test FAS + // with an invalid cert. Otherwise they should be commented (or + // set to True) for security. + // #curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); + // #curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); + $response = json_decode(curl_exec($ch), true); + curl_close ($ch); + + if (!isset($response["help"])) { + form_set_error("authfas_fasurl", 'No JSON interface present at https://' .$fasurl. '/json'); + return FALSE; + } return TRUE; } |