searchcode logo
Dogecoin is an open source peer-to-peer cryptocurrency

osticket /upload/include/class.config.php

git clone https://bitbucket.org/fstech/osticket.git

Language

PHP

MD5 Hash

c90e408f87ce464629034bb914575d12

Lines in File 608
Blank Lines 129 (21.22%)
Comment Lines 23 (4%)
Code Lines 455 (75%)
Estimated Development Effort (Months)1.04
Estimated Development Effort (Years)0
Estimated Developers0.41
Estimated Cost$11764.00
Generated using David A. Wheeler's 'SLOCCount'.
  1. <?php
  2. /*********************************************************************
  3.   class.config.php
  4.  
  5.   osTicket config info manager.
  6.  
  7.   Peter Rotich <peter@osticket.com>
  8.   Copyright (c) 2006-2010 osTicket
  9.   http://www.osticket.com
  10.  
  11.   Released under the GNU General Public License WITHOUT ANY WARRANTY.
  12.   See LICENSE.TXT for details.
  13.  
  14.   vim: expandtab sw=4 ts=4 sts=4:
  15.   $Id: $
  16. **********************************************************************/
  17.  
  18. require_once(INCLUDE_DIR.'class.email.php');
  19.  
  20. class Config {
  21.  
  22. var $id=0;
  23. var $mysqltzoffset=0;
  24. var $config=array();
  25.  
  26. var $defaultDept; //Default Department
  27. var $defaultEmail; //Default Email
  28. var $alertEmail; //Alert Email
  29. var $defaultSMTPEmail; //Default SMTP Email
  30.  
  31. function Config($id) {
  32. $this->load($id);
  33. }
  34.  
  35. function load($id) {
  36.  
  37. if($id && is_numeric($id)):
  38. $this->id=$id;
  39. $this->config=array();
  40. $res=db_query('SELECT * FROM '.CONFIG_TABLE.' WHERE id='.$id);
  41. if($res && db_num_rows($res))
  42. $this->config=db_fetch_array($res);
  43. endif;
  44. return $this->config?true:false;
  45. }
  46.  
  47. //Initialize some default values.
  48. function init(){
  49. list($mysqltz)=db_fetch_row(db_query('SELECT @@session.time_zone '));
  50. $this->setMysqlTZ($mysqltz);
  51. }
  52.  
  53. function reload() {
  54. if($this->load($this->id))
  55. $this->init();
  56. }
  57.  
  58.  
  59. function isHelpDeskOffline() {
  60. return $this->config['isonline']?false:true;
  61. }
  62.  
  63. function getAPIPassphrase(){
  64. return $this->config['api_passphrase'];
  65. }
  66.  
  67. function getVersion(){
  68. return $this->config['ostversion'];
  69. }
  70.  
  71. function setMysqlTZ($tz){
  72. //TODO: Combine the 2 replace regex
  73. $this->mysqltzoffset=($tz=='SYSTEM')?preg_replace('/([+-]\d{2})(\d{2})/','\1',date('O')):preg_replace('/([+-]\d{2})(:)(\d{2})/','\1',$tz);
  74. }
  75.  
  76. function getMysqlTZoffset() {
  77. return $this->mysqltzoffset;
  78. }
  79.  
  80. /* Date & Time Formats */
  81. function observeDaylightSaving() {
  82. return $this->config['enable_daylight_saving']?true:false;
  83. }
  84. function getTimeFormat(){
  85. return $this->config['time_format'];
  86. }
  87. function getDateFormat(){
  88. return $this->config['date_format'];
  89. }
  90.  
  91. function getDateTimeFormat(){
  92. return $this->config['datetime_format'];
  93. }
  94.  
  95. function getDayDateTimeFormat(){
  96. return $this->config['daydatetime_format'];
  97. }
  98.  
  99. function getId() {
  100. return $this->config['id'];
  101. }
  102.  
  103. function getTitle() {
  104. return $this->config['helpdesk_title'];
  105. }
  106.  
  107. function getUrl() {
  108. return $this->config['helpdesk_url'];
  109. }
  110.  
  111. function getBaseUrl(){ //Same as above with no trailing slash.
  112. return rtrim($this->getUrl(),'/');
  113. }
  114.  
  115. function getConfig() {
  116. return $this->config;
  117. }
  118.  
  119. function getTZOffset(){
  120. return $this->config['timezone_offset'];
  121. }
  122.  
  123. function getPageSize() {
  124. return $this->config['max_page_size'];
  125. }
  126.  
  127. function getGracePeriod() {
  128. return $this->config['overdue_grace_period'];
  129. }
  130.  
  131.  
  132. function getClientTimeout() {
  133. return $this->getClientSessionTimeout();
  134. }
  135.  
  136. function getClientSessionTimeout() {
  137. return $this->config['client_session_timeout']*60;
  138. }
  139.  
  140. function getClientLoginTimeout() {
  141. return $this->config['client_login_timeout']*60;
  142. }
  143.  
  144. function getClientMaxLogins() {
  145. return $this->config['client_max_logins'];
  146. }
  147.  
  148. function getStaffTimeout() {
  149. return $this->getStaffSessionTimeout();
  150. }
  151.  
  152. function getStaffSessionTimeout() {
  153. return $this->config['staff_session_timeout']*60;
  154. }
  155.  
  156. function getStaffLoginTimeout() {
  157. return $this->config['staff_login_timeout']*60;
  158. }
  159.  
  160. function getStaffMaxLogins() {
  161. return $this->config['staff_max_logins'];
  162. }
  163.  
  164. function getLockTime() {
  165. return $this->config['autolock_minutes'];
  166. }
  167.  
  168. function getDefaultDeptId(){
  169. return $this->config['default_dept_id'];
  170. }
  171.  
  172. function getDefaultDept(){
  173.  
  174. if(!$this->defaultDept && $this->getDefaultDeptId())
  175. $this->defaultDept= new Dept($this->getDefaultDeptId());
  176. return $this->defaultDept;
  177. }
  178.  
  179. function getDefaultEmailId(){
  180. return $this->config['default_email_id'];
  181. }
  182.  
  183. function getDefaultEmail(){
  184.  
  185. if(!$this->defaultEmail && $this->getDefaultEmailId())
  186. $this->defaultEmail= new Email($this->getDefaultEmailId());
  187. return $this->defaultEmail;
  188. }
  189.  
  190. function getDefaultEmailAddress() {
  191. $email=$this->getDefaultEmail();
  192. return $email?$email->getAddress():null;
  193. }
  194.  
  195. function getAlertEmailId() {
  196. return $this->config['alert_email_id'];
  197. }
  198.  
  199. function getAlertEmail(){
  200.  
  201. if(!$this->alertEmail && $this->config['alert_email_id'])
  202. $this->alertEmail= new Email($this->config['alert_email_id']);
  203. return $this->alertEmail;
  204. }
  205.  
  206. function getDefaultSMTPEmail(){
  207.  
  208. if(!$this->defaultSMTPEmail && $this->config['default_smtp_id'])
  209. $this->defaultSMTPEmail= new Email($this->config['default_smtp_id']);
  210. return $this->defaultSMTPEmail;
  211. }
  212.  
  213. function allowSMTPSpoofing() {
  214. return $this->config['spoof_default_smtp'];
  215. }
  216.  
  217. function getDefaultPriorityId(){
  218. return $this->config['default_priority_id'];
  219. }
  220.  
  221. function getDefaultTemplateId() {
  222. return $this->config['default_template_id'];
  223. }
  224.  
  225. function getMaxOpenTickets() {
  226. return $this->config['max_open_tickets'];
  227. }
  228.  
  229. function getMaxFileSize(){
  230. return $this->config['max_file_size'];
  231. }
  232.  
  233. function getLogLevel(){
  234. return $this->config['log_level'];
  235. }
  236.  
  237. function getLogGracePeriod(){
  238. return $this->config['log_graceperiod'];
  239. }
  240.  
  241. function logTicketActivity(){
  242. return $this->config['log_ticket_activity'];
  243. }
  244.  
  245. function clickableURLS() {
  246. return $this->config['clickable_urls']?true:false;
  247. }
  248.  
  249. function canFetchMail() {
  250. return $this->config['enable_mail_fetch']?true:false;
  251. }
  252.  
  253. function enableStaffIPBinding(){
  254. return $this->config['staff_ip_binding']?true:false;
  255. }
  256.  
  257. function enableCaptcha() {
  258.  
  259. //Checking it in real time!
  260. if(!extension_loaded('gd') || !function_exists('gd_info'))
  261. return false;
  262.  
  263. return $this->config['enable_captcha']?true:false;
  264. }
  265.  
  266. function enableAutoCron() {
  267. return $this->config['enable_auto_cron']?true:false;
  268. }
  269.  
  270. function enableEmailPiping() {
  271. return $this->config['enable_email_piping']?true:false;
  272. }
  273.  
  274. function allowPriorityChange() {
  275. return $this->config['allow_priority_change']?true:false;
  276. }
  277.  
  278.  
  279. function useEmailPriority() {
  280. return $this->config['use_email_priority']?true:false;
  281. }
  282.  
  283. function getAdminEmail(){
  284. return $this->config['admin_email'];
  285. }
  286.  
  287. function getReplySeparator() {
  288. return $this->config['reply_separator'];
  289. }
  290.  
  291. function stripQuotedReply() {
  292. return $this->config['strip_quoted_reply']?true:false;
  293. }
  294.  
  295. function saveEmailHeaders() {
  296. return true; //No longer an option...hint: big plans for headers coming!!
  297. }
  298.  
  299. function useRandomIds() {
  300. return $this->config['random_ticket_ids']?true:false;
  301. }
  302.  
  303. /* autoresponders & Alerts */
  304. function autoRespONNewTicket() {
  305. return $this->config['ticket_autoresponder']?true:false;
  306. }
  307.  
  308. function autoRespONNewMessage() {
  309. return $this->config['message_autoresponder']?true:false;
  310. }
  311.  
  312. function notifyONNewStaffTicket(){
  313. return $this->config['ticket_notice_active']?true:false;
  314. }
  315.  
  316. function alertONNewMessage() {
  317. return $this->config['message_alert_active']?true:false;
  318. }
  319.  
  320. function alertLastRespondentONNewMessage() {
  321. return $this->config['message_alert_laststaff']?true:false;
  322. }
  323.  
  324. function alertAssignedONNewMessage() {
  325. return $this->config['message_alert_assigned']?true:false;
  326. }
  327.  
  328. function alertDeptManagerONNewMessage() {
  329. return $this->config['message_alert_dept_manager']?true:false;
  330. }
  331.  
  332. function alertONNewNote() {
  333. return $this->config['note_alert_active']?true:false;
  334. }
  335.  
  336. function alertLastRespondentONNewNote() {
  337. return $this->config['note_alert_laststaff']?true:false;
  338. }
  339.  
  340. function alertAssignedONNewNote() {
  341. return $this->config['note_alert_assigned']?true:false;
  342. }
  343.  
  344. function alertDeptManagerONNewNote() {
  345. return $this->config['note_alert_dept_manager']?true:false;
  346. }
  347.  
  348. function alertONNewTicket() {
  349. return $this->config['ticket_alert_active']?true:false;
  350. }
  351.  
  352. function alertAdminONNewTicket() {
  353. return $this->config['ticket_alert_admin']?true:false;
  354. }
  355.  
  356. function alertDeptManagerONNewTicket() {
  357. return $this->config['ticket_alert_dept_manager']?true:false;
  358. }
  359.  
  360. function alertDeptMembersONNewTicket() {
  361. return $this->config['ticket_alert_dept_members']?true:false;
  362. }
  363.  
  364. function alertONOverdueTicket() {
  365. return $this->config['overdue_alert_active']?true:false;
  366. }
  367.  
  368. function alertAssignedONOverdueTicket() {
  369. return $this->config['overdue_alert_assigned']?true:false;
  370. }
  371.  
  372. function alertDeptManagerONOverdueTicket() {
  373. return $this->config['overdue_alert_dept_manager']?true:false;
  374. }
  375.  
  376. function alertDeptMembersONOverdueTicket() {
  377. return $this->config['overdue_alert_dept_members']?true:false;
  378. }
  379.  
  380. function autoCloseTicketOnReply() {
  381. return $this->config['auto_close_ticket_on_reply']?true:false;
  382. }
  383.  
  384. function autoAssignReopenedTickets() {
  385. return $this->config['auto_assign_reopened_tickets']?true:false;
  386. }
  387.  
  388. function showAssignedTickets() {
  389. return $this->config['show_assigned_tickets']?true:false;
  390. }
  391.  
  392. function showAnsweredTickets() {
  393. return $this->config['show_answered_tickets']?true:false;
  394. }
  395.  
  396. function hideStaffName() {
  397. return $this->config['hide_staff_name']?true:false;
  398. }
  399.  
  400. function sendOverLimitNotice() {
  401. return $this->config['overlimit_notice_active']?true:false;
  402. }
  403.  
  404. /* Error alerts sent to admin email when enabled */
  405. function alertONSQLError() {
  406. return $this->config['send_sql_errors']?true:false;
  407. }
  408. function alertONLoginError() {
  409. return $this->config['send_login_errors']?true:false;
  410. }
  411.  
  412. function alertONMailParseError() {
  413. return $this->config['send_mailparse_errors']?true:false;
  414. }
  415.  
  416.  
  417.  
  418. /* Attachments */
  419.  
  420. function emailAttachments() {
  421. return $this->config['email_attachments']?true:false;
  422. }
  423.  
  424. function allowAttachments() {
  425. return $this->config['allow_attachments']?true:false;
  426. }
  427.  
  428. function allowOnlineAttachments() {
  429. return ($this->allowAttachments() && $this->config['allow_online_attachments'])?true:false;
  430. }
  431.  
  432. function allowAttachmentsOnlogin() {
  433. return ($this->allowOnlineAttachments() && $this->config['allow_online_attachments_onlogin'])?true:false;
  434. }
  435.  
  436. function allowEmailAttachments() {
  437. return ($this->allowAttachments() && $this->config['allow_email_attachments'])?true:false;
  438. }
  439.  
  440. function getUploadDir() {
  441. return $this->config['upload_dir'];
  442. }
  443.  
  444. //simply checking if destination dir is usable..nothing to do with permission to upload!
  445. function canUploadFiles() {
  446. $dir=$this->config['upload_dir'];
  447. return ($dir && is_writable($dir))?TRUE:FALSE;
  448. }
  449.  
  450. function canUploadFileType($filename) {
  451. $ext = strtolower(preg_replace("/.*\.(.{3,4})$/", "$1", $filename));
  452. $allowed=$this->config['allowed_filetypes']?array_map('trim',explode(',',strtolower($this->config['allowed_filetypes']))):null;
  453. return ($ext && is_array($allowed) && (in_array(".$ext",$allowed) || in_array(".*",$allowed)))?TRUE:FALSE;
  454. }
  455.  
  456. function updatePref($var,&$errors) {
  457.  
  458. if(!$var || $errors)
  459. return false;
  460.  
  461. $f=array();
  462. $f['helpdesk_url']=array('type'=>'string', 'required'=>1, 'error'=>'Helpdesk URl required'); //TODO: Add url validation
  463. $f['helpdesk_title']=array('type'=>'string', 'required'=>1, 'error'=>'Helpdesk title required');
  464. $f['default_dept_id']=array('type'=>'int', 'required'=>1, 'error'=>'Default Dept. required');
  465. $f['default_email_id']=array('type'=>'int', 'required'=>1, 'error'=>'Default email required');
  466. $f['default_template_id']=array('type'=>'int', 'required'=>1, 'error'=>'You must select template.');
  467. $f['staff_session_timeout']=array('type'=>'int', 'required'=>1, 'error'=>'Enter idle time in minutes');
  468. $f['client_session_timeout']=array('type'=>'int', 'required'=>1, 'error'=>'Enter idle time in minutes');
  469. $f['time_format']=array('type'=>'string', 'required'=>1, 'error'=>'Time format required'); //TODO: Add date format validation
  470. $f['date_format']=array('type'=>'string', 'required'=>1, 'error'=>'Date format required');
  471. $f['datetime_format']=array('type'=>'string', 'required'=>1, 'error'=>'Datetime format required');
  472. $f['daydatetime_format']=array('type'=>'string', 'required'=>1, 'error'=>'Day, Datetime format required');
  473. $f['admin_email']=array('type'=>'email', 'required'=>1, 'error'=>'Valid email required');
  474. $f['autolock_minutes']=array('type'=>'int', 'required'=>1, 'error'=>'Enter lock time in minutes');
  475. //TODO: check option fields for validity.
  476.  
  477. //do the validation.
  478. $val = new Validator();
  479. $val->setFields($f);
  480. if(!$val->validate($var)){
  481. $errors=array_merge($errors,$val->errors());
  482. }
  483.  
  484. if($var['ticket_alert_active']
  485. && (!isset($var['ticket_alert_admin'])
  486. && !isset($var['ticket_alert_dept_manager'])
  487. && !isset($var['ticket_alert_dept_members']))){
  488. $errors['ticket_alert_active']='No target recipient(s) selected';
  489. }
  490. if($var['message_alert_active']
  491. && (!isset($var['message_alert_laststaff'])
  492. && !isset($var['message_alert_assigned'])
  493. && !isset($var['message_alert_dept_manager']))){
  494. $errors['message_alert_active']='No target recipient(s) selected';
  495. }
  496.  
  497. if($var['note_alert_active']
  498. && (!isset($var['note_alert_laststaff'])
  499. && !isset($var['note_alert_assigned'])
  500. && !isset($var['note_alert_dept_manager']))){
  501. $errors['note_alert_active']='No target recipient(s) selected';
  502. }
  503.  
  504. if($var['strip_quoted_reply'] && !$var['reply_separator'])
  505. $errors['reply_separator']='Reply separator required (?)';
  506.  
  507. if($var['enable_captcha']){
  508. if (!extension_loaded('gd'))
  509. $errors['enable_captcha']='The GD extension required';
  510. elseif(!function_exists('imagepng'))
  511. $errors['enable_captcha']='PNG support required for Image Captcha';
  512. }
  513.  
  514. if(!$errors['admin_email'] && Email::getIdByEmail($var['admin_email'])) //Make sure admin email is not also a system email.
  515. $errors['admin_email']='Email already setup as system email';
  516.  
  517.  
  518.  
  519.  
  520. if($errors) return false; //No go!
  521.  
  522. //We are good to go...blanket update!
  523. $sql= 'UPDATE '.CONFIG_TABLE.' SET isonline='.db_input($var['isonline']).
  524. ',timezone_offset='.db_input($var['timezone_offset']).
  525. ',enable_daylight_saving='.db_input(isset($var['enable_daylight_saving'])?1:0).
  526. ',staff_ip_binding='.db_input(isset($var['staff_ip_binding'])?1:0).
  527. ',staff_max_logins='.db_input($var['staff_max_logins']).
  528. ',staff_login_timeout='.db_input($var['staff_login_timeout']).
  529. ',staff_session_timeout='.db_input($var['staff_session_timeout']).
  530. ',client_max_logins='.db_input($var['client_max_logins']).
  531. ',client_login_timeout='.db_input($var['client_login_timeout']).
  532. ',client_session_timeout='.db_input($var['client_session_timeout']).
  533. ',max_page_size='.db_input($var['max_page_size']).
  534. ',log_level='.db_input($var['log_level']).
  535. ',log_graceperiod='.db_input($var['log_graceperiod']).
  536. ',max_open_tickets='.db_input($var['max_open_tickets']).
  537. ',autolock_minutes='.db_input($var['autolock_minutes']).
  538. ',overdue_grace_period='.db_input($var['overdue_grace_period']).
  539. ',alert_email_id='.db_input($var['alert_email_id']).
  540. ',default_email_id='.db_input($var['default_email_id']).
  541. ',default_dept_id='.db_input($var['default_dept_id']).
  542. ',default_priority_id='.db_input($var['default_priority_id']).
  543. ',default_template_id='.db_input($var['default_template_id']).
  544. ',default_smtp_id='.db_input($var['default_smtp_id']).
  545. ',spoof_default_smtp='.db_input(($var['default_smtp'] && isset($var['spoof_default_smtp']))?1:0).
  546. ',clickable_urls='.db_input(isset($var['clickable_urls'])?1:0).
  547. ',allow_priority_change='.db_input(isset($var['allow_priority_change'])?1:0).
  548. ',use_email_priority='.db_input(isset($var['use_email_priority'])?1:0).
  549. ',enable_captcha='.db_input(isset($var['enable_captcha'])?1:0).
  550. ',enable_auto_cron='.db_input(isset($var['enable_auto_cron'])?1:0).
  551. ',enable_mail_fetch='.db_input(isset($var['enable_mail_fetch'])?1:0).
  552. ',enable_email_piping='.db_input(isset($var['enable_email_piping'])?1:0).
  553. ',send_sql_errors='.db_input(isset($var['send_sql_errors'])?1:0).
  554. ',send_login_errors='.db_input(isset($var['send_login_errors'])?1:0).
  555. ',save_email_headers='.db_input(isset($var['save_email_headers'])?1:0).
  556. ',strip_quoted_reply='.db_input(isset($var['strip_quoted_reply'])?1:0).
  557. ',log_ticket_activity='.db_input(isset($var['log_ticket_activity'])?1:0).
  558. ',ticket_autoresponder='.db_input($var['ticket_autoresponder']).
  559. ',message_autoresponder='.db_input($var['message_autoresponder']).
  560. ',ticket_notice_active='.db_input($var['ticket_notice_active']).
  561. ',ticket_alert_active='.db_input($var['ticket_alert_active']).
  562. ',ticket_alert_admin='.db_input(isset($var['ticket_alert_admin'])?1:0).
  563. ',ticket_alert_dept_manager='.db_input(isset($var['ticket_alert_dept_manager'])?1:0).
  564. ',ticket_alert_dept_members='.db_input(isset($var['ticket_alert_dept_members'])?1:0).
  565. ',message_alert_active='.db_input($var['message_alert_active']).
  566. ',message_alert_laststaff='.db_input(isset($var['message_alert_laststaff'])?1:0).
  567. ',message_alert_assigned='.db_input(isset($var['message_alert_assigned'])?1:0).
  568. ',message_alert_dept_manager='.db_input(isset($var['message_alert_dept_manager'])?1:0).
  569. ',note_alert_active='.db_input($var['note_alert_active']).
  570. ',note_alert_laststaff='.db_input(isset($var['note_alert_laststaff'])?1:0).
  571. ',note_alert_assigned='.db_input(isset($var['note_alert_assigned'])?1:0).
  572. ',note_alert_dept_manager='.db_input(isset($var['note_alert_dept_manager'])?1:0).
  573. ',overdue_alert_active='.db_input($var['overdue_alert_active']).
  574. ',overdue_alert_assigned='.db_input(isset($var['overdue_alert_assigned'])?1:0).
  575. ',overdue_alert_dept_manager='.db_input(isset($var['overdue_alert_dept_manager'])?1:0).
  576. ',overdue_alert_dept_members='.db_input(isset($var['overdue_alert_dept_members'])?1:0).
  577. ',auto_assign_reopened_tickets='.db_input(isset($var['auto_assign_reopened_tickets'])?1:0).
  578. ',auto_close_ticket_on_reply='.db_input(isset($var['auto_close_ticket_on_reply'])?1:0).
  579. ',show_assigned_tickets='.db_input(isset($var['show_assigned_tickets'])?1:0).
  580. ',show_answered_tickets='.db_input(isset($var['show_answered_tickets'])?1:0).
  581. ',hide_staff_name='.db_input(isset($var['hide_staff_name'])?1:0).
  582. ',overlimit_notice_active='.db_input($var['overlimit_notice_active']).
  583. ',random_ticket_ids='.db_input($var['random_ticket_ids']).
  584. ',time_format='.db_input($var['time_format']).
  585. ',date_format='.db_input($var['date_format']).
  586. ',datetime_format='.db_input($var['datetime_format']).
  587. ',daydatetime_format='.db_input($var['daydatetime_format']).
  588. ',reply_separator='.db_input(trim($var['reply_separator'])).
  589. ',admin_email='.db_input($var['admin_email']).
  590. ',helpdesk_title='.db_input($var['helpdesk_title']).
  591. ',helpdesk_url='.db_input($var['helpdesk_url']).
  592. ' WHERE id='.$this->getId();
  593. //echo $sql;
  594. if(db_query($sql)) {
  595. if(db_affected_rows()) {//Something actually changed!!!!
  596. $this->reload();//Reload the new info.
  597. require_once(INCLUDE_DIR.'class.cron.php');
  598. Sys::purgeLogs(); //Cleanup the logs --- too bad if it was a mistaken config.
  599. Cron::TicketMonitor(); //Age & cleanup
  600. }
  601. return true;
  602. }
  603. return false;
  604. }
  605.  
  606. }
  607. ?>
  608.