f241254578ace7706c4cb6102b756888b2a3a057
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');
4) 
bernd sql-abfragen abstrahiert

bernd authored 16 years ago

5) 
6) function db_query($query)
7) {
8)   DEBUG($query);
9)   $result = @mysql_query($query);
10)   if (mysql_error())
11)   {
12)     $error = mysql_error();
bernd eliminate .php extensions f...

bernd authored 15 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 15 years ago

16)   $count = @mysql_num_rows($result);
17)   if (! $count)
18)     $count = 'no';
19)   DEBUG("=> {$count} rows");
bernd sql-abfragen abstrahiert

bernd authored 16 years ago

20)   return $result; 
21) }
22) 
23) 
bernd Neues Modul für "Kunde werden"

bernd authored 16 years ago

24) 
25) function maybe_null($value)
26) {
bernd maybe_null behandelt jetzt...

bernd authored 15 years ago

27)   if ($value == NULL)
28)     return 'NULL';
29) 
bernd Neues Modul für "Kunde werden"

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

32)   else
33)     return 'NULL';
34) }
35) 
36) 
37) 
bernd Logging aktiviert

bernd authored 16 years ago

38) function logger($scriptname, $scope, $message)
39) {
bernd Logging konfigurierbar

bernd authored 16 years ago

40)   global $config;
41)   if ($config['logging'] == false)
42)     return;
43) 
bernd Logging aktiviert

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

48)     $user = "'{$_SESSION['customerinfo']['customerno']}'";
49)   
50)   $remote = mysql_real_escape_string($_SERVER['REMOTE_ADDR']);
51) 
52)   $scriptname = mysql_real_escape_string($scriptname);
53)   $scope = mysql_real_escape_string($scope);
54)   $message = mysql_real_escape_string($message);
55) 
bernd sql-abfragen abstrahiert

bernd authored 16 years ago

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

57) }
58) 
bernd Allow Header entries and AJAX

bernd authored 15 years ago

59) function html_header($arg)
60) {
61)   global $html_header;
62)   $html_header .= $arg;
63) }
bernd Logging aktiviert

bernd authored 16 years ago

64) 
bernd webinterface => /webinterface

bernd authored 17 years ago

65) function output($arg)
66) {
67)   global $output;
68)   $output .= $arg;
69) }
70) 
71) 
72) function random_string($nc, $a='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789') {
73)     $l=strlen($a)-1; $r='';
74)     while($nc-->0) $r.=$a{mt_rand(0,$l)};
75)     return $r;
76)  }
77) 
78) 
79) function are_you_sure($query_string, $question)
80) {
bernd * alle internen Links sinnv...

bernd authored 15 years ago

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

bernd authored 17 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 15 years ago

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

bernd authored 16 years ago

86)     <div class=\"confirmation\">
87)       <div class=\"question\">{$question}</div>
88)       <p class=\"buttons\">
89)         <input type=\"hidden\" name=\"random_token\" value=\"{$token}\" />
90)         <input type=\"submit\" name=\"really\" value=\"Ja\" />
bernd Entities repariert

bernd authored 16 years ago

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

bernd authored 16 years ago

92)         <input type=\"submit\" name=\"not_really\" value=\"Nein\" />
93)       </p>
94)     </div>");
bernd </form>

bernd authored 17 years ago

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

bernd authored 17 years ago

96) }
97) 
98) 
99) function user_is_sure()
100) {
101)   if (isset($_POST['really']))
102)   {
bernd XSRF-kram fixed

bernd authored 16 years ago

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

bernd authored 17 years ago

104)       return true;
105)     else
106)       system_failure("Possible Cross-site-request-forgery detected!");
107)   }
108)   elseif (isset($_POST['not_really']))
109)     return false;
110)   else
111)     return NULL;
112) }
113) 
114) 
115) 
bernd XSRF-kram fixed

bernd authored 16 years ago

116) function generate_form_token($form_id)
117) {
118)   require_once("inc/debug.php");
119)   $sessid = session_id();
120)   if ($sessid == "") 
121)   {
122)     DEBUG("Uh? Session not running? Wtf?");
bernd Neues Jabber-Modul (noch ni...

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

128) }
129) 
130) 
bernd Umfangreiche Code-Aufräumar...

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

135)   $sessid = session_id();
136)   if ($sessid == "") 
137)   {
138)     DEBUG("Uh? Session not running? Wtf?");
bernd Umfangreiche Code-Aufräumar...

bernd authored 16 years ago

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

bernd authored 16 years ago

140)   }
141) 
bernd Neues Jabber-Modul (noch ni...

bernd authored 16 years ago

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

bernd authored 16 years ago

143) 
144)   if (! ($formtoken == $correct_formtoken))
145)     system_failure("Possible cross-site-request-forgery!");
146) }
147) 
bernd Neues Jabber-Modul (noch ni...

bernd authored 16 years ago

148) 
bernd * alle internen Links sinnv...

bernd authored 15 years ago

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

bernd authored 16 years ago

150) {
151)   global $debugmode;
152)   if ($debugmode)
bernd * alle internen Links sinnv...

bernd authored 15 years ago

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

bernd authored 15 years ago

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

bernd authored 15 years ago

155)   $query = explode('&', $querystring);
bernd Bug im Client-Zertfikat-Man...

bernd authored 15 years ago

156)   DEBUG($query);
bernd * alle internen Links sinnv...

bernd authored 15 years ago

157)   $new_query = array();
158)   foreach ($query AS $item)
159)     if ($item != '')
160)     {
161)       list($key, $val) = explode('=', $item, 2);
bernd Bug im Client-Zertfikat-Man...

bernd authored 15 years ago

162)       if ($val == '')
163)         $new_query[] = $key;
164)       else
165)         $new_query[] = $key.'='.urlencode($val);
bernd * alle internen Links sinnv...

bernd authored 15 years ago

166)     }
bernd Bug im Client-Zertfikat-Man...

bernd authored 15 years ago

167)   DEBUG($new_query);
bernd * alle internen Links sinnv...

bernd authored 15 years ago

168)   $querystring = implode('&amp;', $new_query);
169)   if ($querystring)
170)     $querystring = '?'.$querystring;
bernd Bug im Client-Zertfikat-Man...

bernd authored 15 years ago

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

bernd authored 15 years ago

172)   return $querystring;
173) }
bernd Neues Jabber-Modul (noch ni...

bernd authored 16 years ago

174) 
bernd * alle internen Links sinnv...

bernd authored 15 years ago

175) 
176) 
177) function internal_link($file, $label, $querystring = '', $attribs = '')
178) {
bernd Erlaube absolute Links

bernd authored 15 years ago

179)   global $prefix;
180)   if (strpos($file, '/') == 0)
181)   {
182)     $file = $prefix.substr($file, 1);
183)   }
bernd * alle internen Links sinnv...

bernd authored 15 years ago

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

bernd authored 16 years ago

186) }
187) 
188) 
189) function html_form($form_id, $scriptname, $querystring, $content)
190) {
bernd * alle internen Links sinnv...

bernd authored 15 years ago

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

bernd authored 16 years ago

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

bernd authored 15 years ago

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

bernd authored 16 years ago

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

195)   $ret .= $content;
196)   $ret .= '</form>';
197)   return $ret;  
198) }
199) 
200) 
bernd * wie viele Reihen wurden a...

bernd authored 15 years ago

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

bernd authored 16 years ago

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

bernd authored 15 years ago

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

bernd authored 16 years ago

205)   foreach ($options as $key => $value)
206)   {
207)     $selected = '';
208)     if ($default == $key)
209)       $selected = ' selected="selected" ';
210)     $key = filter_input_general($key);
211)     $value = filter_input_general($value);
212)     $ret .= "  <option value=\"{$key}\"{$selected}>{$value}</option>\n";
213)   }
214)   $ret .= '</select>';
215)   return $ret;
216) }
217) 
bernd Neues Jabber-Modul (noch ni...

bernd authored 16 years ago

218) 
219)