Viewing file: globals.php (19.04 KB) -rwxr-xr-x Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<?php
///////////////////////////////////////////////////////////////////
// WRITES OUT FILE WITH CURRENT DATA
///////////////////////////////////////////////////////////////////
function config_write() {
global $s_dbhost, $s_dbuser, $s_dbpass, $s_dbname, $s_dirurl;
global $s_tx, $s_bg, $s_bord, $s_iplog, $s_cookielog;
global $s_qtx, $s_qbg, $s_optsize, $s_txtsize, $s_txtface;
global $s_width, $s_barimg, $s_barhite, $s_maxopts;
global $s_blength, $s_refer, $s_polllist, $s_resultnums, $s_showtotal;
global $g_message, $ext, $symphome;
$config_fn = "$symphome"."/config."."$ext";
// data to write
$data = "<?php\n";
$data .= "# YOU DO NOT NEED TO EDIT THIS FILE!\n";
$data .= "# USE THE ADMIN PAGE TO CHANGE OPTIONS\n";
$data .= "\$s_dbhost = '$s_dbhost';\n";
$data .= "\$s_dbuser = '$s_dbuser';\n";
$data .= "\$s_dbpass = '$s_dbpass';\n";
$data .= "\$s_dbname = '$s_dbname';\n";
$data .= "\$s_dirurl = '$s_dirurl';\n";
$data .= "\$s_tx = '$s_tx';\n";
$data .= "\$s_bg = '$s_bg';\n";
$data .= "\$s_bord = '$s_bord';\n";
$data .= "\$s_qtx = '$s_qtx';\n";
$data .= "\$s_qbg = '$s_qbg';\n";
$data .= "\$s_optsize = '$s_optsize';\n";
$data .= "\$s_txtsize = '$s_txtsize';\n";
$data .= "\$s_txtface = '$s_txtface';\n";
$data .= "\$s_width = '$s_width';\n";
$data .= "\$s_barimg = '$s_barimg';\n";
$data .= "\$s_barhite = '$s_barhite';\n";
$data .= "\$s_maxopts = '$s_maxopts'; \n";
$data .= "\$s_blength = '$s_blength';\n";
$data .= "\$s_cookielog = '$s_cookielog';\n";
$data .= "\$s_iplog = '$s_iplog';\n";
$data .= "\$s_polllist = '$s_polllist';\n";
$data .= "\$s_resultnums = '$s_resultnums';\n";
$data .= "\$s_showtotal = '$s_showtotal';\n";
if($s_refer == "" || $s_refer == "0") {
$data .= "\$s_refer = '';\n";
} else {
$data .= "\$s_refer = \"\$refer_href\".\"sympoll \".\"\$version\".\"</a>\";\n";
}
$data .= "?>\n";
// open and write and close file
$fp = @fopen($config_fn, "w");
if(!$fp) {
$g_message = "error: cannot open config file for writing";
return FALSE;
}
if(@fwrite($fp, $data) <= 0) {
fclose($fp);
$g_message = "error: cannot write config file; lacking permissions?";
return FALSE;
}
fclose($fp);
return TRUE;
}
///////////////////////////////////////////////////////////////////
// DISPLAYS HTML FOR DATABASE CONFIG
///////////////////////////////////////////////////////////////////
function display_config_db() {
global $ext, $g_message, $title;
global $s_dbhost, $s_dbuser, $s_dbpass, $s_dbname;
if(!verify_access(0)) {
$g_message = "error: you are not the super user!";
return;
}
$odbhost = htmlspecialchars($s_dbhost);
$odbuser = htmlspecialchars($s_dbuser);
$odbpass = htmlspecialchars($s_dbpass);
$odbname = htmlspecialchars($s_dbname);
$title = "Config Database";
spit_header(); ?>
<b>WARNING:</b> If the database information is changed successfully, you
will be logged out.<br>The new database information will immediately be used
to re-authenticate you.<br><br>
<form action="index.<?php echo $ext; ?>" method="post">
<input type="hidden" name="action" value="config_p_db">
Database Server:<br>
<input type="text" maxlength="50" size="20" name="ndbhost" value="<?php echo $odbhost; ?>"><br>
Database Username:<br>
<input type="text" maxlength="50" size="20" name="ndbuser" value="<?php echo $odbuser; ?>"><br>
Database Password:<br>
<input type="password" maxlength="50" size="20" name="ndbpass1" value="<?php echo $odbpass; ?>"><br>
Database Password (verify):<br>
<input type="password" maxlength="50" size="20" name="ndbpass2" value="<?php echo $odbpass; ?>"><br>
Database:<br>
<input type="text" maxlength="50" size="20" name="ndbname" value="<?php echo $odbname; ?>"><br>
<br><br><input type="submit" value="Update Config">
<input type="reset" value="Undo Changes"></form>
<?php spit_footer();
}
///////////////////////////////////////////////////////////////////
// DISPLAYS HTML FOR DISPLAY CONFIG
///////////////////////////////////////////////////////////////////
function display_config_disp() {
global $ext, $g_message, $title;
global $s_tx, $s_bg, $s_bord, $s_qtx, $s_qbg, $s_width;
global $s_optsize, $s_txtsize, $s_txtface, $s_barimg, $s_barhite;
if(!verify_access(0)) {
$g_message = "error: you are not the super user!";
return;
}
$otx = htmlspecialchars($s_tx);
$obg = htmlspecialchars($s_bg);
$obord = htmlspecialchars($s_bord);
$oqtx = htmlspecialchars($s_qtx);
$oqbg = htmlspecialchars($s_qbg);
$ooptsize = htmlspecialchars($s_optsize);
$otxtsize = htmlspecialchars($s_txtsize);
$otxtface = htmlspecialchars($s_txtface);
$owidth = htmlspecialchars($s_width);
$obarimg = htmlspecialchars($s_barimg);
$obarhite = htmlspecialchars($s_barhite);
$title = "Config Display";
spit_header(); ?>
Note: Colors used in the "More Polls" poll list can be controlled
<br>through the BODY tag in the include/header.php file.<br><br><br>
<form action="index.<?php echo $ext; ?>" method="post">
<input type="hidden" name="action" value="config_p_disp">
Primary Text Color:<br>
<input type="text" maxlength="30" size="30" name="ntx" value="<?php echo $otx; ?>"><br>
Primary Background Color:<br>
<input type="text" maxlength="30" size="30" name="nbg" value="<?php echo $obg; ?>"><br>
Booth Question Text Color:<br>
<input type="text" maxlength="30" size="30" name="nqtx" value="<?php echo $oqtx; ?>"><br>
Booth Question Background Color:<br>
<input type="text" maxlength="30" size="30" name="nqbg" value="<?php echo $oqbg; ?>"><br>
Booth Border Color:<br>
<input type="text" maxlength="30" size="30" name="nbord" value="<?php echo $obord; ?>"><br>
Booth Table Width:
<font size="1">(expected as number, not percentage)</font><br>
<input type="text" maxlength="10" size="30" name="nwidth" value="<?php echo $owidth; ?>"><br>
Primary Font Face:<br>
<input type="text" maxlength="50" size="30" name="ntxtface" value="<?php echo $otxtface; ?>"><br>
Primary Font Size:<br>
<input type="text" maxlength="5" size="30" name="ntxtsize" value="<?php echo $otxtsize; ?>"><br>
Options Font Size:<br>
<input type="text" maxlength="5" size="30" name="noptsize" value="<?php echo $ooptsize; ?>"><br>
Results Bar Image:<br>
<input type="text" maxlength="50" size="30" name="nbarimg" value="<?php echo $obarimg; ?>"><br>
Results Bar Height:<br>
<input type="text" maxlength="10" size="30" name="nbarhite" value="<?php echo $obarhite; ?>"><br>
<br><br>
<input type="submit" value="Update Config">
<input type="reset" value="Undo Changes"></form>
<?php spit_footer();
}
///////////////////////////////////////////////////////////////////
// DISPLAYS HTML FOR MISCELLANY CONFIG
///////////////////////////////////////////////////////////////////
function display_config_misc() {
global $ext, $g_message, $title;
global $s_dirurl, $s_maxopts, $s_blength, $s_iplog;
global $s_refer, $s_polllist, $s_resultnums, $s_showtotal, $s_cookielog;
if(!verify_access(0)) {
$g_message = "error: you are not the super user!";
return;
}
$odirurl = htmlspecialchars($s_dirurl);
$omaxopts = htmlspecialchars($s_maxopts);
$oblen = htmlspecialchars($s_blength);
$title = "Config Miscellany";
spit_header(); ?>
<form action="index.<?php echo $ext; ?>" method="post">
<input type="hidden" name="action" value="config_p_misc">
Full URL to Sympoll directory:<br>
<input type="text" maxlength="80" size="40" name="ndirurl" value="<?php echo $odirurl; ?>"><br>
Options allowed in new polls:<br>
<input type="text" maxlength="2" size="20" name="nmaxopts" value="<?php echo $omaxopts; ?>"><br>
Multiple votes blocked for:
<font size="1">(affects cookies <b>and</b> ip logging)</font><br>
<input type="text" maxlength="4" size="20" name="nblen" value="<?php echo $oblen; ?>"> days<br>
<br><br><table border="0" cellpadding="1" cellspacing="0">
<tr><td><font size="2" face="Verdana, Geneva">
Log IPs to block multiple votes? </font></td>
<td><select name="niplog">
<?php if($s_iplog == "0") { ?>
<option selected="selected" value="0">No</option>
<option value="1">Yes</option>
<?php } else { ?>
<option value="0">No</option>
<option selected="selected" value="1">Yes</option>
<?php } ?>
</select></td></tr>
<tr><td><font size="2" face="Verdana, Geneva">
Set cookie to block multiple votes? </font></td>
<td><select name="ncookielog">
<?php if($s_cookielog == "0") { ?>
<option selected="selected" value="0">No</option>
<option value="1">Yes</option>
<?php } else { ?>
<option value="0">No</option>
<option selected="selected" value="1">Yes</option>
<?php } ?>
</select></td></tr>
<tr><td><font size="2" face="Verdana, Geneva">
Display Referral Link? </font></td>
<td><select name="nrefer">
<?php if($s_refer == "0") { ?>
<option selected="selected" value="0">No</option>
<option value="1">Yes</option>
<?php } else { ?>
<option value="0">No</option>
<option selected="selected" value="1">Yes</option>
<?php } ?>
</select></td></tr>
<tr><td><font size="2" face="Verdana, Geneva">
Display 'More Polls' Link? </font></td>
<td><select name="nplist">
<?php if($s_polllist == "0") { ?>
<option selected="selected" value="0">No</option>
<option value="1">Yes</option>
<?php } else { ?>
<option value="0">No</option>
<option selected="selected" value="1">Yes</option>
<?php } ?>
</select></td></tr>
<tr><td><font size="2" face="Verdana, Geneva">
Display Total Vote Count? </font></td>
<td><select name="nstotal">
<?php if($s_showtotal == "0") { ?>
<option selected="selected" value="0">No</option>
<option value="1">Yes</option>
<?php } else { ?>
<option value="0">No</option>
<option selected="selected" value="1">Yes</option>
<?php } ?>
</select></td></tr>
<tr><td><font size="2" face="Verdana, Geneva">
Display Results As: </font></td>
<td><select name="nrnums">
<?php if($s_resultnums == "0") { ?>
<option selected="selected" value="0">Percentages</option>
<option value="1">Vote Count</option>
<?php } else { ?>
<option value="0">Percentages</option>
<option selected="selected" value="1">Vote Count</option>
<?php } ?>
</select></td></tr>
</table><br><br><input type="submit" value="Update Config">
<input type="reset" value="Undo Changes"></form>
<?php spit_footer();
}
///////////////////////////////////////////////////////////////////
// PROCESSES DATABASE CONFIG
///////////////////////////////////////////////////////////////////
function process_config_db($ndbhost, $ndbuser, $ndbpass1, $ndbpass2, $ndbname) {
global $g_message, $s_dbid;
if(!verify_access(0)) {
$g_message = "error: you are not the super user!";
return;
}
if($ndbhost == "" || ereg("[\"']", $ndbhost)) {
$g_message = "database config <b>failed</b> because invalid server";
return;
}
if($ndbuser == "" || ereg("[\"']", $ndbuser)) {
$g_message = "database config <b>failed</b> because invalid username";
return;
}
if(ereg("[\"']", $ndbpass1) != 0) {
$g_message = "database config <b>failed</b> because invalid password";
return;
}
if(strcmp($ndbpass1, $ndbpass2) != 0) {
$g_message = "database config <b>failed</b> because passwords do not match";
return;
}
if($ndbname == "" || ereg("[\"']", $ndbname)) {
$g_message = "database config <b>failed</b> because of invalid database";
return;
}
# make sure database settings work
$link = @mysql_connect($ndbhost,$ndbuser,$ndbpass1);
if(!$link) {
$g_message = "database config <b>failed</b> because unable to connect to new server";
return;
}
if(!@mysql_select_db($ndbname)) {
if($link != $s_dbid) { @mysql_close($link); }
$g_message = "database config <b>failed</b> because connected, but unable to access $ndbname";
return;
}
if($link != $s_dbid) { @mysql_close($link); }
# update values
global $s_dbhost, $s_dbuser, $s_dbpass, $s_dbname;
$s_dbhost = $ndbhost;
$s_dbuser = $ndbuser;
$s_dbpass = $ndbpass1;
$s_dbname = $ndbname;
if(config_write() == TRUE) {
setcookie('sympauth', serialize(array()), "time()", "/");
auth_display();
}
}
///////////////////////////////////////////////////////////////////
// PROCESSES DISPLAY CONFIG
///////////////////////////////////////////////////////////////////
function process_config_disp($ntx,$nbg,$nbord,$nqtx,$nqbg,$noptsize,$ntxtsize,
$ntxtface,$nwidth,$nbarimg,$nbarhite) {
global $g_message;
if(!verify_access(0)) {
$g_message = "error: you are not the super user!";
return;
}
if($ntx == "" || ereg("[\"']", $ntx)) {
$g_message = "display config <b>failed</b> because invalid text color";
return;
}
if($nbg == "" || ereg("[\"']", $nbg)) {
$g_message = "display config <b>failed</b> because invalid background color";
return;
}
if($nqtx == "" || ereg("[\"']", $nqtx)) {
$g_message = "display config <b>failed</b> because invalid question text color";
return;
}
if($nqbg == "" || ereg("[\"']", $nqbg)) {
$g_message = "display config <b>failed</b> because invalid question background color";
return;
}
if($nbord == "" || ereg("[\"']", $nbord)) {
$g_message = "display config <b>failed</b> because invalid border color";
return;
}
if($nwidth == "" || !ereg("^[0-9]+[%]?$", $nwidth)) {
$g_message = "display config <b>failed</b> because invalid table width";
return;
}
if($ntxtface != "" && ereg("[\"']", $ntxtface)) {
$g_message = "display config <b>failed</b> because invalid text font face(s)";
return;
}
if($ntxtsize != "" && !ereg("^[+-]?[0-9]+$", $ntxtsize)) {
$g_message = "display config <b>failed</b> because invalid text font size";
return;
}
if($noptsize != "" && !ereg("^[+-]?[0-9]+$", $noptsize)) {
$g_message = "display config <b>failed</b> because invalid options font size";
return;
}
if($nbarimg == "" || ereg("[\"']",$nbarimg)) {
$g_message = "display config <b>failed</b> because invalid results bar image";
return;
}
if($nbarhite == "" || !ereg("^[0-9]+$", $nbarhite)) {
$g_message = "display config <b>failed</b> because invalid results bar height";
return;
}
# update values
global $s_tx, $s_bg, $s_bord, $s_qtx, $s_qbg, $s_width;
global $s_optsize, $s_txtsize, $s_txtface, $s_barimg, $s_barhite;
$s_tx = $ntx;
$s_bg = $nbg;
$s_bord = $nbord;
$s_qtx = $nqtx;
$s_qbg = $nqbg;
$s_width = $nwidth;
$s_txtface = $ntxtface;
$s_txtsize = $ntxtsize;
$s_optsize = $noptsize;
$s_barimg = $nbarimg;
$s_barhite = $nbarhite;
if(config_write() == TRUE)
{ $g_message = "display successfully configured"; }
}
///////////////////////////////////////////////////////////////////
// PROCESSES MISC CONFIG
///////////////////////////////////////////////////////////////////
function process_config_misc($ndirurl, $nmaxopts, $nblen, $nrefer,
$nplist, $nrnums, $nstotal, $niplog, $ncookielog) {
global $g_message;
if(!verify_access(0)) {
$g_message = "error: you are not the super user!";
return;
}
if($ndirurl == "" || ereg("[\"']", $ndirurl)) {
$g_message = "miscellany config <b>failed</b> because invalid url path";
return;
}
if(!ereg("[/]$", $ndirurl)) { $ndirurl = "$ndirurl"."/"; }
if($nmaxopts == "" || !ereg("^[0-9]+$", $nmaxopts)) {
$g_message = "miscellany config <b>failed</b> because invalid max options";
return;
}
if($nblen == "") { $nblen = 0; }
if(!ereg("^[0-9]+$", $nblen)) {
$g_message = "miscellany config <b>failed</b> because invalid blocking length";
return;
}
# update values
global $s_dirurl, $s_maxopts, $s_blength, $s_refer, $s_cookielog;
global $s_polllist, $s_resultnums, $s_showtotal, $s_iplog;
$s_dirurl = $ndirurl;
$s_maxopts = $nmaxopts;
$s_blength = $nblen;
$s_iplog = $niplog;
$s_refer = $nrefer;
$s_polllist = $nplist;
$s_resultnums = $nrnums;
$s_showtotal = $nstotal;
$s_cookielog = $ncookielog;
if(config_write() == TRUE)
{ $g_message = "miscellany successfully configured"; }
}
function display_iplogmaint() {
global $s_blength, $s_dbid, $title, $ext;
$totalrows = 0;
$stalerows = 0;
$now = time();
$q1 = "SELECT voted FROM sympoll_iplog";
$r1 = mysql_query($q1, $s_dbid);
while($a1 = mysql_fetch_array($r1)) {
$totalrows++;
if($now > ($a1['voted'] + ($s_blength * 86400)) ) {
$stalerows++;
}
}
$title = "IP Log Maintenance";
spit_header(); ?>
<form action="index.<?php echo $ext; ?>" method="post">
<input type="hidden" name="action" value="iplog_p_maint">
There are currently <big><?php echo $stalerows; ?></big> stale rows out
of a total of <big><?php echo $totalrows; ?></big> rows (using a duration
of <?php echo $s_blength; ?> days). This means that of the
<?php echo $totalrows; ?> votes logged, <?php echo $stalerows; ?>
occured more than <?php echo $s_blength; ?> days ago. These will not be
used to block voting anymore, and they can safely be deleted if you do not
plan on increasing your "multiple votes blocked for x days"
option. If there is a very large amount of total rows, deleting the
stale rows _may_ help to speed up ip logging. Deleting all of the rows will
reset the IP logging, meaning previous voters may be able to vote again if
they don't have a cookie preventing it. Neither option will remove any
votes from any polls-- It only affects the actual IP logging record of who
has voted.<br><br>
<font size="+1"><b>WARNING: THIS CANNOT BE UNDONE</b></font><br><br>
<input type="radio" name="confirmation" value="no" checked="checked">
do nothing<br>
<input type="radio" name="confirmation" value="stale">
remove stale rows only<br>
<input type="radio" name="confirmation" value="total">
remove all rows<br>
<br><br><input type="submit" value="Alright!"></form>
<?php spit_footer();
}
function process_iplogmaint($confirm) {
global $s_blength, $s_dbid, $g_message;
$now = time();
if($confirm == 'stale') {
$meat = "(voted + ($s_blength * 86400)) < $now";
$q1 = "DELETE FROM sympoll_iplog WHERE($meat)";
$r1 = mysql_query($q1, $s_dbid);
$g_message = "stale rows were successfully deleted";
} elseif($confirm == 'total') {
$q2 = "DELETE FROM sympoll_iplog";
$r2 = mysql_query($q2, $s_dbid);
$g_message = "ip_log was successfully reset";
} else {
$g_message = "purging of ip_log was <b>aborted</b>";
}
}
?>
|