3d226dfeb89424af34c423264628eb2b4dfbe6b2
bernd webinterface => /webinterface

bernd authored 17 years ago

1) <?php
2) 
bernd Logging aktiviert

bernd authored 16 years ago

3) require_once('inc/db_connect.php');
bernd add a function to handle re...

bernd authored 14 years ago

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

bernd authored 16 years ago

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

bernd authored 14 years ago

6) function config($key)
7) {
8)   global $config;
bernd Erlaube subusers, die nur Z...

bernd authored 13 years ago

9) 
10)   if ($key == 'modules' && isset($_SESSION['restrict_modules']))
11)   {
12)     $modules = array();
13)     foreach ($config['modules'] as $mod)
14)     {
15)       if (in_array($mod, $_SESSION['restrict_modules']))
16)         $modules[] = $mod;
17)     }
18)     return $modules;
19)   }
20) 
bernd config() liest die Datenban...

bernd authored 14 years ago

21)   if (array_key_exists($key, $config))
22)     return $config[$key];
23)   
24)   /* read configuration from database */
25)   $options = db_query( "SELECT `key`, value FROM misc.config" );
26)   
27)   while( $object = mysql_fetch_assoc( $options ) ) {
28) 	  $config[$object['key']]=$object['value'];
29)   }
bernd Passwort-Ändern geht jetzt...

bernd authored 13 years ago

30)   // Sonst wird das Passwort des webadmin-Users mit ausgegeben
31)   $debug_config = $config;
32)   unset($debug_config['db_pass']);
33)   DEBUG($debug_config);
bernd Mehr config-optionen und co...

bernd authored 14 years ago

34)   if (array_key_exists($key, $config))
35)     return $config[$key];
36)   else
bernd Logger mit Logleveln

bernd authored 14 years ago

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

bernd authored 14 years ago

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

bernd authored 14 years ago

39) }
40) 
41) 
bernd add a function to handle re...

bernd authored 14 years ago

42) function redirect($target)
43) {
44)   global $debugmode;
45)   if (! $debugmode)
46)     header("Location: {$target}");
47)   die();
48) }
49) 
50) 
bernd Hilfsfunktionen bzgl. mehre...

bernd authored 14 years ago

51) function my_server_id()
52) {
53)   $uid = (int) $_SESSION['userinfo']['uid'];
54)   $result = db_query("SELECT server FROM system.useraccounts WHERE uid={$uid}");
55)   $r = mysql_fetch_assoc($result);
56)   DEBUG($r);
57)   return $r['server'];
58) }
59) 
60) 
61) function additional_servers()
62) {
63)   $uid = (int) $_SESSION['userinfo']['uid'];
64)   $result = db_query("SELECT server FROM system.user_server WHERE uid={$uid}");
65)   $servers = array();
66)   while ($s = mysql_fetch_assoc($result))
67)     $servers[] = $s['server'];
68)   DEBUG($servers);
69)   return $servers;
70) }
71) 
72) 
73) function server_names()
74) {
75)   $result = db_query("SELECT id, hostname FROM system.servers");
76)   $servers = array();
77)   while ($s = mysql_fetch_assoc($result))
78)     $servers[$s['id']] = $s['hostname'];
79)   DEBUG($servers);
80)   return $servers;
81) }
82) 
83) 
bernd sql-abfragen abstrahiert

bernd authored 16 years ago

84) function db_query($query)
85) {
86)   DEBUG($query);
87)   $result = @mysql_query($query);
88)   if (mysql_error())
89)   {
90)     $error = mysql_error();
bernd Logger mit Logleveln

bernd authored 14 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 15 years ago

94)   $count = @mysql_num_rows($result);
95)   if (! $count)
96)     $count = 'no';
97)   DEBUG("=> {$count} rows");
bernd sql-abfragen abstrahiert

bernd authored 16 years ago

98)   return $result; 
99) }
100) 
101) 
bernd Neues Modul für "Kunde werden"

bernd authored 16 years ago

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

bernd authored 14 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 14 years ago

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

bernd authored 16 years ago

117) 
bernd Logger mit Logleveln

bernd authored 14 years ago

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

bernd authored 16 years ago

119) {
bernd Logger mit Logleveln

bernd authored 14 years ago

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

bernd authored 16 years ago

121)     return;
122) 
bernd Logging aktiviert

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

127)     $user = "'{$_SESSION['customerinfo']['customerno']}'";
128)   
129)   $remote = mysql_real_escape_string($_SERVER['REMOTE_ADDR']);
130) 
131)   $scriptname = mysql_real_escape_string($scriptname);
132)   $scope = mysql_real_escape_string($scope);
133)   $message = mysql_real_escape_string($message);
134) 
bernd sql-abfragen abstrahiert

bernd authored 16 years ago

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

136) }
137) 
bernd Allow Header entries and AJAX

bernd authored 15 years ago

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

bernd authored 16 years ago

143) 
bernd Umstellung auf Theme-Suppor...

bernd authored 13 years ago

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

bernd authored 17 years ago

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

bernd authored 15 years ago

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

bernd authored 17 years ago

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

bernd authored 16 years ago

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

bernd authored 13 years ago

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

bernd authored 15 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 17 years ago

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

bernd authored 16 years ago

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

bernd authored 17 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

225)   if ($formtoken == NULL)
226)     $formtoken = $_POST['formtoken'];
bernd XSRF-kram fixed

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

240) 
bernd Zeige Links auf dem Startse...

bernd authored 14 years ago

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

bernd authored 14 years ago

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

bernd authored 14 years ago

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

bernd authored 15 years ago

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

bernd authored 16 years ago

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

bernd authored 15 years ago

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

bernd authored 15 years ago

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

bernd authored 15 years ago

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

bernd authored 14 years ago

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

bernd authored 15 years ago

261)       else
bernd fix a warning

bernd authored 14 years ago

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

bernd authored 15 years ago

263)     }
264)   $querystring = implode('&amp;', $new_query);
265)   if ($querystring)
266)     $querystring = '?'.$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)   return $querystring;
269) }
bernd Neues Jabber-Modul (noch ni...

bernd authored 16 years ago

270) 
bernd * alle internen Links sinnv...

bernd authored 15 years ago

271) 
bernd addnew() eingeführt

bernd authored 14 years ago

272) function addnew($file, $label, $querystring = '')
273) {
bernd Parameter querystring bei a...

bernd authored 14 years ago

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

bernd authored 14 years ago

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

bernd authored 15 years ago

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

bernd authored 14 years ago

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

bernd authored 14 years ago

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

bernd authored 14 years ago

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

bernd authored 15 years ago

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

bernd authored 16 years ago

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

bernd authored 15 years ago

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

bernd authored 16 years ago

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

bernd authored 15 years ago

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

bernd authored 16 years ago

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

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

bernd authored 15 years ago

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

bernd authored 16 years ago

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

bernd authored 15 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

319) 
320)