45e40a07d1a77169b8f303e1a7c24ee4da96465d
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 17 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 15 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 15 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);
172)   $new_query = array();
173)   foreach ($query AS $item)
174)     if ($item != '')
175)     {
176)       list($key, $val) = explode('=', $item, 2);
bernd Bug im Client-Zertfikat-Man...

bernd authored 15 years ago

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

bernd authored 15 years ago

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

bernd authored 15 years ago

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

bernd authored 15 years ago

186)   return $querystring;
187) }
bernd Neues Jabber-Modul (noch ni...

bernd authored 16 years ago

188) 
bernd * alle internen Links sinnv...

bernd authored 15 years ago

189) 
bernd addnew() eingeführt

bernd authored 14 years ago

190) function addnew($file, $label, $querystring = '')
191) {
192)   output('<p class="addnew">'.internal_link($file, $label).'</p>');
193) }
194) 
bernd * alle internen Links sinnv...

bernd authored 15 years ago

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

bernd authored 15 years ago

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

bernd authored 15 years ago

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

bernd authored 15 years ago

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

bernd authored 15 years ago

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

bernd authored 16 years ago

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

bernd authored 15 years ago

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

bernd authored 16 years ago

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

bernd authored 15 years ago

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

bernd authored 16 years ago

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

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

bernd authored 15 years ago

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

bernd authored 16 years ago

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

bernd authored 15 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

237) 
238)