summaryrefslogtreecommitdiff
path: root/fs_selfservice/fri/includes/bootstrap.php
blob: a01a2f5c8b28d26ab39e7dba9cc6ae26ee365c91 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
<?php

/**
 * @file
 * Functions that need to be loaded on every request.
 */

/**
 * Sets doc root
 */
function setARIRoot() {

  $found = 0;
  if (isset($_SERVER['PHP_SELF'])) {
    if ($_SERVER['PHP_SELF']!='') {
      $_SESSION['ARI_ROOT'] = $_SERVER['PHP_SELF'];
    }
  }
  
  if (!$found) {
    $_SESSION['ARI_ROOT'] = "index.php";
  }
}

/**
 * Return a arguments.
 *
 * @param $args
 *   The name of the array being acted upon.
 * @param $name
 *   The name of the variable to return.
 * @return
 *   The value of the variable.
 */
function getArgument($args, $name) {

  return isset($args[$name]) ? $args[$name] : '';
}

/*
 * Gets top level directory names 
 *
 * @param $path
 *   directory to search
 * @param $filter
 *   string to use as a filter to match files to return
 * @return $directories
 *   directories found
 */
function getDirectories($path,$filter) {

  $directories = array();

  if (is_dir($path)) {

    $dh = opendir($path);
    while (false!== ($item = readdir($dh))) {
      if($item!="." && $item!="..") {

        $path = fixPathSlash($path);
        $directory = $path;
        $directory = appendPath($directory,$item);

        if (is_dir($directory)) {

          $found = 0;
          if ($filter) {
            if (strpos($directory,$filter)) {
              $found = 1;
            }
          } else {
            $found = 1;
          }
          if ($found) {
            $directories[count($directories) + 1] = $directory;
          }
        }
      }
    } 
  }

  return $directories;
}

/*
 * Gets file names recursively 6 folders deep
 *
 * @param $path
 *   directory to search
 * @param $filter
 *   string to use as a filter to match files to return
 * @param $recursive_max
 *   max number of sub folders to search
 * @param $recursive_count
 *   current sub folder count
 * @return $files
 *   files found
 */
function getFiles($path,$filter,$recursive_max,$recursive_count) {

  $files = array();

  if (@is_dir($path) && @is_readable($path)) {
    $dh = opendir($path);
    while (false!== ($item = readdir($dh))) {
      if($item[0]!=".") {

        $path = fixPathSlash($path);
        $msg_path = appendPath($path,$item);

        $fileCount++;
        if ($fileCount>3000) {
          $_SESSION['ari_error'] 
            .= _("To many files in $msg_path Not all files processed") . "<br>";
          return;
        }

        if ($recursive_count<$recursive_max && is_dir($msg_path)) {

          $dirCount++;
          if ($dirCount>10) {
            $_SESSION['ari_error'] 
              .= sprintf(_("To many directories in %s Not all files processed"),$msg_path) . "<br>";
            return;
          }

          $count = $recursive_count + 1;
          $path_files = getFiles($msg_path,$filter,$recursive_max,$count);
          $files = array_merge($files,$path_files);
        } 
        else {
          $found = 0;
          if ($filter) {
            if (strpos($msg_path,$filter)) {
              $found = 1;
            }
          } else {
            $found = 1;
          }
          if ($found) {
            $files[count($files) + 1] = $msg_path;
          }
        }
      }
    } 
  }

  return $files;
}

/* Utilities */

/**
 * Fixes the path for a trailing slash
 *
 * @param $path
 *   path to append
 * @return $ret
 *   path to returned
 */
function fixPathSlash($path) {

  $ret = $path;

  $slash = '';
  if (!preg_match('/\/$/',$path)) {
    $slash = '/';
  } 
  $ret .= $slash;

  return $ret; 
}

/**
 * Appends folder to end of path
 *
 * @param $path
 *   path to append
 * @param $folder
 *   folder to append to path
 * @return $ret
 *   path to returned
 */
function appendPath($path,$folder) {

  $ret = $path;

  $m = '';
  if (!preg_match('/\/$/',$path)) {
    $m = '/';
  } 
  $ret .= $m . $folder; 

  return $ret;
}

/**
 * Get Date format 
 *
 * @param $timestamp
 *   timestamp to be converted
 */
function getDateFormat($timestamp) {
  return date('Y-m-d', $timestamp);
}

/**
 * Get time format 
 *
 * @param $timestamp
 *   timestamp to be converted
 */
function getTimeFormat($timestamp) {   
  return date('G:i:s', $timestamp);
}

/* */

/**
 * Checks ARI dependencies
 */
function checkDependencies() {

  // check for PHP
  if (!version_compare(phpversion(), '4.3', '>=')) {
    echo _("ARI requires a version of PHP 4.3 or later");
    exit();
  }

  // check for PEAR
  $include_path = ini_get('include_path');
  $buf = split(':|,',$include_path);

  $found = 0;
  foreach ($buf as $path) {
    $path = fixPathSlash($path);
    $pear_check_path = $path . "DB.php";
    if (is_file($pear_check_path)) {
      $found = 1;
      break;
    }
  }

  if (!$found) {
    echo _("PHP PEAR must be installed.  Visit http://pear.php.net for help with installation.");
    exit();
  }
}

/**
 * Starts the session
 */
function startARISession() {

  if (!isset($_SESSION['ari_user']) ) {

    // start a new session for the user 
    ini_set('session.name', 'ARI');             // prevent session name clashes
    ini_set('session.gc_maxlifetime', '3900');  // make the session timeout a long time
    set_time_limit(360);
    session_start();
  }
}

/**
 * Bootstrap
 *
 * Loads critical variables needed for every page request
 *
 */
function bootstrap() {

  // set error reporting
  error_reporting (E_ALL & ~ E_NOTICE);  
}

/**
 * Set HTTP headers in preparation for a page response.
 *
 * TODO: Figure out caching
 */
function ariPageHeader() {

  bootstrap();
}

/**
 * Perform end-of-request tasks.
 *
 * This function sets the page cache if appropriate, and allows modules to
 * react to the closing of the page by calling hook_exit().
 */
function ariPageFooter() {

}

/**
 * Includes and run functions
 */

include_once("./includes/lang.php");
$language = new Language();
$language->set();

checkDependencies();
startARISession();
setARIRoot();

include_once("./includes/main.conf.php");
include_once("./version.php");
include_once("./includes/crypt.php"); 
include_once("./includes/login.php");


?>