Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
O
osticket
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
docker
osticket
Commits
50535478
Commit
50535478
authored
12 years ago
by
Peter Rotich
Browse files
Options
Downloads
Patches
Plain Diff
Core osTicket loader - extends config + provides runtime obj store + logging facility.
parent
33c1936f
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
include/class.osticket.php
+210
-0
210 additions, 0 deletions
include/class.osticket.php
with
210 additions
and
0 deletions
include/class.osticket.php
0 → 100644
+
210
−
0
View file @
50535478
<?php
/*************************************************************************
class.osticket.php
osTicket (sys) -> Config.
Core osTicket object: extends congfig and provides loggging facility.
Use osTicket::start(configId)
Peter Rotich <peter@osticket.com>
Copyright (c) 2006-2012 osTicket
http://www.osticket.com
Released under the GNU General Public License WITHOUT ANY WARRANTY.
See LICENSE.TXT for details.
vim: expandtab sw=4 ts=4 sts=4:
**********************************************************************/
require_once
(
INCLUDE_DIR
.
'class.config.php'
);
//Config helper
define
(
'LOG_WARN'
,
LOG_WARNING
);
class
osTicket
extends
Config
{
var
$loglevel
=
array
(
1
=>
'Error'
,
'Warning'
,
'Debug'
);
var
$errors
;
var
$warning
;
var
$message
;
var
$headers
;
var
$session
;
function
osTicket
(
$id
)
{
parent
::
Config
(
$id
);
$this
->
session
=
osTicketSession
::
start
(
SESSION_TTL
);
// start_session
}
function
getSession
()
{
return
$this
->
session
;
}
function
addExtraHeader
(
$header
)
{
$this
->
headers
[
md5
(
$header
)]
=
$header
;
}
function
getExtraHeaders
()
{
return
$this
->
headers
;
}
function
getErrors
()
{
return
$this
->
errors
;
}
function
setErrors
(
$errors
)
{
if
(
!
is_array
(
$errors
))
return
$this
->
setError
(
$errors
);
$this
->
errors
=
$errors
;
}
function
getError
()
{
return
$this
->
errors
[
'err'
];
}
function
setError
(
$error
)
{
$this
->
errors
[
'err'
]
=
$error
;
}
function
clearError
()
{
$this
->
setError
(
''
);
}
function
getWarning
()
{
return
$this
->
warning
;
}
function
setWarning
(
$warn
)
{
$this
->
warning
=
$warn
;
}
function
clearWarning
()
{
$this
->
setWarning
(
''
);
}
function
getMessage
()
{
return
$this
->
message
;
}
function
setMessage
(
$msg
)
{
$this
->
message
=
$msg
;
}
function
clearMessage
()
{
$this
->
setMessage
(
''
);
}
function
alertAdmin
(
$subject
,
$message
,
$log
=
false
)
{
//Set admin's email address
if
(
!
(
$to
=
$this
->
getAdminEmail
()))
$to
=
ADMIN_EMAIL
;
//Try getting the alert email.
$email
=
null
;
if
(
!
(
$email
=
$this
->
getAlertEmail
()))
$email
=
$this
->
getDefaultEmail
();
//will take the default email.
if
(
$email
)
{
$email
->
send
(
$to
,
$subject
,
$message
);
}
else
{
//no luck - try the system mail.
Email
::
sendmail
(
$to
,
$subject
,
$message
,
sprintf
(
'"osTicket Alerts"<%s>'
,
$to
));
}
//log the alert? Watch out for loops here.
if
(
$log
)
$this
->
log
(
LOG_CRIT
,
$subject
,
$message
,
false
);
//Log the entry...and make sure no alerts are resent.
}
function
logDebug
(
$title
,
$message
,
$alert
=
false
)
{
return
$this
->
log
(
LOG_DEBUG
,
$title
,
$message
,
$alert
);
}
function
logInfo
(
$title
,
$message
,
$alert
=
false
)
{
return
$this
->
log
(
LOG_INFO
,
$title
,
$message
,
$alert
);
}
function
logWarning
(
$title
,
$message
,
$alert
=
true
)
{
return
$this
->
log
(
LOG_WARN
,
$title
,
$message
,
$alert
);
}
function
logError
(
$title
,
$error
,
$alert
=
true
)
{
return
$this
->
log
(
LOG_ERR
,
$title
,
$error
,
$alert
);
}
function
log
(
$priority
,
$title
,
$message
,
$alert
=
false
)
{
//We are providing only 3 levels of logs. Windows style.
switch
(
$priority
)
{
case
LOG_EMERG
:
case
LOG_ALERT
:
case
LOG_CRIT
:
case
LOG_ERR
:
$level
=
1
;
//Error
break
;
case
LOG_WARN
:
case
LOG_WARNING
:
$level
=
2
;
//Warning
break
;
case
LOG_NOTICE
:
case
LOG_INFO
:
case
LOG_DEBUG
:
default
:
$level
=
3
;
//Debug
}
//Alert admin if enabled...
if
(
$alert
)
$this
->
alertAdmin
(
$title
,
$message
);
if
(
$this
->
getLogLevel
()
<
$level
)
return
false
;
//Save log based on system log level settings.
$loglevel
=
array
(
1
=>
'Error'
,
'Warning'
,
'Debug'
);
$sql
=
'INSERT INTO '
.
SYSLOG_TABLE
.
' SET created=NOW(), updated=NOW() '
.
',title='
.
db_input
(
$title
)
.
',log_type='
.
db_input
(
$loglevel
[
$level
])
.
',log='
.
db_input
(
$message
)
.
',ip_address='
.
db_input
(
$_SERVER
[
'REMOTE_ADDR'
]);
mysql_query
(
$sql
);
//don't use db_query to avoid possible loop.
return
true
;
}
function
purgeLogs
()
{
if
(
!
(
$gp
=
$this
->
getLogGracePeriod
())
||
!
is_numeric
(
$gp
))
return
false
;
//System logs
$sql
=
'DELETE FROM '
.
SYSLOG_TABLE
.
' WHERE DATE_ADD(created, INTERVAL '
.
$gp
.
' MONTH)<=NOW()'
;
db_query
(
$sql
);
//TODO: Activity logs
return
true
;
}
/**** static functions ****/
function
start
(
$configId
)
{
if
(
!
$configId
||
!
(
$ost
=
new
osTicket
(
$configId
))
||
$ost
->
getId
()
!=
$configId
)
return
null
;
//Set default time zone... user/staff settting will overwrite it (on login).
$_SESSION
[
'TZ_OFFSET'
]
=
$ost
->
getTZoffset
();
$_SESSION
[
'TZ_DST'
]
=
$ost
->
observeDaylightSaving
();
return
$ost
;
}
}
?>
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment