f2550e90ad37215b9d890155806986336bf0170c
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');
bernd add a function to handle re...

bernd authored 14 years ago

4) require_once('inc/debug.php');
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;
bernd config() liest die Datenban...

bernd authored 14 years ago

9)   if (array_key_exists($key, $config))
10)     return $config[$key];
11)   
12)   /* read configuration from database */
13)   $options = db_query( "SELECT `key`, value FROM misc.config" );
14)   
15)   while( $object = mysql_fetch_assoc( $options ) ) {
16) 	  $config[$object['key']]=$object['value'];
17)   }
18)   DEBUG($config);
bernd Mehr config-optionen und co...

bernd authored 14 years ago

19)   if (array_key_exists($key, $config))
20)     return $config[$key];
21)   else
bernd Logger mit Logleveln

bernd authored 14 years ago

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

bernd authored 14 years ago

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

bernd authored 14 years ago

24) }
25) 
26) 
bernd add a function to handle re...

bernd authored 14 years ago

27) function redirect($target)
28) {
29)   global $debugmode;
30)   if (! $debugmode)
31)     header("Location: {$target}");
32)   die();
33) }
34) 
35) 
bernd Hilfsfunktionen bzgl. mehre...

bernd authored 14 years ago

36) function my_server_id()
37) {
38)   $uid = (int) $_SESSION['userinfo']['uid'];
39)   $result = db_query("SELECT server FROM system.useraccounts WHERE uid={$uid}");
40)   $r = mysql_fetch_assoc($result);
41)   DEBUG($r);
42)   return $r['server'];
43) }
44) 
45) 
46) function additional_servers()
47) {
48)   $uid = (int) $_SESSION['userinfo']['uid'];
49)   $result = db_query("SELECT server FROM system.user_server WHERE uid={$uid}");
50)   $servers = array();
51)   while ($s = mysql_fetch_assoc($result))
52)     $servers[] = $s['server'];
53)   DEBUG($servers);
54)   return $servers;
55) }
56) 
57) 
58) function server_names()
59) {
60)   $result = db_query("SELECT id, hostname FROM system.servers");
61)   $servers = array();
62)   while ($s = mysql_fetch_assoc($result))
63)     $servers[$s['id']] = $s['hostname'];
64)   DEBUG($servers);
65)   return $servers;
66) }
67) 
68) 
bernd sql-abfragen abstrahiert

bernd authored 16 years ago

69) function db_query($query)
70) {
71)   DEBUG($query);
72)   $result = @mysql_query($query);
73)   if (mysql_error())
74)   {
75)     $error = mysql_error();
bernd Logger mit Logleveln

bernd authored 14 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 15 years ago

79)   $count = @mysql_num_rows($result);
80)   if (! $count)
81)     $count = 'no';
82)   DEBUG("=> {$count} rows");
bernd sql-abfragen abstrahiert

bernd authored 16 years ago

83)   return $result; 
84) }
85) 
86) 
bernd Neues Modul für "Kunde werden"

bernd authored 16 years ago

87) 
88) function maybe_null($value)
89) {
bernd maybe_null behandelt jetzt...

bernd authored 15 years ago

90)   if ($value == NULL)
91)     return 'NULL';
92) 
bernd Neues Modul für "Kunde werden"

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

95)   else
96)     return 'NULL';
97) }
98) 
bernd Logger mit Logleveln

bernd authored 14 years ago

99) #define('LOG_ERR', 3);
100) #define('LOG_WARNING', 4);
101) #define('LOG_INFO', 6);
bernd Neues Modul für "Kunde werden"

bernd authored 16 years ago

102) 
bernd Logger mit Logleveln

bernd authored 14 years ago

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

bernd authored 16 years ago

104) {
bernd Logger mit Logleveln

bernd authored 14 years ago

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

bernd authored 16 years ago

106)     return;
107) 
bernd Logging aktiviert

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

112)     $user = "'{$_SESSION['customerinfo']['customerno']}'";
113)   
114)   $remote = mysql_real_escape_string($_SERVER['REMOTE_ADDR']);
115) 
116)   $scriptname = mysql_real_escape_string($scriptname);
117)   $scope = mysql_real_escape_string($scope);
118)   $message = mysql_real_escape_string($message);
119) 
bernd sql-abfragen abstrahiert

bernd authored 16 years ago

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

121) }
122) 
bernd Allow Header entries and AJAX

bernd authored 15 years ago

123) function html_header($arg)
124) {
125)   global $html_header;
126)   $html_header .= $arg;
127) }
bernd Logging aktiviert

bernd authored 16 years ago

128) 
bernd Umstellung auf Theme-Suppor...

bernd authored 13 years ago

129) function title($arg)
130) {
131)   global $title;
132)   $title = $arg;
133) }
134) 
135) function headline($arg)
136) {
137)   global $headline;
138)   $headline = $arg;
139) }
140) 
bernd webinterface => /webinterface

bernd authored 17 years ago

141) function output($arg)
142) {
143)   global $output;
144)   $output .= $arg;
145) }
146) 
147) 
148) function random_string($nc, $a='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789') {
149)     $l=strlen($a)-1; $r='';
150)     while($nc-->0) $r.=$a{mt_rand(0,$l)};
151)     return $r;
152)  }
153) 
154) 
155) function are_you_sure($query_string, $question)
156) {
bernd * alle internen Links sinnv...

bernd authored 15 years ago

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

bernd authored 17 years ago

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

bernd authored 16 years ago

159)   $_SESSION['are_you_sure_token'] = $token;
bernd Benutze überall title() sta...

bernd authored 13 years ago

160)   title('Sicherheitsabfrage');
161)   output("
bernd * alle internen Links sinnv...

bernd authored 15 years ago

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

bernd authored 16 years ago

163)     <div class=\"confirmation\">
164)       <div class=\"question\">{$question}</div>
165)       <p class=\"buttons\">
166)         <input type=\"hidden\" name=\"random_token\" value=\"{$token}\" />
167)         <input type=\"submit\" name=\"really\" value=\"Ja\" />
bernd Entities repariert

bernd authored 16 years ago

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

bernd authored 16 years ago

169)         <input type=\"submit\" name=\"not_really\" value=\"Nein\" />
170)       </p>
171)     </div>");
bernd </form>

bernd authored 17 years ago

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

bernd authored 17 years ago

173) }
174) 
175) 
176) function user_is_sure()
177) {
178)   if (isset($_POST['really']))
179)   {
bernd XSRF-kram fixed

bernd authored 16 years ago

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

bernd authored 17 years ago

181)       return true;
182)     else
183)       system_failure("Possible Cross-site-request-forgery detected!");
184)   }
185)   elseif (isset($_POST['not_really']))
186)     return false;
187)   else
188)     return NULL;
189) }
190) 
191) 
192) 
bernd XSRF-kram fixed

bernd authored 16 years ago

193) function generate_form_token($form_id)
194) {
195)   require_once("inc/debug.php");
196)   $sessid = session_id();
197)   if ($sessid == "") 
198)   {
199)     DEBUG("Uh? Session not running? Wtf?");
bernd Neues Jabber-Modul (noch ni...

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

205) }
206) 
207) 
bernd Umfangreiche Code-Aufräumar...

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

212)   $sessid = session_id();
213)   if ($sessid == "") 
214)   {
215)     DEBUG("Uh? Session not running? Wtf?");
bernd Umfangreiche Code-Aufräumar...

bernd authored 16 years ago

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

bernd authored 16 years ago

217)   }
218) 
bernd Neues Jabber-Modul (noch ni...

bernd authored 16 years ago

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

bernd authored 16 years ago

220) 
221)   if (! ($formtoken == $correct_formtoken))
222)     system_failure("Possible cross-site-request-forgery!");
223) }
224) 
bernd Neues Jabber-Modul (noch ni...

bernd authored 16 years ago

225) 
bernd Zeige Links auf dem Startse...

bernd authored 15 years ago

226) function have_module($modname)
227) {
bernd Mehr config-optionen und co...

bernd authored 14 years ago

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

bernd authored 15 years ago

229) }
230) 
231) 
bernd * alle internen Links sinnv...

bernd authored 15 years ago

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

bernd authored 16 years ago

233) {
234)   global $debugmode;
235)   if ($debugmode)
bernd * alle internen Links sinnv...

bernd authored 15 years ago

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

bernd authored 15 years ago

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

bernd authored 15 years ago

238)   $query = explode('&', $querystring);
239)   $new_query = array();
240)   foreach ($query AS $item)
241)     if ($item != '')
242)     {
bernd fix a warning

bernd authored 14 years ago

243)       $split = explode('=', $item, 2);
244)       if (count($split) == 1)
245)         $new_query[] = $split[0];
bernd Bug im Client-Zertfikat-Man...

bernd authored 15 years ago

246)       else
bernd fix a warning

bernd authored 14 years ago

247)         $new_query[] = $split[0].'='.urlencode($split[1]);
bernd * alle internen Links sinnv...

bernd authored 15 years ago

248)     }
249)   $querystring = implode('&amp;', $new_query);
250)   if ($querystring)
251)     $querystring = '?'.$querystring;
bernd Bug im Client-Zertfikat-Man...

bernd authored 15 years ago

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

bernd authored 15 years ago

253)   return $querystring;
254) }
bernd Neues Jabber-Modul (noch ni...

bernd authored 16 years ago

255) 
bernd * alle internen Links sinnv...

bernd authored 15 years ago

256) 
bernd addnew() eingeführt

bernd authored 14 years ago

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

bernd authored 14 years ago

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

bernd authored 14 years ago

260) }
261) 
bernd * alle internen Links sinnv...

bernd authored 15 years ago

262) 
263) function internal_link($file, $label, $querystring = '', $attribs = '')
264) {
bernd Erlaube absolute Links

bernd authored 15 years ago

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

bernd authored 15 years ago

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

bernd authored 15 years ago

267)   {
268)     $file = $prefix.substr($file, 1);
269)   }
bernd * alle internen Links sinnv...

bernd authored 15 years ago

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

bernd authored 16 years ago

272) }
273) 
274) 
275) function html_form($form_id, $scriptname, $querystring, $content)
276) {
bernd * alle internen Links sinnv...

bernd authored 15 years ago

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

bernd authored 16 years ago

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

bernd authored 15 years ago

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

bernd authored 16 years ago

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

281)   $ret .= $content;
282)   $ret .= '</form>';
283)   return $ret;  
284) }
285) 
286) 
bernd * wie viele Reihen wurden a...

bernd authored 15 years ago

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

bernd authored 16 years ago

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

bernd authored 15 years ago

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

bernd authored 16 years ago

291)   foreach ($options as $key => $value)
292)   {
293)     $selected = '';
294)     if ($default == $key)
295)       $selected = ' selected="selected" ';
296)     $key = filter_input_general($key);
297)     $value = filter_input_general($value);
298)     $ret .= "  <option value=\"{$key}\"{$selected}>{$value}</option>\n";
299)   }
300)   $ret .= '</select>';
301)   return $ret;
302) }
303) 
bernd Neues Jabber-Modul (noch ni...

bernd authored 16 years ago

304) 
305)