ispman/ispman-web/cgi-bin/tmpl/databases add.tmpl, 1.3, 1.4 edit.tmpl, 1.3, 1.4

Joerg Delker <[email protected]> Mon, 29 Dec 2008 16:14:23 +0000
Newsgroups gmane.comp.isp.ispman.cvs
Message-ID <[email protected]>
Update of /cvsroot/ispman/ispman/ispman-web/cgi-bin/tmpl/databases
In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv30006/ispman-web/cgi-bin/tmpl/databases

Modified Files:
	add.tmpl edit.tmpl 
Log Message:
added database forms

Index: add.tmpl
===================================================================
RCS file: /cvsroot/ispman/ispman/ispman-web/cgi-bin/tmpl/databases/add.tmpl,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- add.tmpl	11 Dec 2007 01:17:50 -0000	1.3
+++ add.tmpl	29 Dec 2008 16:14:21 -0000	1.4
@@ -1,80 +1,139 @@
-<form method="post" name="form">
-<br>
-
+<perl>
+   use String::MkPasswd qw(mkpasswd);
 
-<table border="0" cellpadding="4" cellspacing="1" width="100%" bgcolor="white">
-<td>
+   $ispmanDBName=$r->param("ispmanDomain")."_".$r->param("ispmanDBName");
+   $ispmanDBName =~ s/\./_/g;
+   "";
+</perl>
 
+<script type="text/javascript">
+<!--
 
-        <table border="0" cellpadding="4" cellspacing="1" width="100%" bgcolor="white">
-<perl>
-$text="";
-if ($ispman->{'session'}->param("logintype") eq "admin") {
-        $text.="<tr><td>@{[_('Type')]}</td><td> <select name=ispmanDatabaseType>";
-        $dbTypes=$ispman->getDatabaseTypes();
-        for (keys %$dbTypes){
-                $text.=sprintf("<option value='%s'>%s</option>", $_, $dbTypes->{$_});
-        }
-        $text.="</select></td></tr>";
-        $text;
+function verifyForm (form) {
+  if (form.dbName.value == "") {
+    alert("Database Name is undefined!");
+    form.ispmanDBName.focus();
+    return false;
+  }
+  if (form.dbUser.value == "") {
+    alert("Database User is undefined!");
+    form.ispmanDBUser.focus();
+    return false;
+  }
+  if (form.dbPass.value == "") {
+    alert("Database Password is undefined!");
+    form.ispmanDBPass.focus();
+    return false;
+  }
+  if (form.dbAccessFilter.value == "") {
+    alert("Database Access Filter is undefined!");
+    form.ispmanDBAccessFilter.focus();
+    return false;
+  }
 }
-</perl>
-<tr>
-	<td class=head4><a href="javascript:void(0)" title="<perl>_("Host where the database should be created")</perl>"><perl>_("Host")</perl></a></td>
 
-	<td>
-        <select name="dbHost">
-        <perl>
-        my $text="";
-        my @dbhosts=$ispman->getGroupMembers("databasegroup");
-        my @defaulthosts=$ispman->as_array($ispman->{'domain'}->{'ispmanDomainDefaultWebHost'});
+//-->
+</script>
 
-        for (@dbhosts){
-            my $tag="";
-            $text.="<option VALUE=\"$_\" $tag>$_</option>";
-        }
+<h1>Add new database</h1>
+<hr>
+<table border="0" cellspacing="0" cellpadding="3">
+<form id="edit_database" onsubmit="return verifyForm(this)" action="<perl>$ispman->getConfig('ispmanUrlPrefix')</perl>/admin/index.cgi" method="POST">
+  <tr>
+    <td id="title">Database Type:</td>
+    <td id="field">
+      <select name="ispmanDBType" id="ispmanDBType">
+      <perl>
+         join "\n", map { "<option value=\"$_\">$_</option>" } split(/\s*,\s*/,$ispman->getConf("dbTypes"));
+      </perl>
+      </select>
+    </td>
+  </tr>
+  <tr>
+    <td id="title">Database Name:</td>
+    <td id="field"><input type="text" name="ispmanDBName" id="ispmanDBName" value="<perl>$ispmanDBName</perl>"></td>
+  </tr>
+  <tr>
+    <td id="title">Username:</td>
+    <td id="field">
+      <input type="text" maxlength="16" name="ispmanDBUser" id="ispmanDBUser" value="<perl>$ispmanDBName</perl>"><br/>
+      <div id="note">(user name to connect to database)</div>
+    </td>
+  </tr>
+  <tr>
+    <td id="title">Password:</td>
+    <td id="field">
+      <input type="text" name="ispmanDBPass" id="ispmanDBPass" value="<perl>mkpasswd();</perl>"><br/>
+      <div id="note">(password to connect to database)</div>
+    </td>
+  </tr>
+  <tr>
+    <td id="title">Allowed Hosts:</td>
+    <td id="field">
+      <input type="text" name="ispmanDBAccessFilter" value="<perl>$ispman->getConf("dbAccessHostFilter")</perl>"><br/>
+      <div id="note">(allowed hosts to connect to database)</div>
+    </td>
+  </tr>
+  <tr>
+    <td id="title">Privileges:</td>
+    <td id="field">
+      <table id="ispmanDBPrivileges" width="100%" border="0" cellpadding="2" cellspacing="1">
+      <perl>
+        my $out="";
+        my %acl;
+        my $maxrows=0;
 
-        if  ($#dbhosts<0){
-            $text.="<option VALUE=''>WARNING: No members in group databasegroup defined</option>";
+        for (split ",",$ispman->getConf("dbAccessPermissions")) {
+          if ($_ =~ /(.*)\((.*)\)/) {
+            push @sections,$1;
+            $acl{$1} = [ split '\|',$2 ];
+            $maxrows = ($maxrows < @{$acl{$1}})?@{$acl{$1}}:$maxrows;
+          }
         }
 
-        $text
-	
-
-        </perl>
-        </select>
-	</td>
-
-
-</tr>
-                        
-        
-        
-        <tr>
-                <td class=head4><perl>_("Database name")</perl></a></td>
-                <td ><input CLASS="formtext" maxlength=10 size=10 type=text name=cn value="">_<perl>$ispman->{"domain"}{"uidNumber"}</perl></td>
-        </tr>
-        <tr>
-                <td class=head4><perl>_("Password")</perl></td>
-                <td ><input CLASS="formtext" type=text name=userPassword value="<perl>$ispman->{'client'}{'userPassword'}</perl>"></td>
-        </tr>
-
-<input type=hidden name="mode" value="<perl>($r->param("mode") eq "createDatabase")?"AddDatabase":"ModifyClient"</perl>">
-<input type=hidden name="ispmanDomain" value="<perl>$ispman->{'domain'}{"ispmanDomain"}</perl>">
-<input type=hidden name="suffix" value="<perl>$ispman->{'domain'}{"uidNumber"}</perl>">
+        $out .= "<tr>".join("",map { "<td>$_</td>" } @sections)."</tr>\n";
 
+        for (my $row=0; $row < $maxrows; $row++) {
+          $out .= "<tr>\n";
 
+          foreach (@sections) {
+            my $grant=$acl{$_}[$row];
+            my $default=($grant =~ s/\*$//)?'checked="checked"':'';
+            $out .= "<td>";
+            $out .= qq|<input type="checkbox" name="ispmanDBPrivilege" id="ispmanDBPrivilege" value="$grant" $default>$grant| unless !defined($grant);
+            $out .= "</td>\n";
+          }
+          $out .= "</tr>\n";
+        }
+        $out;
+      </perl>
+      </table>
+    </td>
+  </tr>
 
+  <tr>
+    <td id="title">Server:</td>
+    <td id="field">
+      <select name="ispmanDBHost" id="ispmanDBHost">
+      <perl>
+        my @dbhosts=$ispman->getGroupMembers("databasegroup");
+        my $defaulthost = $ispman->getDomainInfo($r->param("ispmanDomain"))->{'ispmanDomainDefaultDBHost'};
+        join "\n", map { "<option VALUE=\"$_\"".(($_ eq $defaulthost)?"selected":"").">$_</option>" } @dbhosts;
+      </perl>
+      </select>
+    </td>
+  </tr>
 
+  <tr>
+    <td></td>
+    <td id="buttons" colspan=2>
+         <input type=button class="button" onClick="document.forms[0].reset()" value="Reset">
+         <input type=button class="button" onClick="document.forms[0].submit()" value="Add">
+    </td>
+  </tr>
 
+<input type=hidden name="mode" value="add_database_cgi">
+<input type=hidden name="ispmanDomain" value="<perl>$r->param("ispmanDomain")</perl>">
 
-<input type="submit" value="Add this database"></td>
-<br>
 </form>
-
-
-
-
-
-
-
+</table>

Index: edit.tmpl
===================================================================
RCS file: /cvsroot/ispman/ispman/ispman-web/cgi-bin/tmpl/databases/edit.tmpl,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- edit.tmpl	11 Dec 2007 01:17:50 -0000	1.3
+++ edit.tmpl	29 Dec 2008 16:14:21 -0000	1.4
@@ -1,42 +1,113 @@
-<form method="post" name="form">
-<br>
-
-
-
-
-<table border="0" cellpadding="4" cellspacing="1" width="100%" bgcolor="white">
-<tr>
-	<th>Type</th>
-	<td><perl>$ispman->{"thisDbInfo"}{'ispmanDBType'}</perl></th>
-</tr>
-
-<tr>
-	<th>Host</th>
-	<td><perl>$ispman->{"thisDbInfo"}{'ispmanDBHost'}</perl></th>
-</tr>
-
-<tr>
-	<th>Name</th>
-	<td><perl>$ispman->{"thisDbInfo"}{'cn'}</perl></th>
-</tr>
-
-<tr>
-	<th>User</th>
-	<td><perl>$ispman->{"thisDbInfo"}{'ispmanDBUser'}</perl></th>
-</tr>
-
-<tr>
-	<th>Pass</th>
-	<td><perl>$ispman->{"thisDbInfo"}{'ispmanDBPass'}</perl></th>
-</tr>
-
-</table>
-
-</form>
-
-
-
-
-
-
-
+<script>
+  function deleteDatabase() {
+    if(confirm('Are you sure? THIS DELETES THE DATABASE AND ALL CONTENT!')){
+      document.forms[0].mode.value='delete_database_cgi';
+      document.forms[0].submit();
+    }
+  }
+</script>
+
+<h1>Edit database</h1>
+<hr>
+<table id="edit_database" border="0" cellspacing="0" cellpadding="3">
+<form action="<perl>$ispman->getConfig('ispmanUrlPrefix')</perl>/admin/index.cgi" method="POST">
+  <tr>
+    <td id="title">Database Type:</td>
+    <td id="field">
+      <select name="ispmanDBType" id="ispmanDBType" disabled>
+      <perl>join "\n", map { "<option value=\"$_\"".(($dbInfo->{'ispmanDBType'} eq $_)?"selected":"").">$_</option>" }
+                             split(/\s*,\s*/,$ispman->getConf("dbTypes"));</perl>
+      </select>
+    </td>
+  </tr>
+  <tr>
+    <td id="title">Database Name:</td>
+    <td id="field"><input type="text" name="ispmanDBName" id="ispmanDBName" maxlength="64" value="<perl>$dbInfo->{'ispmanDBName'}</perl>"></td>
+  </tr>
+  <tr>
+    <td id="title">Username:</td>
+    <td id="field">
+      <input type="text" maxlength="16" name="ispmanDBUser" id="ispmanDBUser" value="<perl>$dbInfo->{'ispmanDBUser'}</perl>"><br/>
+      <div id="note">(user name to connect to database)</div>
+    </td>
+  </tr>
+  <tr>
+    <td id="title">Password:</td>
+    <td id="field">
+      <input type="text" name="ispmanDBPass" id="ispmanDBPass" value="<perl>$dbInfo->{'ispmanDBPass'}</perl>"><br/>
+      <div id="note">(password to connect to database)</div>
+    </td>
+  </tr>
+  <tr>
+    <td id="title">Access Filter:</td>
+    <td id="field">
+      <input type="text" name="ispmanDBAccessFilter" id="ispmanDBAccessFilter"
+             value="<perl>$dbInfo->{'ispmanDBAccessFilter'}</perl>"><br/>
+      <div id="note">(allowed hosts to connect to database)</div>
+    </td>
+  </tr>
+  <tr>
+    <td id="title">Privileges:</td>
+    <td id="field">
+      <table id="ispmanDBPrivilege" width="100%" border="0" cellpadding="2" cellspacing="1">
+      <perl>
+        my $out="";
+        my %acl;
+        my $maxrows=0;
+        my $selected = $ispman->as_hashref($dbInfo->{'ispmanDBPrivilege'});
+
+        for (split ",",$ispman->getConf("dbAccessPermissions")) {
+          if ($_ =~ /(.*)\((.*)\)/) {
+            push @sections,$1;
+            $acl{$1} = [ split '\|',$2 ];
+            $maxrows = ($maxrows < @{$acl{$1}})?@{$acl{$1}}:$maxrows;
+          }
+        }
+
+        $out .= "<tr>".join("",map { "<td>$_</td>" } @sections)."</tr>\n";
+
+        for (my $row=0; $row < $maxrows; $row++) {
+          $out .= "<tr>\n";
+
+          foreach (@sections) {
+            my $grant=$acl{$_}[$row];
+            $grant =~ s/\*$//;
+            my $default=($selected->{$grant})?'checked="checked"':'';
+            $out .= "<td>";
+            $out .= qq|<input type="checkbox" name="ispmanDBPrivilege" id="ispmanDBPrivilege" value="$grant" $default>$grant| unless !defined($grant);
+            $out .= "</td>\n";
+          }
+          $out .= "</tr>\n";
+        }
+        $out;
+      </perl>
+    </table></td>
+  </tr>
+
+  <tr>
+    <td id="title">DB Host:</td>
+    <td id="field">
+      <select name="ispmanDBHost" id="ispmanDBHost">
+      <perl>
+        my @dbhosts=$ispman->getGroupMembers("databasegroup");
+        join "\n", map { "<option VALUE=\"$_\"".(($dbInfo->{'ispmanDBHost'} eq $_)?"selected":"").">$_</option>" } @dbhosts;
+      </perl>
+      </select><br/>
+      <div id="note">(server that will host this database)</div>
+    </td>
+  </tr>
+
+  <tr>
+    <td></td>
+    <td id="buttons" colspan=2>
+         <input type=button class="button" onClick="document.forms[0].submit()" value="Save">
+         <input type=button class="button" onClick="deleteDatabase()" value="Drop">
+    </td>
+  </tr>
+
+<input type=hidden name="mode" value="modify_database_cgi">
+<input type=hidden name="oldDBName" value="<perl>$dbInfo->{'ispmanDBName'}</perl>">
+<input type=hidden name="ispmanDomain" value="<perl>$r->param("ispmanDomain")</perl>">
+
+</form>
+</table>


------------------------------------------------------------------------------