8fe42e37581d18cb508c6c99b90182580ee2d7ad
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 add a function to handle re...

bernd authored 14 years ago

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

bernd authored 16 years ago

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

bernd authored 14 years ago

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

bernd authored 13 years ago

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

bernd authored 14 years ago

34)   if (array_key_exists($key, $config))
35)     return $config[$key];
36)   
37)   /* read configuration from database */
Bernd Wurst Umstellung auf mysqli

Bernd Wurst authored 10 years ago

38)   $options = DB::query( "SELECT `key`, value FROM misc.config" );
bernd config() liest die Datenban...

bernd authored 14 years ago

39)   
Bernd Wurst fehler beim merge behoben

Bernd Wurst authored 10 years ago

40)   while( $object = $options->fetch_assoc() ) {
schokokeks.org web services Config-File-Optionen werden...

schokokeks.org web services authored 10 years ago

41)     if (!array_key_exists($object['key'], $config)) {
42)       $config[$object['key']]=$object['value'];
43)     }
bernd config() liest die Datenban...

bernd authored 14 years ago

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

bernd authored 13 years ago

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

bernd authored 14 years ago

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

bernd authored 14 years ago

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

bernd authored 14 years ago

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

bernd authored 14 years ago

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

bernd authored 13 years ago

56) function get_server_by_id($id) {
57)   $id = (int) $id;
Bernd Wurst Umstellung auf mysqli

Bernd Wurst authored 10 years ago

58)   $result = DB::query("SELECT hostname FROM system.servers WHERE id='{$id}'");
59)   $server = $result->fetch_assoc();
60)   return $server['hostname'];
bernd Info-Seite über Mail-Login-...

bernd authored 13 years ago

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

bernd authored 14 years ago

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

bernd authored 14 years ago

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

bernd authored 14 years ago

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

Bernd Wurst authored 10 years ago

76)   $result = DB::query("SELECT server FROM system.useraccounts WHERE uid={$uid}");
77)   $r = $result->fetch_assoc();
bernd Hilfsfunktionen bzgl. mehre...

bernd authored 14 years ago

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

Bernd Wurst authored 10 years ago

86)   $result = DB::query("SELECT server FROM system.user_server WHERE uid={$uid}");
bernd Hilfsfunktionen bzgl. mehre...

bernd authored 14 years ago

87)   $servers = array();
Bernd Wurst Umstellung auf mysqli

Bernd Wurst authored 10 years ago

88)   while ($s = $result->fetch_assoc())
bernd Hilfsfunktionen bzgl. mehre...

bernd authored 14 years ago

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

Bernd Wurst authored 10 years ago

97)   $result = DB::query("SELECT id, hostname FROM system.servers");
bernd Hilfsfunktionen bzgl. mehre...

bernd authored 14 years ago

98)   $servers = array();
Bernd Wurst Umstellung auf mysqli

Bernd Wurst authored 10 years ago

99)   while ($s = $result->fetch_assoc())
bernd Hilfsfunktionen bzgl. mehre...

bernd authored 14 years ago

100)     $servers[$s['id']] = $s['hostname'];
101)   DEBUG($servers);
102)   return $servers;
103) }
104) 
105) 
bernd Neues Modul für "Kunde werden"

bernd authored 16 years ago

106) function maybe_null($value)
107) {
bernd maybe_null behandelt jetzt...

bernd authored 15 years ago

108)   if ($value == NULL)
109)     return 'NULL';
110) 
bernd Neues Modul für "Kunde werden"

bernd authored 16 years ago

111)   if (strlen( (string) $value ) > 0)
Bernd Wurst Fehler aus der mysqli-Umste...

Bernd Wurst authored 10 years ago

112)     return "'".DB::escape($value)."'";
bernd Neues Modul für "Kunde werden"

bernd authored 16 years ago

113)   else
114)     return 'NULL';
115) }
116) 
bernd Logger mit Logleveln

bernd authored 14 years ago

117) #define('LOG_ERR', 3);
118) #define('LOG_WARNING', 4);
119) #define('LOG_INFO', 6);
bernd Neues Modul für "Kunde werden"

bernd authored 16 years ago

120) 
bernd Logger mit Logleveln

bernd authored 14 years ago

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

bernd authored 16 years ago

122) {
bernd Logger mit Logleveln

bernd authored 14 years ago

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

bernd authored 16 years ago

124)     return;
125) 
bernd Logging aktiviert

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

130)     $user = "'{$_SESSION['customerinfo']['customerno']}'";
131)   
Bernd Wurst Umstellung auf mysqli

Bernd Wurst authored 10 years ago

132)   $remote = DB::escape($_SERVER['REMOTE_ADDR']);
bernd Logging aktiviert

bernd authored 16 years ago

133) 
Bernd Wurst Umstellung auf mysqli

Bernd Wurst authored 10 years ago

134)   $scriptname = DB::escape($scriptname);
135)   $scope = DB::escape($scope);
136)   $message = DB::escape($message);
bernd Logging aktiviert

bernd authored 16 years ago

137) 
Bernd Wurst Umstellung auf mysqli

Bernd Wurst authored 10 years ago

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

139) }
140) 
bernd Allow Header entries and AJAX

bernd authored 15 years ago

141) function html_header($arg)
142) {
143)   global $html_header;
144)   $html_header .= $arg;
145) }
bernd Logging aktiviert

bernd authored 16 years ago

146) 
bernd Umstellung auf Theme-Suppor...

bernd authored 13 years ago

147) function title($arg)
148) {
149)   global $title;
150)   $title = $arg;
151) }
152) 
153) function headline($arg)
154) {
155)   global $headline;
156)   $headline = $arg;
157) }
158) 
bernd webinterface => /webinterface

bernd authored 17 years ago

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

bernd authored 15 years ago

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

bernd authored 17 years ago

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

bernd authored 16 years ago

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

bernd authored 13 years ago

178)   title('Sicherheitsabfrage');
179)   output("
bernd * alle internen Links sinnv...

bernd authored 15 years ago

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

bernd authored 16 years ago

181)     <div class=\"confirmation\">
182)       <div class=\"question\">{$question}</div>
183)       <p class=\"buttons\">
184)         <input type=\"hidden\" name=\"random_token\" value=\"{$token}\" />
185)         <input type=\"submit\" name=\"really\" value=\"Ja\" />
bernd Entities repariert

bernd authored 16 years ago

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

bernd authored 16 years ago

187)         <input type=\"submit\" name=\"not_really\" value=\"Nein\" />
188)       </p>
189)     </div>");
bernd </form>

bernd authored 17 years ago

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

bernd authored 17 years ago

191) }
192) 
193) 
194) function user_is_sure()
195) {
196)   if (isset($_POST['really']))
197)   {
bernd XSRF-kram fixed

bernd authored 16 years ago

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

bernd authored 17 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

223) }
224) 
225) 
bernd Umfangreiche Code-Aufräumar...

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

Bernd Wurst authored 11 years ago

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

bernd authored 16 years ago

230)   $sessid = session_id();
231)   if ($sessid == "") 
232)   {
233)     DEBUG("Uh? Session not running? Wtf?");
bernd Umfangreiche Code-Aufräumar...

bernd authored 16 years ago

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

bernd authored 16 years ago

235)   }
236) 
bernd Neues Jabber-Modul (noch ni...

bernd authored 16 years ago

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

bernd authored 16 years ago

238) 
239)   if (! ($formtoken == $correct_formtoken))
240)     system_failure("Possible cross-site-request-forgery!");
241) }
242) 
bernd Neues Jabber-Modul (noch ni...

bernd authored 16 years ago

243) 
bernd Zeige Links auf dem Startse...

bernd authored 15 years ago

244) function have_module($modname)
245) {
bernd Mehr config-optionen und co...

bernd authored 14 years ago

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

bernd authored 15 years ago

247) }
248) 
249) 
bernd * alle internen Links sinnv...

bernd authored 15 years ago

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

bernd authored 16 years ago

251) {
252)   global $debugmode;
253)   if ($debugmode)
bernd * alle internen Links sinnv...

bernd authored 15 years ago

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

bernd authored 15 years ago

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

bernd authored 15 years ago

256)   $query = explode('&', $querystring);
257)   $new_query = array();
258)   foreach ($query AS $item)
259)     if ($item != '')
260)     {
bernd fix a warning

bernd authored 14 years ago

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

bernd authored 15 years ago

264)       else
bernd fix a warning

bernd authored 14 years ago

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

bernd authored 15 years ago

266)     }
267)   $querystring = implode('&amp;', $new_query);
268)   if ($querystring)
269)     $querystring = '?'.$querystring;
bernd Bug im Client-Zertfikat-Man...

bernd authored 15 years ago

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

bernd authored 15 years ago

271)   return $querystring;
272) }
bernd Neues Jabber-Modul (noch ni...

bernd authored 16 years ago

273) 
bernd * alle internen Links sinnv...

bernd authored 15 years ago

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

Bernd Wurst authored 11 years ago

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

bernd authored 14 years ago

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

Bernd Wurst authored 11 years ago

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

bernd authored 14 years ago

278) }
279) 
bernd * alle internen Links sinnv...

bernd authored 15 years ago

280) 
281) function internal_link($file, $label, $querystring = '', $attribs = '')
282) {
bernd Erlaube absolute Links

bernd authored 15 years ago

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

bernd authored 15 years ago

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

bernd authored 15 years ago

285)   {
286)     $file = $prefix.substr($file, 1);
287)   }
bernd * alle internen Links sinnv...

bernd authored 15 years ago

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

bernd authored 16 years ago

290) }
291) 
292) 
293) function html_form($form_id, $scriptname, $querystring, $content)
294) {
bernd * alle internen Links sinnv...

bernd authored 15 years ago

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

bernd authored 16 years ago

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

bernd authored 15 years ago

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

bernd authored 16 years ago

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

299)   $ret .= $content;
300)   $ret .= '</form>';
301)   return $ret;  
302) }
303) 
304) 
bernd * wie viele Reihen wurden a...

bernd authored 15 years ago

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

bernd authored 16 years ago

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

bernd authored 15 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

322) 
bernd Neue Funktion zur Anzeige e...

bernd authored 12 years ago

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

bernd authored 12 years ago

335)   $current_year = (int) date('Y');
336)   $valid_years = array($current_year => $current_year, 
337)                        $current_year+1 => $current_year+1,
338)                        $current_year+2 => $current_year+2,
339)                        $current_year+3 => $current_year+3,
340)                        $current_year+4 => $current_year+4);
341)               
bernd Neue Funktion zur Anzeige e...

bernd authored 12 years ago

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

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

bernd authored 12 years ago

349)   return $ret;
350) }
351) 
bernd Index-Blöcke werden jetzt v...

bernd authored 12 years ago

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

bernd authored 16 years ago

366)