8561dcc482e93e1f6870885841541bb315368864
bernd webinterface => /webinterface

bernd authored 17 years ago

1) <?php
2) 
bernd Logging aktiviert

bernd authored 16 years ago

3) require_once('inc/db_connect.php');
bernd add a function to handle re...

bernd authored 14 years ago

4) require_once('inc/debug.php');
bernd sql-abfragen abstrahiert

bernd authored 16 years ago

5) 
bernd Mehr config-optionen und co...

bernd authored 14 years ago

6) function config($key)
7) {
8)   global $config;
bernd Erlaube subusers, die nur Z...

bernd authored 13 years ago

9) 
10)   if ($key == 'modules' && isset($_SESSION['restrict_modules']))
11)   {
12)     $modules = array();
13)     foreach ($config['modules'] as $mod)
14)     {
15)       if (in_array($mod, $_SESSION['restrict_modules']))
16)         $modules[] = $mod;
17)     }
18)     return $modules;
19)   }
20) 
bernd config() liest die Datenban...

bernd authored 14 years ago

21)   if (array_key_exists($key, $config))
22)     return $config[$key];
23)   
24)   /* read configuration from database */
25)   $options = db_query( "SELECT `key`, value FROM misc.config" );
26)   
27)   while( $object = mysql_fetch_assoc( $options ) ) {
28) 	  $config[$object['key']]=$object['value'];
29)   }
bernd Passwort-Ändern geht jetzt...

bernd authored 13 years ago

30)   // Sonst wird das Passwort des webadmin-Users mit ausgegeben
31)   $debug_config = $config;
32)   unset($debug_config['db_pass']);
33)   DEBUG($debug_config);
bernd Mehr config-optionen und co...

bernd authored 14 years ago

34)   if (array_key_exists($key, $config))
35)     return $config[$key];
36)   else
bernd Logger mit Logleveln

bernd authored 14 years ago

37)     logger(LOG_ERR, "inc/base", "config", "Request to read nonexistant config option »{$key}«.");
bernd Einige Dummheiten repariert...

bernd authored 14 years ago

38)     return NULL;
bernd Mehr config-optionen und co...

bernd authored 14 years ago

39) }
40) 
bernd Info-Seite über Mail-Login-...

bernd authored 13 years ago

41) function get_server_by_id($id) {
42)   $id = (int) $id;
43)   $result = mysql_fetch_assoc(db_query("SELECT hostname FROM system.servers WHERE id='{$id}'"));
44)   return $result['hostname'];
45) }
46) 
bernd Mehr config-optionen und co...

bernd authored 14 years ago

47) 
bernd add a function to handle re...

bernd authored 14 years ago

48) function redirect($target)
49) {
50)   global $debugmode;
51)   if (! $debugmode)
52)     header("Location: {$target}");
53)   die();
54) }
55) 
56) 
bernd Hilfsfunktionen bzgl. mehre...

bernd authored 14 years ago

57) function my_server_id()
58) {
59)   $uid = (int) $_SESSION['userinfo']['uid'];
60)   $result = db_query("SELECT server FROM system.useraccounts WHERE uid={$uid}");
61)   $r = mysql_fetch_assoc($result);
62)   DEBUG($r);
63)   return $r['server'];
64) }
65) 
66) 
67) function additional_servers()
68) {
69)   $uid = (int) $_SESSION['userinfo']['uid'];
70)   $result = db_query("SELECT server FROM system.user_server WHERE uid={$uid}");
71)   $servers = array();
72)   while ($s = mysql_fetch_assoc($result))
73)     $servers[] = $s['server'];
74)   DEBUG($servers);
75)   return $servers;
76) }
77) 
78) 
79) function server_names()
80) {
81)   $result = db_query("SELECT id, hostname FROM system.servers");
82)   $servers = array();
83)   while ($s = mysql_fetch_assoc($result))
84)     $servers[$s['id']] = $s['hostname'];
85)   DEBUG($servers);
86)   return $servers;
87) }
88) 
89) 
bernd sql-abfragen abstrahiert

bernd authored 16 years ago

90) function db_query($query)
91) {
92)   DEBUG($query);
93)   $result = @mysql_query($query);
94)   if (mysql_error())
95)   {
96)     $error = mysql_error();
bernd Logger mit Logleveln

bernd authored 14 years ago

97)     logger(LOG_ERR, "inc/base", "dberror", "mysql error: {$error}");
bernd MySQL-Fehler kommen als Lat...

bernd authored 16 years ago

98)     system_failure('Interner Datenbankfehler: »'.iconv('ISO-8859-1', 'UTF-8', $error).'«.');
bernd sql-abfragen abstrahiert

bernd authored 16 years ago

99)   }
bernd * wie viele Reihen wurden a...

bernd authored 15 years ago

100)   $count = @mysql_num_rows($result);
101)   if (! $count)
102)     $count = 'no';
103)   DEBUG("=> {$count} rows");
bernd sql-abfragen abstrahiert

bernd authored 16 years ago

104)   return $result; 
105) }
106) 
107) 
bernd Neues Modul für "Kunde werden"

bernd authored 16 years ago

108) 
109) function maybe_null($value)
110) {
bernd maybe_null behandelt jetzt...

bernd authored 14 years ago

111)   if ($value == NULL)
112)     return 'NULL';
113) 
bernd Neues Modul für "Kunde werden"

bernd authored 16 years ago

114)   if (strlen( (string) $value ) > 0)
bernd Strings für mysql esapen (z...

bernd authored 16 years ago

115)     return "'".mysql_real_escape_string($value)."'";
bernd Neues Modul für "Kunde werden"

bernd authored 16 years ago

116)   else
117)     return 'NULL';
118) }
119) 
bernd Logger mit Logleveln

bernd authored 14 years ago

120) #define('LOG_ERR', 3);
121) #define('LOG_WARNING', 4);
122) #define('LOG_INFO', 6);
bernd Neues Modul für "Kunde werden"

bernd authored 16 years ago

123) 
bernd Logger mit Logleveln

bernd authored 14 years ago

124) function logger($severity, $scriptname, $scope, $message)
bernd Logging aktiviert

bernd authored 16 years ago

125) {
bernd Logger mit Logleveln

bernd authored 14 years ago

126)   if (config('logging') <= $severity)
bernd Logging konfigurierbar

bernd authored 16 years ago

127)     return;
128) 
bernd Logging aktiviert

bernd authored 16 years ago

129)   $user = 'NULL';
bernd Bugfix: Logger zeigt wieder...

bernd authored 16 years ago

130)   if ($_SESSION['role'] & ROLE_SYSTEMUSER)
bernd Logging aktiviert

bernd authored 16 years ago

131)     $user = "'{$_SESSION['userinfo']['username']}'";
bernd Bugfix: Logger zeigt wieder...

bernd authored 16 years ago

132)   elseif ($_SESSION['role'] & ROLE_CUSTOMER)
bernd Logging aktiviert

bernd authored 16 years ago

133)     $user = "'{$_SESSION['customerinfo']['customerno']}'";
134)   
135)   $remote = mysql_real_escape_string($_SERVER['REMOTE_ADDR']);
136) 
137)   $scriptname = mysql_real_escape_string($scriptname);
138)   $scope = mysql_real_escape_string($scope);
139)   $message = mysql_real_escape_string($message);
140) 
bernd sql-abfragen abstrahiert

bernd authored 16 years ago

141)   db_query("INSERT INTO misc.scriptlog (remote, user,scriptname,scope,message) VALUES ('{$remote}', {$user}, '{$scriptname}', '{$scope}', '{$message}');");
bernd Logging aktiviert

bernd authored 16 years ago

142) }
143) 
bernd Allow Header entries and AJAX

bernd authored 15 years ago

144) function html_header($arg)
145) {
146)   global $html_header;
147)   $html_header .= $arg;
148) }
bernd Logging aktiviert

bernd authored 16 years ago

149) 
bernd Umstellung auf Theme-Suppor...

bernd authored 13 years ago

150) function title($arg)
151) {
152)   global $title;
153)   $title = $arg;
154) }
155) 
156) function headline($arg)
157) {
158)   global $headline;
159)   $headline = $arg;
160) }
161) 
bernd webinterface => /webinterface

bernd authored 17 years ago

162) function output($arg)
163) {
164)   global $output;
165)   $output .= $arg;
166) }
167) 
168) 
169) function random_string($nc, $a='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789') {
170)     $l=strlen($a)-1; $r='';
171)     while($nc-->0) $r.=$a{mt_rand(0,$l)};
172)     return $r;
173)  }
174) 
175) 
176) function are_you_sure($query_string, $question)
177) {
bernd * alle internen Links sinnv...

bernd authored 15 years ago

178)   $query_string = encode_querystring($query_string);
bernd webinterface => /webinterface

bernd authored 17 years ago

179)   $token = random_string(20);
bernd XSRF-kram fixed

bernd authored 16 years ago

180)   $_SESSION['are_you_sure_token'] = $token;
bernd Benutze überall title() sta...

bernd authored 13 years ago

181)   title('Sicherheitsabfrage');
182)   output("
bernd * alle internen Links sinnv...

bernd authored 15 years ago

183)     <form action=\"{$query_string}\" method=\"post\">
bernd Umfangreiche Code-Aufräumar...

bernd authored 16 years ago

184)     <div class=\"confirmation\">
185)       <div class=\"question\">{$question}</div>
186)       <p class=\"buttons\">
187)         <input type=\"hidden\" name=\"random_token\" value=\"{$token}\" />
188)         <input type=\"submit\" name=\"really\" value=\"Ja\" />
bernd Entities repariert

bernd authored 16 years ago

189)         &#160; &#160;
bernd Umfangreiche Code-Aufräumar...

bernd authored 16 years ago

190)         <input type=\"submit\" name=\"not_really\" value=\"Nein\" />
191)       </p>
192)     </div>");
bernd </form>

bernd authored 16 years ago

193)   output("</form>\n");
bernd webinterface => /webinterface

bernd authored 17 years ago

194) }
195) 
196) 
197) function user_is_sure()
198) {
199)   if (isset($_POST['really']))
200)   {
bernd XSRF-kram fixed

bernd authored 16 years ago

201)     if ($_POST['random_token'] == $_SESSION['are_you_sure_token'])
bernd webinterface => /webinterface

bernd authored 17 years ago

202)       return true;
203)     else
204)       system_failure("Possible Cross-site-request-forgery detected!");
205)   }
206)   elseif (isset($_POST['not_really']))
207)     return false;
208)   else
209)     return NULL;
210) }
211) 
212) 
213) 
bernd XSRF-kram fixed

bernd authored 16 years ago

214) function generate_form_token($form_id)
215) {
216)   require_once("inc/debug.php");
217)   $sessid = session_id();
218)   if ($sessid == "") 
219)   {
220)     DEBUG("Uh? Session not running? Wtf?");
bernd Neues Jabber-Modul (noch ni...

bernd authored 16 years ago

221)     system_failure("Internal error!");
bernd XSRF-kram fixed

bernd authored 16 years ago

222)   }
223)   if (! isset($_SESSION['session_token']))
224)     $_SESSION['session_token'] = random_string(10);
bernd Umfangreiche Code-Aufräumar...

bernd authored 16 years ago

225)   return hash('sha256', $sessid.$form_id.$_SESSION['session_token']);
bernd XSRF-kram fixed

bernd authored 16 years ago

226) }
227) 
228) 
bernd Umfangreiche Code-Aufräumar...

bernd authored 16 years ago

229) function check_form_token($form_id, $formtoken = NULL)
bernd XSRF-kram fixed

bernd authored 16 years ago

230) {
bernd Umfangreiche Code-Aufräumar...

bernd authored 16 years ago

231)   if ($formtoken == NULL)
232)     $formtoken = $_POST['formtoken'];
bernd XSRF-kram fixed

bernd authored 16 years ago

233)   $sessid = session_id();
234)   if ($sessid == "") 
235)   {
236)     DEBUG("Uh? Session not running? Wtf?");
bernd Umfangreiche Code-Aufräumar...

bernd authored 16 years ago

237)     system_failure("Internal error! (Session not running)");
bernd XSRF-kram fixed

bernd authored 16 years ago

238)   }
239) 
bernd Neues Jabber-Modul (noch ni...

bernd authored 16 years ago

240)   $correct_formtoken = hash('sha256', $sessid.$form_id.$_SESSION['session_token']);
bernd XSRF-kram fixed

bernd authored 16 years ago

241) 
242)   if (! ($formtoken == $correct_formtoken))
243)     system_failure("Possible cross-site-request-forgery!");
244) }
245) 
bernd Neues Jabber-Modul (noch ni...

bernd authored 16 years ago

246) 
bernd Zeige Links auf dem Startse...

bernd authored 14 years ago

247) function have_module($modname)
248) {
bernd Mehr config-optionen und co...

bernd authored 14 years ago

249)   return in_array($modname, config('modules'));
bernd Zeige Links auf dem Startse...

bernd authored 14 years ago

250) }
251) 
252) 
bernd * alle internen Links sinnv...

bernd authored 15 years ago

253) function encode_querystring($querystring)
bernd Neues Jabber-Modul (noch ni...

bernd authored 16 years ago

254) {
255)   global $debugmode;
256)   if ($debugmode)
bernd * alle internen Links sinnv...

bernd authored 15 years ago

257)     $querystring = 'debug&'.$querystring;
bernd Bug im Client-Zertfikat-Man...

bernd authored 15 years ago

258)   DEBUG($querystring);
bernd * alle internen Links sinnv...

bernd authored 15 years ago

259)   $query = explode('&', $querystring);
260)   $new_query = array();
261)   foreach ($query AS $item)
262)     if ($item != '')
263)     {
bernd fix a warning

bernd authored 14 years ago

264)       $split = explode('=', $item, 2);
265)       if (count($split) == 1)
266)         $new_query[] = $split[0];
bernd Bug im Client-Zertfikat-Man...

bernd authored 15 years ago

267)       else
bernd fix a warning

bernd authored 14 years ago

268)         $new_query[] = $split[0].'='.urlencode($split[1]);
bernd * alle internen Links sinnv...

bernd authored 15 years ago

269)     }
270)   $querystring = implode('&amp;', $new_query);
271)   if ($querystring)
272)     $querystring = '?'.$querystring;
bernd Bug im Client-Zertfikat-Man...

bernd authored 15 years ago

273)   DEBUG($querystring);
bernd * alle internen Links sinnv...

bernd authored 15 years ago

274)   return $querystring;
275) }
bernd Neues Jabber-Modul (noch ni...

bernd authored 16 years ago

276) 
bernd * alle internen Links sinnv...

bernd authored 15 years ago

277) 
bernd addnew() eingeführt

bernd authored 14 years ago

278) function addnew($file, $label, $querystring = '')
279) {
bernd Parameter querystring bei a...

bernd authored 14 years ago

280)   output('<p class="addnew">'.internal_link($file, $label, $querystring).'</p>');
bernd addnew() eingeführt

bernd authored 14 years ago

281) }
282) 
bernd * alle internen Links sinnv...

bernd authored 15 years ago

283) 
284) function internal_link($file, $label, $querystring = '', $attribs = '')
285) {
bernd Erlaube absolute Links

bernd authored 14 years ago

286)   global $prefix;
bernd Das böse ==0

bernd authored 14 years ago

287)   if (strpos($file, '/') === 0)
bernd Erlaube absolute Links

bernd authored 14 years ago

288)   {
289)     $file = $prefix.substr($file, 1);
290)   }
bernd * alle internen Links sinnv...

bernd authored 15 years ago

291)   $querystring = encode_querystring($querystring);
292)   return "<a href=\"{$file}{$querystring}\" {$attribs} >{$label}</a>";
bernd Neues Jabber-Modul (noch ni...

bernd authored 16 years ago

293) }
294) 
295) 
296) function html_form($form_id, $scriptname, $querystring, $content)
297) {
bernd * alle internen Links sinnv...

bernd authored 15 years ago

298)   $querystring = encode_querystring($querystring);
bernd Neues Jabber-Modul (noch ni...

bernd authored 16 years ago

299)   $ret = '';
bernd * alle internen Links sinnv...

bernd authored 15 years ago

300)   $ret .= '<form action="'.$scriptname.$querystring.'" method="post">'."\n";
bernd Umfangreiche Code-Aufräumar...

bernd authored 16 years ago

301)   $ret .= '<p style="display: none;"><input type="hidden" name="formtoken" value="'.generate_form_token($form_id).'" /></p>'."\n";
bernd Neues Jabber-Modul (noch ni...

bernd authored 16 years ago

302)   $ret .= $content;
303)   $ret .= '</form>';
304)   return $ret;  
305) }
306) 
307) 
bernd * wie viele Reihen wurden a...

bernd authored 15 years ago

308) function html_select($name, $options, $default='', $free='')
bernd Neues Modul für "Kunde werden"

bernd authored 16 years ago

309) {
310)   require_once('inc/security.php');
bernd * wie viele Reihen wurden a...

bernd authored 15 years ago

311)   $ret = "<select name=\"{$name}\" id=\"{$name}\" size=\"1\" {$free} >\n";
bernd Neues Modul für "Kunde werden"

bernd authored 16 years ago

312)   foreach ($options as $key => $value)
313)   {
314)     $selected = '';
315)     if ($default == $key)
316)       $selected = ' selected="selected" ';
317)     $key = filter_input_general($key);
318)     $value = filter_input_general($value);
319)     $ret .= "  <option value=\"{$key}\"{$selected}>{$value}</option>\n";
320)   }
321)   $ret .= '</select>';
322)   return $ret;
323) }
324) 
bernd Neues Jabber-Modul (noch ni...

bernd authored 16 years ago

325) 
326)