cdc4b3f907f194e97d08038bb95e657465131d5b
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 Umstellung auf mysqli

Bernd Wurst authored 10 years ago

40)   while( $object = $options->fetch_assoc() ) {
bernd config() liest die Datenban...

bernd authored 14 years ago

41) 	  $config[$object['key']]=$object['value'];
42)   }
bernd Passwort-Ändern geht jetzt...

bernd authored 13 years ago

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

bernd authored 14 years ago

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

bernd authored 14 years ago

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

bernd authored 14 years ago

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

bernd authored 14 years ago

52) }
53) 
bernd Info-Seite über Mail-Login-...

bernd authored 13 years ago

54) function get_server_by_id($id) {
55)   $id = (int) $id;
Bernd Wurst Umstellung auf mysqli

Bernd Wurst authored 10 years ago

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

bernd authored 13 years ago

59) }
60) 
bernd Mehr config-optionen und co...

bernd authored 14 years ago

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

bernd authored 14 years ago

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

bernd authored 14 years ago

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

Bernd Wurst authored 10 years ago

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

bernd authored 14 years ago

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

Bernd Wurst authored 10 years ago

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

bernd authored 14 years ago

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

Bernd Wurst authored 10 years ago

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

bernd authored 14 years ago

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

Bernd Wurst authored 10 years ago

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

bernd authored 14 years ago

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

Bernd Wurst authored 10 years ago

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

bernd authored 14 years ago

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

bernd authored 16 years ago

104) function maybe_null($value)
105) {
bernd maybe_null behandelt jetzt...

bernd authored 15 years ago

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

bernd authored 16 years ago

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

Bernd Wurst authored 10 years ago

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

bernd authored 16 years ago

111)   else
112)     return 'NULL';
113) }
114) 
bernd Logger mit Logleveln

bernd authored 14 years ago

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

bernd authored 16 years ago

118) 
bernd Logger mit Logleveln

bernd authored 14 years ago

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

bernd authored 16 years ago

120) {
bernd Logger mit Logleveln

bernd authored 14 years ago

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

bernd authored 16 years ago

122)     return;
123) 
bernd Logging aktiviert

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

Bernd Wurst authored 10 years ago

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

bernd authored 16 years ago

131) 
Bernd Wurst Umstellung auf mysqli

Bernd Wurst authored 10 years ago

132)   $scriptname = DB::escape($scriptname);
133)   $scope = DB::escape($scope);
134)   $message = DB::escape($message);
bernd Logging aktiviert

bernd authored 16 years ago

135) 
Bernd Wurst Umstellung auf mysqli

Bernd Wurst authored 10 years ago

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

137) }
138) 
bernd Allow Header entries and AJAX

bernd authored 15 years ago

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

bernd authored 16 years ago

144) 
bernd Umstellung auf Theme-Suppor...

bernd authored 13 years ago

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

bernd authored 17 years ago

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

bernd authored 15 years ago

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

bernd authored 17 years ago

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

bernd authored 16 years ago

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

bernd authored 13 years ago

176)   title('Sicherheitsabfrage');
177)   output("
bernd * alle internen Links sinnv...

bernd authored 15 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 17 years ago

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

bernd authored 17 years ago

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

bernd authored 16 years ago

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

bernd authored 17 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

221) }
222) 
223) 
bernd Umfangreiche Code-Aufräumar...

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

Bernd Wurst authored 11 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

233)   }
234) 
bernd Neues Jabber-Modul (noch ni...

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

241) 
bernd Zeige Links auf dem Startse...

bernd authored 15 years ago

242) function have_module($modname)
243) {
bernd Mehr config-optionen und co...

bernd authored 14 years ago

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

bernd authored 15 years ago

245) }
246) 
247) 
bernd * alle internen Links sinnv...

bernd authored 15 years ago

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

bernd authored 16 years ago

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

bernd authored 15 years ago

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

bernd authored 15 years ago

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

bernd authored 15 years ago

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

bernd authored 14 years ago

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

bernd authored 15 years ago

262)       else
bernd fix a warning

bernd authored 14 years ago

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

bernd authored 15 years ago

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

bernd authored 15 years ago

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

bernd authored 15 years ago

269)   return $querystring;
270) }
bernd Neues Jabber-Modul (noch ni...

bernd authored 16 years ago

271) 
bernd * alle internen Links sinnv...

bernd authored 15 years ago

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

Bernd Wurst authored 11 years ago

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

bernd authored 14 years ago

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

Bernd Wurst authored 11 years ago

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

bernd authored 14 years ago

276) }
277) 
bernd * alle internen Links sinnv...

bernd authored 15 years ago

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

bernd authored 15 years ago

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

bernd authored 15 years ago

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

bernd authored 15 years ago

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

bernd authored 15 years ago

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

bernd authored 16 years ago

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

bernd authored 15 years ago

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

bernd authored 16 years ago

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

bernd authored 15 years ago

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

bernd authored 16 years ago

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

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

bernd authored 15 years ago

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

bernd authored 16 years ago

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

bernd authored 15 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

320) 
bernd Neue Funktion zur Anzeige e...

bernd authored 12 years ago

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

bernd authored 12 years ago

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

bernd authored 12 years ago

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

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

bernd authored 12 years ago

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

bernd authored 12 years ago

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

bernd authored 16 years ago

364)