c208bd906b3991555db11b9229846c4601ca408c
bernd webinterface => /webinterface

bernd authored 17 years ago

1) <?php
Bernd Wurst Added license tags for CC0,...

Bernd Wurst authored 12 years ago

2) /*
3) This file belongs to the Webinterface of schokokeks.org Hosting
4) 
5) Written 2008-2012 by schokokeks.org Hosting, namely
6)   Bernd Wurst <bernd@schokokeks.org>
7)   Hanno Böck <hanno@schokokeks.org>
8) 
9) To the extent possible under law, the author(s) have dedicated all copyright and related and neighboring rights to this software to the public domain worldwide. This software is distributed without any warranty.
10) 
11) You should have received a copy of the CC0 Public Domain Dedication along with this software. If not, see 
12) http://creativecommons.org/publicdomain/zero/1.0/
13) 
14) Nevertheless, in case you use a significant part of this code, we ask (but not require, see the license) that you keep the authors' names in place and return your changes to the public. We would be especially happy if you tell us what you're going to do with this code.
15) */
bernd webinterface => /webinterface

bernd authored 17 years ago

16) 
bernd Logging aktiviert

bernd authored 16 years ago

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

bernd authored 14 years ago

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

bernd authored 16 years ago

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

bernd authored 14 years ago

20) function config($key)
21) {
22)   global $config;
bernd Erlaube subusers, die nur Z...

bernd authored 13 years ago

23) 
24)   if ($key == 'modules' && isset($_SESSION['restrict_modules']))
25)   {
26)     $modules = array();
27)     foreach ($config['modules'] as $mod)
28)     {
29)       if (in_array($mod, $_SESSION['restrict_modules']))
30)         $modules[] = $mod;
31)     }
32)     return $modules;
33)   }
34) 
bernd config() liest die Datenban...

bernd authored 14 years ago

35)   if (array_key_exists($key, $config))
36)     return $config[$key];
37)   
38)   /* read configuration from database */
39)   $options = db_query( "SELECT `key`, value FROM misc.config" );
40)   
41)   while( $object = mysql_fetch_assoc( $options ) ) {
42) 	  $config[$object['key']]=$object['value'];
43)   }
bernd Passwort-Ändern geht jetzt...

bernd authored 13 years ago

44)   // Sonst wird das Passwort des webadmin-Users mit ausgegeben
45)   $debug_config = $config;
46)   unset($debug_config['db_pass']);
47)   DEBUG($debug_config);
bernd Mehr config-optionen und co...

bernd authored 14 years ago

48)   if (array_key_exists($key, $config))
49)     return $config[$key];
50)   else
bernd Logger mit Logleveln

bernd authored 14 years ago

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

bernd authored 14 years ago

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

bernd authored 14 years ago

53) }
54) 
bernd Info-Seite über Mail-Login-...

bernd authored 13 years ago

55) function get_server_by_id($id) {
56)   $id = (int) $id;
57)   $result = mysql_fetch_assoc(db_query("SELECT hostname FROM system.servers WHERE id='{$id}'"));
58)   return $result['hostname'];
59) }
60) 
bernd Mehr config-optionen und co...

bernd authored 14 years ago

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

bernd authored 14 years ago

62) function redirect($target)
63) {
64)   global $debugmode;
65)   if (! $debugmode)
66)     header("Location: {$target}");
67)   die();
68) }
69) 
70) 
bernd Hilfsfunktionen bzgl. mehre...

bernd authored 14 years ago

71) function my_server_id()
72) {
73)   $uid = (int) $_SESSION['userinfo']['uid'];
74)   $result = db_query("SELECT server FROM system.useraccounts WHERE uid={$uid}");
75)   $r = mysql_fetch_assoc($result);
76)   DEBUG($r);
77)   return $r['server'];
78) }
79) 
80) 
81) function additional_servers()
82) {
83)   $uid = (int) $_SESSION['userinfo']['uid'];
84)   $result = db_query("SELECT server FROM system.user_server WHERE uid={$uid}");
85)   $servers = array();
86)   while ($s = mysql_fetch_assoc($result))
87)     $servers[] = $s['server'];
88)   DEBUG($servers);
89)   return $servers;
90) }
91) 
92) 
93) function server_names()
94) {
95)   $result = db_query("SELECT id, hostname FROM system.servers");
96)   $servers = array();
97)   while ($s = mysql_fetch_assoc($result))
98)     $servers[$s['id']] = $s['hostname'];
99)   DEBUG($servers);
100)   return $servers;
101) }
102) 
103) 
bernd sql-abfragen abstrahiert

bernd authored 16 years ago

104) function db_query($query)
105) {
106)   DEBUG($query);
107)   $result = @mysql_query($query);
108)   if (mysql_error())
109)   {
110)     $error = mysql_error();
bernd Logger mit Logleveln

bernd authored 14 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 15 years ago

114)   $count = @mysql_num_rows($result);
115)   if (! $count)
116)     $count = 'no';
117)   DEBUG("=> {$count} rows");
bernd sql-abfragen abstrahiert

bernd authored 16 years ago

118)   return $result; 
119) }
120) 
121) 
bernd Neues Modul für "Kunde werden"

bernd authored 16 years ago

122) 
123) function maybe_null($value)
124) {
bernd maybe_null behandelt jetzt...

bernd authored 14 years ago

125)   if ($value == NULL)
126)     return 'NULL';
127) 
bernd Neues Modul für "Kunde werden"

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

130)   else
131)     return 'NULL';
132) }
133) 
bernd Logger mit Logleveln

bernd authored 14 years ago

134) #define('LOG_ERR', 3);
135) #define('LOG_WARNING', 4);
136) #define('LOG_INFO', 6);
bernd Neues Modul für "Kunde werden"

bernd authored 16 years ago

137) 
bernd Logger mit Logleveln

bernd authored 14 years ago

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

bernd authored 16 years ago

139) {
bernd Logger mit Logleveln

bernd authored 14 years ago

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

bernd authored 16 years ago

141)     return;
142) 
bernd Logging aktiviert

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

147)     $user = "'{$_SESSION['customerinfo']['customerno']}'";
148)   
149)   $remote = mysql_real_escape_string($_SERVER['REMOTE_ADDR']);
150) 
151)   $scriptname = mysql_real_escape_string($scriptname);
152)   $scope = mysql_real_escape_string($scope);
153)   $message = mysql_real_escape_string($message);
154) 
bernd sql-abfragen abstrahiert

bernd authored 16 years ago

155)   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

156) }
157) 
bernd Allow Header entries and AJAX

bernd authored 15 years ago

158) function html_header($arg)
159) {
160)   global $html_header;
161)   $html_header .= $arg;
162) }
bernd Logging aktiviert

bernd authored 16 years ago

163) 
bernd Umstellung auf Theme-Suppor...

bernd authored 13 years ago

164) function title($arg)
165) {
166)   global $title;
167)   $title = $arg;
168) }
169) 
170) function headline($arg)
171) {
172)   global $headline;
173)   $headline = $arg;
174) }
175) 
bernd webinterface => /webinterface

bernd authored 17 years ago

176) function output($arg)
177) {
178)   global $output;
179)   $output .= $arg;
180) }
181) 
182) 
183) function random_string($nc, $a='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789') {
184)     $l=strlen($a)-1; $r='';
185)     while($nc-->0) $r.=$a{mt_rand(0,$l)};
186)     return $r;
187)  }
188) 
189) 
190) function are_you_sure($query_string, $question)
191) {
bernd * alle internen Links sinnv...

bernd authored 15 years ago

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

bernd authored 17 years ago

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

bernd authored 16 years ago

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

bernd authored 13 years ago

195)   title('Sicherheitsabfrage');
196)   output("
bernd * alle internen Links sinnv...

bernd authored 15 years ago

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

bernd authored 16 years ago

198)     <div class=\"confirmation\">
199)       <div class=\"question\">{$question}</div>
200)       <p class=\"buttons\">
201)         <input type=\"hidden\" name=\"random_token\" value=\"{$token}\" />
202)         <input type=\"submit\" name=\"really\" value=\"Ja\" />
bernd Entities repariert

bernd authored 16 years ago

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

bernd authored 16 years ago

204)         <input type=\"submit\" name=\"not_really\" value=\"Nein\" />
205)       </p>
206)     </div>");
bernd </form>

bernd authored 16 years ago

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

bernd authored 17 years ago

208) }
209) 
210) 
211) function user_is_sure()
212) {
213)   if (isset($_POST['really']))
214)   {
bernd XSRF-kram fixed

bernd authored 16 years ago

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

bernd authored 17 years ago

216)       return true;
217)     else
218)       system_failure("Possible Cross-site-request-forgery detected!");
219)   }
220)   elseif (isset($_POST['not_really']))
221)     return false;
222)   else
223)     return NULL;
224) }
225) 
226) 
227) 
bernd XSRF-kram fixed

bernd authored 16 years ago

228) function generate_form_token($form_id)
229) {
230)   require_once("inc/debug.php");
231)   $sessid = session_id();
232)   if ($sessid == "") 
233)   {
234)     DEBUG("Uh? Session not running? Wtf?");
bernd Neues Jabber-Modul (noch ni...

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

240) }
241) 
242) 
bernd Umfangreiche Code-Aufräumar...

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

247)   $sessid = session_id();
248)   if ($sessid == "") 
249)   {
250)     DEBUG("Uh? Session not running? Wtf?");
bernd Umfangreiche Code-Aufräumar...

bernd authored 16 years ago

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

bernd authored 16 years ago

252)   }
253) 
bernd Neues Jabber-Modul (noch ni...

bernd authored 16 years ago

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

bernd authored 16 years ago

255) 
256)   if (! ($formtoken == $correct_formtoken))
257)     system_failure("Possible cross-site-request-forgery!");
258) }
259) 
bernd Neues Jabber-Modul (noch ni...

bernd authored 16 years ago

260) 
bernd Zeige Links auf dem Startse...

bernd authored 14 years ago

261) function have_module($modname)
262) {
bernd Mehr config-optionen und co...

bernd authored 14 years ago

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

bernd authored 14 years ago

264) }
265) 
266) 
bernd * alle internen Links sinnv...

bernd authored 15 years ago

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

bernd authored 16 years ago

268) {
269)   global $debugmode;
270)   if ($debugmode)
bernd * alle internen Links sinnv...

bernd authored 15 years ago

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

bernd authored 14 years ago

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

bernd authored 15 years ago

273)   $query = explode('&', $querystring);
274)   $new_query = array();
275)   foreach ($query AS $item)
276)     if ($item != '')
277)     {
bernd fix a warning

bernd authored 14 years ago

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

bernd authored 14 years ago

281)       else
bernd fix a warning

bernd authored 14 years ago

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

bernd authored 15 years ago

283)     }
284)   $querystring = implode('&amp;', $new_query);
285)   if ($querystring)
286)     $querystring = '?'.$querystring;
bernd Bug im Client-Zertfikat-Man...

bernd authored 14 years ago

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

bernd authored 15 years ago

288)   return $querystring;
289) }
bernd Neues Jabber-Modul (noch ni...

bernd authored 16 years ago

290) 
bernd * alle internen Links sinnv...

bernd authored 15 years ago

291) 
bernd addnew() eingeführt

bernd authored 14 years ago

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

bernd authored 14 years ago

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

bernd authored 14 years ago

295) }
296) 
bernd * alle internen Links sinnv...

bernd authored 15 years ago

297) 
298) function internal_link($file, $label, $querystring = '', $attribs = '')
299) {
bernd Erlaube absolute Links

bernd authored 14 years ago

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

bernd authored 14 years ago

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

bernd authored 14 years ago

302)   {
303)     $file = $prefix.substr($file, 1);
304)   }
bernd * alle internen Links sinnv...

bernd authored 15 years ago

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

bernd authored 16 years ago

307) }
308) 
309) 
310) function html_form($form_id, $scriptname, $querystring, $content)
311) {
bernd * alle internen Links sinnv...

bernd authored 15 years ago

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

bernd authored 16 years ago

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

bernd authored 15 years ago

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

bernd authored 16 years ago

315)   $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

316)   $ret .= $content;
317)   $ret .= '</form>';
318)   return $ret;  
319) }
320) 
321) 
bernd * wie viele Reihen wurden a...

bernd authored 15 years ago

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

bernd authored 16 years ago

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

bernd authored 15 years ago

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

bernd authored 16 years ago

326)   foreach ($options as $key => $value)
327)   {
328)     $selected = '';
329)     if ($default == $key)
330)       $selected = ' selected="selected" ';
331)     $key = filter_input_general($key);
332)     $value = filter_input_general($value);
333)     $ret .= "  <option value=\"{$key}\"{$selected}>{$value}</option>\n";
334)   }
335)   $ret .= '</select>';
336)   return $ret;
337) }
338) 
bernd Neues Jabber-Modul (noch ni...

bernd authored 16 years ago

339) 
bernd Neue Funktion zur Anzeige e...

bernd authored 12 years ago

340) function html_datepicker($nameprefix, $timestamp)
341) {
342)   $valid_days = array( 1 =>  1,  2 =>  2,  3 =>  3,  4 =>  4,  5 =>  5,
343)                        6 =>  6,  7 =>  7,  8 =>  8,  9 =>  9, 10 => 10,
344)                       11 => 11, 12 => 12, 13 => 13, 14 => 14, 15 => 15,
345)                       16 => 16, 17 => 17, 18 => 18, 19 => 19, 20 => 20,
346)                       21 => 21, 22 => 22, 23 => 23, 24 => 24, 25 => 25,
347)                       26 => 26, 27 => 27, 28 => 28, 29 => 29, 30 => 30,
348)                       31 => 31);
349)   $valid_months = array( 1 =>  1,  2 =>  2,  3 =>  3,  4 =>  4,  5 =>  5,
350)                          6 =>  6,  7 =>  7,  8 =>  8,  9 =>  9, 10 => 10,
351)                         11 => 11, 12 => 12);
bernd Datums-Check und Daten in u...

bernd authored 12 years ago

352)   $current_year = (int) date('Y');
353)   $valid_years = array($current_year => $current_year, 
354)                        $current_year+1 => $current_year+1,
355)                        $current_year+2 => $current_year+2,
356)                        $current_year+3 => $current_year+3,
357)                        $current_year+4 => $current_year+4);
358)               
bernd Neue Funktion zur Anzeige e...

bernd authored 12 years ago

359)   $selected_day = date('d', $timestamp);
360)   $selected_month = date('m', $timestamp);
361)   $selected_year = date('Y', $timestamp);
362)   $ret = '';
363)   $ret .= html_select($nameprefix.'_day', $valid_days, $selected_day, 'style="text-align: right;"').". ";
364)   $ret .= html_select($nameprefix.'_month', $valid_months, $selected_month, 'style="text-align: right;"').". ";
bernd Datums-Check und Daten in u...

bernd authored 12 years ago

365)   $ret .= html_select($nameprefix.'_year', $valid_years, $selected_year);
bernd Neue Funktion zur Anzeige e...

bernd authored 12 years ago

366)   return $ret;
367) }
368) 
bernd Index-Blöcke werden jetzt v...

bernd authored 12 years ago

369) function get_modules_info() 
370) {
371)   $modules = config('modules');
372)   $modconfig = array();
373)   foreach ($modules AS $name) {
374)     $modconfig[$name] = NULL;
375)     if (file_exists('modules/'.$name.'/module.info')) {
376)       $modconfig[$name] = parse_ini_file('modules/'.$name.'/module.info');
377)     }
378)   }
379)   return $modconfig;
380) }
381) 
382) 
bernd Neues Jabber-Modul (noch ni...

bernd authored 16 years ago

383)