⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 design

📁 Event Calendar是一个在线事件日程
💻
📖 第 1 页 / 共 2 页
字号:
INTRODUCTION============This event calendar system was designed with several objectives in mind.We wanted people to be able to:1. Browse events (obviously).2. Search for specific events.3. Submit their own events.4. Change or possibly delete events.Unfortunately, we don't trust the maturity of every single one of ourstudents, so we wanted events to be subject to some sort of approval, andwe wanted to know who was submitting offensive material (if any wassubmitted).  We weren't up to creating an entirely new authenticationsystem, nor did we want to have yet another set of accounts to administer,so we decided to check logins against user accounts on our web server.  Westill needed a separate way of storing various access levels and sessioninformation, which we ended up doing in a postgres database, but it gaveus the ability to let certain people approve/modify/delete certain eventsbased on their location.  I suppose that's about as much detail as I canput into an introduction, so I guess I'll get on with the followingsections:	Backend - postgres	Backend - sessions	Backend - authentication	Backend - permissions	Backend - events	Main Page Structure	Boxes	Box - Calendar	Box - Search	Box - Login	Box - Submit	Box - Approve	Box - Modify	Box - Delete	Box - HelpBACKEND - POSTGRES==================Obviously we needed a place to store the events.  In spite of my priorexperience with LDAP (which might have made things like the SELECTstatements easier to manage), there's too much writing to the database tomake it a reasonable choice.  SQL was the next logical thing, and wealready had postgresql installed, so that's what we went with.We created two databases in postgres, one of which was for the actualcalendar: events, locations, categories, audiences, etc; the other ofwhich was for authentication purposes.  While the actual accounts are/etc/shadow based, we needed to keep track of who was logged in, whenthey've last logged in, what permissions they have, etc.One of the big disadvantages of not having accounts managed by postgreswas that we couldn't just connect to the database with whatever accountinformation the end-user provided.  We also didn't want guest accounts tobe able to write to the database.  To handle this, we created a couplefunctions that would be kept in a separate file, readable only by the webserver, that would connect to the databases with the appropriateinformation and return a connection index.  There are read-write andread-only functions for both the calendar and authentication databases.All connections to the database are done through these functions, sochanges in access to the database should be easy to accomodate.BACKEND - SESSIONS==================We didn't want to be tossing accounts and passwords back and forth acrossthe internet, even over SSL, so we came up with a session class that keepstrack of a whole bunch of stuff and uses a simple session key that's setas a cookie.  The session keeps track of the following stuff: user ID,username, gecos (from /etc/passwd), expiration timestamp, remote address,and permissions.  All of these are stuck together in one big string andencrypted using MD5, with a salt formed by Unix crypting the same string.This encrypted string is the session key.  The remote address is used toprotect from a replay-type attack.  There's a small chance ofinconsistency with this if people use a proxy though.  The expiration isto help prevent problems with people logging in and leaving the terminal.Browsers should delete the cookie when it expires, and whenever someonelogs in, the database is sent a delete statement to remove expiredsessions.  The session key uses MD5 because Unix crypt only looks at thefirst 8 or so characters.  MD5 crypts the whole thing.  I just used Unixcrypt to get a nice random salt for MD5.  The permissions and random userinfo probably isn't necessary, but is convenient to stick in the session.Permissions are updated in the session when it is renewed.  Now back totext with a followable string of thought.BACKEND - AUTHENTICATION========================We decided to use the existing user accounts that we had in /etc/shadowfor this system, rather than setting up more accounts and having everybodyremember yet another password.  In order for PHP to get at the accountinformation, there are a few executables that it uses.  One is asetuid-root thingy called getshcrypt which prints the crypted passwordfrom /etc/shadow when given a user ID.  (It prints it so PHP can grab it.)Two others, getpwinfo and getuidinfo, echo the line from /etc/passwd forthe given username or user ID respectively.  The verifyPassword function (inauth-shadow.php3) uses these executables to verify the supplied usernameand password, returning an error if the login failed.  This function keepstrack of things like multiple failed login attempts (using the LastLoginclass), and will fail a login unconditionally if there have been too manyrecent failures.Other authentication mechanisms have been supplied to me (a PAM module byBruce Tenison and an NIS module by Scott Moser).  These are relativelyeasy to implement by creating some new file (auth-something.php3) whichdefines a function verifyPassword and takes a username and password forparameters.  This file can then be included by edittingcalendar/includes/config.inc and changing $config_auth_module and therelated variables for the executables called by the module.The actual session creation is done by the login box, which will beexplained later.  The login box calls verifyPassword and creates a newsession if the attempt is successful.Aside from the table keeping track of sessions, there is another thatkeeps track of last logins.  If there is a certain number of failureswithin a given amount of time, then the account is temporarily locked.The last login table keeps track of the last failed attempt, the lastsuccessful attempt, the number of failures since last login, and thenumber of recent failures.BACKEND - PERMISSIONS=====================The permissions table has an easy to decipher layout.  The user_id columncontains the user's ID from /etc/passwd.  The location_id column containsthe ID for the location for which you are setting permissions.  Thepermissions column contains a number which is formed by binary or-ing thedesired permissions, defined in permissions.php3.  The primary key forthis table is compound, based on location and user ID, so a user can havedifferent permissions for different locations.BACKEND - EVENTS================In order to allow easy changes in the form of an event, there is aseparate event class.  The event itself is stored in the database acrossseveral tables.  (It's a standard relational db thing).  The items thatare selected as a list are stored in the event table as an ID or listof IDs that point to those items.  The event class contains variables forevery field of the event.  The fields that are IDs also have a matchingvariable for the string representation of the value.The base event class contains a constructor function that takes each ofthe values as a parameter.  Most of the parameters are optional.  Thereare also subclasses for different forms of initialization:  a subclassthat can be initialized from an array of values, one that can be createdwhen given the event ID from the database, one that will also fetch thestring representations from the database, one that will create an emptyevent, and one that will get all of its values from global variables (suchas from a submitted form).The event also handles any output, so if the event structure changes, theother pages do not need to be updated.  There are a few different forms ofoutput:  detail view, which spits out a bunch of HTML; text-only view,which overrides the rest of the pages so that only the event text isoutput (not the rest of the calendar page); and an editable view, whichoutputs form elements for all the fields.  Some event output is also donein the rejectEvent function to include the event in an e-mail to thesubmitter.Several functions deal with the database operations on the event.  ThesubmitEvent function will build an SQL statement and insert all of thenecessary variables into the calendar database.  rejectEvent will deletethe event from the database and e-mail the submitter to let them knowtheir event was rejected.  deleteEvent, of course, deletes the event fromthe database.  approveEvent approves the event by adding an approver ID.updateEvent will save all variable to the database with an SQL UPDATEstatement.  For many of these operations, several SQL queries must beconstructed and sent to the server.  The event class makes use of SQLtransactions which may be rolled back if an error occurs to avoidinconsistencies.While modifying an event in any way, the event class is responsible forupdating the index table as well.  The event takes into consideration itsstart and end times and the list of weekdays on which it occurs to producean array of timestamps for the days on which the event takes place.  Thisarray is then added to the index for easier browsing later on.Before an event is submitted or updated, the validateEvent function shouldbe called to make sure all the required fields are included.  TheverifyAction function should also be called to make sure the currentsession has the correct access to do whatever it is trying to do to theevent.MAIN PAGE STRUCTURE===================The HTML structure of the calendar is actually pretty simple.  It consistsof a header and footer, included from the includes directory, whichcontain whatever banners you want at the top and bottom of the page (at

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -