f53efe1896f3cfcbf6046cfe7c4e47ff484c0a7f
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 Updated copyright notice (2...

Bernd Wurst authored 11 years ago

5) Written 2008-2013 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) 
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)   
schokokeks.org web services Ermögliche Socket-Angabe fü...

schokokeks.org web services authored 10 years ago

38)   if ($localonly) {
39)     return NULL;
40)   }  
41) 
bernd config() liest die Datenban...

bernd authored 14 years ago

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

Bernd Wurst authored 10 years ago

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

bernd authored 14 years ago

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

Bernd Wurst authored 10 years ago

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

schokokeks.org web services authored 10 years ago

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

Bernd Wurst authored 10 years ago

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

schokokeks.org web services authored 10 years ago

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

bernd authored 14 years ago

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

bernd authored 13 years ago

50)   // Sonst wird das Passwort des webadmin-Users mit ausgegeben
51)   $debug_config = $config;
52)   unset($debug_config['db_pass']);
53)   DEBUG($debug_config);
bernd Mehr config-optionen und co...

bernd authored 14 years ago

54)   if (array_key_exists($key, $config))
55)     return $config[$key];
56)   else
bernd Logger mit Logleveln

bernd authored 14 years ago

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

bernd authored 14 years ago

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

bernd authored 14 years ago

59) }
60) 
bernd Info-Seite über Mail-Login-...

bernd authored 13 years ago

61) function get_server_by_id($id) {
62)   $id = (int) $id;
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

63)   $result = db_query("SELECT hostname FROM system.servers WHERE id='{$id}'");
64)   $ret = $result->fetch();
65)   return $ret['hostname'];
bernd Info-Seite über Mail-Login-...

bernd authored 13 years ago

66) }
67) 
bernd Mehr config-optionen und co...

bernd authored 14 years ago

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

bernd authored 14 years ago

69) function redirect($target)
70) {
71)   global $debugmode;
72)   if (! $debugmode)
73)     header("Location: {$target}");
74)   die();
75) }
76) 
77) 
bernd Hilfsfunktionen bzgl. mehre...

bernd authored 14 years ago

78) function my_server_id()
79) {
80)   $uid = (int) $_SESSION['userinfo']['uid'];
Bernd Wurst Revert "Umstellung auf mysqli"

Bernd Wurst authored 10 years ago

81)   $result = db_query("SELECT server FROM system.useraccounts WHERE uid={$uid}");
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

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

bernd authored 14 years ago

83)   DEBUG($r);
84)   return $r['server'];
85) }
86) 
87) 
88) function additional_servers()
89) {
90)   $uid = (int) $_SESSION['userinfo']['uid'];
Bernd Wurst Revert "Umstellung auf mysqli"

Bernd Wurst authored 10 years ago

91)   $result = db_query("SELECT server FROM system.user_server WHERE uid={$uid}");
bernd Hilfsfunktionen bzgl. mehre...

bernd authored 14 years ago

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

Bernd Wurst authored 10 years ago

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

bernd authored 14 years ago

94)     $servers[] = $s['server'];
95)   DEBUG($servers);
96)   return $servers;
97) }
98) 
99) 
100) function server_names()
101) {
Bernd Wurst Revert "Umstellung auf mysqli"

Bernd Wurst authored 10 years ago

102)   $result = db_query("SELECT id, hostname FROM system.servers");
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['id']] = $s['hostname'];
106)   DEBUG($servers);
107)   return $servers;
108) }
109) 
110) 
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

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

bernd authored 16 years ago

113) function maybe_null($value)
114) {
bernd maybe_null behandelt jetzt...

bernd authored 15 years ago

115)   if ($value == NULL)
116)     return 'NULL';
117) 
bernd Neues Modul für "Kunde werden"

bernd authored 16 years ago

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

Bernd Wurst authored 10 years ago

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

bernd authored 16 years ago

120)   else
121)     return 'NULL';
122) }
123) 
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

124) 
bernd Logger mit Logleveln

bernd authored 14 years ago

125) #define('LOG_ERR', 3);
126) #define('LOG_WARNING', 4);
127) #define('LOG_INFO', 6);
bernd Neues Modul für "Kunde werden"

bernd authored 16 years ago

128) 
bernd Logger mit Logleveln

bernd authored 14 years ago

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

bernd authored 16 years ago

130) {
bernd Logger mit Logleveln

bernd authored 14 years ago

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

bernd authored 16 years ago

132)     return;
133) 
bernd Logging aktiviert

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

138)     $user = "'{$_SESSION['customerinfo']['customerno']}'";
139)   
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

140)   $remote = db_escape_string($_SERVER['REMOTE_ADDR']);
bernd Logging aktiviert

bernd authored 16 years ago

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

Bernd Wurst authored 10 years ago

142)   $scriptname = db_escape_string($scriptname);
143)   $scope = db_escape_string($scope);
144)   $message = db_escape_string($message);
bernd Logging aktiviert

bernd authored 16 years ago

145) 
Bernd Wurst Revert "Umstellung auf mysqli"

Bernd Wurst authored 10 years ago

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

147) }
148) 
bernd Allow Header entries and AJAX

bernd authored 15 years ago

149) function html_header($arg)
150) {
151)   global $html_header;
152)   $html_header .= $arg;
153) }
bernd Logging aktiviert

bernd authored 16 years ago

154) 
bernd Umstellung auf Theme-Suppor...

bernd authored 13 years ago

155) function title($arg)
156) {
157)   global $title;
158)   $title = $arg;
159) }
160) 
161) function headline($arg)
162) {
163)   global $headline;
164)   $headline = $arg;
165) }
166) 
bernd webinterface => /webinterface

bernd authored 17 years ago

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

bernd authored 15 years ago

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

bernd authored 17 years ago

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

bernd authored 16 years ago

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

bernd authored 13 years ago

186)   title('Sicherheitsabfrage');
187)   output("
bernd * alle internen Links sinnv...

bernd authored 15 years ago

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

bernd authored 16 years ago

189)     <div class=\"confirmation\">
190)       <div class=\"question\">{$question}</div>
191)       <p class=\"buttons\">
192)         <input type=\"hidden\" name=\"random_token\" value=\"{$token}\" />
193)         <input type=\"submit\" name=\"really\" value=\"Ja\" />
bernd Entities repariert

bernd authored 16 years ago

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

bernd authored 16 years ago

195)         <input type=\"submit\" name=\"not_really\" value=\"Nein\" />
196)       </p>
197)     </div>");
bernd </form>

bernd authored 17 years ago

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

bernd authored 17 years ago

199) }
200) 
201) 
202) function user_is_sure()
203) {
204)   if (isset($_POST['really']))
205)   {
bernd XSRF-kram fixed

bernd authored 16 years ago

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

bernd authored 17 years ago

207)       return true;
208)     else
209)       system_failure("Possible Cross-site-request-forgery detected!");
210)   }
211)   elseif (isset($_POST['not_really']))
212)     return false;
213)   else
214)     return NULL;
215) }
216) 
217) 
218) 
bernd XSRF-kram fixed

bernd authored 16 years ago

219) function generate_form_token($form_id)
220) {
221)   require_once("inc/debug.php");
222)   $sessid = session_id();
223)   if ($sessid == "") 
224)   {
225)     DEBUG("Uh? Session not running? Wtf?");
bernd Neues Jabber-Modul (noch ni...

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

231) }
232) 
233) 
bernd Umfangreiche Code-Aufräumar...

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

Bernd Wurst authored 11 years ago

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

bernd authored 16 years ago

238)   $sessid = session_id();
239)   if ($sessid == "") 
240)   {
241)     DEBUG("Uh? Session not running? Wtf?");
bernd Umfangreiche Code-Aufräumar...

bernd authored 16 years ago

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

bernd authored 16 years ago

243)   }
244) 
bernd Neues Jabber-Modul (noch ni...

bernd authored 16 years ago

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

bernd authored 16 years ago

246) 
247)   if (! ($formtoken == $correct_formtoken))
248)     system_failure("Possible cross-site-request-forgery!");
249) }
250) 
bernd Neues Jabber-Modul (noch ni...

bernd authored 16 years ago

251) 
bernd Zeige Links auf dem Startse...

bernd authored 15 years ago

252) function have_module($modname)
253) {
bernd Mehr config-optionen und co...

bernd authored 14 years ago

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

bernd authored 15 years ago

255) }
256) 
257) 
bernd * alle internen Links sinnv...

bernd authored 15 years ago

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

bernd authored 16 years ago

259) {
260)   global $debugmode;
261)   if ($debugmode)
bernd * alle internen Links sinnv...

bernd authored 15 years ago

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

bernd authored 15 years ago

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

bernd authored 15 years ago

264)   $query = explode('&', $querystring);
265)   $new_query = array();
266)   foreach ($query AS $item)
267)     if ($item != '')
268)     {
bernd fix a warning

bernd authored 14 years ago

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

bernd authored 15 years ago

272)       else
bernd fix a warning

bernd authored 14 years ago

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

bernd authored 15 years ago

274)     }
275)   $querystring = implode('&amp;', $new_query);
276)   if ($querystring)
277)     $querystring = '?'.$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)   return $querystring;
280) }
bernd Neues Jabber-Modul (noch ni...

bernd authored 16 years ago

281) 
bernd * alle internen Links sinnv...

bernd authored 15 years ago

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

Bernd Wurst authored 11 years ago

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

bernd authored 14 years ago

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

Bernd Wurst authored 11 years ago

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

bernd authored 14 years ago

286) }
287) 
bernd * alle internen Links sinnv...

bernd authored 15 years ago

288) 
289) function internal_link($file, $label, $querystring = '', $attribs = '')
290) {
bernd Erlaube absolute Links

bernd authored 15 years ago

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

bernd authored 15 years ago

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

bernd authored 15 years ago

293)   {
294)     $file = $prefix.substr($file, 1);
295)   }
bernd * alle internen Links sinnv...

bernd authored 15 years ago

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

bernd authored 16 years ago

298) }
299) 
300) 
301) function html_form($form_id, $scriptname, $querystring, $content)
302) {
bernd * alle internen Links sinnv...

bernd authored 15 years ago

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

bernd authored 16 years ago

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

bernd authored 15 years ago

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

bernd authored 16 years ago

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

307)   $ret .= $content;
308)   $ret .= '</form>';
309)   return $ret;  
310) }
311) 
312) 
bernd * wie viele Reihen wurden a...

bernd authored 15 years ago

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

bernd authored 16 years ago

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

bernd authored 15 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

330) 
bernd Neue Funktion zur Anzeige e...

bernd authored 12 years ago

331) function html_datepicker($nameprefix, $timestamp)
332) {
333)   $valid_days = array( 1 =>  1,  2 =>  2,  3 =>  3,  4 =>  4,  5 =>  5,
334)                        6 =>  6,  7 =>  7,  8 =>  8,  9 =>  9, 10 => 10,
335)                       11 => 11, 12 => 12, 13 => 13, 14 => 14, 15 => 15,
336)                       16 => 16, 17 => 17, 18 => 18, 19 => 19, 20 => 20,
337)                       21 => 21, 22 => 22, 23 => 23, 24 => 24, 25 => 25,
338)                       26 => 26, 27 => 27, 28 => 28, 29 => 29, 30 => 30,
339)                       31 => 31);
340)   $valid_months = array( 1 =>  1,  2 =>  2,  3 =>  3,  4 =>  4,  5 =>  5,
341)                          6 =>  6,  7 =>  7,  8 =>  8,  9 =>  9, 10 => 10,
342)                         11 => 11, 12 => 12);
bernd Datums-Check und Daten in u...

bernd authored 12 years ago

343)   $current_year = (int) date('Y');
344)   $valid_years = array($current_year => $current_year, 
345)                        $current_year+1 => $current_year+1,
346)                        $current_year+2 => $current_year+2,
347)                        $current_year+3 => $current_year+3,
348)                        $current_year+4 => $current_year+4);
349)               
bernd Neue Funktion zur Anzeige e...

bernd authored 12 years ago

350)   $selected_day = date('d', $timestamp);
351)   $selected_month = date('m', $timestamp);
352)   $selected_year = date('Y', $timestamp);
353)   $ret = '';
354)   $ret .= html_select($nameprefix.'_day', $valid_days, $selected_day, 'style="text-align: right;"').". ";
355)   $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

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

bernd authored 12 years ago

357)   return $ret;
358) }
359) 
bernd Index-Blöcke werden jetzt v...

bernd authored 12 years ago

360) function get_modules_info() 
361) {
362)   $modules = config('modules');
363)   $modconfig = array();
364)   foreach ($modules AS $name) {
365)     $modconfig[$name] = NULL;
366)     if (file_exists('modules/'.$name.'/module.info')) {
367)       $modconfig[$name] = parse_ini_file('modules/'.$name.'/module.info');
368)     }
369)   }
370)   return $modconfig;
371) }
372) 
373) 
bernd Neues Jabber-Modul (noch ni...

bernd authored 16 years ago

374)