]>
git.defcon.no Git - hermes/blob - api/lib/auth_base.php
2 require_once('config.php');
4 $config = get_config();
6 /*******************************
7 * Load authentication plugin ..
8 *******************************/
9 if ( preg_match('/^\w+$/', $config['auth_backend']))
11 if ( !@include_once
( 'lib/auth_plugins/' . $config['auth_backend'] . ".php" ) )
12 { print json_encode( array( 'response' => 'error', 'cause' => 'auth-load' ) ); exit; }
15 { print json_encode( array( 'response' => 'error', 'cause' => 'config-error' ) ); exit; }
16 /*******************************/
18 function check_authkey ( $key )
21 if ( $key == "6327c08b70f9" ) return true;
28 // Basically this is at the moment a slightly modified
29 // version of generate_password() from user_functiions.php
30 // The behaviour/output of this function is expected to change
31 // so using generate_password() directly does not make sense...
34 while ( strlen( $string ) < $length )
36 $string .= crypt( substr(sha1(rand()), 0, $length) );
37 $string = preg_replace( '/\W/', '', $string);
39 return substr( $string, 0, $length );
42 function simple_authfail()
44 print json_encode( array( 'response' => 'failed', 'cause' => 'unauthorized', 'description' => 'Not authorized') );
48 function token_auth( )
52 if ( array_key_exists('auth_key', $_GET ) )
53 { if ( ! check_authkey($_GET['auth_key'] ) ) simple_authfail(); }
54 else simple_authfail();
57 function can_write ( )
59 // Stub, to be called on any API nodes taht write data in the DB.