1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
<?php
require_once "model/master.mod.php";
require_once "class/form.class.php";
class SysconfModel extends MasterModel
{
var $CONF_FILE = "scrott.conf.php";
/*
* Default action
*/
function deflt()
{
}
/*
* Save the submitted data to the config file
*/
function save($input)
{
$form = new Form();
$form->field_text("dbAddress");
$form->field_text("dbName");
$form->field_text("dbUser");
$form->field_text("dbPass", null, false);
$form->field_enum("settSSL", array("force", "neither", "forbid"));
if (!$form->populate($input))
{
$this->logFormErrors($form);
return;
}
/* TODO -- test database connection before proceeding */
$f = fopen($this->CONF_FILE, "w");
if (!$f)
{
$this->logError("Can not create configuration file");
return;
}
fwrite($f, "<?php\n");
fwrite($f, "\$_SCROTT['conf'] = 'conf';\n");
fwrite($f, "\$_SCROTT['dbEngine'] = 'mysql';\n");
fwrite($f, "\$_SCROTT['dbAddress'] = '" . $form->dbAddress . "';\n");
fwrite($f, "\$_SCROTT['dbName'] = '" . $form->dbName . "';\n");
fwrite($f, "\$_SCROTT['dbUser'] = '" . $form->dbUser . "';\n");
fwrite($f, "\$_SCROTT['dbPass'] = '" . $form->dbPass . "';\n");
fwrite($f, "\$_SCROTT['settSSL'] = '" . $form->settSSL . "';\n");
fwrite($f, "?>\n");
fclose($f);
$this->redirectTo($this->ar());
}
}
?>
|