3048f62fff991cd7ccc258cffbc691434ee6000e
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) 
bernd Mehr config-optionen und co...

bernd authored 14 years ago

6) function config($key)
7) {
8)   global $config;
9)   if (array_key_exists($key, $config))
10)     return $config[$key];
11)   else
bernd Logger mit Logleveln

bernd authored 14 years ago

12)     logger(LOG_ERR, "inc/base", "config", "Request to read nonexistant config option »{$key}«.");
bernd Einige Dummheiten repariert...

bernd authored 14 years ago

13)     return NULL;
bernd Mehr config-optionen und co...

bernd authored 14 years ago

14) }
15) 
16) 
bernd sql-abfragen abstrahiert

bernd authored 16 years ago

17) function db_query($query)
18) {
19)   DEBUG($query);
20)   $result = @mysql_query($query);
21)   if (mysql_error())
22)   {
23)     $error = mysql_error();
bernd Logger mit Logleveln

bernd authored 14 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 15 years ago

27)   $count = @mysql_num_rows($result);
28)   if (! $count)
29)     $count = 'no';
30)   DEBUG("=> {$count} rows");
bernd sql-abfragen abstrahiert

bernd authored 16 years ago

31)   return $result; 
32) }
33) 
34) 
bernd Neues Modul für "Kunde werden"

bernd authored 16 years ago

35) 
36) function maybe_null($value)
37) {
bernd maybe_null behandelt jetzt...

bernd authored 14 years ago

38)   if ($value == NULL)
39)     return 'NULL';
40) 
bernd Neues Modul für "Kunde werden"

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

43)   else
44)     return 'NULL';
45) }
46) 
bernd Logger mit Logleveln

bernd authored 14 years ago

47) #define('LOG_ERR', 3);
48) #define('LOG_WARNING', 4);
49) #define('LOG_INFO', 6);
bernd Neues Modul für "Kunde werden"

bernd authored 16 years ago

50) 
bernd Logger mit Logleveln

bernd authored 14 years ago

51) function logger($severity, $scriptname, $scope, $message)
bernd Logging aktiviert

bernd authored 16 years ago

52) {
bernd Logger mit Logleveln

bernd authored 14 years ago

53)   if (config('logging') <= $severity)
bernd Logging konfigurierbar

bernd authored 16 years ago

54)     return;
55) 
bernd Logging aktiviert

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

60)     $user = "'{$_SESSION['customerinfo']['customerno']}'";
61)   
62)   $remote = mysql_real_escape_string($_SERVER['REMOTE_ADDR']);
63) 
64)   $scriptname = mysql_real_escape_string($scriptname);
65)   $scope = mysql_real_escape_string($scope);
66)   $message = mysql_real_escape_string($message);
67) 
bernd sql-abfragen abstrahiert

bernd authored 16 years ago

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

69) }
70) 
bernd Allow Header entries and AJAX

bernd authored 15 years ago

71) function html_header($arg)
72) {
73)   global $html_header;
74)   $html_header .= $arg;
75) }
bernd Logging aktiviert

bernd authored 16 years ago

76) 
bernd webinterface => /webinterface

bernd authored 17 years ago

77) function output($arg)
78) {
79)   global $output;
80)   $output .= $arg;
81) }
82) 
83) 
84) function random_string($nc, $a='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789') {
85)     $l=strlen($a)-1; $r='';
86)     while($nc-->0) $r.=$a{mt_rand(0,$l)};
87)     return $r;
88)  }
89) 
90) 
91) function are_you_sure($query_string, $question)
92) {
bernd * alle internen Links sinnv...

bernd authored 15 years ago

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

bernd authored 17 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 15 years ago

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

bernd authored 16 years ago

98)     <div class=\"confirmation\">
99)       <div class=\"question\">{$question}</div>
100)       <p class=\"buttons\">
101)         <input type=\"hidden\" name=\"random_token\" value=\"{$token}\" />
102)         <input type=\"submit\" name=\"really\" value=\"Ja\" />
bernd Entities repariert

bernd authored 16 years ago

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

bernd authored 16 years ago

104)         <input type=\"submit\" name=\"not_really\" value=\"Nein\" />
105)       </p>
106)     </div>");
bernd </form>

bernd authored 16 years ago

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

bernd authored 17 years ago

108) }
109) 
110) 
111) function user_is_sure()
112) {
113)   if (isset($_POST['really']))
114)   {
bernd XSRF-kram fixed

bernd authored 16 years ago

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

bernd authored 17 years ago

116)       return true;
117)     else
118)       system_failure("Possible Cross-site-request-forgery detected!");
119)   }
120)   elseif (isset($_POST['not_really']))
121)     return false;
122)   else
123)     return NULL;
124) }
125) 
126) 
127) 
bernd XSRF-kram fixed

bernd authored 16 years ago

128) function generate_form_token($form_id)
129) {
130)   require_once("inc/debug.php");
131)   $sessid = session_id();
132)   if ($sessid == "") 
133)   {
134)     DEBUG("Uh? Session not running? Wtf?");
bernd Neues Jabber-Modul (noch ni...

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

140) }
141) 
142) 
bernd Umfangreiche Code-Aufräumar...

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

147)   $sessid = session_id();
148)   if ($sessid == "") 
149)   {
150)     DEBUG("Uh? Session not running? Wtf?");
bernd Umfangreiche Code-Aufräumar...

bernd authored 16 years ago

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

bernd authored 16 years ago

152)   }
153) 
bernd Neues Jabber-Modul (noch ni...

bernd authored 16 years ago

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

bernd authored 16 years ago

155) 
156)   if (! ($formtoken == $correct_formtoken))
157)     system_failure("Possible cross-site-request-forgery!");
158) }
159) 
bernd Neues Jabber-Modul (noch ni...

bernd authored 16 years ago

160) 
bernd Zeige Links auf dem Startse...

bernd authored 14 years ago

161) function have_module($modname)
162) {
bernd Mehr config-optionen und co...

bernd authored 14 years ago

163)   return in_array($modname, config('modules'));
bernd Zeige Links auf dem Startse...

bernd authored 14 years ago

164) }
165) 
166) 
bernd * alle internen Links sinnv...

bernd authored 15 years ago

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

bernd authored 16 years ago

168) {
169)   global $debugmode;
170)   if ($debugmode)
bernd * alle internen Links sinnv...

bernd authored 15 years ago

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

bernd authored 15 years ago

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

bernd authored 15 years ago

173)   $query = explode('&', $querystring);
174)   $new_query = array();
175)   foreach ($query AS $item)
176)     if ($item != '')
177)     {
178)       list($key, $val) = explode('=', $item, 2);
bernd Bug im Client-Zertfikat-Man...

bernd authored 15 years ago

179)       if ($val == '')
180)         $new_query[] = $key;
181)       else
182)         $new_query[] = $key.'='.urlencode($val);
bernd * alle internen Links sinnv...

bernd authored 15 years ago

183)     }
184)   $querystring = implode('&amp;', $new_query);
185)   if ($querystring)
186)     $querystring = '?'.$querystring;
bernd Bug im Client-Zertfikat-Man...

bernd authored 15 years ago

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

bernd authored 15 years ago

188)   return $querystring;
189) }
bernd Neues Jabber-Modul (noch ni...

bernd authored 16 years ago

190) 
bernd * alle internen Links sinnv...

bernd authored 15 years ago

191) 
bernd addnew() eingeführt

bernd authored 14 years ago

192) function addnew($file, $label, $querystring = '')
193) {
bernd Parameter querystring bei a...

bernd authored 14 years ago

194)   output('<p class="addnew">'.internal_link($file, $label, $querystring).'</p>');
bernd addnew() eingeführt

bernd authored 14 years ago

195) }
196) 
bernd * alle internen Links sinnv...

bernd authored 15 years ago

197) 
198) function internal_link($file, $label, $querystring = '', $attribs = '')
199) {
bernd Erlaube absolute Links

bernd authored 14 years ago

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

bernd authored 14 years ago

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

bernd authored 14 years ago

202)   {
203)     $file = $prefix.substr($file, 1);
204)   }
bernd * alle internen Links sinnv...

bernd authored 15 years ago

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

bernd authored 16 years ago

207) }
208) 
209) 
210) function html_form($form_id, $scriptname, $querystring, $content)
211) {
bernd * alle internen Links sinnv...

bernd authored 15 years ago

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

bernd authored 16 years ago

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

bernd authored 15 years ago

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

bernd authored 16 years ago

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

216)   $ret .= $content;
217)   $ret .= '</form>';
218)   return $ret;  
219) }
220) 
221) 
bernd * wie viele Reihen wurden a...

bernd authored 15 years ago

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

bernd authored 16 years ago

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

bernd authored 15 years ago

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

bernd authored 16 years ago

226)   foreach ($options as $key => $value)
227)   {
228)     $selected = '';
229)     if ($default == $key)
230)       $selected = ' selected="selected" ';
231)     $key = filter_input_general($key);
232)     $value = filter_input_general($value);
233)     $ret .= "  <option value=\"{$key}\"{$selected}>{$value}</option>\n";
234)   }
235)   $ret .= '</select>';
236)   return $ret;
237) }
238) 
bernd Neues Jabber-Modul (noch ni...

bernd authored 16 years ago

239) 
240)