PageRenderTime 83ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/ festos/core/core.php

http://festos.googlecode.com/
PHP | 405 lines | 262 code | 55 blank | 88 comment | 49 complexity | 616a346ef279f64a109140557566500e MD5 | raw file
Possible License(s): LGPL-2.1, BSD-3-Clause
  1. <?php
  2. /* **************************************************
  3. Copyright (c) 2008, Skypanther(r) Studios, Inc.
  4. Skypanther(r) is a registered trademark of Skypanther Studios, Inc.
  5. ************************************************** */
  6. /*
  7. * DON'T CHANGE ANYTHING IN THIS FILE
  8. * ALL CONFIGURATION IS DONE IN config.php AND lang.PHP
  9. */
  10. require_once(dirname(dirname(__FILE__)).'/core/config.php');
  11. define('THEMEDIR',$config["ABSOLUTE_FILE_PATH"].'themes/'.$config["THEME"]);
  12. error_reporting($config['ERRORLEVEL']);
  13. $config["ARTISTS_APPTYPID"] = '1';
  14. $config["EXHIBITORS_APPTYPID"] = '2';
  15. $config["FOODVENDORS_APPTYPID"] = '3';
  16. $config["ENTERTAINERS_APPTYPID"] = '4';
  17. $config["VOLUNTEERS_APPTYPID"] = '5';
  18. /* INCLUDE THE CORE FILES OF THE APPLICATION */
  19. require_once($config['ABSOLUTE_FILE_PATH'].'cache/dates.php');
  20. require_once($config['ABSOLUTE_FILE_PATH'].'cache/roleinfo.php');
  21. require_once($config['ABSOLUTE_FILE_PATH']."cache/lang.php");
  22. require_once($config['ABSOLUTE_FILE_PATH']."cache/photolang.php");
  23. require_once($config['ABSOLUTE_FILE_PATH']."core/output.php");
  24. require_once($config['ABSOLUTE_FILE_PATH']."core/FestOS.php");
  25. $festos = new FestOS($config);
  26. //error_reporting($config['ERRORLEVEL']);
  27. /* APPLICATION CONSTANTS - DON'T CHANGE THESE!!!! */
  28. define('ADMINISTRATOR_ROLE_ID',1);
  29. define('VENDOR_ROLE_ID',2);
  30. define('USER_ROLE_ID',3);
  31. /* INCLUDE THE MAIL HANDLING FUNCTIONS...OKAY, SO NOT EVERY PAGE WILL NEED THEM
  32. SO THIS IS A RESOURCE WASTE. I'LL PUT THESE WHERE THEY BELONG SOMEDAY */
  33. require_once($config['ABSOLUTE_FILE_PATH'].'core/check_email_address.php');
  34. require_once($config['ABSOLUTE_FILE_PATH'].'core/class.phpmailer.php');
  35. require_once($config['ABSOLUTE_FILE_PATH'].'core/class.smtp.php');
  36. /* SOME FUNCTIONS THAT WE'LL USE A LOT, SO THEY'RE INCLUDED EVERYWHERE */
  37. ## #####################################################
  38. ## despam()
  39. ## Modifies an email address to make it less spam-scraper-friendly
  40. ## despam($email, $linkText)
  41. ## returns a complete mailto link
  42. ## #####################################################
  43. function despam($email) {
  44. $partA = substr($email,0, strpos($email,'@'));
  45. $partB = substr($email,strpos($email,'@'));
  46. $linkText = (func_num_args() == 2) ? func_get_arg(1) : $email;
  47. $linkText = str_replace('@', '<span class="nospam">&#64;</span> ', $linkText);
  48. return '<a href="#" onClick=\'a="'.$partA.'";this.href="mail"+"to:"+a+"'.$partB.'";\'>'.$linkText.'</a>';
  49. }
  50. ## #####################################################
  51. ## sendEmail()
  52. ## sends an email using mailer values in config.php
  53. ## returns nothing on success, phpMailer error string on failure
  54. ## #####################################################
  55. function sendEmail($to, $subject, $message) {
  56. global $festos, $lang, $config;
  57. // email address is good, process message
  58. $mail = new PHPMailer();
  59. $mail->SetLanguage($config['PHPMAILER_LANGUAGE'], $config['ABSOLUTE_FILE_PATH'].'/core/language');
  60. $mail->IsSMTP(); // telling the class to use SMTP
  61. $mail->SMTPAuth = $config['SMTP_AUTH']; // telling the class to use SMTP Auth
  62. $mail->Username = $config['SMTP_USER'];
  63. $mail->Password = $config['SMTP_USER_PASSWORD'];
  64. $mail->Host = $config['SMTP_SERVER'];
  65. $mail->From = (isset($festos->email) && $festos->email!='') ? $festos->email : $config['SMTP_SENDER'];
  66. $mail->FromName = (isset($festos->nickname) && $festos->nickname!='') ? $festos->nickname : '';
  67. if(strpos($to, ',')!==FALSE) {
  68. // if (substr_count($mystring, "Hello") == 0)
  69. // passed multiple addresses, so, explode it and add them all
  70. $toArray = explode(',',$to);
  71. $cnt=count($toArray);
  72. for($i=0;$i<$cnt;$i++) {
  73. $mail->AddAddress($toArray[$i]);
  74. } // end for()
  75. } else {
  76. // passed a single address, add it as the to list
  77. $mail->AddAddress($to);
  78. } // end if(strpos...
  79. $mail->Subject = $subject;
  80. $mail->Body = $message;
  81. $mail->WordWrap = 70;
  82. if(!$mail->Send()) {
  83. return $lang['phpmailer_error'] . $mail->ErrorInfo;
  84. }
  85. }
  86. ## #####################################################
  87. ## generatePassword()
  88. ## Generates a random password
  89. ## returns string
  90. ## #####################################################
  91. function generatePassword ($length = 8) {
  92. // start with a blank password
  93. $password = "";
  94. // define possible characters
  95. $possible = "0123456789bcdfghjkmnpqrstvwxyz";
  96. // set up a counter
  97. $i = 0;
  98. // add random characters to $password until $length is reached
  99. while ($i < $length) {
  100. // pick a random character from the possible ones
  101. $char = substr($possible, mt_rand(0, strlen($possible)-1), 1);
  102. // we don't want this character if it's already in the password
  103. if (!strstr($password, $char)) {
  104. $password .= $char;
  105. $i++;
  106. }
  107. }
  108. // done!
  109. return $password;
  110. }
  111. ## #####################################################
  112. ## passTheQueryString()
  113. ## Given the $_GET array, build a query string that can be
  114. ## appended to a URL for passing to a page, include, or template
  115. ## returns string
  116. ## #####################################################
  117. function passTheQueryString($q) {
  118. // TAKES THE $_GET ARRAY AND BUILDS A NEW QUERY STRING
  119. // FROM IT, FOR PASSING TO INCLUDED PAGES AND TEMPLATES
  120. $str = '';
  121. if(count($q)>0) {
  122. $str = '?';
  123. foreach($q as $qskey => $qsval) {
  124. $str .= ($qskey.'='.$qsval.'&');
  125. }
  126. }
  127. return rtrim($str,'&');
  128. }
  129. ## #####################################################
  130. ## ParamTester class
  131. ## Object class for checking a querystring parameter, options
  132. ## include testing for required value, integer value, etc.
  133. ## Use example:
  134. ## $pt = new ParamTester($_GET, 'id','integer','login.php');
  135. ## $pt->go();
  136. ## Above would check that the id was an integer, if not, would redirect to the login.php page
  137. ## #####################################################
  138. class ParamTester {
  139. var $coll;
  140. var $vbl;
  141. var $varToTest;
  142. var $type;
  143. var $redir;
  144. function ParamTester ($coll, $vbl, $type = 'integer', $redir = 'index.php') {
  145. $this->coll = &$coll; // collection ($_GET or $_POST normally)
  146. $this->vbl = $vbl; // var within the collection to actually test
  147. $this->type = $type; // data type
  148. $this->redir = $redir; // redirection URL
  149. }
  150. function setColl ($theColl) {
  151. $this->coll = $theColl;
  152. }
  153. function setVarToTest ($theVar) {
  154. $this->vbl = $theVar;
  155. }
  156. function setCheckType ($t) {
  157. $this->type = $t;
  158. }
  159. function setRedirURL ($u) {
  160. $this->redir = $u;
  161. }
  162. function go() {
  163. if(!isset($this->coll) || !isset($this->vbl) || !isset($this->coll[$this->vbl]) ) {
  164. // first, handle the cases where variables aren't set or the variable isn't in the collection
  165. header('Location:'.$this->redir);
  166. die();
  167. }
  168. $this->varToTest = $this->coll[$this->vbl];
  169. switch($this->type) {
  170. case 'integer':
  171. if(!isset($this->varToTest) || ctype_digit($this->varToTest)===FALSE) {
  172. header('Location:'.$this->redir);
  173. die();
  174. }
  175. break;
  176. case 'required':
  177. if(!isset($this->varToTest)) {
  178. header('Location:'.$this->redir);
  179. die();
  180. }
  181. break;
  182. case 'string':
  183. if(!isset($this->varToTest) || ctype_alnum($this->varToTest)===FALSE) {
  184. header('Location:'.$this->redir);
  185. die();
  186. }
  187. break;
  188. case 'letters':
  189. if(!isset($this->varToTest) || ctype_alpha($this->varToTest)===FALSE) {
  190. header('Location:'.$this->redir);
  191. die();
  192. }
  193. break;
  194. }
  195. }
  196. } // end ParamTester
  197. ## #####################################################
  198. ## VarTester class
  199. ## Object class for checking a variable (typically a querystring parameter
  200. ## that could be passed as either a GET or POST param)
  201. ## Essentially a copy of the ParamTester class
  202. ## Use example:
  203. ## $vt = new VarTester($vbl,'integer','login.php');
  204. ## $vt->go();
  205. ## Above would check that $vbl is set, is an integer, and if not, would redirect to the login.php page
  206. ## #####################################################
  207. class VarTester {
  208. var $vbl;
  209. var $type;
  210. var $redir;
  211. function VarTester ( $vbl, $type = 'integer', $redir = 'index.php') {
  212. $this->vbl = $vbl; // var within the collection to actually test
  213. $this->type = $type; // data type
  214. $this->redir = $redir; // redirection URL
  215. }
  216. function setVarToTest ($theVar) {
  217. $this->vbl = $theVar;
  218. }
  219. function setCheckType ($t) {
  220. $this->type = $t;
  221. }
  222. function setRedirURL ($u) {
  223. $this->redir = $u;
  224. }
  225. function go() {
  226. switch($this->vbl) {
  227. case 'integer':
  228. if(!isset($this->vbl) || ctype_digit($this->vbl)===FALSE) {
  229. header('Location:'.$this->redir);
  230. die();
  231. }
  232. break;
  233. case 'required':
  234. if(!isset($this->vbl)) {
  235. header('Location:'.$this->redir);
  236. die();
  237. }
  238. break;
  239. case 'string':
  240. if(!isset($this->vbl) || ctype_alnum($this->vbl)===FALSE) {
  241. header('Location:'.$this->redir);
  242. die();
  243. }
  244. break;
  245. case 'letters':
  246. if(!isset($this->vbl) || ctype_alpha($this->vbl)===FALSE) {
  247. header('Location:'.$this->redir);
  248. die();
  249. }
  250. break;
  251. }
  252. }
  253. } // end VarTester
  254. /* ************************************************************
  255. Geocoding function from http://www.hostip.info
  256. ************************************************************ */
  257. function hostip_geocode($ip_address){
  258. $url = "http://api.hostip.info/get_html.php?ip=$ip_address&position=true";
  259. $ch = curl_init(); // initialize curl handle
  260. curl_setopt($ch, CURLOPT_URL,$url); // set url to post to
  261. curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); // return into a variable
  262. curl_setopt($ch, CURLOPT_TIMEOUT, 4); // times out after 4s
  263. curl_setopt($ch, CURLOPT_POSTFIELDS, $XPost); // add POST fields
  264. $result = curl_exec($ch); // run the whole process
  265. //print $result . "<BR>";
  266. //print "$url<BR>$result<BR>";
  267. $find_string = "Country:";
  268. $start = strpos($result,$find_string);
  269. if ($start != false){
  270. $start = strpos($result,$find_string);
  271. $line_end = strpos($result,"\n",$start) - strlen($find_string) - $start;
  272. $geocode['country'] = trim(substr($result,$start + strlen($find_string),$line_end));
  273. }
  274. $find_string = "City:";
  275. $start = strpos($result,$find_string);
  276. if ($start != false){
  277. $line_end = strpos($result,"\n",$start) - strlen($find_string) - $start;
  278. $city_state = trim(substr($result,$start + strlen($find_string),$line_end));
  279. $geocode['city'] = trim(substr($city_state,0,strpos($city_state,",")));
  280. $geocode['state'] = trim(substr($city_state,strpos($city_state,",")+1));
  281. }
  282. $find_string = "Latitude:";
  283. $start = strpos($result,$find_string);
  284. if ($start != false){
  285. $line_end = strpos($result,"\n",$start) - strlen($find_string) - $start;
  286. $geocode['latitude'] = trim(substr($result,$start + strlen($find_string),$line_end));
  287. }
  288. $find_string = "Longitude:";
  289. $start = strpos($result,$find_string);
  290. if ($start != false){
  291. $line_end = strpos($result,"\n",$start) - strlen($find_string) - $start;
  292. if ($line_end <= 0) $line_end = strlen($result) - $start - strlen($find_string);
  293. $geocode['longitude'] = trim(substr($result,$start + strlen($find_string),$line_end));
  294. }
  295. return $geocode;
  296. }
  297. //==== Redirect... Try PHP header redirect, then Java redirect, then try http redirect.:
  298. function redirect($url){
  299. if (!headers_sent()){ //If headers not sent yet... then do php redirect
  300. header('Location: '.$url); exit;
  301. }else{ //If headers are sent... do java redirect... if java disabled, do html redirect.
  302. echo '<script type="text/javascript">';
  303. echo 'window.location.href="'.$url.'";';
  304. echo '</script>';
  305. echo '<noscript>';
  306. echo '<meta http-equiv="refresh" content="0;url='.$url.'" />';
  307. echo '</noscript>'; exit;
  308. }
  309. }//==== End -- Redirect
  310. //==== Turn on HTTPS - Detect if HTTPS, if not on, then turn on HTTPS:
  311. function SSLon(){
  312. if($_SERVER['HTTPS'] != 'on'){
  313. $url = "https://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
  314. redirect($url);
  315. }
  316. }//==== End -- Turn On HTTPS
  317. //==== Turn Off HTTPS -- Detect if HTTPS, if so, then turn off HTTPS:
  318. function SSLoff(){
  319. if($_SERVER['HTTPS'] == 'on'){
  320. $url = "http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
  321. redirect($url);
  322. }
  323. }//==== End -- Turn Off HTTPS
  324. /* 2009-12-21 skypanther
  325. Exploit: http://www.exploit-db.com/exploits/10552
  326. Reports that you can append one of the config fields to the URL to execute an RFI attack
  327. Doesn't work for me. But, assuming this file is included, I'll at least try to block such attacks by
  328. stripping any $config variables out of the $_GET array.
  329. */
  330. foreach($config as $cfg => $vlu) {
  331. if(isset($_GET[$cfg])) unset($_GET[$cfg]);
  332. }
  333. /*
  334. INPUT FILTERING
  335. Abstraction function so that I can replace with a different library in the
  336. future if desired
  337. */
  338. require_once($config['ABSOLUTE_FILE_PATH']."core/htmLawed.php");
  339. function filterHTML($htext) {
  340. global $config;
  341. if(!isset($config['filtertags']) || $config['filtertags'] == '' || $config['filtertags'] == NULL) {
  342. $config['filtertags'] = '*-applet-embed-iframe-object-script';
  343. }
  344. if(get_magic_quotes_gpc()) {
  345. return htmLawed(stripslashes($htext), array('comments'=>0, 'cdata'=>0, 'deny_attribute'=>'on*', 'elements'=>$config['filtertags'], 'scheme'=>'href: aim, feed, file, ftp, gopher, http, https, irc, mailto, news, nntp, sftp, ssh, telnet; style: nil; *:file, http, https' ));
  346. } else {
  347. return htmLawed($htext, array('comments'=>0, 'cdata'=>0, 'deny_attribute'=>'on*', 'elements'=>$config['filtertags'], 'scheme'=>'href: aim, feed, file, ftp, gopher, http, https, irc, mailto, news, nntp, sftp, ssh, telnet; style: nil; *:file, http, https' ));
  348. }
  349. } // end filterHTML
  350. ?>