Constants.pm 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495
  1. # -*- Mode: perl; indent-tabs-mode: nil -*-
  2. #
  3. # The contents of this file are subject to the Mozilla Public
  4. # License Version 1.1 (the "License"); you may not use this file
  5. # except in compliance with the License. You may obtain a copy of
  6. # the License at http://www.mozilla.org/MPL/
  7. #
  8. # Software distributed under the License is distributed on an "AS
  9. # IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
  10. # implied. See the License for the specific language governing
  11. # rights and limitations under the License.
  12. #
  13. # The Original Code is the Bugzilla Bug Tracking System.
  14. #
  15. # The Initial Developer of the Original Code is Netscape Communications
  16. # Corporation. Portions created by Netscape are
  17. # Copyright (C) 1998 Netscape Communications Corporation. All
  18. # Rights Reserved.
  19. #
  20. # Contributor(s): Terry Weissman <terry@mozilla.org>
  21. # Dawn Endico <endico@mozilla.org>
  22. # Dan Mosedale <dmose@mozilla.org>
  23. # Joe Robins <jmrobins@tgix.com>
  24. # Jake <jake@bugzilla.org>
  25. # J. Paul Reed <preed@sigkill.com>
  26. # Bradley Baetz <bbaetz@student.usyd.edu.au>
  27. # Christopher Aillon <christopher@aillon.com>
  28. # Shane H. W. Travis <travis@sedsystems.ca>
  29. # Max Kanat-Alexander <mkanat@bugzilla.org>
  30. # Marc Schumann <wurblzap@gmail.com>
  31. package Bugzilla::Constants;
  32. use strict;
  33. use base qw(Exporter);
  34. # For bz_locations
  35. use File::Basename;
  36. @Bugzilla::Constants::EXPORT = qw(
  37. BUGZILLA_VERSION
  38. bz_locations
  39. IS_NULL
  40. NOT_NULL
  41. CONTROLMAPNA
  42. CONTROLMAPSHOWN
  43. CONTROLMAPDEFAULT
  44. CONTROLMAPMANDATORY
  45. AUTH_OK
  46. AUTH_NODATA
  47. AUTH_ERROR
  48. AUTH_LOGINFAILED
  49. AUTH_DISABLED
  50. AUTH_NO_SUCH_USER
  51. USER_PASSWORD_MIN_LENGTH
  52. USER_PASSWORD_MAX_LENGTH
  53. LOGIN_OPTIONAL
  54. LOGIN_NORMAL
  55. LOGIN_REQUIRED
  56. LOGOUT_ALL
  57. LOGOUT_CURRENT
  58. LOGOUT_KEEP_CURRENT
  59. GRANT_DIRECT
  60. GRANT_REGEXP
  61. GROUP_MEMBERSHIP
  62. GROUP_BLESS
  63. GROUP_VISIBLE
  64. MAILTO_USER
  65. MAILTO_GROUP
  66. DEFAULT_COLUMN_LIST
  67. DEFAULT_QUERY_NAME
  68. QUERY_LIST
  69. LIST_OF_BUGS
  70. COMMENT_COLS
  71. COMMENT_COLS_WRAP
  72. MAX_COMMENT_LENGTH
  73. CMT_NORMAL
  74. CMT_DUPE_OF
  75. CMT_HAS_DUPE
  76. CMT_POPULAR_VOTES
  77. CMT_MOVED_TO
  78. THROW_ERROR
  79. RELATIONSHIPS
  80. REL_ASSIGNEE REL_QA REL_REPORTER REL_CC REL_VOTER REL_GLOBAL_WATCHER
  81. REL_ANY
  82. POS_EVENTS
  83. EVT_OTHER EVT_ADDED_REMOVED EVT_COMMENT EVT_ATTACHMENT EVT_ATTACHMENT_DATA
  84. EVT_PROJ_MANAGEMENT EVT_OPENED_CLOSED EVT_KEYWORD EVT_CC EVT_DEPEND_BLOCK
  85. NEG_EVENTS
  86. EVT_UNCONFIRMED EVT_CHANGED_BY_ME
  87. GLOBAL_EVENTS
  88. EVT_FLAG_REQUESTED EVT_REQUESTED_FLAG
  89. FULLTEXT_BUGLIST_LIMIT
  90. ADMIN_GROUP_NAME
  91. PER_PRODUCT_PRIVILEGES
  92. SENDMAIL_EXE
  93. SENDMAIL_PATH
  94. FIELD_TYPE_UNKNOWN
  95. FIELD_TYPE_FREETEXT
  96. FIELD_TYPE_SINGLE_SELECT
  97. FIELD_TYPE_MULTI_SELECT
  98. FIELD_TYPE_TEXTAREA
  99. FIELD_TYPE_DATETIME
  100. USAGE_MODE_BROWSER
  101. USAGE_MODE_CMDLINE
  102. USAGE_MODE_WEBSERVICE
  103. USAGE_MODE_EMAIL
  104. ERROR_MODE_WEBPAGE
  105. ERROR_MODE_DIE
  106. ERROR_MODE_DIE_SOAP_FAULT
  107. INSTALLATION_MODE_INTERACTIVE
  108. INSTALLATION_MODE_NON_INTERACTIVE
  109. DB_MODULE
  110. ROOT_USER
  111. ON_WINDOWS
  112. MAX_TOKEN_AGE
  113. MAX_LOGINCOOKIE_AGE
  114. SAFE_PROTOCOLS
  115. MIN_SMALLINT
  116. MAX_SMALLINT
  117. MAX_LEN_QUERY_NAME
  118. MAX_MILESTONE_SIZE
  119. MAX_COMPONENT_SIZE
  120. MAX_FREETEXT_LENGTH
  121. );
  122. @Bugzilla::Constants::EXPORT_OK = qw(contenttypes);
  123. # CONSTANTS
  124. #
  125. # Bugzilla version
  126. use constant BUGZILLA_VERSION => "3.2.3";
  127. # These are unique values that are unlikely to match a string or a number,
  128. # to be used in criteria for match() functions and other things. They start
  129. # and end with spaces because most Bugzilla stuff has trim() called on it,
  130. # so this is unlikely to match anything we get out of the DB.
  131. #
  132. # We can't use a reference, because Template Toolkit doesn't work with
  133. # them properly (constants.IS_NULL => {} just returns an empty string instead
  134. # of the reference).
  135. use constant IS_NULL => ' __IS_NULL__ ';
  136. use constant NOT_NULL => ' __NOT_NULL__ ';
  137. #
  138. # ControlMap constants for group_control_map.
  139. # membercontol:othercontrol => meaning
  140. # Na:Na => Bugs in this product may not be restricted to this
  141. # group.
  142. # Shown:Na => Members of the group may restrict bugs
  143. # in this product to this group.
  144. # Shown:Shown => Members of the group may restrict bugs
  145. # in this product to this group.
  146. # Anyone who can enter bugs in this product may initially
  147. # restrict bugs in this product to this group.
  148. # Shown:Mandatory => Members of the group may restrict bugs
  149. # in this product to this group.
  150. # Non-members who can enter bug in this product
  151. # will be forced to restrict it.
  152. # Default:Na => Members of the group may restrict bugs in this
  153. # product to this group and do so by default.
  154. # Default:Default => Members of the group may restrict bugs in this
  155. # product to this group and do so by default and
  156. # nonmembers have this option on entry.
  157. # Default:Mandatory => Members of the group may restrict bugs in this
  158. # product to this group and do so by default.
  159. # Non-members who can enter bug in this product
  160. # will be forced to restrict it.
  161. # Mandatory:Mandatory => Bug will be forced into this group regardless.
  162. # All other combinations are illegal.
  163. use constant CONTROLMAPNA => 0;
  164. use constant CONTROLMAPSHOWN => 1;
  165. use constant CONTROLMAPDEFAULT => 2;
  166. use constant CONTROLMAPMANDATORY => 3;
  167. # See Bugzilla::Auth for docs on AUTH_*, LOGIN_* and LOGOUT_*
  168. use constant AUTH_OK => 0;
  169. use constant AUTH_NODATA => 1;
  170. use constant AUTH_ERROR => 2;
  171. use constant AUTH_LOGINFAILED => 3;
  172. use constant AUTH_DISABLED => 4;
  173. use constant AUTH_NO_SUCH_USER => 5;
  174. # The minimum and maximum lengths a password must have.
  175. use constant USER_PASSWORD_MIN_LENGTH => 3;
  176. use constant USER_PASSWORD_MAX_LENGTH => 16;
  177. use constant LOGIN_OPTIONAL => 0;
  178. use constant LOGIN_NORMAL => 1;
  179. use constant LOGIN_REQUIRED => 2;
  180. use constant LOGOUT_ALL => 0;
  181. use constant LOGOUT_CURRENT => 1;
  182. use constant LOGOUT_KEEP_CURRENT => 2;
  183. use constant contenttypes =>
  184. {
  185. "html"=> "text/html" ,
  186. "rdf" => "application/rdf+xml" ,
  187. "atom"=> "application/atom+xml" ,
  188. "xml" => "application/xml" ,
  189. "js" => "application/x-javascript" ,
  190. "csv" => "text/csv" ,
  191. "png" => "image/png" ,
  192. "ics" => "text/calendar" ,
  193. };
  194. use constant GRANT_DIRECT => 0;
  195. use constant GRANT_REGEXP => 2;
  196. use constant GROUP_MEMBERSHIP => 0;
  197. use constant GROUP_BLESS => 1;
  198. use constant GROUP_VISIBLE => 2;
  199. use constant MAILTO_USER => 0;
  200. use constant MAILTO_GROUP => 1;
  201. # The default list of columns for buglist.cgi
  202. use constant DEFAULT_COLUMN_LIST => (
  203. "bug_severity", "priority", "op_sys","assigned_to",
  204. "bug_status", "resolution", "short_desc"
  205. );
  206. # Used by query.cgi and buglist.cgi as the named-query name
  207. # for the default settings.
  208. use constant DEFAULT_QUERY_NAME => '(Default query)';
  209. # The possible types for saved searches.
  210. use constant QUERY_LIST => 0;
  211. use constant LIST_OF_BUGS => 1;
  212. # The column width (cols attribute) of HTML textareas for inputting comments.
  213. use constant COMMENT_COLS => 80;
  214. # The column width at which to wrap comments prior to display -- using
  215. # Perl's Text::Wrap::wrap(). Only Bugzilla/Util.pm's wrap_comment() method
  216. # uses this constant.
  217. #
  218. # Empirical testing showed that $Text::Wrap::columns must be a value
  219. # between 2 and 32766, inclusive. We choose a large value to prevent
  220. # wrap() from inserting any hard line breaks at all. This lets us use
  221. # "white-space: pre-wrap" in the CSS to do line-wrapping instead. We
  222. # arbitrarily choose 8000, which is enough for a 100-line paragraph.
  223. use constant COMMENT_COLS_WRAP => 8000;
  224. # Used in _check_comment(). Gives the max length allowed for a comment.
  225. use constant MAX_COMMENT_LENGTH => 65535;
  226. # The type of bug comments.
  227. use constant CMT_NORMAL => 0;
  228. use constant CMT_DUPE_OF => 1;
  229. use constant CMT_HAS_DUPE => 2;
  230. use constant CMT_POPULAR_VOTES => 3;
  231. use constant CMT_MOVED_TO => 4;
  232. # Determine whether a validation routine should return 0 or throw
  233. # an error when the validation fails.
  234. use constant THROW_ERROR => 1;
  235. use constant REL_ASSIGNEE => 0;
  236. use constant REL_QA => 1;
  237. use constant REL_REPORTER => 2;
  238. use constant REL_CC => 3;
  239. use constant REL_VOTER => 4;
  240. use constant REL_GLOBAL_WATCHER => 5;
  241. use constant RELATIONSHIPS => REL_ASSIGNEE, REL_QA, REL_REPORTER, REL_CC,
  242. REL_VOTER, REL_GLOBAL_WATCHER;
  243. # Used for global events like EVT_FLAG_REQUESTED
  244. use constant REL_ANY => 100;
  245. # There are two sorts of event - positive and negative. Positive events are
  246. # those for which the user says "I want mail if this happens." Negative events
  247. # are those for which the user says "I don't want mail if this happens."
  248. #
  249. # Exactly when each event fires is defined in wants_bug_mail() in User.pm; I'm
  250. # not commenting them here in case the comments and the code get out of sync.
  251. use constant EVT_OTHER => 0;
  252. use constant EVT_ADDED_REMOVED => 1;
  253. use constant EVT_COMMENT => 2;
  254. use constant EVT_ATTACHMENT => 3;
  255. use constant EVT_ATTACHMENT_DATA => 4;
  256. use constant EVT_PROJ_MANAGEMENT => 5;
  257. use constant EVT_OPENED_CLOSED => 6;
  258. use constant EVT_KEYWORD => 7;
  259. use constant EVT_CC => 8;
  260. use constant EVT_DEPEND_BLOCK => 9;
  261. use constant POS_EVENTS => EVT_OTHER, EVT_ADDED_REMOVED, EVT_COMMENT,
  262. EVT_ATTACHMENT, EVT_ATTACHMENT_DATA,
  263. EVT_PROJ_MANAGEMENT, EVT_OPENED_CLOSED, EVT_KEYWORD,
  264. EVT_CC, EVT_DEPEND_BLOCK;
  265. use constant EVT_UNCONFIRMED => 50;
  266. use constant EVT_CHANGED_BY_ME => 51;
  267. use constant NEG_EVENTS => EVT_UNCONFIRMED, EVT_CHANGED_BY_ME;
  268. # These are the "global" flags, which aren't tied to a particular relationship.
  269. # and so use REL_ANY.
  270. use constant EVT_FLAG_REQUESTED => 100; # Flag has been requested of me
  271. use constant EVT_REQUESTED_FLAG => 101; # I have requested a flag
  272. use constant GLOBAL_EVENTS => EVT_FLAG_REQUESTED, EVT_REQUESTED_FLAG;
  273. # Number of bugs to return in a buglist when performing
  274. # a fulltext search.
  275. use constant FULLTEXT_BUGLIST_LIMIT => 200;
  276. # Default administration group name.
  277. use constant ADMIN_GROUP_NAME => 'admin';
  278. # Privileges which can be per-product.
  279. use constant PER_PRODUCT_PRIVILEGES => ('editcomponents', 'editbugs', 'canconfirm');
  280. # Path to sendmail.exe (Windows only)
  281. use constant SENDMAIL_EXE => '/usr/lib/sendmail.exe';
  282. # Paths to search for the sendmail binary (non-Windows)
  283. use constant SENDMAIL_PATH => '/usr/lib:/usr/sbin:/usr/ucblib';
  284. # Field types. Match values in fielddefs.type column. These are purposely
  285. # not named after database column types, since Bugzilla fields comprise not
  286. # only storage but also logic. For example, we might add a "user" field type
  287. # whose values are stored in an integer column in the database but for which
  288. # we do more than we would do for a standard integer type (f.e. we might
  289. # display a user picker).
  290. use constant FIELD_TYPE_UNKNOWN => 0;
  291. use constant FIELD_TYPE_FREETEXT => 1;
  292. use constant FIELD_TYPE_SINGLE_SELECT => 2;
  293. use constant FIELD_TYPE_MULTI_SELECT => 3;
  294. use constant FIELD_TYPE_TEXTAREA => 4;
  295. use constant FIELD_TYPE_DATETIME => 5;
  296. # The maximum number of days a token will remain valid.
  297. use constant MAX_TOKEN_AGE => 3;
  298. # How many days a logincookie will remain valid if not used.
  299. use constant MAX_LOGINCOOKIE_AGE => 30;
  300. # Protocols which are considered as safe.
  301. use constant SAFE_PROTOCOLS => ('afs', 'cid', 'ftp', 'gopher', 'http', 'https',
  302. 'irc', 'mid', 'news', 'nntp', 'prospero', 'telnet',
  303. 'view-source', 'wais');
  304. # Usage modes. Default USAGE_MODE_BROWSER. Use with Bugzilla->usage_mode.
  305. use constant USAGE_MODE_BROWSER => 0;
  306. use constant USAGE_MODE_CMDLINE => 1;
  307. use constant USAGE_MODE_WEBSERVICE => 2;
  308. use constant USAGE_MODE_EMAIL => 3;
  309. # Error modes. Default set by Bugzilla->usage_mode (so ERROR_MODE_WEBPAGE
  310. # usually). Use with Bugzilla->error_mode.
  311. use constant ERROR_MODE_WEBPAGE => 0;
  312. use constant ERROR_MODE_DIE => 1;
  313. use constant ERROR_MODE_DIE_SOAP_FAULT => 2;
  314. # The various modes that checksetup.pl can run in.
  315. use constant INSTALLATION_MODE_INTERACTIVE => 0;
  316. use constant INSTALLATION_MODE_NON_INTERACTIVE => 1;
  317. # Data about what we require for different databases.
  318. use constant DB_MODULE => {
  319. 'mysql' => {db => 'Bugzilla::DB::Mysql', db_version => '4.1.2',
  320. dbd => {
  321. package => 'DBD-mysql',
  322. module => 'DBD::mysql',
  323. # Disallow development versions
  324. blacklist => ['_'],
  325. # For UTF-8 support
  326. version => '4.00',
  327. },
  328. name => 'MySQL'},
  329. 'pg' => {db => 'Bugzilla::DB::Pg', db_version => '8.00.0000',
  330. dbd => {
  331. package => 'DBD-Pg',
  332. module => 'DBD::Pg',
  333. version => '1.45',
  334. },
  335. name => 'PostgreSQL'},
  336. 'oracle'=> {db => 'Bugzilla::DB::Oracle', db_version => '10.02.0',
  337. dbd => {
  338. package => 'DBD-Oracle',
  339. module => 'DBD::Oracle',
  340. version => '1.19',
  341. },
  342. name => 'Oracle'},
  343. };
  344. # The user who should be considered "root" when we're giving
  345. # instructions to Bugzilla administrators.
  346. use constant ROOT_USER => $^O =~ /MSWin32/i ? 'Administrator' : 'root';
  347. # True if we're on Win32.
  348. use constant ON_WINDOWS => ($^O =~ /MSWin32/i);
  349. use constant MIN_SMALLINT => -32768;
  350. use constant MAX_SMALLINT => 32767;
  351. # The longest that a saved search name can be.
  352. use constant MAX_LEN_QUERY_NAME => 64;
  353. # The longest milestone name allowed.
  354. use constant MAX_MILESTONE_SIZE => 20;
  355. # The longest component name allowed.
  356. use constant MAX_COMPONENT_SIZE => 64;
  357. # Maximum length allowed for free text fields.
  358. use constant MAX_FREETEXT_LENGTH => 255;
  359. sub bz_locations {
  360. # We know that Bugzilla/Constants.pm must be in %INC at this point.
  361. # So the only question is, what's the name of the directory
  362. # above it? This is the most reliable way to get our current working
  363. # directory under both mod_cgi and mod_perl. We call dirname twice
  364. # to get the name of the directory above the "Bugzilla/" directory.
  365. #
  366. # Calling dirname twice like that won't work on VMS or AmigaOS
  367. # but I doubt anybody runs Bugzilla on those.
  368. #
  369. # On mod_cgi this will be a relative path. On mod_perl it will be an
  370. # absolute path.
  371. my $libpath = dirname(dirname($INC{'Bugzilla/Constants.pm'}));
  372. # We have to detaint $libpath, but we can't use Bugzilla::Util here.
  373. $libpath =~ /(.*)/;
  374. $libpath = $1;
  375. my ($project, $localconfig, $datadir);
  376. if ($ENV{'PROJECT'} && $ENV{'PROJECT'} =~ /^(\w+)$/) {
  377. $project = $1;
  378. $localconfig = "localconfig.$project";
  379. $datadir = "data/$project";
  380. } else {
  381. $localconfig = "localconfig";
  382. $datadir = "data";
  383. }
  384. # We have to return absolute paths for mod_perl.
  385. # That means that if you modify these paths, they must be absolute paths.
  386. return {
  387. 'libpath' => $libpath,
  388. 'ext_libpath' => "$libpath/lib",
  389. # If you put the libraries in a different location than the CGIs,
  390. # make sure this still points to the CGIs.
  391. 'cgi_path' => $libpath,
  392. 'templatedir' => "$libpath/template",
  393. 'project' => $project,
  394. 'localconfig' => "$libpath/$localconfig",
  395. 'datadir' => "$libpath/$datadir",
  396. 'attachdir' => "$libpath/$datadir/attachments",
  397. 'skinsdir' => "$libpath/skins",
  398. # $webdotdir must be in the web server's tree somewhere. Even if you use a
  399. # local dot, we output images to there. Also, if $webdotdir is
  400. # not relative to the bugzilla root directory, you'll need to
  401. # change showdependencygraph.cgi to set image_url to the correct
  402. # location.
  403. # The script should really generate these graphs directly...
  404. 'webdotdir' => "$libpath/$datadir/webdot",
  405. 'extensionsdir' => "$libpath/extensions",
  406. };
  407. }
  408. 1;