a1bdbea87fa7bb3deb71234e8e2d0ca754d940de
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 config() liest die Datenban...

bernd authored 14 years ago

9)   if (array_key_exists($key, $config))
10)     return $config[$key];
11)   
12)   /* read configuration from database */
13)   $options = db_query( "SELECT `key`, value FROM misc.config" );
14)   
15)   while( $object = mysql_fetch_assoc( $options ) ) {
16) 	  $config[$object['key']]=$object['value'];
17)   }
18)   DEBUG($config);
bernd Mehr config-optionen und co...

bernd authored 14 years ago

19)   if (array_key_exists($key, $config))
20)     return $config[$key];
21)   else
bernd Logger mit Logleveln

bernd authored 14 years ago

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

bernd authored 14 years ago

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

bernd authored 14 years ago

24) }
25) 
26) 
bernd add a function to handle re...

bernd authored 14 years ago

27) function redirect($target)
28) {
29)   global $debugmode;
30)   if (! $debugmode)
31)     header("Location: {$target}");
32)   die();
33) }
34) 
35) 
bernd sql-abfragen abstrahiert

bernd authored 16 years ago

36) function db_query($query)
37) {
38)   DEBUG($query);
39)   $result = @mysql_query($query);
40)   if (mysql_error())
41)   {
42)     $error = mysql_error();
bernd Logger mit Logleveln

bernd authored 14 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 15 years ago

46)   $count = @mysql_num_rows($result);
47)   if (! $count)
48)     $count = 'no';
49)   DEBUG("=> {$count} rows");
bernd sql-abfragen abstrahiert

bernd authored 16 years ago

50)   return $result; 
51) }
52) 
53) 
bernd Neues Modul für "Kunde werden"

bernd authored 16 years ago

54) 
55) function maybe_null($value)
56) {
bernd maybe_null behandelt jetzt...

bernd authored 15 years ago

57)   if ($value == NULL)
58)     return 'NULL';
59) 
bernd Neues Modul für "Kunde werden"

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

62)   else
63)     return 'NULL';
64) }
65) 
bernd Logger mit Logleveln

bernd authored 14 years ago

66) #define('LOG_ERR', 3);
67) #define('LOG_WARNING', 4);
68) #define('LOG_INFO', 6);
bernd Neues Modul für "Kunde werden"

bernd authored 16 years ago

69) 
bernd Logger mit Logleveln

bernd authored 14 years ago

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

bernd authored 16 years ago

71) {
bernd Logger mit Logleveln

bernd authored 14 years ago

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

bernd authored 16 years ago

73)     return;
74) 
bernd Logging aktiviert

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

79)     $user = "'{$_SESSION['customerinfo']['customerno']}'";
80)   
81)   $remote = mysql_real_escape_string($_SERVER['REMOTE_ADDR']);
82) 
83)   $scriptname = mysql_real_escape_string($scriptname);
84)   $scope = mysql_real_escape_string($scope);
85)   $message = mysql_real_escape_string($message);
86) 
bernd sql-abfragen abstrahiert

bernd authored 16 years ago

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

88) }
89) 
bernd Allow Header entries and AJAX

bernd authored 15 years ago

90) function html_header($arg)
91) {
92)   global $html_header;
93)   $html_header .= $arg;
94) }
bernd Logging aktiviert

bernd authored 16 years ago

95) 
bernd webinterface => /webinterface

bernd authored 17 years ago

96) function output($arg)
97) {
98)   global $output;
99)   $output .= $arg;
100) }
101) 
102) 
103) function random_string($nc, $a='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789') {
104)     $l=strlen($a)-1; $r='';
105)     while($nc-->0) $r.=$a{mt_rand(0,$l)};
106)     return $r;
107)  }
108) 
109) 
110) function are_you_sure($query_string, $question)
111) {
bernd * alle internen Links sinnv...

bernd authored 15 years ago

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

bernd authored 17 years ago

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

bernd authored 16 years ago

114)   $_SESSION['are_you_sure_token'] = $token;
bernd Umfangreiche Code-Aufräumar...

bernd authored 16 years ago

115)   output("<h3>Sicherheitsabfrage</h3>
bernd * alle internen Links sinnv...

bernd authored 15 years ago

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

bernd authored 16 years ago

117)     <div class=\"confirmation\">
118)       <div class=\"question\">{$question}</div>
119)       <p class=\"buttons\">
120)         <input type=\"hidden\" name=\"random_token\" value=\"{$token}\" />
121)         <input type=\"submit\" name=\"really\" value=\"Ja\" />
bernd Entities repariert

bernd authored 16 years ago

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

bernd authored 16 years ago

123)         <input type=\"submit\" name=\"not_really\" value=\"Nein\" />
124)       </p>
125)     </div>");
bernd </form>

bernd authored 17 years ago

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

bernd authored 17 years ago

127) }
128) 
129) 
130) function user_is_sure()
131) {
132)   if (isset($_POST['really']))
133)   {
bernd XSRF-kram fixed

bernd authored 16 years ago

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

bernd authored 17 years ago

135)       return true;
136)     else
137)       system_failure("Possible Cross-site-request-forgery detected!");
138)   }
139)   elseif (isset($_POST['not_really']))
140)     return false;
141)   else
142)     return NULL;
143) }
144) 
145) 
146) 
bernd XSRF-kram fixed

bernd authored 16 years ago

147) function generate_form_token($form_id)
148) {
149)   require_once("inc/debug.php");
150)   $sessid = session_id();
151)   if ($sessid == "") 
152)   {
153)     DEBUG("Uh? Session not running? Wtf?");
bernd Neues Jabber-Modul (noch ni...

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

159) }
160) 
161) 
bernd Umfangreiche Code-Aufräumar...

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

166)   $sessid = session_id();
167)   if ($sessid == "") 
168)   {
169)     DEBUG("Uh? Session not running? Wtf?");
bernd Umfangreiche Code-Aufräumar...

bernd authored 16 years ago

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

bernd authored 16 years ago

171)   }
172) 
bernd Neues Jabber-Modul (noch ni...

bernd authored 16 years ago

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

bernd authored 16 years ago

174) 
175)   if (! ($formtoken == $correct_formtoken))
176)     system_failure("Possible cross-site-request-forgery!");
177) }
178) 
bernd Neues Jabber-Modul (noch ni...

bernd authored 16 years ago

179) 
bernd Zeige Links auf dem Startse...

bernd authored 15 years ago

180) function have_module($modname)
181) {
bernd Mehr config-optionen und co...

bernd authored 14 years ago

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

bernd authored 15 years ago

183) }
184) 
185) 
bernd * alle internen Links sinnv...

bernd authored 15 years ago

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

bernd authored 16 years ago

187) {
188)   global $debugmode;
189)   if ($debugmode)
bernd * alle internen Links sinnv...

bernd authored 15 years ago

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

bernd authored 15 years ago

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

bernd authored 15 years ago

192)   $query = explode('&', $querystring);
193)   $new_query = array();
194)   foreach ($query AS $item)
195)     if ($item != '')
196)     {
bernd fix a warning

bernd authored 14 years ago

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

bernd authored 15 years ago

200)       else
bernd fix a warning

bernd authored 14 years ago

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

bernd authored 15 years ago

202)     }
203)   $querystring = implode('&amp;', $new_query);
204)   if ($querystring)
205)     $querystring = '?'.$querystring;
bernd Bug im Client-Zertfikat-Man...

bernd authored 15 years ago

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

bernd authored 15 years ago

207)   return $querystring;
208) }
bernd Neues Jabber-Modul (noch ni...

bernd authored 16 years ago

209) 
bernd * alle internen Links sinnv...

bernd authored 15 years ago

210) 
bernd addnew() eingeführt

bernd authored 14 years ago

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

bernd authored 14 years ago

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

bernd authored 14 years ago

214) }
215) 
bernd * alle internen Links sinnv...

bernd authored 15 years ago

216) 
217) function internal_link($file, $label, $querystring = '', $attribs = '')
218) {
bernd Erlaube absolute Links

bernd authored 15 years ago

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

bernd authored 15 years ago

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

bernd authored 15 years ago

221)   {
222)     $file = $prefix.substr($file, 1);
223)   }
bernd * alle internen Links sinnv...

bernd authored 15 years ago

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

bernd authored 16 years ago

226) }
227) 
228) 
229) function html_form($form_id, $scriptname, $querystring, $content)
230) {
bernd * alle internen Links sinnv...

bernd authored 15 years ago

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

bernd authored 16 years ago

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

bernd authored 15 years ago

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

bernd authored 16 years ago

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

235)   $ret .= $content;
236)   $ret .= '</form>';
237)   return $ret;  
238) }
239) 
240) 
bernd * wie viele Reihen wurden a...

bernd authored 15 years ago

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

bernd authored 16 years ago

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

bernd authored 15 years ago

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

bernd authored 16 years ago

245)   foreach ($options as $key => $value)
246)   {
247)     $selected = '';
248)     if ($default == $key)
249)       $selected = ' selected="selected" ';
250)     $key = filter_input_general($key);
251)     $value = filter_input_general($value);
252)     $ret .= "  <option value=\"{$key}\"{$selected}>{$value}</option>\n";
253)   }
254)   $ret .= '</select>';
255)   return $ret;
256) }
257) 
bernd Neues Jabber-Modul (noch ni...

bernd authored 16 years ago

258) 
259)