Skip to content
Browse files

vars.php now takes settings from sss.php -s

  • Loading branch information...
1 parent 258e971 commit 58e83adb47f96754548450a8f30b41e91218f355 @tommyrot committed Dec 31, 2012
Showing with 49 additions and 24 deletions.
  1. +5 −0 MANUAL
  2. +28 −7 sss.php
  3. +2 −2 www/history.php
  4. +14 −15 www/vars.php
View
5 MANUAL
@@ -3,6 +3,7 @@ usage: php sss.php [-c <file>] [-i <file|directory>]
php sss.php [-c <file>] [-e <file>]
php sss.php [-c <file>] [-m]
php sss.php [-c <file>] [-n <file>]
+ php sss.php [-c <file>] [-s]
options:
-b <numbits>
@@ -44,6 +45,10 @@ options:
-o <file>
Generate statistics and output to <file>.
+ -s
+ Export settings from the configuration file in the format
+ "vars.php" accepts them. See "vars.php" for details.
+
examples:
Parse all logfiles found in "/home/foo/bar/" and create a statspage
named "/var/www/foobar.html" containing only Activity and URLs data:
View
35 sss.php
@@ -82,11 +82,11 @@ public function __construct()
/**
* Read options from the command line. If an illegal combination of valid options is given the program will print the manual on screen and exit.
*/
- $options = getopt('b:c:e:i:mn:o:');
+ $options = getopt('b:c:e:i:mn:o:s');
ksort($options);
$options_keys = implode('', array_keys($options));
- if (!preg_match('/^(bc?i?o|c|c?(e|i|i?o|m|n))$/', $options_keys)) {
+ if (!preg_match('/^(bc?i?o|c|c?(e|i|i?o|m|n|s))$/', $options_keys)) {
$this->print_manual();
}
@@ -111,6 +111,13 @@ public function __construct()
}
/**
+ * Export settings from the configuration file in the format vars.php accepts them.
+ */
+ if (array_key_exists('s', $options)) {
+ $this->export_settings();
+ }
+
+ /**
* Make the database connection. Always needed.
*/
$this->mysqli = @mysqli_connect($this->db_host, $this->db_user, $this->db_pass, $this->db_name, $this->db_port) or $this->output('critical', 'mysqli: '.mysqli_connect_error());
@@ -225,6 +232,23 @@ private function export_nicks($file)
$this->output('notice', 'export_nicks(): '.number_format($i).' nicks exported');
}
+ private function export_settings()
+ {
+ if (!empty($this->settings['cid'])) {
+ $vars = '$settings[\''.$this->settings['cid'].'\'] = array(';
+ } elseif (!empty($this->settings['channel'])) {
+ $vars = '$settings[\''.$this->settings['channel'].'\'] = array(';
+ } else {
+ $this->output('critical', 'export_settings(): both \'cid\' and \'channel\' are empty');
+ }
+
+ foreach ($this->settings as $key => $value) {
+ $vars .= "\n\t".'\''.$key.'\' => \''.$value.'\',';
+ }
+
+ exit(rtrim($vars, ',')."\n".');'."\n");
+ }
+
private function import_nicks($file)
{
$this->output('notice', 'import_nicks(): importing nicks');
@@ -556,11 +580,8 @@ private function parse_log($filedir)
private function print_manual()
{
$man = 'usage: php sss.php [-c <file>] [-i <file|directory>]'."\n"
- . ' [-o <file> [-b <numbits>]]'."\n"
- . ' php sss.php [-c <file>] [-e <file>]'."\n"
- . ' php sss.php [-c <file>] [-m]'."\n"
- . ' php sss.php [-c <file>] [-n <file>]'."\n\n"
- . 'See the MANUAL file for an overview of available options.'."\n";
+ . ' [-o <file> [-b <numbits>]]'."\n\n"
+ . 'See the MANUAL file for an overview of all available options.'."\n";
exit($man);
}
View
4 www/history.php
@@ -32,9 +32,9 @@
private $db_user = '';
private $debug = false;
private $mainpage = './';
- private $maxrows_people_month = 30;
+ private $maxrows_people_month = 10;
private $maxrows_people_timeofday = 10;
- private $maxrows_people_year = 30;
+ private $maxrows_people_year = 10;
private $stylesheet = 'sss.css';
private $timezone = 'UTC';
private $userstats = false;
View
29 www/vars.php
@@ -1,22 +1,21 @@
<?php
/**
- * These settings only apply to user.php and history.php.
+ * This file contains settings used by user.php and history.php. It should not
+ * display to your visitors. Said pages need only read-access to MySQL, you
+ * might want to create a separate account for them with minimal rights.
+ *
+ * Use sss.php with the -s flag to export settings from the configuration file
+ * in the format that is accepted in here. Multiple arrays of settings may be
+ * included in this file, as long as they have unique identifiers (cid).
+ *
+ * Optional settings are, with their defauls:
+ * 'debug' => 'false' # can be true or false
+ * 'mainpage' => './' # (relative) path to the main stats page
*/
-/**
- * Each channel can have their own specific settings overriding the global ones.
- * Create a new array with the appropriate channel ID and put the settings in it
- * that differ from the global values (seen above). You can find the channel ID
- * for your channel in sss.conf - they must be identical! It is advisable to
- * leave out the hash mark from the channel ID (here and in sss.conf) since it
- * will be used in the URL.
- */
-$settings['mychannel'] = array(
- 'channel' => '#mychannel',
- 'db_name' => 'sss-mychannel',
- 'mainpage' => './mychan.html',
- 'userstats' => true
-);
+
+/* -- paste output of sss.php -s here -- */
+
?>

0 comments on commit 58e83ad

Please sign in to comment.
Something went wrong with that request. Please try again.