root/trunk/wifidog-auth/wifidog/include/common.php @ 672

Revision 672, 5.0 KB (checked in by benoitg, 8 years ago)

2005-07-11 Benoit Gr�goire <bock@…>

  • classes/RssPressReview.php: Begin rewrite.
  • classes/MainUI.php: Add addFooterScript() function.
  • venues_map.php: Workaround the IE DOM problem.
  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
Line 
1<?php
2error_reporting(E_ALL);
3require_once BASEPATH.'config.php';
4require_once BASEPATH.'classes/AbstractDb.php';
5require_once BASEPATH.'classes/Session.php';
6require_once BASEPATH.'include/schema_validate.php';
7global $db;
8$db = new AbstractDb();
9validate_schema();
10
11/* NEVER edit these, as they mush match the C code of the gateway */
12define('ACCOUNT_STATUS_ERROR',          -1);
13define('ACCOUNT_STATUS_DENIED',         0);
14define('ACCOUNT_STATUS_ALLOWED',        1);
15define('ACCOUNT_STATUS_VALIDATION',     5);
16define('ACCOUNT_STATUS_VALIDATION_FAILED',      6);
17define('ACCOUNT_STATUS_LOCKED',         254);
18
19$account_status_to_text[ACCOUNT_STATUS_ERROR] = "Error";
20$account_status_to_text[ACCOUNT_STATUS_DENIED] = "Denied";
21$account_status_to_text[ACCOUNT_STATUS_ALLOWED] = "Allowed";
22$account_status_to_text[ACCOUNT_STATUS_VALIDATION] = "Validation";
23$account_status_to_text[ACCOUNT_STATUS_VALIDATION_FAILED] = "Validation Failed";
24$account_status_to_text[ACCOUNT_STATUS_LOCKED] = "Locked";
25
26define('TOKEN_UNUSED',          'UNUSED');
27define('TOKEN_INUSE',           'INUSE');
28define('TOKEN_USED',            'USED');
29
30$token_to_text[TOKEN_UNUSED] = "Unused";
31$token_to_text[TOKEN_INUSE] = "In use";
32$token_to_text[TOKEN_USED] = "Used";
33
34define('STAGE_LOGIN',   "login");
35define('STAGE_LOGOUT',  "logout");
36define('STAGE_COUNTERS',"counters");
37
38define('ONLINE_STATUS_ONLINE',  1);
39define('ONLINE_STATUS_OFFLINE', 2);
40
41/* This section deals with sessions */
42
43define('SESS_USERNAME_VAR', 'SESS_USERNAME');
44define('SESS_USER_ID_VAR', 'SESS_USER_ID');
45define('SESS_PASSWORD_HASH_VAR', 'SESS_PASSWORD_HASH');
46define('SESS_ORIGINAL_URL_VAR', 'SESS_ORIGINAL_URL');
47define('SESS_LANGUAGE_VAR', 'SESS_LANGUAGE');
48define('SESS_GW_ADDRESS_VAR', 'SESS_GW_ADDRESS');
49define('SESS_GW_PORT_VAR', 'SESS_GW_PORT');
50define('SESS_GW_ID_VAR', 'SESS_GW_ID');
51
52/* End */
53
54/* This section deals with PATHs */
55define('BASE_NON_SSL_PATH', 'http://' . $_SERVER['SERVER_NAME'] . SYSTEM_PATH);
56
57//echo "<pre>";print_r($_SERVER);echo "</pre>";
58
59$curent_url='http';
60if($_SERVER['SERVER_PORT']=='443'){$curent_url.='s';}
61$curent_url.= '://'.$_SERVER['HTTP_HOST'];
62if($_SERVER['SERVER_PORT']!=80 && $_SERVER['SERVER_PORT']!=443) $curent_url.=':'.$_SERVER['SERVER_PORT'];
63$curent_url.=$_SERVER['REQUEST_URI'];
64define('CURRENT_REQUEST_URL', $curent_url);
65
66
67
68if(SSL_AVAILABLE)
69  {
70    define('BASE_SSL_PATH', 'https://' . $_SERVER['SERVER_NAME'] . SYSTEM_PATH);
71  }
72else
73  {
74    define('BASE_SSL_PATH', BASE_NON_SSL_PATH);
75  }
76 
77  /* If we actually ARE in SSL mode, make all URLS http:// to avoid security warnings. */
78if(isset($_SERVER['HTTPS']))
79  {
80  define('BASE_URL_PATH', BASE_SSL_PATH); 
81  }
82  else
83  {
84  define('BASE_URL_PATH', BASE_NON_SSL_PATH);
85  }
86 
87if(empty($_REQUEST['gw_id']))
88  {
89    define('CURRENT_NODE_ID', DEFAULT_NODE_ID);
90  }
91else
92  {
93    define('CURRENT_NODE_ID', trim($_REQUEST['gw_id']));
94  }
95
96define('DEFAULT_CONTENT_URL', BASE_URL_PATH.LOCAL_CONTENT_REL_PATH.DEFAULT_NODE_ID.'/');
97define('DEFAULT_CONTENT_PHP_RELATIVE_PATH', BASEPATH.LOCAL_CONTENT_REL_PATH.DEFAULT_NODE_ID.'/');
98
99define('NODE_CONTENT_URL', BASE_URL_PATH.LOCAL_CONTENT_REL_PATH.CURRENT_NODE_ID.'/');
100define('NODE_CONTENT_PHP_RELATIVE_PATH', BASEPATH.LOCAL_CONTENT_REL_PATH.CURRENT_NODE_ID.'/');
101
102define('COMMON_CONTENT_URL', BASE_URL_PATH.LOCAL_CONTENT_REL_PATH.'common/');
103
104
105define('GENERIC_OBJECT_ADMIN_ABS_HREF', BASE_URL_PATH.'/admin/generic_object_admin.php');
106define('CONTENT_ADMIN_ABS_HREF', BASE_URL_PATH.'/admin/content_admin.php');
107     
108/** Convert a password hash form a NoCat passwd file into the same format as get_password_hash().
109* @return The 32 character hash.
110*/
111function convert_nocat_password_hash($hash)
112{
113 return $hash . '==';
114}
115
116function iso8601_date($unix_timestamp) {
117   $tzd = date('O',$unix_timestamp);
118   $tzd = substr(chunk_split($tzd, 3, ':'),0,6);
119   $date = date('Y-m-d\TH:i:s', $unix_timestamp) . $tzd;
120   return $date; 
121}
122
123/** Cleanup dangling tokens and connections from the database, left if a gateway crashed, etc. */
124function garbage_collect()
125{
126  global $db;
127
128  // 10 minutes
129  $expiration = time() - 60*10;
130  $expiration=iso8601_date($expiration);
131  $db -> ExecSqlUpdate ("UPDATE connections SET token_status='" . TOKEN_USED . "' WHERE last_updated < '$expiration' AND token_status = '".TOKEN_INUSE."'", false);
132}
133
134/** Get the url from the local content_specific folder if the file exists, and from the default content folder otherwise */
135function find_local_content_url($filename)
136{
137//echo "find_local_content_url():  Looking for:                  ".NODE_CONTENT_PHP_RELATIVE_PATH.$filename."<br>\n";
138  if (is_file(NODE_CONTENT_PHP_RELATIVE_PATH.$filename))
139    {
140       $retval = NODE_CONTENT_URL.$filename;
141    }
142  else
143    {
144      $retval = DEFAULT_CONTENT_URL.$filename;
145    }
146    //echo "find_local_content_url():  Returned:                  $retval<br>\n";
147    return $retval;
148}
149
150/** Return a 32 byte guid valid for database use */
151function get_guid()
152{
153  return  md5(uniqid(rand(), true));
154}
155
156/** like the php function print_r(), but the way it was meant to be... */
157function pretty_print_r($param)
158{
159        echo "\n<pre>\n";
160        print_r($param);
161        echo "\n</pre>\n";
162}
163?>
Note: See TracBrowser for help on using the browser.