PDA

View Full Version : $doc->deck[$id]->elements[] fix script


danf.1979
14th February 2007, 13:27
I'm working on a script to replace id from elements with the names, I'll finish it and post it here...

till
14th February 2007, 13:52
Thats great news! Thanks.

danf.1979
14th February 2007, 14:23
I have a problem. For example, here:

if($tablevalues["web_individual_error_pages"] == 0) {

$doc->deck[6]->getElementByName("t5")->visible = 0;

// PROBLEM START
$doc->deck[6]->elements[10]->visible = 0;
// END PROBLEM

$doc->deck[6]->getElementByName("error_400")->visible = 0;

$doc->deck[6]->getElementByName("error_401")->visible = 0;

$doc->deck[6]->getElementByName("error_403")->visible = 0;

I cannot translate it. It doesn't have a name. This is the object, and is messing with my id to name numeration! :(

stdClass Object
(
[visible] => 0
)

How to fix this?


$deck_id = 0;
foreach ($doc->deck as $deck) {
$x = 0;
if (isset($doc->deck[$deck_id])) {
print "&nbsp;&nbsp;&nbsp;&nbsp;#deck[".$deck_id."]<br>";
print "&nbsp;&nbsp;&nbsp;&nbsp;{<br>";
while ($x <= 200) {
if (isset($deck->elements[$x])) {
print "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".$x.": \"".$deck->elements[$x]->name."\",<br>";
}
$x++;
}
print "&nbsp;&nbsp;&nbsp;&nbsp;},<br>";
}
$deck_id++;
}

I'm using while $x<200 (200 for a safe high number only) because a foreach loop skippes some elements. Yes, strange. I couldn't find out why.
This is generated, and it would be a perfect copy paste for my dictionary in the python script, but THAT little $doc->deck[6]->elements[10], and others like him, are getting on the way.

#deck[0]
{
0: "server_id",
1: "web_host",
3: "web_domain",
4: "web_ip",
5: "web_dns",
6: "web_dns_mx",
7: "t1",
8: "web_speicher",
9: "web_traffic",
10: "web_traffic_ueberschreitung",
11: "web_mailquota",
12: "web_userlimit",
13: "web_domainlimit",
14: "t2",
15: "web_shell",
16: "web_cgi",
17: "web_cgi_mod_perl",
20: "web_standard_cgi",
21: "web_php",
22: "web_php_safe_mode",
23: "web_ssi",
24: "web_ftp",
25: "web_frontpage",
26: "web_mysql",
27: "web_mysql_anzahl_dbs",
28: "web_mysql_quota",
29: "web_ssl",
30: "web_anonftp",
31: "web_anonftplimit",
32: "web_postgresql",
33: "web_wap",
34: "web_individual_error_pages",
35: "status",
36: "web_mailuser_login",
37: "trweb",
38: "web_httpd_include",
39: "web_traffic_status",
},
#deck[1]
{
0: "user",
},
#deck[2]
{
0: "domain_abh",
},
#deck[3]
{
1: "ssl_country",
2: "ssl_state",
3: "ssl_locality",
4: "ssl_organization",
5: "ssl_organization_unit",
7: "ssl_days",
8: "t4",
9: "ssl_request",
10: "ssl_cert",
11: "ssl_action",
},
#deck[4]
{
0: "web_shop",
1: "web_phpmyadmin",
2: "web_webmail",
3: "web_webalizer",
},
#deck[5]
{
0: "check_webspace",
1: "traffic",
},
#deck[6]
{
0: "optionen_db_liste",
1: "optionen_mysql_user",
2: "check_database",
3: "optionen_mysql_passwort",
4: "optionen_mysql_remote_access",
5: "optionen_frontpage_passwort",
6: "optionen_local_mailserver",
7: "optionen_logsize",
8: "optionen_directory_index",
9: "t5",
11: "error_400",
12: "error_401",
13: "error_403",
14: "error_404",
15: "error_405",
16: "error_500",
17: "error_503",
18: "t6",
19: "webalizer_stats",
},
#deck[7]
{
0: "isp_web_faktura",
},

danf.1979
14th February 2007, 14:35
This are all my problems:

$doc->deck[6]->elements[10]->visible = 0;
$doc->deck[0]->elements[18]->value = $vorlage["web_php"];

$doc->deck[0]->elements[19]->value = $vorlage["web_php_safe_mode"];

I think they are all of them.

printf("<pre>%s</pre>", print_r($doc->deck[0]->elements[18], true));
printf("<pre>%s</pre>", print_r($doc->deck[0]->elements[19], true));
Nothing on the screen.

Are this things used for something?

danf.1979
14th February 2007, 14:42
Sorry for the several posts. Here IS my problem:

$doc->deck[0]->getElementByName("web_cgi")->value = $vorlage["web_cgi"];

$doc->deck[0]->getElementByName("web_cgi_mod_perl")->value = $vorlage["web_standard_cgi"];

$doc->deck[0]->elements[18]->value = $vorlage["web_php"];

$doc->deck[0]->elements[19]->value = $vorlage["web_php_safe_mode"];

$doc->deck[0]->getElementByName("web_php")->value = $vorlage["web_ssi"];

$doc->deck[0]->getElementByName("web_php_safe_mode")->value = $vorlage["web_ftp"];

:(

till
15th February 2007, 10:53
The variable "$vorlage" contains the values from the hostingplan, so they are only true if they are set to true in the hosting plan.

To the elements 18 + 19, If i remember correctly, every elemnt has a name by default. So maybe these two elements where not used anymore? Do you see any differences when you comment out the two lines?

danf.1979
16th February 2007, 01:47
It seems to be working now... Did you fix something?

danf.1979
16th February 2007, 22:07
Ok here is the script if someone needs it from now on. Although I think I've changed all files that used $doc->deck[]->elements, at least in lib/classes/.
Paste the php code on the constructor or show function.
Then paste the output to the list named 'decks' inside this script. It should map every id with its corresponding name. Just paste it as it appears on the screen. Nothing more to do. Then define the file that is going to be parsed and changed. Changes respects identation.


#!/usr/bin/env python
import os,sys

# PHP
#$deck_id = 0;
#foreach ($doc->deck as $deck) {
# $x = 0;
# if (isset($doc->deck[$deck_id])) {
# print "&nbsp;&nbsp;&nbsp;&nbsp;#deck[".$deck_id."]<br>";
# print "&nbsp;&nbsp;&nbsp;&nbsp;{<br>";
# while ($x <= 200) {
# if (isset($deck->elements[$x])) {
# print "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".$x.": \"".$deck->elements[$x]->name."\",<br>";
# }
# $x++;
# }
# print "&nbsp;&nbsp;&nbsp;&nbsp;},<br>";
# }
# $deck_id++;
#}
# END PHP

# file here
file = "/home/admispconfig/ispconfig/lib/classes/ispconfig_isp_user.lib.php"

if not os.path.exists(file):
sys.exit("%s does not exist" % file)


decks = [
#PASTE HERE
# This is the list of dictionary definitions
]

lines = open(file, "r").readlines()
newlines = []
count = 0
for line in lines:
if line[-1] == "\n":
line = line[:-1]
deck_id = 0
found = False
for deck in decks:
for id,name in deck.items():
old = "$doc->deck["+str(deck_id)+"]->elements["+str(id)+"]"
new = "$doc->deck["+str(deck_id)+"]->getElementByName(\""+str(name)+"\")"
if old in line:
found = True
line = line.replace(old, new)
newlines.append(line)
count = count + 1
deck_id = deck_id+1
if not found:
newlines.append(line)

f = open(file, "w")
f.writelines("\n".join(newlines))
print count, "lines modified"
f.close()