8132c40e4814317f84ba2e42ac2e87485ddd9a47
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 Weitere Prepared-Statement-...

Bernd Wurst authored 10 years ago

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

Bernd Wurst authored 10 years ago

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 Einige Statements auf Prepa...

Bernd Wurst authored 10 years ago

81)   $result = db_query("SELECT server FROM system.useraccounts WHERE uid=?", array($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 Einige Statements auf Prepa...

Bernd Wurst authored 10 years ago

91)   $result = db_query("SELECT server FROM system.user_server WHERE uid=?", array($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 Wurst * Weitere Module auf prepar...

Bernd Wurst authored 10 years ago

115)   if (config("enable_debug")) {
116)     $backtrace = debug_backtrace();
117)     warning("call to maybe_null() in {$backtrace[1]['file']} line {$backtrace[1]['line']}");
118)   }
bernd maybe_null behandelt jetzt...

bernd authored 15 years ago

119)   if ($value == NULL)
120)     return 'NULL';
121) 
bernd Neues Modul für "Kunde werden"

bernd authored 16 years ago

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

Bernd Wurst authored 10 years ago

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

bernd authored 16 years ago

124)   else
125)     return 'NULL';
126) }
127) 
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

128) 
bernd Logger mit Logleveln

bernd authored 14 years ago

129) #define('LOG_ERR', 3);
130) #define('LOG_WARNING', 4);
131) #define('LOG_INFO', 6);
bernd Neues Modul für "Kunde werden"

bernd authored 16 years ago

132) 
bernd Logger mit Logleveln

bernd authored 14 years ago

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

bernd authored 16 years ago

134) {
bernd Logger mit Logleveln

bernd authored 14 years ago

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

bernd authored 16 years ago

136)     return;
137) 
Bernd Wurst * Weitere Module auf prepar...

Bernd Wurst authored 10 years ago

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

bernd authored 16 years ago

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

Bernd Wurst authored 10 years ago

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

bernd authored 16 years ago

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

Bernd Wurst authored 10 years ago

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

bernd authored 16 years ago

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

Bernd Wurst authored 10 years ago

144)   $args = array(":user" => $user,
145)                 ":remote" => $_SERVER['REMOTE_ADDR'],
146)                 ":scriptname" => $scriptname,
147)                 ":scope" => $scope,
148)                 ":message" => $message);
bernd Logging aktiviert

bernd authored 16 years ago

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

Bernd Wurst authored 10 years ago

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

151) }
152) 
bernd Allow Header entries and AJAX

bernd authored 15 years ago

153) function html_header($arg)
154) {
155)   global $html_header;
156)   $html_header .= $arg;
157) }
bernd Logging aktiviert

bernd authored 16 years ago

158) 
bernd Umstellung auf Theme-Suppor...

bernd authored 13 years ago

159) function title($arg)
160) {
161)   global $title;
162)   $title = $arg;
163) }
164) 
165) function headline($arg)
166) {
167)   global $headline;
168)   $headline = $arg;
169) }
170) 
bernd webinterface => /webinterface

bernd authored 17 years ago

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

bernd authored 15 years ago

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

bernd authored 17 years ago

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

bernd authored 16 years ago

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

bernd authored 13 years ago

190)   title('Sicherheitsabfrage');
191)   output("
bernd * alle internen Links sinnv...

bernd authored 15 years ago

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

bernd authored 16 years ago

193)     <div class=\"confirmation\">
194)       <div class=\"question\">{$question}</div>
195)       <p class=\"buttons\">
196)         <input type=\"hidden\" name=\"random_token\" value=\"{$token}\" />
197)         <input type=\"submit\" name=\"really\" value=\"Ja\" />
bernd Entities repariert

bernd authored 16 years ago

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

bernd authored 16 years ago

199)         <input type=\"submit\" name=\"not_really\" value=\"Nein\" />
200)       </p>
201)     </div>");
bernd </form>

bernd authored 17 years ago

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

bernd authored 17 years ago

203) }
204) 
205) 
206) function user_is_sure()
207) {
208)   if (isset($_POST['really']))
209)   {
bernd XSRF-kram fixed

bernd authored 16 years ago

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

bernd authored 17 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

235) }
236) 
237) 
bernd Umfangreiche Code-Aufräumar...

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

Bernd Wurst authored 11 years ago

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

bernd authored 16 years ago

242)   $sessid = session_id();
243)   if ($sessid == "") 
244)   {
245)     DEBUG("Uh? Session not running? Wtf?");
bernd Umfangreiche Code-Aufräumar...

bernd authored 16 years ago

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

bernd authored 16 years ago

247)   }
248) 
bernd Neues Jabber-Modul (noch ni...

bernd authored 16 years ago

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

bernd authored 16 years ago

250) 
251)   if (! ($formtoken == $correct_formtoken))
252)     system_failure("Possible cross-site-request-forgery!");
253) }
254) 
bernd Neues Jabber-Modul (noch ni...

bernd authored 16 years ago

255) 
bernd Zeige Links auf dem Startse...

bernd authored 14 years ago

256) function have_module($modname)
257) {
bernd Mehr config-optionen und co...

bernd authored 14 years ago

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

bernd authored 14 years ago

259) }
260) 
261) 
bernd * alle internen Links sinnv...

bernd authored 15 years ago

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

bernd authored 16 years ago

263) {
264)   global $debugmode;
265)   if ($debugmode)
bernd * alle internen Links sinnv...

bernd authored 15 years ago

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

bernd authored 15 years ago

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

bernd authored 15 years ago

268)   $query = explode('&', $querystring);
269)   $new_query = array();
270)   foreach ($query AS $item)
271)     if ($item != '')
272)     {
bernd fix a warning

bernd authored 14 years ago

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

bernd authored 15 years ago

276)       else
bernd fix a warning

bernd authored 14 years ago

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

bernd authored 15 years ago

278)     }
279)   $querystring = implode('&amp;', $new_query);
280)   if ($querystring)
281)     $querystring = '?'.$querystring;
bernd Bug im Client-Zertfikat-Man...

bernd authored 15 years ago

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

bernd authored 15 years ago

283)   return $querystring;
284) }
bernd Neues Jabber-Modul (noch ni...

bernd authored 16 years ago

285) 
bernd * alle internen Links sinnv...

bernd authored 15 years ago

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

Bernd Wurst authored 11 years ago

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

bernd authored 14 years ago

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

Bernd Wurst authored 11 years ago

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

bernd authored 14 years ago

290) }
291) 
bernd * alle internen Links sinnv...

bernd authored 15 years ago

292) 
293) function internal_link($file, $label, $querystring = '', $attribs = '')
294) {
bernd Erlaube absolute Links

bernd authored 15 years ago

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

bernd authored 15 years ago

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

bernd authored 15 years ago

297)   {
298)     $file = $prefix.substr($file, 1);
299)   }
bernd * alle internen Links sinnv...

bernd authored 15 years ago

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

bernd authored 16 years ago

302) }
303) 
304) 
305) function html_form($form_id, $scriptname, $querystring, $content)
306) {
bernd * alle internen Links sinnv...

bernd authored 15 years ago

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

bernd authored 16 years ago

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

bernd authored 15 years ago

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

bernd authored 16 years ago

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

311)   $ret .= $content;
312)   $ret .= '</form>';
313)   return $ret;  
314) }
315) 
316) 
bernd * wie viele Reihen wurden a...

bernd authored 15 years ago

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

bernd authored 16 years ago

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

bernd authored 15 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

334) 
bernd Neue Funktion zur Anzeige e...

bernd authored 12 years ago

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

bernd authored 12 years ago

347)   $current_year = (int) date('Y');
348)   $valid_years = array($current_year => $current_year, 
349)                        $current_year+1 => $current_year+1,
350)                        $current_year+2 => $current_year+2,
351)                        $current_year+3 => $current_year+3,
352)                        $current_year+4 => $current_year+4);
353)               
bernd Neue Funktion zur Anzeige e...

bernd authored 12 years ago

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

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

bernd authored 12 years ago

361)   return $ret;
362) }
363) 
bernd Index-Blöcke werden jetzt v...

bernd authored 12 years ago

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

bernd authored 16 years ago

378)