esconsut1 / revsense-ad-server

Revsense Ad Server - Comprehensive ad server to serve/rotate Text and Banner in CPC, CPM, CPA and CPD methods.

This URL has Read+Write access

revsense-ad-server / install.php
100644 378 lines (335 sloc) 12.698 kb
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
<?
//
// AdRevenue Ad Management
// install.php
//
// (C) 2004 W3matter LLC
// This is commercial software!
// Please read the license at:
// http://www.w3matter.com/license
//
// Installation Script
 
include_once("libs/startup.php");
 
$f = $_REQUEST[f];
 
$tpl = new XTemplate("templates/install.html");
 
 
// Lets get some intermediary information
$port = $_SERVER["SERVER_PORT"] == 80 ? "http" : "https";
$path = "$port://" . $_SERVER[HTTP_HOST] . preg_replace("/install\.php.*?$/i", "", $_SERVER[REQUEST_URI]);
$p = urlencode($path);
 
// Step 1
// Check Permissions for all writable areas
$writable = array();
if(!is_writable('cache'))
$writable[] = array("cache","directory");
if(!is_writable('settings.php'))
$writable[] = array("settings.php", "file");
if(!is_writable('banners'))
$writable[] = array("banners", "directory");
if(count($writable) > 0)
{
$gen = new formgen();
foreach($writable as $rec)
{
$gen->startrow("#FFFFEE");
$gen->column("$rec[0] ($rec[1])");
$gen->endrow();
}
 
$out = "<font size=4 face=Arial,Helvetica,sans-serif><b>Set File & Directory Permissions</b></font><p>";
$out .= "You need proper permissions for the webserver to write to the following files or directories.<p>";
$out .= $gen->gentable("300", 0, 1, 3, "#EEEEEE") . "<p>";
$out .= "You need to fix this problem before continuing.<br>";
$out .= "<b>For UNIX servers:</b><br>";
$out .= "<code>> chmod ugo+rw <b>filename</b></code><br>";
$out .= "<code>> chmod ugo+rw <b>directory</b></code><p>";
$out .= "<b>For Windows servers:</b><br>";
$out .= "Use your FTP software to change the settings.<p>";
$out .= "<A href=install.php>Continue when you are done.</a><p>&nbsp;";
 
$tpl->assign("BODY", $out);
$tpl->assign("TITLE", "INSTALLATION STEP 1: File Permissions");
$tpl->parse("main");
echo $tpl->text("main");
exit;
}
 
// Step 2
// Decide what database we want to use, and create the settings file
if(!$DEFAULT[engine] || !$DEFAULT[host] || !$DEFAULT[database] || !$DEFAULT[user])
{
if($f[engine] && $f[host] && $f[user])
{
// Set some psuedo defaults
$DEFAULT[engine] = $f[engine];
$DEFAULT[host] = $f[host];
$DEFAULT[database] = $f[database];
$DEFAULT[user] = $f[user];
$DEFAULT[password] = $f[password];
 
// Test the connection
$db = new database();
$db->connect();
 
if(!$db->errormsg)
{
// Write to the settings file
$fp = fopen("settings.php","w");
if($fp)
{
// We got the schema, so create the tables
// $schema = @file("http://www.w3matter.com/installs/adrevenue2." . $DEFAULT[engine] . ".sql");
$schema = @file("cache/revsense.sql");
if(@count($schema) == 0)
{
$errormsg .= "<li> ERROR: Could not access database creating instructions. Please contact W3matter.com";
}
else
{
foreach($schema as $s)
{
if(preg_match('/CREATE TABLE\s+(.*?)\s/i', $s, $match))
{
$table = trim($match[1]);
if($db->exists($table))
{
$found = TRUE;
$tables[] = "<li> $table";
}
}
}
 
if($found)
{
$errormsg .= "<li> ERROR: some adrevenue tables currently exist:<br><i>". implode(",", $tables) . "</i><br>They should be dropped first!";
}
else
{
foreach($schema as $s)
{
if(trim($s))
{
$db->errormsg = "";
$db->getsql($s);
if($db->errormsg)
$error .= $db->errormsg . "<br>";
}
}
 
if($error)
$errormsg .= "<li> ERROR: There were some errors creating the tables:<br><font size=1>$error</font>";
}
}
 
// Now we add the extra settings
if(!$errormsg)
{
$db->getsql("INSERT INTO adrev_settings VALUES ('paypal_email','$f[email]')");
$db->getsql("INSERT INTO adrev_settings VALUES ('currency','$f[currency]')");
$db->getsql("INSERT INTO adrev_settings VALUES ('name','$f[organization]')");
$db->getsql("INSERT INTO adrev_settings VALUES ('url','$f[url]')");
$db->getsql("INSERT INTO adrev_settings VALUES ('hostname','$f[url]')");
$db->getsql("INSERT INTO adrev_settings VALUES ('email','$f[email]')");
$db->getsql("INSERT INTO adrev_settings VALUES ('default_redir','$f[url]')");
 
// Add a new user
$i = array();
$i[admin] = 3;
$i[zid] = uniqid("");
$i[date] = time();
$i[ip] = $_SERVER[REMOTE_ADDR];
$i[status] = 1;
$i[email] = $f[email];
$i[password] = $f[admin_password];
$i[name] = "Administrator";
$i[organization] = $f[organization];
$i[country] = $f[country];
$i[url] = $f[url];
$db->insert("adrev_users", $i);
}
 
// Finally, we create the settings file
if(!$errormsg)
{
fputs($fp, "<?\n");
fputs($fp, "// Adrevenue Configuration Settings\n");
fputs($fp, "// Generated on " . date("r") . "\n\n");
fputs($fp, "\$DEFAULT[engine]='$f[engine]';\n");
fputs($fp, "\$DEFAULT[host]='$f[host]';\n");
fputs($fp, "\$DEFAULT[database]='$f[database]';\n");
fputs($fp, "\$DEFAULT[user]='$f[user]';\n");
fputs($fp, "\$DEFAULT[password]='$f[password]';\n");
fputs($fp, "?>");
fclose($fp);
 
header("Location: index.php");
}
 
}
else
{
$errormsg = "<li> ERROR creating file <b>settings.php</b>. Make sure permissions are correct.";
}
}
else
{
$errormsg = "<li> $db->errormsg";
}
}
 
// Show the form
$form = new formgen();
if(!$f[url])
$f[url] = $path;
if(!$f[country])
$f[country] = "US";
if(!$f[currency])
$f[currency] = "USD";
if(!$f[organization])
$f[organization] = "My Advertising Portal";
 
$dbs = array("mysql"=>"MySQL", "pg"=>"PostgreSQL");
if($errormsg)
$form->comment("<font color=red>$errormsg</font>");
 
$form->comment("<font size=3><b>Enter your database settings:</b></font>");
$form->dropdown("<b>DB Type</b>", "f[engine]", lib_htlist_array($dbs, $f[engine]), "Choose the kind of database server you have");
$form->input("<b>Hostname</b>", "f[host]", stripslashes($f[host]), 40, "The Domain Name or IP Address for your Database Server");
$form->input("<b>Username</b>", "f[user]", stripslashes($f[user]), 20, "Database Login");
$form->input("Password", "f[password]", stripslashes($f[password]), 20, "Database Password");
$form->input("<b>DB Name</b>", "f[database]", stripslashes($f[database]), 20, "The name of the database where AdRevenue Data will live. You should have already created this.");
$form->comment("<hr size=1><b><font size=3>Enter your Site Settings:</font></b><br>");
$form->input("<b>Admin&nbsp;Email</b>", "f[email]", stripslashes($f[email]), 30);
$form->input("<b>Admin&nbsp;Password</b>", "f[admin_password]", stripslashes($f[admin_password]), 20);
$form->input("<b>Site Name</b>", "f[organization]", stripslashes($f[organization]), 30);
$form->input("<b>URL</b>", "f[url]", stripslashes($f[url]), 50, "The URL where AdREvenue is installed. (It must have the trailing slash \"/\" at the end).");
$form->dropdown("<b>Country</b>", "f[country]", lib_htlist_array($DEFAULT[country],$f[country]));
$form->input("<b>Currency</b>", "f[currency]", $f[currency],5, "Your currency code -- eg: USD");
$out = $form->generate("post", "Create AdRevenue Installation") . "<p>&nbsp;";
 
$tpl->assign("BODY", $out);
$tpl->assign("TITLE", "INSTALLATION STEP 2: Database Settings");
$tpl->parse("main");
echo $tpl->text("main");
exit;
}
 
 
exit;
#--------------------------------- DEPRECATED --------------------------------------------#
 
// Step 3
// Download the schema and create the tables
// If tables already exist, we should carp
$db = new database();
$db->connect();
 
$found = FALSE;
$schema = file("http://www.w3matter.com/installs/adrevenue2." . $DEFAULT[engine] . ".sql");
if(count($schema) > 0 && !$_REQUEST[created])
{
foreach($schema as $s)
{
if(preg_match('/CREATE TABLE\s+(.*?)\s/i', $s, $match))
{
$table = trim($match[1]);
if($db->exists($table))
{
$found = TRUE;
$tables[] = "<li> $table";
}
}
}
 
if($found)
{
$out = "<font size=3><b>The following tables already exist in your database</b></font><p>";
$out .= implode("<br>", $tables);
$out .= "<p>You need to drop those tables before continuing.<p>";
$out .= "<a href=install.php>Continue</a><p>&nbsp;";
$tpl->assign("BODY", $out);
$tpl->assign("TITLE", "INSTALLATION STEP 3: Create Tables");
$tpl->parse("main");
echo $tpl->text("main");
exit;
}
else
{
foreach($schema as $s)
{
if(trim($s))
{
$db->errormsg = "";
$db->getsql($s);
if($db->errormsg)
print "<li> " . $db->errormsg . "<br>";
}
}
}
}
 
 
 
 
// Step 4
// Create a base user and add some basic settings
$db = new database();
$db->connect();
$u = $db->getsql("SELECT * FROM adrev_users LIMIT 1");
if(!$u[0][id])
{
if($f[email] && $f[password] && $f[organization] && $f[url])
{
// Add a new user
$i = array();
$i[admin] = 3;
$i[zid] = uniqid("");
$i[date] = time();
$i[ip] = $_SERVER[REMOTE_ADDR];
$i[status] = 1;
$i[email] = $f[email];
$i[password] = $f[password];
$i[name] = "Administrator";
$i[organization] = $f[organization];
$i[country] = $f[country];
$i[url] = $f[url];
$db->insert("adrev_users", $i);
 
// Add some settings
$db->getsql("INSERT INTO adrev_settings VALUES ('currency','$f[currency]')");
$db->getsql("INSERT INTO adrev_settings VALUES ('name','$f[organization]')");
$db->getsql("INSERT INTO adrev_settings VALUES ('url','$f[url]')");
$db->getsql("INSERT INTO adrev_settings VALUES ('hostname','$f[url]')");
$db->getsql("INSERT INTO adrev_settings VALUES ('email','$f[email]')");
$db->getsql("INSERT INTO adrev_settings VALUES ('default_redir','$f[url]')");
$db->getsql("INSERT INTO adrev_settings VALUES ('min_payment','$f[min_payment]')");
 
$db->getsql("INSERT INTO adrev_settings VALUES ('terms','Terms and conditions')");
$db->getsql("INSERT INTO adrev_settings VALUES ('frontpage','My Frontpage text, you can change this.')");
$db->getsql("INSERT INTO adrev_settings VALUES ('payment_module','paypal')");
$db->getsql("INSERT INTO adrev_settings VALUES ('approve_ads','1')");
$db->getsql("INSERT INTO adrev_settings VALUES ('min_bid','0.10')");
$db->getsql("INSERT INTO adrev_settings VALUES ('max_bid','50.00')");
 
$db->getsql("INSERT INTO adrev_settings VALUES ('faq','Your frequently asked questions')");
$db->getsql("INSERT INTO adrev_settings VALUES ('p3p','policyref=\"http://cookie.example.com/w3c/p3p.xml\",CP=\"NON DSP ADM DEV PSD OUR IND PRE NAV UNI\"')");
$db->getsql("INSERT INTO adrev_settings VALUES ('cache','0')");
$db->getsql("INSERT INTO adrev_settings VALUES ('confirm_registration','0')");
$db->getsql("INSERT INTO adrev_settings VALUES ('dup_clicks','300')");
$db->getsql("INSERT INTO adrev_settings VALUES ('dup_impressions','300')");
$db->getsql("INSERT INTO adrev_settings VALUES ('language','EN')");
$db->getsql("INSERT INTO adrev_settings VALUES ('content_adv_login','This content is for advertisers when they login')");
$db->getsql("INSERT INTO adrev_settings VALUES ('content_pub_login','This content is for publishers when they login')");
 
// Download default zones and install them
$data = file('http://w3matter.com/installs/zone_types.sql');
if(count($data) > 0)
{
foreach($data as $rec)
{
$db->getsql(trim(substr($rec,0,strlen($rec)-2)));
}
}
 
header("Location: install.php?created=1");
exit;
}
 
if(!$f[url])
$f[url] = $path;
if(!$f[country])
$f[country] = "US";
if(!$f[currency])
$f[currency] = "USD";
 
// Show the form
$form = new formgen();
if($errormsg)
$form->comment("<font color=red>$errormsg</font>");
$form->comment("<b>Enter your base site settings</b><p>");
$form->input("<b>Admin&nbsp;Email</b>", "f[email]", stripslashes($f[email]), 30);
$form->input("<b>Password</b>", "f[password]", stripslashes($f[password]), 20);
$form->input("<b>Site Name</b>", "f[organization]", stripslashes($f[organization]), 30);
$form->input("<b>URL</b>", "f[url]", stripslashes($f[url]), 50, "The URL where AdREvenue is installed. (It must have the trailing slash \"/\" at the end).");
$form->dropdown("<b>Country</b>", "f[country]", lib_htlist_array($DEFAULT[country],$f[country]));
$form->input("<b>Currency</b>", "f[currency]", $f[currency],5);
$form->hidden("created", "1");
$out = $form->generate("post", "Save Site Settings") . "<p>&nbsp;";
 
$tpl->assign("BODY", $out);
$tpl->assign("TITLE", "INSTALLATION STEP 4: Administrator Site Settings");
$tpl->parse("main");
echo $tpl->text("main");
exit;
}
 
 
// Step 5
// Write home about this installation
header("Location: index.php");
exit;
 
?>