5effc2bd7685822df276c1372dab480cff321941
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) 
Bernd Wurst Lizenzinfos in eigenes Modu...

Bernd Wurst authored 10 years ago

5) Written 2008-2014 by schokokeks.org Hosting, namely
Bernd Wurst Added license tags for CC0,...

Bernd Wurst authored 12 years ago

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 Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

17) require_once('class/database.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) 
schokokeks.org web services Ermögliche Socket-Angabe fü...

schokokeks.org web services authored 10 years ago

20) function config($key, $localonly = false)
bernd Mehr config-optionen und co...

bernd authored 14 years ago

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

bernd authored 13 years ago

23) 
Bernd Wurst Lizenzinfos in eigenes Modu...

Bernd Wurst authored 10 years ago

24)   if ($key == "modules") {
25)     // Stelle sicher, dass das "index"-Modul immer aktiv ist!
26)     if (! in_array("index", $config['modules'])) {
27)       $config['modules'][] = "index";
28)     }
29)     // Stelle sicher, dass das "about"-Modul immer aktiv ist!
30)     if (! in_array("about", $config['modules'])) {
31)       $config['modules'][] = "about";
32)     }
33)   }
34) 
bernd Erlaube subusers, die nur Z...

bernd authored 13 years ago

35)   if ($key == 'modules' && isset($_SESSION['restrict_modules']))
36)   {
37)     $modules = array();
38)     foreach ($config['modules'] as $mod)
39)     {
40)       if (in_array($mod, $_SESSION['restrict_modules']))
41)         $modules[] = $mod;
42)     }
43)     return $modules;
44)   }
45) 
bernd config() liest die Datenban...

bernd authored 14 years ago

46)   if (array_key_exists($key, $config))
47)     return $config[$key];
48)   
schokokeks.org web services Ermögliche Socket-Angabe fü...

schokokeks.org web services authored 10 years ago

49)   if ($localonly) {
50)     return NULL;
51)   }  
52) 
bernd config() liest die Datenban...

bernd authored 14 years ago

53)   /* read configuration from database */
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

54)   $result = db_query( "SELECT `key`, value FROM misc.config" );
bernd config() liest die Datenban...

bernd authored 14 years ago

55)   
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

56)   while( $object = $result->fetch() ) {
schokokeks.org web services Config-File-Optionen werden...

schokokeks.org web services authored 10 years ago

57)     if (!array_key_exists($object['key'], $config)) {
Bernd Wurst Revert "Umstellung auf mysqli"

Bernd Wurst authored 10 years ago

58) 	    $config[$object['key']]=$object['value'];
schokokeks.org web services Config-File-Optionen werden...

schokokeks.org web services authored 10 years ago

59)     }
bernd config() liest die Datenban...

bernd authored 14 years ago

60)   }
bernd Passwort-Ändern geht jetzt...

bernd authored 13 years ago

61)   // Sonst wird das Passwort des webadmin-Users mit ausgegeben
62)   $debug_config = $config;
63)   unset($debug_config['db_pass']);
64)   DEBUG($debug_config);
bernd Mehr config-optionen und co...

bernd authored 14 years ago

65)   if (array_key_exists($key, $config))
66)     return $config[$key];
67)   else
bernd Logger mit Logleveln

bernd authored 14 years ago

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

bernd authored 14 years ago

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

bernd authored 14 years ago

70) }
71) 
bernd Info-Seite über Mail-Login-...

bernd authored 13 years ago

72) function get_server_by_id($id) {
73)   $id = (int) $id;
Bernd Wurst Weitere Prepared-Statement-...

Bernd Wurst authored 10 years ago

74)   $result = db_query("SELECT hostname FROM system.servers WHERE id=?", array($id));
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

75)   $ret = $result->fetch();
76)   return $ret['hostname'];
bernd Info-Seite über Mail-Login-...

bernd authored 13 years ago

77) }
78) 
bernd Mehr config-optionen und co...

bernd authored 14 years ago

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

bernd authored 14 years ago

80) function redirect($target)
81) {
82)   global $debugmode;
83)   if (! $debugmode)
84)     header("Location: {$target}");
85)   die();
86) }
87) 
88) 
bernd Hilfsfunktionen bzgl. mehre...

bernd authored 14 years ago

89) function my_server_id()
90) {
91)   $uid = (int) $_SESSION['userinfo']['uid'];
Bernd Wurst Einige Statements auf Prepa...

Bernd Wurst authored 10 years ago

92)   $result = db_query("SELECT server FROM system.useraccounts WHERE uid=?", array($uid));
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

93)   $r = $result->fetch();
bernd Hilfsfunktionen bzgl. mehre...

bernd authored 14 years ago

94)   DEBUG($r);
95)   return $r['server'];
96) }
97) 
98) 
99) function additional_servers()
100) {
101)   $uid = (int) $_SESSION['userinfo']['uid'];
Bernd Wurst Einige Statements auf Prepa...

Bernd Wurst authored 10 years ago

102)   $result = db_query("SELECT server FROM system.user_server WHERE uid=?", array($uid));
bernd Hilfsfunktionen bzgl. mehre...

bernd authored 14 years ago

103)   $servers = array();
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

104)   while ($s = $result->fetch())
bernd Hilfsfunktionen bzgl. mehre...

bernd authored 14 years ago

105)     $servers[] = $s['server'];
106)   DEBUG($servers);
107)   return $servers;
108) }
109) 
110) 
111) function server_names()
112) {
Bernd Wurst Revert "Umstellung auf mysqli"

Bernd Wurst authored 10 years ago

113)   $result = db_query("SELECT id, hostname FROM system.servers");
bernd Hilfsfunktionen bzgl. mehre...

bernd authored 14 years ago

114)   $servers = array();
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

115)   while ($s = $result->fetch())
bernd Hilfsfunktionen bzgl. mehre...

bernd authored 14 years ago

116)     $servers[$s['id']] = $s['hostname'];
117)   DEBUG($servers);
118)   return $servers;
119) }
120) 
121) 
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

122) // FIXME
123) // Diese Funktion funktioniert nicht für preprared statements
bernd Neues Modul für "Kunde werden"

bernd authored 16 years ago

124) function maybe_null($value)
125) {
Bernd Wurst * Weitere Module auf prepar...

Bernd Wurst authored 10 years ago

126)   if (config("enable_debug")) {
127)     $backtrace = debug_backtrace();
128)     warning("call to maybe_null() in {$backtrace[1]['file']} line {$backtrace[1]['line']}");
129)   }
bernd maybe_null behandelt jetzt...

bernd authored 15 years ago

130)   if ($value == NULL)
131)     return 'NULL';
132) 
bernd Neues Modul für "Kunde werden"

bernd authored 16 years ago

133)   if (strlen( (string) $value ) > 0)
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

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

bernd authored 16 years ago

135)   else
136)     return 'NULL';
137) }
138) 
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

139) 
bernd Logger mit Logleveln

bernd authored 14 years ago

140) #define('LOG_ERR', 3);
141) #define('LOG_WARNING', 4);
142) #define('LOG_INFO', 6);
bernd Neues Modul für "Kunde werden"

bernd authored 16 years ago

143) 
bernd Logger mit Logleveln

bernd authored 14 years ago

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

bernd authored 16 years ago

145) {
bernd Logger mit Logleveln

bernd authored 14 years ago

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

bernd authored 16 years ago

147)     return;
148) 
Bernd Wurst * Weitere Module auf prepar...

Bernd Wurst authored 10 years ago

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

bernd authored 16 years ago

150)   if ($_SESSION['role'] & ROLE_SYSTEMUSER)
Bernd Wurst * Weitere Module auf prepar...

Bernd Wurst authored 10 years ago

151)     $user = $_SESSION['userinfo']['username'];
bernd Bugfix: Logger zeigt wieder...

bernd authored 16 years ago

152)   elseif ($_SESSION['role'] & ROLE_CUSTOMER)
Bernd Wurst * Weitere Module auf prepar...

Bernd Wurst authored 10 years ago

153)     $user = $_SESSION['customerinfo']['customerno'];
bernd Logging aktiviert

bernd authored 16 years ago

154)   
Bernd Wurst * Weitere Module auf prepar...

Bernd Wurst authored 10 years ago

155)   $args = array(":user" => $user,
156)                 ":remote" => $_SERVER['REMOTE_ADDR'],
157)                 ":scriptname" => $scriptname,
158)                 ":scope" => $scope,
159)                 ":message" => $message);
bernd Logging aktiviert

bernd authored 16 years ago

160) 
Bernd Wurst * Weitere Module auf prepar...

Bernd Wurst authored 10 years ago

161)   db_query("INSERT INTO misc.scriptlog (remote, user,scriptname,scope,message) VALUES (:remote, :user, :scriptname, :scope, :message)", $args);
bernd Logging aktiviert

bernd authored 16 years ago

162) }
163) 
bernd Allow Header entries and AJAX

bernd authored 15 years ago

164) function html_header($arg)
165) {
166)   global $html_header;
167)   $html_header .= $arg;
168) }
bernd Logging aktiviert

bernd authored 16 years ago

169) 
bernd Umstellung auf Theme-Suppor...

bernd authored 13 years ago

170) function title($arg)
171) {
172)   global $title;
173)   $title = $arg;
174) }
175) 
176) function headline($arg)
177) {
178)   global $headline;
179)   $headline = $arg;
180) }
181) 
bernd webinterface => /webinterface

bernd authored 17 years ago

182) function output($arg)
183) {
184)   global $output;
185)   $output .= $arg;
186) }
187) 
188) 
189) function random_string($nc, $a='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789') {
190)     $l=strlen($a)-1; $r='';
191)     while($nc-->0) $r.=$a{mt_rand(0,$l)};
192)     return $r;
193)  }
194) 
195) 
196) function are_you_sure($query_string, $question)
197) {
bernd * alle internen Links sinnv...

bernd authored 15 years ago

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

bernd authored 17 years ago

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

bernd authored 16 years ago

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

bernd authored 13 years ago

201)   title('Sicherheitsabfrage');
202)   output("
bernd * alle internen Links sinnv...

bernd authored 15 years ago

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

bernd authored 16 years ago

204)     <div class=\"confirmation\">
205)       <div class=\"question\">{$question}</div>
206)       <p class=\"buttons\">
207)         <input type=\"hidden\" name=\"random_token\" value=\"{$token}\" />
208)         <input type=\"submit\" name=\"really\" value=\"Ja\" />
bernd Entities repariert

bernd authored 16 years ago

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

bernd authored 16 years ago

210)         <input type=\"submit\" name=\"not_really\" value=\"Nein\" />
211)       </p>
212)     </div>");
bernd </form>

bernd authored 16 years ago

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

bernd authored 17 years ago

214) }
215) 
216) 
217) function user_is_sure()
218) {
219)   if (isset($_POST['really']))
220)   {
bernd XSRF-kram fixed

bernd authored 16 years ago

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

bernd authored 17 years ago

222)       return true;
223)     else
224)       system_failure("Possible Cross-site-request-forgery detected!");
225)   }
226)   elseif (isset($_POST['not_really']))
227)     return false;
228)   else
229)     return NULL;
230) }
231) 
232) 
233) 
bernd XSRF-kram fixed

bernd authored 16 years ago

234) function generate_form_token($form_id)
235) {
236)   require_once("inc/debug.php");
237)   $sessid = session_id();
238)   if ($sessid == "") 
239)   {
240)     DEBUG("Uh? Session not running? Wtf?");
bernd Neues Jabber-Modul (noch ni...

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

246) }
247) 
248) 
bernd Umfangreiche Code-Aufräumar...

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

251)   if ($formtoken == NULL)
Bernd Wurst Neue MySQL-Verwaltung

Bernd Wurst authored 11 years ago

252)     $formtoken = $_REQUEST['formtoken'];
bernd XSRF-kram fixed

bernd authored 16 years ago

253)   $sessid = session_id();
254)   if ($sessid == "") 
255)   {
256)     DEBUG("Uh? Session not running? Wtf?");
bernd Umfangreiche Code-Aufräumar...

bernd authored 16 years ago

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

bernd authored 16 years ago

258)   }
259) 
bernd Neues Jabber-Modul (noch ni...

bernd authored 16 years ago

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

bernd authored 16 years ago

261) 
262)   if (! ($formtoken == $correct_formtoken))
263)     system_failure("Possible cross-site-request-forgery!");
264) }
265) 
bernd Neues Jabber-Modul (noch ni...

bernd authored 16 years ago

266) 
bernd Zeige Links auf dem Startse...

bernd authored 14 years ago

267) function have_module($modname)
268) {
bernd Mehr config-optionen und co...

bernd authored 14 years ago

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

bernd authored 14 years ago

270) }
271) 
272) 
bernd * alle internen Links sinnv...

bernd authored 15 years ago

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

bernd authored 16 years ago

274) {
275)   global $debugmode;
276)   if ($debugmode)
bernd * alle internen Links sinnv...

bernd authored 15 years ago

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

bernd authored 15 years ago

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

bernd authored 15 years ago

279)   $query = explode('&', $querystring);
280)   $new_query = array();
281)   foreach ($query AS $item)
282)     if ($item != '')
283)     {
bernd fix a warning

bernd authored 14 years ago

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

bernd authored 15 years ago

287)       else
bernd fix a warning

bernd authored 14 years ago

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

bernd authored 15 years ago

289)     }
290)   $querystring = implode('&amp;', $new_query);
291)   if ($querystring)
292)     $querystring = '?'.$querystring;
bernd Bug im Client-Zertfikat-Man...

bernd authored 15 years ago

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

bernd authored 15 years ago

294)   return $querystring;
295) }
bernd Neues Jabber-Modul (noch ni...

bernd authored 16 years ago

296) 
bernd * alle internen Links sinnv...

bernd authored 15 years ago

297) 
Bernd Wurst Google-Auth-Token setzen un...

Bernd Wurst authored 11 years ago

298) function addnew($file, $label, $querystring = '', $attribs = '')
bernd addnew() eingeführt

bernd authored 14 years ago

299) {
Bernd Wurst Google-Auth-Token setzen un...

Bernd Wurst authored 11 years ago

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

bernd authored 14 years ago

301) }
302) 
bernd * alle internen Links sinnv...

bernd authored 15 years ago

303) 
304) function internal_link($file, $label, $querystring = '', $attribs = '')
305) {
bernd Erlaube absolute Links

bernd authored 15 years ago

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

bernd authored 15 years ago

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

bernd authored 15 years ago

308)   {
309)     $file = $prefix.substr($file, 1);
310)   }
bernd * alle internen Links sinnv...

bernd authored 15 years ago

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

bernd authored 16 years ago

313) }
314) 
315) 
316) function html_form($form_id, $scriptname, $querystring, $content)
317) {
bernd * alle internen Links sinnv...

bernd authored 15 years ago

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

bernd authored 16 years ago

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

bernd authored 15 years ago

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

bernd authored 16 years ago

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

322)   $ret .= $content;
323)   $ret .= '</form>';
324)   return $ret;  
325) }
326) 
327) 
bernd * wie viele Reihen wurden a...

bernd authored 15 years ago

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

bernd authored 16 years ago

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

bernd authored 15 years ago

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

bernd authored 16 years ago

332)   foreach ($options as $key => $value)
333)   {
334)     $selected = '';
335)     if ($default == $key)
336)       $selected = ' selected="selected" ';
337)     $key = filter_input_general($key);
338)     $value = filter_input_general($value);
339)     $ret .= "  <option value=\"{$key}\"{$selected}>{$value}</option>\n";
340)   }
341)   $ret .= '</select>';
342)   return $ret;
343) }
344) 
bernd Neues Jabber-Modul (noch ni...

bernd authored 16 years ago

345) 
bernd Neue Funktion zur Anzeige e...

bernd authored 12 years ago

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

bernd authored 12 years ago

358)   $current_year = (int) date('Y');
359)   $valid_years = array($current_year => $current_year, 
360)                        $current_year+1 => $current_year+1,
361)                        $current_year+2 => $current_year+2,
362)                        $current_year+3 => $current_year+3,
363)                        $current_year+4 => $current_year+4);
364)               
bernd Neue Funktion zur Anzeige e...

bernd authored 12 years ago

365)   $selected_day = date('d', $timestamp);
366)   $selected_month = date('m', $timestamp);
367)   $selected_year = date('Y', $timestamp);
368)   $ret = '';
369)   $ret .= html_select($nameprefix.'_day', $valid_days, $selected_day, 'style="text-align: right;"').". ";
370)   $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

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

bernd authored 12 years ago

372)   return $ret;
373) }
374) 
bernd Index-Blöcke werden jetzt v...

bernd authored 12 years ago

375) function get_modules_info() 
376) {
377)   $modules = config('modules');
378)   $modconfig = array();
379)   foreach ($modules AS $name) {
380)     $modconfig[$name] = NULL;
381)     if (file_exists('modules/'.$name.'/module.info')) {
382)       $modconfig[$name] = parse_ini_file('modules/'.$name.'/module.info');
383)     }
384)   }
385)   return $modconfig;
386) }
387) 
388) 
bernd Neues Jabber-Modul (noch ni...

bernd authored 16 years ago

389)