d5f2f3f40845c818f65b41258a2ba19f6c494175
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) {
27)   if (strlen( (string) $value ) > 0)
bernd Strings für mysql esapen (z...

bernd authored 16 years ago

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

bernd authored 16 years ago

29)   else
30)     return 'NULL';
31) }
32) 
33) 
34) 
bernd Logging aktiviert

bernd authored 16 years ago

35) function logger($scriptname, $scope, $message)
36) {
bernd Logging konfigurierbar

bernd authored 16 years ago

37)   global $config;
38)   if ($config['logging'] == false)
39)     return;
40) 
bernd Logging aktiviert

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

54) }
55) 
bernd Allow Header entries and AJAX

bernd authored 15 years ago

56) function html_header($arg)
57) {
58)   global $html_header;
59)   $html_header .= $arg;
60) }
bernd Logging aktiviert

bernd authored 16 years ago

61) 
bernd webinterface => /webinterface

bernd authored 17 years ago

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

bernd authored 15 years ago

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

bernd authored 17 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 15 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

89)         <input type=\"submit\" name=\"not_really\" value=\"Nein\" />
90)       </p>
91)     </div>");
bernd </form>

bernd authored 16 years ago

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

bernd authored 17 years ago

93) }
94) 
95) 
96) function user_is_sure()
97) {
98)   if (isset($_POST['really']))
99)   {
bernd XSRF-kram fixed

bernd authored 16 years ago

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

bernd authored 17 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

125) }
126) 
127) 
bernd Umfangreiche Code-Aufräumar...

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

137)   }
138) 
bernd Neues Jabber-Modul (noch ni...

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

145) 
bernd * alle internen Links sinnv...

bernd authored 15 years ago

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

bernd authored 16 years ago

147) {
148)   global $debugmode;
149)   if ($debugmode)
bernd * alle internen Links sinnv...

bernd authored 15 years ago

150)     $querystring = 'debug&'.$querystring;
151)   $query = explode('&', $querystring);
152)   $new_query = array();
153)   foreach ($query AS $item)
154)     if ($item != '')
155)     {
156)       list($key, $val) = explode('=', $item, 2);
157)       $new_query[] = $key.'='.($val);
158)     }
159)   $querystring = implode('&amp;', $new_query);
160)   if ($querystring)
161)     $querystring = '?'.$querystring;
162)   
163)   return $querystring;
164) }
bernd Neues Jabber-Modul (noch ni...

bernd authored 16 years ago

165) 
bernd * alle internen Links sinnv...

bernd authored 15 years ago

166) 
167) 
168) function internal_link($file, $label, $querystring = '', $attribs = '')
169) {
170)   $querystring = encode_querystring($querystring);
171)   return "<a href=\"{$file}{$querystring}\" {$attribs} >{$label}</a>";
bernd Neues Jabber-Modul (noch ni...

bernd authored 16 years ago

172) }
173) 
174) 
175) function html_form($form_id, $scriptname, $querystring, $content)
176) {
bernd * alle internen Links sinnv...

bernd authored 15 years ago

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

bernd authored 16 years ago

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

bernd authored 15 years ago

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

bernd authored 16 years ago

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

181)   $ret .= $content;
182)   $ret .= '</form>';
183)   return $ret;  
184) }
185) 
186) 
bernd * wie viele Reihen wurden a...

bernd authored 15 years ago

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

bernd authored 16 years ago

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

bernd authored 15 years ago

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

bernd authored 16 years ago

191)   foreach ($options as $key => $value)
192)   {
193)     $selected = '';
194)     if ($default == $key)
195)       $selected = ' selected="selected" ';
196)     $key = filter_input_general($key);
197)     $value = filter_input_general($value);
198)     $ret .= "  <option value=\"{$key}\"{$selected}>{$value}</option>\n";
199)   }
200)   $ret .= '</select>';
201)   return $ret;
202) }
203) 
bernd Neues Jabber-Modul (noch ni...

bernd authored 16 years ago

204) 
205)