3e33855cff22766978c6813833157ce58160acd9
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)   }
16)   return $result; 
17) }
18) 
19) 
bernd Neues Modul für "Kunde werden"

bernd authored 16 years ago

20) 
21) function maybe_null($value)
22) {
23)   if (strlen( (string) $value ) > 0)
bernd Strings für mysql esapen (z...

bernd authored 16 years ago

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

bernd authored 16 years ago

25)   else
26)     return 'NULL';
27) }
28) 
29) 
30) 
bernd Logging aktiviert

bernd authored 16 years ago

31) function logger($scriptname, $scope, $message)
32) {
bernd Logging konfigurierbar

bernd authored 16 years ago

33)   global $config;
34)   if ($config['logging'] == false)
35)     return;
36) 
bernd Logging aktiviert

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

41)     $user = "'{$_SESSION['customerinfo']['customerno']}'";
42)   
43)   $remote = mysql_real_escape_string($_SERVER['REMOTE_ADDR']);
44) 
45)   $scriptname = mysql_real_escape_string($scriptname);
46)   $scope = mysql_real_escape_string($scope);
47)   $message = mysql_real_escape_string($message);
48) 
bernd sql-abfragen abstrahiert

bernd authored 16 years ago

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

50) }
51) 
52) 
bernd webinterface => /webinterface

bernd authored 17 years ago

53) function output($arg)
54) {
55)   global $output;
56)   $output .= $arg;
57) }
58) 
59) 
60) function random_string($nc, $a='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789') {
61)     $l=strlen($a)-1; $r='';
62)     while($nc-->0) $r.=$a{mt_rand(0,$l)};
63)     return $r;
64)  }
65) 
66) 
67) function are_you_sure($query_string, $question)
68) {
bernd Neues Jabber-Modul (noch ni...

bernd authored 16 years ago

69)   global $debugmode;
70)   if ($debugmode)
71)     $query_string = 'debug&amp;'.$query_string;
bernd webinterface => /webinterface

bernd authored 17 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

74)   output("<h3>Sicherheitsabfrage</h3>
75)     <form action=\"?{$query_string}\" method=\"post\">
76)     <div class=\"confirmation\">
77)       <div class=\"question\">{$question}</div>
78)       <p class=\"buttons\">
79)         <input type=\"hidden\" name=\"random_token\" value=\"{$token}\" />
80)         <input type=\"submit\" name=\"really\" value=\"Ja\" />
bernd Entities repariert

bernd authored 16 years ago

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

bernd authored 16 years ago

82)         <input type=\"submit\" name=\"not_really\" value=\"Nein\" />
83)       </p>
84)     </div>");
bernd </form>

bernd authored 16 years ago

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

bernd authored 17 years ago

86) }
87) 
88) 
89) function user_is_sure()
90) {
91)   if (isset($_POST['really']))
92)   {
bernd XSRF-kram fixed

bernd authored 16 years ago

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

bernd authored 17 years ago

94)       return true;
95)     else
96)       system_failure("Possible Cross-site-request-forgery detected!");
97)   }
98)   elseif (isset($_POST['not_really']))
99)     return false;
100)   else
101)     return NULL;
102) }
103) 
104) 
105) 
bernd XSRF-kram fixed

bernd authored 16 years ago

106) function generate_form_token($form_id)
107) {
108)   require_once("inc/debug.php");
109)   $sessid = session_id();
110)   if ($sessid == "") 
111)   {
112)     DEBUG("Uh? Session not running? Wtf?");
bernd Neues Jabber-Modul (noch ni...

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

118) }
119) 
120) 
bernd Umfangreiche Code-Aufräumar...

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

125)   $sessid = session_id();
126)   if ($sessid == "") 
127)   {
128)     DEBUG("Uh? Session not running? Wtf?");
bernd Umfangreiche Code-Aufräumar...

bernd authored 16 years ago

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

bernd authored 16 years ago

130)   }
131) 
bernd Neues Jabber-Modul (noch ni...

bernd authored 16 years ago

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

bernd authored 16 years ago

133) 
134)   if (! ($formtoken == $correct_formtoken))
135)     system_failure("Possible cross-site-request-forgery!");
136) }
137) 
bernd Neues Jabber-Modul (noch ni...

bernd authored 16 years ago

138) 
139) 
140) function internal_link($file, $label, $querystring = '')
141) {
142)   $debugstr = '';
143)   global $debugmode;
144)   if ($debugmode)
145)     $debugstr = 'debug&amp;';
146)   $querystring = str_replace('&', '&amp;', $querystring);
147) 
148)   return "<a href=\"{$file}?{$debugstr}${querystring}\">{$label}</a>";
149) }
150) 
151) 
152) function html_form($form_id, $scriptname, $querystring, $content)
153) {
154)   $debugstr = '';
155)   global $debugmode;
156)   if ($debugmode)
157)     $debugstr = 'debug&amp;';
158)   $querystring = str_replace('&', '&amp;', $querystring);
bernd Fragezeichen bei html_form...

bernd authored 16 years ago

159)   $qmark = '?';
160)   if ($debugstr == '' && $querystring == '')
161)     $qmark = '';
bernd Neues Jabber-Modul (noch ni...

bernd authored 16 years ago

162)   $ret = '';
bernd Fragezeichen bei html_form...

bernd authored 16 years ago

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

bernd authored 16 years ago

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

165)   $ret .= $content;
166)   $ret .= '</form>';
167)   return $ret;  
168) }
169) 
170) 
bernd Neues Modul für "Kunde werden"

bernd authored 16 years ago

171) function html_select($name, $options, $default)
172) {
173)   require_once('inc/security.php');
174)   $ret = "<select name=\"{$name}\" size=\"1\">\n";
175)   foreach ($options as $key => $value)
176)   {
177)     $selected = '';
178)     if ($default == $key)
179)       $selected = ' selected="selected" ';
180)     $key = filter_input_general($key);
181)     $value = filter_input_general($value);
182)     $ret .= "  <option value=\"{$key}\"{$selected}>{$value}</option>\n";
183)   }
184)   $ret .= '</select>';
185)   return $ret;
186) }
187) 
bernd Neues Jabber-Modul (noch ni...

bernd authored 16 years ago

188) 
189)