3d979297795a9f63ab876a76f3e847f1f298c92e
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 Zeige Links auf dem Startse...

bernd authored 15 years ago

149) function have_module($modname)
150) {
151)   global $config;
152)   return in_array($modname, $config['modules']);
153) }
154) 
155) 
bernd * alle internen Links sinnv...

bernd authored 15 years ago

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

bernd authored 16 years ago

157) {
158)   global $debugmode;
159)   if ($debugmode)
bernd * alle internen Links sinnv...

bernd authored 15 years ago

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

bernd authored 15 years ago

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

bernd authored 15 years ago

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

bernd authored 15 years ago

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

bernd authored 15 years ago

164)   $new_query = array();
165)   foreach ($query AS $item)
166)     if ($item != '')
167)     {
168)       list($key, $val) = explode('=', $item, 2);
bernd Bug im Client-Zertfikat-Man...

bernd authored 15 years ago

169)       if ($val == '')
170)         $new_query[] = $key;
171)       else
172)         $new_query[] = $key.'='.urlencode($val);
bernd * alle internen Links sinnv...

bernd authored 15 years ago

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

bernd authored 15 years ago

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

bernd authored 15 years ago

175)   $querystring = implode('&amp;', $new_query);
176)   if ($querystring)
177)     $querystring = '?'.$querystring;
bernd Bug im Client-Zertfikat-Man...

bernd authored 15 years ago

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

bernd authored 15 years ago

179)   return $querystring;
180) }
bernd Neues Jabber-Modul (noch ni...

bernd authored 16 years ago

181) 
bernd * alle internen Links sinnv...

bernd authored 15 years ago

182) 
183) 
184) function internal_link($file, $label, $querystring = '', $attribs = '')
185) {
bernd Erlaube absolute Links

bernd authored 15 years ago

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

bernd authored 15 years ago

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

bernd authored 15 years ago

188)   {
189)     $file = $prefix.substr($file, 1);
190)   }
bernd * alle internen Links sinnv...

bernd authored 15 years ago

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

bernd authored 16 years ago

193) }
194) 
195) 
196) function html_form($form_id, $scriptname, $querystring, $content)
197) {
bernd * alle internen Links sinnv...

bernd authored 15 years ago

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

bernd authored 16 years ago

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

bernd authored 15 years ago

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

bernd authored 16 years ago

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

202)   $ret .= $content;
203)   $ret .= '</form>';
204)   return $ret;  
205) }
206) 
207) 
bernd * wie viele Reihen wurden a...

bernd authored 15 years ago

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

bernd authored 16 years ago

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

bernd authored 15 years ago

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

bernd authored 16 years ago

212)   foreach ($options as $key => $value)
213)   {
214)     $selected = '';
215)     if ($default == $key)
216)       $selected = ' selected="selected" ';
217)     $key = filter_input_general($key);
218)     $value = filter_input_general($value);
219)     $ret .= "  <option value=\"{$key}\"{$selected}>{$value}</option>\n";
220)   }
221)   $ret .= '</select>';
222)   return $ret;
223) }
224) 
bernd Neues Jabber-Modul (noch ni...

bernd authored 16 years ago

225) 
226)