"Fossies" - the Fresh Open Source Software Archive

Member "betterawstats/core/config.inc.php" (17 Mar 2008, 18737 Bytes) of package /linux/www/old/betterawstats-1.0.zip:


The requested HTML page contains a <FORM> tag that is unusable on "Fossies" in "automatic" (rendered) mode so that page is shown as HTML source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 <?php
    2 /**
    3  * betterawstats - an alternative display for awstats data
    4  *
    5  * @author      Oliver Spiesshofer, support at betterawstats dot com
    6  * @copyright   2008 Oliver Spiesshofer
    7  * @version     1.0
    8  * @link        http://betterawstats.com
    9  *
   10  * Based on the GPL AWStats Totals script by:
   11  * Jeroen de Jong <jeroen@telartis.nl>
   12  * copyright   2004-2006 Telartis
   13  * version 1.13 (http://www.telartis.nl/xcms/awstats)
   14  *
   15  * This program is free software; you can redistribute it and/or
   16  * modify it under the terms of the GNU General Public License
   17  * as published by the Free Software Foundation; either version 2
   18  * of the License, or (at your option) any later version.
   19  *
   20  * This program is distributed in the hope that it will be useful,
   21  * but WITHOUT ANY WARRANTY; without even the implied warranty of
   22  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   23  * GNU General Public License for more details.
   24  *
   25  * You should have received a copy of the GNU General Public License
   26  * along with this program; if not, write to the Free Software
   27  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
   28  */
   29 
   30 
   31 /**
   32  * File contents:
   33  *
   34  * This file contains only function related to the online config manager. It handles
   35  * editing & saving the config as well as logging the admin in and out.
   36  */
   37 
   38 // this file can't be used on its own
   39 if (strpos ($_SERVER['PHP_SELF'], 'config_default.php') !== false) {
   40     die ('This file can not be used on its own!');
   41 }
   42 /*
   43 * Saves the config settings to file
   44 *
   45 */
   46 function baw_action_save_config() {
   47     global $BAW_CONF, $BAW_CONF_DEF, $BAW_CONF_DIS_DEF, $BAW_CONF_DIS;
   48     global $BAW_MES, $BAW_CONF_DIS_TYP, $BAW_FILE_HEADER;
   49     @session_start();
   50     if (!baw_check_user()) {
   51         return baw_site_header() . baw_config_login_form();
   52     };
   53 
   54     if (isset($_POST['exit']) && ($_POST['exit'] == $BAW_MES['cfg_exit'])) {
   55         return baw_display_index();
   56     }
   57     if (isset($_POST['logout']) && ($_POST['logout'] == $BAW_MES['cfg_logout'])) {
   58         baw_logout();
   59         return baw_display_index();
   60     }
   61     if (!$BAW_CONF['online_config']) {
   62         return baw_raise_error('configdisabled');
   63     }
   64     $filename = $BAW_CONF['site_path'].'/config.php';
   65     if (is_writable($filename)) {
   66         // prepare config for writing
   67         $str = "<?php\r\n";
   68         $intro = $BAW_MES['config_intro'];
   69         $str .= $BAW_FILE_HEADER;
   70         $str .= wordwrap($intro, 75, "\r\n// ");
   71 
   72         foreach ($BAW_CONF_DEF as $sect => $sectdata) {
   73             $sect = strtoupper($sect);
   74             $str .= "\r\n\r\n//*********************************************************/\r\n"
   75                  . "//*          $sect\r\n"
   76                  . "//*********************************************************/\r\n\r\n";
   77             foreach ($sectdata as $setting => $misc) {
   78                 if ($misc['type'] !== 'fixed') {
   79                     // set standard first
   80                     $allowed_values = '';
   81                     $val = $_POST[$setting];
   82                     $default = $misc['default'];
   83                     $val_str = "'$val'";
   84                     $default_str = "'$default'";
   85                     // now set the execptions
   86                     if ($val == 'true' or $val == 'false') {
   87                         $val_str = "$val";
   88                         if ($default == true) {
   89                             $default_str = 'true';
   90                         } else {
   91                             $default_str = 'false';
   92                         }
   93                         $allowed_values = "// POSSIBLE VALUES: true, false\r\n";
   94                     } else if ($val == "'"){
   95                         $val_str = '"\'"';
   96                     } else {
   97                         $val_str = "'$val'";
   98                     }
   99                     if ($default == "'"){
  100                         $default_str = '"\'"';
  101                     }
  102 
  103                     if ($setting == 'limit_server') { // dont print domain names into the config file
  104                         $allowed_values = "// POSSIBLE VALUES: 'sitename.org', 'show_all'\r\n";//
  105                     } else if ($misc['type'] == 'dropdown' && ($val !== 'true' && $val !== 'false')) {
  106                         $allowed_values = implode("', '", array_keys($misc['values']));
  107                         $allowed_values = wordwrap($allowed_values, 60, "\r\n//                  ");
  108                         $allowed_values = "// POSSIBLE VALUES: '$allowed_values'\r\n";
  109                     } else if ($misc['type'] == 'password') {
  110                         $val = $_POST[$setting];
  111                         if ($val[0] !== $val[1]) {
  112                             echo baw_raise_error('password_match');
  113                             exit;
  114                         } else if ($val[0] == '') { // password will not change if empty
  115                             $val_str = "'{$BAW_CONF['online_config_password']}'";
  116                         } else if (strlen($val[0]) < 5) { // password too short
  117                             echo baw_raise_error('password_short');
  118                             exit;
  119                         } else {
  120                             $val_str = "'{$val[0]}'";
  121                         }
  122                     }
  123                     $out_help = wordwrap(
  124                         strip_tags(html_entity_decode($misc['help'])),
  125                         68
  126                         , "\r\n//          "
  127                     );
  128                     $name = html_entity_decode($misc['name']);
  129                     $str .= "// {$BAW_MES['cfg_name']} $name\r\n"
  130                           . "// {$BAW_MES['cfg_info']} {$out_help}\r\n"
  131                           . "// {$BAW_MES['cfg_def']} $default_str\r\n"
  132                           . $allowed_values
  133                           . "\$BAW_CONF['$setting'] = $val_str;\r\n\r\n";
  134                 }
  135             }
  136         }
  137         $str .= "\r\n\r\n//*********************************************************/\r\n"
  138              . "//*          {$BAW_MES['cfg_display']}\r\n"
  139              . "//*********************************************************/\r\n\r\n";
  140 
  141         foreach ($BAW_CONF_DIS_DEF as $setting => $misc) {
  142             $val_arr = $_POST[$setting];
  143             $name = html_entity_decode($misc['name']);
  144             $help = html_entity_decode($misc['help']);
  145             $str .= "// {$BAW_MES['cfg_name']} {$name}\r\n"
  146                   . "// {$BAW_MES['cfg_info']} {$help}\r\n";
  147             $this_conf = $BAW_CONF_DIS[$setting];
  148             $substr ='';
  149             foreach ($this_conf as $name => $oldval) {
  150                 $type = $BAW_CONF_DIS_TYP[$name][1];
  151                 $desc = $BAW_CONF_DIS_TYP[$name][0];
  152                 $val = $val_arr[$name];
  153                 if ($type == 'string') {
  154                     $val = "'$val'";
  155                 } else if ($type == 'sorting1') {
  156                     $desc2 = $BAW_MES['cfg_possible_values'] ."\r\n    // ";
  157                     foreach ($misc['sorting'] as $key => $value) {
  158                         $desc2 .= "'$key'=$value, ";
  159                     }
  160                     $desc2 = substr($desc2, 0, -2);
  161                     $desc2 = wordwrap($desc2, 75, "\r\n    // ");
  162                     $desc .= $desc2;
  163                     $val = "'$val'";
  164                 } else if ($type == 'sorting2') {
  165                     $desc .= $BAW_MES['cfg_possible_values'] . "\r\n"
  166                         . "    // " . $BAW_MES['cfg_type_sort_dir_opts'];
  167                 } else {
  168                     $val = "$val";
  169                 }
  170                 $desc = strip_tags(html_entity_decode($desc));
  171                 $substr .= "    '$name' => $val,    // $desc\r\n";
  172             }
  173             $str .= "\$BAW_CONF_DIS['$setting'] = array(\r\n$substr);\r\n\r\n";
  174         }
  175         $str .= "\r\n?>";
  176         if (!$handle = fopen($filename, 'w+')) {
  177             return baw_raise_error('configread');
  178         }
  179         if (fwrite($handle, $str) === FALSE) {
  180             return baw_raise_error('configwrite');
  181         }
  182 
  183         $out = $BAW_MES['cfg_saved'];
  184         $out = baw_site_header() . "<div class=\"errorbox\"><h1>BetterAWstats</h1>$out</div></body></html>";
  185         fclose($handle);
  186     } else {
  187         $out = baw_site_header() . baw_raise_error('configwrite');
  188     }
  189     return $out;
  190 }
  191 
  192 /*
  193 * Shows the login form
  194 *
  195 */
  196 function baw_config_login_form(){
  197     global $BAW_MES, $BAW_CONF;
  198     $out = "<form class=\"login_form\" action=\"{$BAW_CONF['site_url']}/index.php\" method=\"post\">\n"
  199         ."<p>"
  200         . $BAW_MES['require_password'] . "<br" . XHTML . ">". "<br" . XHTML . ">"
  201         . "<input type=\"password\" name=\"password\" value=\"\" size=\"20\"" . XHTML . "> "
  202         . "<input type=\"hidden\" name=\"action\" value=\"do_login\"" . XHTML . "> "
  203         . "<input type=\"submit\" name=\"submit\" value=\"Ok\"" . XHTML . ">\n"
  204         . "<input type=\"submit\" name=\"exit\" value=\"{$BAW_MES['cfg_exit']}\"" . XHTML . ">\n"
  205         ."</p>"
  206         . "</form>";
  207     return $out;
  208 }
  209 
  210 /*
  211 * Checks the password and logs the user in if OK
  212 *
  213 */
  214 function baw_action_do_login() {
  215     global $BAW_CONF, $BAW_MES;
  216     if (isset($_POST['exit']) && ($_POST['exit'] == $BAW_MES['cfg_exit'])) {
  217         return baw_display_index();
  218     }
  219     if (isset($_POST['password'])) {
  220         if ($_POST['password'] == $BAW_CONF['online_config_password']) {
  221             session_start();
  222             $_SESSION['loggedin'] = true;
  223             $_SESSION['password'] = MD5($_POST['password']);
  224             $out = baw_action_config_editor();
  225         } else {
  226             $out = baw_site_header()
  227                 . baw_raise_error('password_incorrect')
  228                 . baw_config_login_form();
  229         }
  230     } else {
  231         $out = baw_site_header()
  232             . baw_config_login_form();
  233     }
  234     echo $out;
  235 }
  236 
  237 /*
  238 * Check if the user is logged in and if the password has changed
  239 *
  240 */
  241 function baw_check_user() {
  242     global $BAW_CONF;
  243     if (isset($_SESSION['loggedin']) &&
  244         $_SESSION['loggedin'] == true &&
  245         isset ($_SESSION['password']) &&
  246         strlen($BAW_CONF['online_config_password']) > 5 &&
  247         $_SESSION['password'] == MD5($BAW_CONF['online_config_password'])) {
  248         return true;
  249     }
  250     if (strlen($BAW_CONF['online_config_password']) <= 5) {
  251         echo "The password has to be longer than 5 letters!";
  252     }
  253     return false;
  254 }
  255 
  256 /*
  257 * This logs the user out and displays the index.
  258 *
  259 */
  260 function baw_action_do_logout() {
  261     baw_logout();
  262     echo baw_display_index();
  263 }
  264 
  265 /*
  266 * This logs the user out physically.
  267 *
  268 */
  269 function baw_logout() {
  270     @session_start();
  271     $_SESSION = array();
  272     if (isset($_COOKIE[session_name()])) {
  273         setcookie(session_name(), '', time()-42000, '/');
  274     }
  275     @session_destroy();
  276 }
  277 
  278 /*
  279 * Displays the config editor.
  280 *
  281 */
  282 function baw_action_config_editor() {
  283     global $BAW_CONF, $BAW_CONF_DEF, $BAW_CONF_DIS_DEF, $BAW_CONF_DIS;
  284     global $BAW_MES, $BAW_CONF_DIS_TYP, $BAW_DFILES;
  285     if (!$BAW_CONF['online_config']) {
  286         return baw_raise_error('configdisabled');
  287     }
  288     @session_start();
  289     if(!baw_check_user()) {
  290         return baw_site_header() . baw_config_login_form();
  291     };
  292     $top = baw_site_header();
  293     $top .= "\n<form action=\"{$BAW_CONF['site_url']}/index.php\" method=\"post\">\n"
  294         . "  <div class=\"clearfix\">\n"
  295         . "    <input type=\"hidden\" name=\"action\" value=\"save_config\"" . XHTML . ">\n";
  296     $submit = "    <div class=\"conf_button_active\">\n      <input type=\"submit\" name=\"submit\" value=\"{$BAW_MES['cfg_save']}\"" . XHTML . ">\n"
  297         . "      <input type=\"reset\" name=\"reset\" value=\"{$BAW_MES['cfg_reset']}\"" . XHTML . ">\n"
  298         . "      <input type=\"submit\" name=\"exit\" value=\"{$BAW_MES['cfg_exit']}\"" . XHTML . ">\n"
  299         . "      <input type=\"submit\" name=\"logout\" value=\"{$BAW_MES['cfg_logout']}\"" . XHTML . ">\n"
  300         . "    </div>\n";
  301     $i = 0;
  302     $out = '';
  303     $section_count = count($BAW_CONF_DEF) + 1;
  304     foreach ($BAW_CONF_DEF as $section => $set_arr) {
  305         $out .= "<!-- CONF SECTION $i -->\n\n";
  306         if ($i >0) {
  307             $top .= "    <div class=\"conf_button_inactive\" id=\"button_1_$i\" onclick=\"toggleBox($i, 1, $section_count, 'conf');\">$section</div>\n";
  308             $out .= "  <div class=\"conf_section_inactive\" id=\"box_1_$i\">\n";
  309         } else {
  310             $top .= "    <div class=\"conf_button_active\" id=\"button_1_$i\" onclick=\"toggleBox($i, 1, $section_count, 'conf');\">$section</div>\n";
  311             $out .= "  <div class=\"conf_section_active\" id=\"box_1_$i\">\n";
  312         }
  313         foreach ($set_arr as $cfgname => $cfgdata) {
  314             $default = $cfgdata['default'];
  315             if (isset($BAW_CONF[$cfgname])) {
  316                 $val = $BAW_CONF[$cfgname];
  317             } else {
  318                 $val = $BAW_CONF_DEF[$section][$cfgname]['default'];
  319             }
  320             if ($cfgdata['type'] == 'fixed') {
  321                 $input = $val;
  322             } else if ($cfgdata['type'] == 'string') {
  323                 $input = "<input type=\"text\" name=\"$cfgname\" value=\"$val\" size=\"40\"" . XHTML . ">";
  324             } else if ($cfgdata['type'] == 'password') {
  325                 $input = "<input type=\"password\" name=\"{$cfgname}[]\" value=\"\" size=\"40\"" . XHTML . "><br" . XHTML . ">"
  326                     . $BAW_MES['confirm_password']
  327                     . "<input type=\"password\" name=\"{$cfgname}[]\" value=\"\" size=\"40\"" . XHTML . ">";
  328             } else if ($cfgdata['type'] == 'dropdown') {
  329                 $input = baw_generic_dropdown($cfgname, $cfgdata['values'],$val);
  330                 $default = $cfgdata['values'][$cfgdata['default']];
  331             } else if ($cfgdata['type'] == 'server_select') {
  332                 $input = baw_generic_dropdown($cfgname, $servers_arr, $BAW_DFILES['cfg_server_drop']);
  333             }
  334         $out .= "    <div class=\"conf_setting\"><h3>{$cfgdata['name']}</h3>\n"
  335             . $cfgdata['help'] . "<br " . XHTML . ">"
  336             . "$cfgname = $input"
  337             . "<br " . XHTML . ">(Default: \"<span class=\"default\">$default</span>\")\n"
  338             . "    </div>\n";
  339         }
  340         $out .= "  </div>\n";
  341         $i++;
  342 
  343     }
  344     $top .= "    <div class=\"conf_button_inactive\" id=\"button_1_$i\" onclick=\"toggleBox($i, 1, $section_count, 'conf');\">{$BAW_MES['cfg_display2']}</div>\n";
  345     $out .= "<!-- CONF SECTION $i -->\n\n";
  346     $out .= "  <div class=\"conf_section_inactive\" id=\"box_1_$i\">\n";
  347     $BAW_CONF_DIS = baw_array_sorting($BAW_CONF_DIS, 'order', SORT_ASC);
  348     foreach ($BAW_CONF_DIS as $cfgname => $cfgdata) {
  349         $input = '';
  350         $default = '';
  351         $name = $BAW_CONF_DIS_DEF[$cfgname]['name'];
  352         $help = $BAW_CONF_DIS_DEF[$cfgname]['help'];
  353 
  354         foreach ($BAW_CONF_DIS_TYP as $setname => $setdata) {
  355             if (isset($cfgdata[$setname])) {
  356                 $val = $BAW_CONF_DIS[$cfgname][$setname];
  357                 if ($setdata[1] == 'bool') {
  358                     if ($val == true) {
  359                         $selyes = ' checked="checked"';
  360                         $selno = "";
  361                     } else {
  362                         $selno = ' checked="checked"';
  363                         $selyes = "";
  364                     }
  365                     $input .= "<fieldset><legend>{$setdata[0]}</legend>\n"
  366                         ."{$BAW_MES[112]} <input type=\"radio\" name=\"".$cfgname."[".$setname."]\" value=\"true\"$selyes" . XHTML . "> "
  367                         . "{$BAW_MES[113]} <input type=\"radio\" name=\"".$cfgname."[".$setname."]\" value=\"false\"$selno" . XHTML . "> "
  368                         . "</fieldset>\n";
  369                 } else if ($setdata[1] == 'string') {
  370                     $input .= "<fieldset><legend>{$setdata[0]}</legend>\n"
  371                         ."<input type=\"text\" name=\"".$cfgname."[".$setname."]\" value=\"$val\" size=\"5\"" . XHTML . ">"
  372                         . "</fieldset>\n";
  373                 } else if ($setdata[1] == 'sorting1') {
  374                     $sort_arr = $BAW_CONF_DIS_DEF[$cfgname]['sorting'];
  375                     $input .= "<fieldset><legend>{$setdata[0]}</legend>\n"
  376                         . baw_generic_dropdown($cfgname."[".$setname."]", $sort_arr,$val)
  377                         . "</fieldset>\n";
  378                 } else if ($setdata[1] == 'sorting2') {
  379                     if ($val == 4) {
  380                         $selyes = ' checked="checked"';
  381                         $selno = '';
  382                     } else {
  383                         $selno = ' checked="checked"';
  384                         $selyes = '';
  385                     }
  386                     $input .= "<fieldset><legend>{$setdata[0]}</legend>\n"
  387                         ."{$BAW_MES['cfg_asc']} <input type=\"radio\" name=\"".$cfgname."[".$setname."]\" value=\"SORT_ASC\"$selyes" . XHTML . "> "
  388                         . "{$BAW_MES['cfg_desc']} <input type=\"radio\" name=\"".$cfgname."[".$setname."]\" value=\"SORT_DESC\"$selno" . XHTML . "> "
  389                         . "</fieldset>\n";
  390                 }
  391             }
  392         }
  393         $out .= "<div class=\"conf_setting\"><h3>$name</h3>\n"
  394             . $help . "<br " . XHTML . ">"
  395             . "<div class=\"clearfix\">$input</div>"
  396             . $default
  397             . "</div>\n";
  398     }
  399 
  400     $out .= "</div>\n"
  401         . "</form>"
  402         . baw_site_footer();
  403     return $top . "$submit  </div>\n". $out;
  404 }
  405 
  406 $BAW_FILE_HEADER = "/**
  407  * betterawstats - an alternative display for awstats data
  408  *
  409  * @author      Oliver Spiesshofer, support at betterawstats dot com
  410  * @copyright   2008 Oliver Spiesshofer
  411  * @version     1.0
  412  * @link        http://betterawstats.com
  413  *
  414  * Based on the GPL AWStats Totals script by:
  415  * Jeroen de Jong <jeroen@telartis.nl>
  416  * copyright   2004-2006 Telartis
  417  * version 1.13 (http://www.telartis.nl/xcms/awstats)
  418  *
  419  * This program is free software; you can redistribute it and/or
  420  * modify it under the terms of the GNU General Public License
  421  * as published by the Free Software Foundation; either version 2
  422  * of the License, or (at your option) any later version.
  423  *
  424  * This program is distributed in the hope that it will be useful,
  425  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  426  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  427  * GNU General Public License for more details.
  428  *
  429  * You should have received a copy of the GNU General Public License
  430  * along with this program; if not, write to the Free Software
  431  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  432  */
  433 
  434 // this file can't be used on its own - do not change these 3 lines
  435 if (strpos (\$_SERVER['PHP_SELF'], 'config.php') !== false) {
  436     die ('This file can not be used on its own!');
  437 }
  438 ";
  439 
  440 
  441 ?>