547266d91fe8e09f41fb6e974a2f1a3c38b4390f
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 Neues Jabber-Modul (noch ni...

bernd authored 16 years ago

78)   global $debugmode;
79)   if ($debugmode)
80)     $query_string = 'debug&amp;'.$query_string;
bernd webinterface => /webinterface

bernd authored 17 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

83)   output("<h3>Sicherheitsabfrage</h3>
84)     <form action=\"?{$query_string}\" method=\"post\">
85)     <div class=\"confirmation\">
86)       <div class=\"question\">{$question}</div>
87)       <p class=\"buttons\">
88)         <input type=\"hidden\" name=\"random_token\" value=\"{$token}\" />
89)         <input type=\"submit\" name=\"really\" value=\"Ja\" />
bernd Entities repariert

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 17 years ago

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

bernd authored 16 years ago

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

bernd authored 17 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

147) 
148) 
bernd Neues Design, neue Startseite

bernd authored 15 years ago

149) function internal_link($file, $label, $querystring = '', $attribs = '')
bernd Neues Jabber-Modul (noch ni...

bernd authored 16 years ago

150) {
151)   $debugstr = '';
152)   global $debugmode;
153)   if ($debugmode)
154)     $debugstr = 'debug&amp;';
155)   $querystring = str_replace('&', '&amp;', $querystring);
156) 
bernd Neues Design, neue Startseite

bernd authored 15 years ago

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

bernd authored 16 years ago

158) }
159) 
160) 
161) function html_form($form_id, $scriptname, $querystring, $content)
162) {
163)   $debugstr = '';
164)   global $debugmode;
165)   if ($debugmode)
166)     $debugstr = 'debug&amp;';
167)   $querystring = str_replace('&', '&amp;', $querystring);
bernd Fragezeichen bei html_form...

bernd authored 16 years ago

168)   $qmark = '?';
169)   if ($debugstr == '' && $querystring == '')
170)     $qmark = '';
bernd Neues Jabber-Modul (noch ni...

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

174)   $ret .= $content;
175)   $ret .= '</form>';
176)   return $ret;  
177) }
178) 
179) 
bernd * wie viele Reihen wurden a...

bernd authored 15 years ago

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

bernd authored 16 years ago

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

bernd authored 15 years ago

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

bernd authored 16 years ago

184)   foreach ($options as $key => $value)
185)   {
186)     $selected = '';
187)     if ($default == $key)
188)       $selected = ' selected="selected" ';
189)     $key = filter_input_general($key);
190)     $value = filter_input_general($value);
191)     $ret .= "  <option value=\"{$key}\"{$selected}>{$value}</option>\n";
192)   }
193)   $ret .= '</select>';
194)   return $ret;
195) }
196) 
bernd Neues Jabber-Modul (noch ni...

bernd authored 16 years ago

197) 
198)