d73051da9b31a70a6349868ef3c83400b3f1ae47
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 Umfangreiche Code-Aufräumar...

bernd authored 16 years ago

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

bernd authored 15 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 17 years ago

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

bernd authored 16 years ago

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

bernd authored 17 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

224) 
bernd Zeige Links auf dem Startse...

bernd authored 14 years ago

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

bernd authored 14 years ago

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

bernd authored 14 years ago

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

bernd authored 15 years ago

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

bernd authored 16 years ago

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

bernd authored 15 years ago

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

bernd authored 15 years ago

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

bernd authored 15 years ago

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

bernd authored 14 years ago

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

bernd authored 15 years ago

245)       else
bernd fix a warning

bernd authored 14 years ago

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

bernd authored 15 years ago

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

bernd authored 15 years ago

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

bernd authored 15 years ago

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

bernd authored 16 years ago

254) 
bernd * alle internen Links sinnv...

bernd authored 15 years ago

255) 
bernd addnew() eingeführt

bernd authored 14 years ago

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

bernd authored 14 years ago

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

bernd authored 14 years ago

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

bernd authored 15 years ago

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

bernd authored 15 years ago

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

bernd authored 15 years ago

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

bernd authored 15 years ago

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

bernd authored 15 years ago

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

bernd authored 16 years ago

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

bernd authored 15 years ago

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

bernd authored 16 years ago

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

bernd authored 15 years ago

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

bernd authored 16 years ago

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

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

bernd authored 15 years ago

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

bernd authored 16 years ago

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

bernd authored 15 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

303) 
304)