923f33a33bfa9727b5ab5b3cffb69eaa4374dc86
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 Logging aktiviert

bernd authored 16 years ago

17) require_once('inc/db_connect.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 */
39)   $options = db_query( "SELECT `key`, value FROM misc.config" );
40)   
41)   while( $object = mysql_fetch_assoc( $options ) ) {
schokokeks.org web services Config-File-Optionen werden...

schokokeks.org web services authored 10 years ago

42)     if (!array_key_exists($object['key'], $config)) {
43)       $config[$object['key']]=$object['value'];
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;
59)   $result = mysql_fetch_assoc(db_query("SELECT hostname FROM system.servers WHERE id='{$id}'"));
60)   return $result['hostname'];
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'];
76)   $result = db_query("SELECT server FROM system.useraccounts WHERE uid={$uid}");
77)   $r = mysql_fetch_assoc($result);
78)   DEBUG($r);
79)   return $r['server'];
80) }
81) 
82) 
83) function additional_servers()
84) {
85)   $uid = (int) $_SESSION['userinfo']['uid'];
86)   $result = db_query("SELECT server FROM system.user_server WHERE uid={$uid}");
87)   $servers = array();
88)   while ($s = mysql_fetch_assoc($result))
89)     $servers[] = $s['server'];
90)   DEBUG($servers);
91)   return $servers;
92) }
93) 
94) 
95) function server_names()
96) {
97)   $result = db_query("SELECT id, hostname FROM system.servers");
98)   $servers = array();
99)   while ($s = mysql_fetch_assoc($result))
100)     $servers[$s['id']] = $s['hostname'];
101)   DEBUG($servers);
102)   return $servers;
103) }
104) 
105) 
bernd sql-abfragen abstrahiert

bernd authored 16 years ago

106) function db_query($query)
107) {
108)   DEBUG($query);
109)   $result = @mysql_query($query);
110)   if (mysql_error())
111)   {
112)     $error = mysql_error();
bernd Logger mit Logleveln

bernd authored 14 years ago

113)     logger(LOG_ERR, "inc/base", "dberror", "mysql error: {$error}");
bernd MySQL-Fehler kommen als Lat...

bernd authored 16 years ago

114)     system_failure('Interner Datenbankfehler: »'.iconv('ISO-8859-1', 'UTF-8', $error).'«.');
bernd sql-abfragen abstrahiert

bernd authored 16 years ago

115)   }
bernd * wie viele Reihen wurden a...

bernd authored 15 years ago

116)   $count = @mysql_num_rows($result);
117)   if (! $count)
118)     $count = 'no';
119)   DEBUG("=> {$count} rows");
bernd sql-abfragen abstrahiert

bernd authored 16 years ago

120)   return $result; 
121) }
122) 
123) 
bernd Neues Modul für "Kunde werden"

bernd authored 16 years ago

124) 
125) function maybe_null($value)
126) {
bernd maybe_null behandelt jetzt...

bernd authored 15 years ago

127)   if ($value == NULL)
128)     return 'NULL';
129) 
bernd Neues Modul für "Kunde werden"

bernd authored 16 years ago

130)   if (strlen( (string) $value ) > 0)
bernd Strings für mysql esapen (z...

bernd authored 16 years ago

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

bernd authored 16 years ago

132)   else
133)     return 'NULL';
134) }
135) 
bernd Logger mit Logleveln

bernd authored 14 years ago

136) #define('LOG_ERR', 3);
137) #define('LOG_WARNING', 4);
138) #define('LOG_INFO', 6);
bernd Neues Modul für "Kunde werden"

bernd authored 16 years ago

139) 
bernd Logger mit Logleveln

bernd authored 14 years ago

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

bernd authored 16 years ago

141) {
bernd Logger mit Logleveln

bernd authored 14 years ago

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

bernd authored 16 years ago

143)     return;
144) 
bernd Logging aktiviert

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

149)     $user = "'{$_SESSION['customerinfo']['customerno']}'";
150)   
151)   $remote = mysql_real_escape_string($_SERVER['REMOTE_ADDR']);
152) 
153)   $scriptname = mysql_real_escape_string($scriptname);
154)   $scope = mysql_real_escape_string($scope);
155)   $message = mysql_real_escape_string($message);
156) 
bernd sql-abfragen abstrahiert

bernd authored 16 years ago

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

158) }
159) 
bernd Allow Header entries and AJAX

bernd authored 15 years ago

160) function html_header($arg)
161) {
162)   global $html_header;
163)   $html_header .= $arg;
164) }
bernd Logging aktiviert

bernd authored 16 years ago

165) 
bernd Umstellung auf Theme-Suppor...

bernd authored 13 years ago

166) function title($arg)
167) {
168)   global $title;
169)   $title = $arg;
170) }
171) 
172) function headline($arg)
173) {
174)   global $headline;
175)   $headline = $arg;
176) }
177) 
bernd webinterface => /webinterface

bernd authored 17 years ago

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

bernd authored 15 years ago

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

bernd authored 17 years ago

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

bernd authored 16 years ago

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

bernd authored 13 years ago

197)   title('Sicherheitsabfrage');
198)   output("
bernd * alle internen Links sinnv...

bernd authored 15 years ago

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

bernd authored 16 years ago

200)     <div class=\"confirmation\">
201)       <div class=\"question\">{$question}</div>
202)       <p class=\"buttons\">
203)         <input type=\"hidden\" name=\"random_token\" value=\"{$token}\" />
204)         <input type=\"submit\" name=\"really\" value=\"Ja\" />
bernd Entities repariert

bernd authored 16 years ago

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

bernd authored 16 years ago

206)         <input type=\"submit\" name=\"not_really\" value=\"Nein\" />
207)       </p>
208)     </div>");
bernd </form>

bernd authored 17 years ago

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

bernd authored 17 years ago

210) }
211) 
212) 
213) function user_is_sure()
214) {
215)   if (isset($_POST['really']))
216)   {
bernd XSRF-kram fixed

bernd authored 16 years ago

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

bernd authored 17 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

242) }
243) 
244) 
bernd Umfangreiche Code-Aufräumar...

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

Bernd Wurst authored 11 years ago

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

bernd authored 16 years ago

249)   $sessid = session_id();
250)   if ($sessid == "") 
251)   {
252)     DEBUG("Uh? Session not running? Wtf?");
bernd Umfangreiche Code-Aufräumar...

bernd authored 16 years ago

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

bernd authored 16 years ago

254)   }
255) 
bernd Neues Jabber-Modul (noch ni...

bernd authored 16 years ago

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

bernd authored 16 years ago

257) 
258)   if (! ($formtoken == $correct_formtoken))
259)     system_failure("Possible cross-site-request-forgery!");
260) }
261) 
bernd Neues Jabber-Modul (noch ni...

bernd authored 16 years ago

262) 
bernd Zeige Links auf dem Startse...

bernd authored 15 years ago

263) function have_module($modname)
264) {
bernd Mehr config-optionen und co...

bernd authored 14 years ago

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

bernd authored 15 years ago

266) }
267) 
268) 
bernd * alle internen Links sinnv...

bernd authored 15 years ago

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

bernd authored 16 years ago

270) {
271)   global $debugmode;
272)   if ($debugmode)
bernd * alle internen Links sinnv...

bernd authored 15 years ago

273)     $querystring = 'debug&'.$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)   $query = explode('&', $querystring);
276)   $new_query = array();
277)   foreach ($query AS $item)
278)     if ($item != '')
279)     {
bernd fix a warning

bernd authored 14 years ago

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

bernd authored 15 years ago

283)       else
bernd fix a warning

bernd authored 14 years ago

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

bernd authored 15 years ago

285)     }
286)   $querystring = implode('&amp;', $new_query);
287)   if ($querystring)
288)     $querystring = '?'.$querystring;
bernd Bug im Client-Zertfikat-Man...

bernd authored 15 years ago

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

bernd authored 15 years ago

290)   return $querystring;
291) }
bernd Neues Jabber-Modul (noch ni...

bernd authored 16 years ago

292) 
bernd * alle internen Links sinnv...

bernd authored 15 years ago

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

Bernd Wurst authored 11 years ago

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

bernd authored 14 years ago

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

Bernd Wurst authored 11 years ago

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

bernd authored 14 years ago

297) }
298) 
bernd * alle internen Links sinnv...

bernd authored 15 years ago

299) 
300) function internal_link($file, $label, $querystring = '', $attribs = '')
301) {
bernd Erlaube absolute Links

bernd authored 15 years ago

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

bernd authored 15 years ago

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

bernd authored 15 years ago

304)   {
305)     $file = $prefix.substr($file, 1);
306)   }
bernd * alle internen Links sinnv...

bernd authored 15 years ago

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

bernd authored 16 years ago

309) }
310) 
311) 
312) function html_form($form_id, $scriptname, $querystring, $content)
313) {
bernd * alle internen Links sinnv...

bernd authored 15 years ago

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

bernd authored 16 years ago

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

bernd authored 15 years ago

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

bernd authored 16 years ago

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

318)   $ret .= $content;
319)   $ret .= '</form>';
320)   return $ret;  
321) }
322) 
323) 
bernd * wie viele Reihen wurden a...

bernd authored 15 years ago

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

bernd authored 16 years ago

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

bernd authored 15 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

341) 
bernd Neue Funktion zur Anzeige e...

bernd authored 12 years ago

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

bernd authored 12 years ago

354)   $current_year = (int) date('Y');
355)   $valid_years = array($current_year => $current_year, 
356)                        $current_year+1 => $current_year+1,
357)                        $current_year+2 => $current_year+2,
358)                        $current_year+3 => $current_year+3,
359)                        $current_year+4 => $current_year+4);
360)               
bernd Neue Funktion zur Anzeige e...

bernd authored 12 years ago

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

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

bernd authored 12 years ago

368)   return $ret;
369) }
370) 
bernd Index-Blöcke werden jetzt v...

bernd authored 12 years ago

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

bernd authored 16 years ago

385)