f1f231f5e074dfa038e70a67d39849e80f2b4b4d
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) 
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 */
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

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

bernd authored 14 years ago

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

Bernd Wurst authored 10 years ago

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

schokokeks.org web services authored 10 years ago

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

Bernd Wurst authored 10 years ago

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

schokokeks.org web services authored 10 years ago

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

bernd authored 14 years ago

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

bernd authored 13 years ago

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

bernd authored 14 years ago

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

bernd authored 14 years ago

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

bernd authored 14 years ago

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

bernd authored 14 years ago

55) }
56) 
bernd Info-Seite über Mail-Login-...

bernd authored 13 years ago

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

Bernd Wurst authored 10 years ago

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

bernd authored 13 years ago

62) }
63) 
bernd Mehr config-optionen und co...

bernd authored 14 years ago

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

bernd authored 14 years ago

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

bernd authored 14 years ago

74) function my_server_id()
75) {
76)   $uid = (int) $_SESSION['userinfo']['uid'];
Bernd Wurst Revert "Umstellung auf mysqli"

Bernd Wurst authored 10 years ago

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

Bernd Wurst authored 10 years ago

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

bernd authored 14 years ago

79)   DEBUG($r);
80)   return $r['server'];
81) }
82) 
83) 
84) function additional_servers()
85) {
86)   $uid = (int) $_SESSION['userinfo']['uid'];
Bernd Wurst Revert "Umstellung auf mysqli"

Bernd Wurst authored 10 years ago

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

bernd authored 14 years ago

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

Bernd Wurst authored 10 years ago

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

bernd authored 14 years ago

90)     $servers[] = $s['server'];
91)   DEBUG($servers);
92)   return $servers;
93) }
94) 
95) 
96) function server_names()
97) {
Bernd Wurst Revert "Umstellung auf mysqli"

Bernd Wurst authored 10 years ago

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

bernd authored 14 years ago

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

Bernd Wurst authored 10 years ago

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

bernd authored 14 years ago

101)     $servers[$s['id']] = $s['hostname'];
102)   DEBUG($servers);
103)   return $servers;
104) }
105) 
106) 
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

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

bernd authored 16 years ago

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

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

Bernd Wurst authored 10 years ago

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

bernd authored 16 years ago

116)   else
117)     return 'NULL';
118) }
119) 
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

120) 
bernd Logger mit Logleveln

bernd authored 14 years ago

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

bernd authored 16 years ago

124) 
bernd Logger mit Logleveln

bernd authored 14 years ago

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

bernd authored 16 years ago

126) {
bernd Logger mit Logleveln

bernd authored 14 years ago

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

bernd authored 16 years ago

128)     return;
129) 
bernd Logging aktiviert

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

Bernd Wurst authored 10 years ago

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

bernd authored 16 years ago

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

Bernd Wurst authored 10 years ago

138)   $scriptname = db_escape_string($scriptname);
139)   $scope = db_escape_string($scope);
140)   $message = db_escape_string($message);
bernd Logging aktiviert

bernd authored 16 years ago

141) 
Bernd Wurst Revert "Umstellung auf mysqli"

Bernd Wurst authored 10 years ago

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

143) }
144) 
bernd Allow Header entries and AJAX

bernd authored 15 years ago

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

bernd authored 16 years ago

150) 
bernd Umstellung auf Theme-Suppor...

bernd authored 13 years ago

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

bernd authored 17 years ago

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

bernd authored 15 years ago

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

bernd authored 17 years ago

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

bernd authored 16 years ago

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

bernd authored 13 years ago

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

bernd authored 15 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 17 years ago

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

bernd authored 17 years ago

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

bernd authored 16 years ago

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

bernd authored 17 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

Bernd Wurst authored 11 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

247) 
bernd Zeige Links auf dem Startse...

bernd authored 15 years ago

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

bernd authored 14 years ago

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

bernd authored 15 years ago

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

bernd authored 15 years ago

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

bernd authored 16 years ago

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

bernd authored 15 years ago

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

bernd authored 15 years ago

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

bernd authored 15 years ago

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

bernd authored 14 years ago

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

bernd authored 15 years ago

268)       else
bernd fix a warning

bernd authored 14 years ago

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

bernd authored 15 years ago

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

bernd authored 15 years ago

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

bernd authored 15 years ago

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

bernd authored 16 years ago

277) 
bernd * alle internen Links sinnv...

bernd authored 15 years ago

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

Bernd Wurst authored 11 years ago

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

bernd authored 14 years ago

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

Bernd Wurst authored 11 years ago

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

bernd authored 14 years ago

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

bernd authored 15 years ago

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

bernd authored 15 years ago

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

bernd authored 15 years ago

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

bernd authored 15 years ago

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

bernd authored 15 years ago

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

bernd authored 16 years ago

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

bernd authored 15 years ago

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

bernd authored 16 years ago

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

bernd authored 15 years ago

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

bernd authored 16 years ago

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

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

bernd authored 15 years ago

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

bernd authored 16 years ago

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

bernd authored 15 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

326) 
bernd Neue Funktion zur Anzeige e...

bernd authored 12 years ago

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

bernd authored 12 years ago

339)   $current_year = (int) date('Y');
340)   $valid_years = array($current_year => $current_year, 
341)                        $current_year+1 => $current_year+1,
342)                        $current_year+2 => $current_year+2,
343)                        $current_year+3 => $current_year+3,
344)                        $current_year+4 => $current_year+4);
345)               
bernd Neue Funktion zur Anzeige e...

bernd authored 12 years ago

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

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

bernd authored 12 years ago

353)   return $ret;
354) }
355) 
bernd Index-Blöcke werden jetzt v...

bernd authored 12 years ago

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

bernd authored 16 years ago

370)