ff0f9b9b8aecdc1dfd011fdfbee2cf577b00e3a2
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)   }
30)   DEBUG($config);
bernd Mehr config-optionen und co...

bernd authored 14 years ago

31)   if (array_key_exists($key, $config))
32)     return $config[$key];
33)   else
bernd Logger mit Logleveln

bernd authored 14 years ago

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

bernd authored 14 years ago

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

bernd authored 14 years ago

36) }
37) 
38) 
bernd add a function to handle re...

bernd authored 14 years ago

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

bernd authored 14 years ago

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

bernd authored 16 years ago

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

bernd authored 14 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 15 years ago

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

bernd authored 16 years ago

95)   return $result; 
96) }
97) 
98) 
bernd Neues Modul für "Kunde werden"

bernd authored 16 years ago

99) 
100) function maybe_null($value)
101) {
bernd maybe_null behandelt jetzt...

bernd authored 15 years ago

102)   if ($value == NULL)
103)     return 'NULL';
104) 
bernd Neues Modul für "Kunde werden"

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

107)   else
108)     return 'NULL';
109) }
110) 
bernd Logger mit Logleveln

bernd authored 14 years ago

111) #define('LOG_ERR', 3);
112) #define('LOG_WARNING', 4);
113) #define('LOG_INFO', 6);
bernd Neues Modul für "Kunde werden"

bernd authored 16 years ago

114) 
bernd Logger mit Logleveln

bernd authored 14 years ago

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

bernd authored 16 years ago

116) {
bernd Logger mit Logleveln

bernd authored 14 years ago

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

bernd authored 16 years ago

118)     return;
119) 
bernd Logging aktiviert

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

133) }
134) 
bernd Allow Header entries and AJAX

bernd authored 15 years ago

135) function html_header($arg)
136) {
137)   global $html_header;
138)   $html_header .= $arg;
139) }
bernd Logging aktiviert

bernd authored 16 years ago

140) 
bernd Umstellung auf Theme-Suppor...

bernd authored 13 years ago

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

bernd authored 17 years ago

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

bernd authored 15 years ago

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

bernd authored 17 years ago

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

bernd authored 16 years ago

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

bernd authored 13 years ago

172)   title('Sicherheitsabfrage');
173)   output("
bernd * alle internen Links sinnv...

bernd authored 15 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

181)         <input type=\"submit\" name=\"not_really\" value=\"Nein\" />
182)       </p>
183)     </div>");
bernd </form>

bernd authored 17 years ago

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

bernd authored 17 years ago

185) }
186) 
187) 
188) function user_is_sure()
189) {
190)   if (isset($_POST['really']))
191)   {
bernd XSRF-kram fixed

bernd authored 16 years ago

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

bernd authored 17 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

217) }
218) 
219) 
bernd Umfangreiche Code-Aufräumar...

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

229)   }
230) 
bernd Neues Jabber-Modul (noch ni...

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

237) 
bernd Zeige Links auf dem Startse...

bernd authored 14 years ago

238) function have_module($modname)
239) {
bernd Mehr config-optionen und co...

bernd authored 14 years ago

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

bernd authored 14 years ago

241) }
242) 
243) 
bernd * alle internen Links sinnv...

bernd authored 15 years ago

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

bernd authored 16 years ago

245) {
246)   global $debugmode;
247)   if ($debugmode)
bernd * alle internen Links sinnv...

bernd authored 15 years ago

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

bernd authored 15 years ago

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

bernd authored 15 years ago

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

bernd authored 14 years ago

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

bernd authored 15 years ago

258)       else
bernd fix a warning

bernd authored 14 years ago

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

bernd authored 15 years ago

260)     }
261)   $querystring = implode('&amp;', $new_query);
262)   if ($querystring)
263)     $querystring = '?'.$querystring;
bernd Bug im Client-Zertfikat-Man...

bernd authored 15 years ago

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

bernd authored 15 years ago

265)   return $querystring;
266) }
bernd Neues Jabber-Modul (noch ni...

bernd authored 16 years ago

267) 
bernd * alle internen Links sinnv...

bernd authored 15 years ago

268) 
bernd addnew() eingeführt

bernd authored 14 years ago

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

bernd authored 14 years ago

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

bernd authored 14 years ago

272) }
273) 
bernd * alle internen Links sinnv...

bernd authored 15 years ago

274) 
275) function internal_link($file, $label, $querystring = '', $attribs = '')
276) {
bernd Erlaube absolute Links

bernd authored 15 years ago

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

bernd authored 15 years ago

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

bernd authored 15 years ago

279)   {
280)     $file = $prefix.substr($file, 1);
281)   }
bernd * alle internen Links sinnv...

bernd authored 15 years ago

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

bernd authored 16 years ago

284) }
285) 
286) 
287) function html_form($form_id, $scriptname, $querystring, $content)
288) {
bernd * alle internen Links sinnv...

bernd authored 15 years ago

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

bernd authored 16 years ago

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

bernd authored 15 years ago

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

bernd authored 16 years ago

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

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

bernd authored 15 years ago

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

bernd authored 16 years ago

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

bernd authored 15 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

316) 
317)