75feee8b9da782dc92d0e7ba2f67349942809ed1
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
12)     logger("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 eliminate .php extensions f...

bernd authored 15 years ago

24)     logger("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 15 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) 
47) 
48) 
bernd Logging aktiviert

bernd authored 16 years ago

49) function logger($scriptname, $scope, $message)
50) {
bernd Mehr config-optionen und co...

bernd authored 14 years ago

51)   if (config('logging') == false)
bernd Logging konfigurierbar

bernd authored 16 years ago

52)     return;
53) 
bernd Logging aktiviert

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

67) }
68) 
bernd Allow Header entries and AJAX

bernd authored 15 years ago

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

bernd authored 16 years ago

74) 
bernd webinterface => /webinterface

bernd authored 17 years ago

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

bernd authored 15 years ago

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

bernd authored 17 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 15 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 17 years ago

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

bernd authored 16 years ago

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

bernd authored 17 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

138) }
139) 
140) 
bernd Umfangreiche Code-Aufräumar...

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

150)   }
151) 
bernd Neues Jabber-Modul (noch ni...

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

158) 
bernd Zeige Links auf dem Startse...

bernd authored 14 years ago

159) function have_module($modname)
160) {
bernd Mehr config-optionen und co...

bernd authored 14 years ago

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

bernd authored 14 years ago

162) }
163) 
164) 
bernd * alle internen Links sinnv...

bernd authored 15 years ago

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

bernd authored 16 years ago

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

bernd authored 15 years ago

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

bernd authored 15 years ago

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

bernd authored 15 years ago

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

bernd authored 15 years ago

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

bernd authored 15 years ago

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

bernd authored 15 years ago

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

bernd authored 15 years ago

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

bernd authored 15 years ago

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

bernd authored 15 years ago

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) 
192) 
193) function internal_link($file, $label, $querystring = '', $attribs = '')
194) {
bernd Erlaube absolute Links

bernd authored 15 years ago

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

bernd authored 15 years ago

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

bernd authored 15 years ago

197)   {
198)     $file = $prefix.substr($file, 1);
199)   }
bernd * alle internen Links sinnv...

bernd authored 15 years ago

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

bernd authored 16 years ago

202) }
203) 
204) 
205) function html_form($form_id, $scriptname, $querystring, $content)
206) {
bernd * alle internen Links sinnv...

bernd authored 15 years ago

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

bernd authored 16 years ago

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

bernd authored 15 years ago

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

bernd authored 16 years ago

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

211)   $ret .= $content;
212)   $ret .= '</form>';
213)   return $ret;  
214) }
215) 
216) 
bernd * wie viele Reihen wurden a...

bernd authored 15 years ago

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

bernd authored 16 years ago

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

bernd authored 15 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

234) 
235)