Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: sNews Automatic Remote Installer  (Read 12341 times)

Luka

  • Administrator
  • ULTIMATE member
  • ******
  • Karma: 36
  • Posts: 1716
    • http://www.snewscms.com
sNews Automatic Remote Installer
« on: September 27, 2007, 05:36:06 PM »

This is for testing purposes only and should not be used on a live server!

Description:

Collects credentials, takes sNews install files from Solucija.com and tries to set up sNews automatically. Ideally, you would just have to upload a single php file where you want sNews installed and everything would be set up automatically.

How to try it out:

1) Save this file

2) Rename it to install.php and copy to your www folder if you're testing locally. (On Linux make that folder 777)

3) Run install.php
Logged

centered

  • Guest
Re: sNews Automatic Remote Installer
« Reply #1 on: September 27, 2007, 05:57:40 PM »

Haven't tried this out Luka but it seems like a great idea!

oh and by the way.... any word on that gallery??
Logged

Rui Mendes

  • Development,Testing, Support
  • Hero Member
  • *****
  • Karma: 195
  • Posts: 1009
  • sNews1.7
    • Comunidade Portuguesa
Re: sNews Automatic Remote Installer
« Reply #2 on: September 27, 2007, 07:00:13 PM »

LUKA impressive, ideia.

I tried in local host, works 100%.

Congratulations for this amazing project, Future is for sNews for sure.

Thank You, you deserve 100 karma.  ;D
Logged
Need a Job on Europe. Linkdin - Facebook / Group

Fred K

  • Still trying to learn stuff
  • ULTIMATE member
  • ******
  • Karma: 130
  • Posts: 2728
    • Personal
Re: sNews Automatic Remote Installer
« Reply #3 on: September 27, 2007, 08:01:37 PM »

101! 8)
Logged

jared351

  • Sr. Member
  • ****
  • Karma: 4
  • Posts: 276
Re: sNews Automatic Remote Installer
« Reply #4 on: September 27, 2007, 08:09:59 PM »

102 ;D
Logged

piXelatedEmpire

  • MIA
  • ULTIMATE member
  • ******
  • Karma: 37
  • Posts: 1401
  • currently MIA
Re: sNews Automatic Remote Installer
« Reply #5 on: September 28, 2007, 01:26:21 AM »

wow this is neato! :D
Logged
my apologies to the sNews crew, but I will be MIA for the forseeable future

centered

  • Guest
Re: sNews Automatic Remote Installer
« Reply #6 on: January 30, 2008, 12:38:57 PM »

Bug on Mac. 
Quote
sNews Installer
Installing Database

Connection successfull for user: root
Database was not created!
Articles Table: OK
Categories Table: OK
Comments Table: OK
Settings Table: OK
Installing Files

.htaccess successfully copied
index.php successfully copied
style.css successfully copied
snews.php successfully copied
Done!

Database was clearly created but script is saying it wasn't
Logged

Keyrocks

  • Doug
  • ULTIMATE member
  • ******
  • Karma: 449
  • Posts: 6019
  • Semantically Challenged
    • snews.ca
Re: sNews Automatic Remote Installer
« Reply #7 on: January 30, 2008, 08:04:22 PM »

Bug on Mac. 
Database was clearly created but script is saying it wasn't.

Just gave this a test-run on my localhost (XP) machine. I hadn't tried this before until Jason revived the discussion (thanks Jason).
My result - a near perfect install.  :)
After install was complete, script said the database was installed successfully.
I did not realize that is also created the database as well as install the tables... until I used a dbase name that didn't exist yet.
I also wasn't sure what the site uname and password fields were for and left them empty. It appeared to have created some other U & P string-set in the settings rows 22 & 23... which I didn't know of course... so I added the default hashed strings for "test | test" to get logged in.
Other than that little learning curve... it works 100%.
Logged
Do it now... later may not come.
-------------------------------------------------------------------------------------------------
sNews 1.6 MESU | sNews 1.6 MEMU

lessismore

  • Jr. Member
  • **
  • Karma: 0
  • Posts: 67
Re: sNews Automatic Remote Installer
« Reply #8 on: January 18, 2009, 02:45:18 AM »

The link in the original post to the auto install script is no longer valid - does someone have a copy of this they could provide?

This installer looks to be a good idea (not surprising given where the idea came from).
Logged

centered

  • Guest
Re: sNews Automatic Remote Installer
« Reply #9 on: January 18, 2009, 05:42:42 AM »

May not work if the files it needs is not on Luka's site... it is also not supported at all. 

Code: [Select]
<?php 

/****************************************************

sNews Installer
Installer version: .97
     Copyright sNewsCMS.com
     
     ================================================
     
     Description:
     
     Collects credentials, takes sNews install files 
     from Solucija.com and tries to set up sNews 
     automatically.
     
     
     ================================================
     
     Future Ideas:
     
     This installer would work along with an automod
     script for sNews. Users would be able to choose
     which mods they would like installed and have it
     all automatically set up by uploading only
     this single file installer.
     
         
     
     == WARNING =====================================
     

This file should only serve as an example how
sNews could be installed remotely and easily.
You should not attempt to use this installer
on a live server because you might loose files
or database data.

FOR INTERNAL USE AND TESTING PURPOSES ONLY!!
     

****************************************************/
 

error_reporting(0);
doajax();

 
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="Robots" content="nofollow" />
<link rel="stylesheet" type="text/css" href="style.css" media="screen" />
<title>sNews Installer</title>
<style type="text/css">
body { font: .9em Arial; margin: 4% 5%; }
h1, h2 { color: #F74600; }
label { display: block; }
input.field { padding: 3px; font: 1.3em Arial; }
input.submit { padding: 3px; font: 1.3em Arial; }
fieldset { float: left; width: 260px; margin: 0 20px 0 0; border: 1px solid #ccc; padding: 15px; }
.red { font-weight: bold; color: #F74600; }
.green { font-weight: bold; color: #13BD00; }
.link { color: #F74600; text-decoration: underline; cursor: pointer; }
</style>
<script type="text/javascript">
var http = false;
if(navigator.appName == "Microsoft Internet Explorer") {
http = new ActiveXObject("Microsoft.XMLHTTP");
} else {
http = new XMLHttpRequest();
}

function go() {
var dbhost = document.install_form.dbhost.value;
var dbuname = document.install_form.dbuname.value;
var dbpass = document.install_form.dbpass.value;

http.open("GET", "install.php?action=check_connection&dbhost="+dbhost+"&dbuname="+dbuname+"&dbpass="+dbpass, true);
http.onreadystatechange=function() {
if(http.readyState == 4) {
document.getElementById('connection').innerHTML = http.responseText;
}
}
http.send(null);
}
</script>

</head>
<body>

<div class="wrap">
<h1>sNews Installer</h1>

<div class="box">
<?php 

if ($_POST['install']) {


echo '<h3>Installing Database</h3>';

/* DATABASE INSTALLATION */


$dbhost $_POST['dbhost'];
$dbname $_POST['dbname'];
$dbuname $_POST['dbuname'];
$dbpass $_POST['dbpass'];
$prefix $_POST['prefix'];


$url clean($_POST['url']);
$uname md5(clean($_POST['uname']));
$password md5(clean($_POST['password']));
$passwordr md5(clean($_POST['passwordr']));


/* check if the passwords exist and are the same */
if (!$password || $password <> $passwordr) {
form('pass_error');
} else {

/* test connection to mysql */
$connection mysql_connect($dbhost$dbuname$dbpass);
  if ( !$connection  ) {
form('connection_error');

} else {

echo 'Connection successfull for user: <strong>'.$dbuname.'</strong><br />';
if ($dbname) {
$query  "CREATE DATABASE ".$dbname;
$result mysql_query($query);
} else {
form('dbname_error');
}
if (!$result) { 
echo 'Database was not created!<br />'
} else {
echo 'database created ok<br />'
}

mysql_select_db($dbname) or die('Cannot select database'); 
$articles_query "CREATE TABLE ".$dbprefix."articles (
id int(11) primary key auto_increment,
title varchar(100) default NULL,
seftitle varchar(100) default NULL,
   `text` longtext,
   `date` datetime default NULL,
   category int(8) NOT NULL default '0',
   position int(6) default NULL,
   displaytitle char(3) NOT NULL default 'YES',
   displayinfo char(3) NOT NULL default 'YES',
   commentable varchar(5) NOT NULL default '',
   published int(3) NOT NULL default '1',
   description_meta varchar(255) default NULL,
   keywords_meta varchar(255) default NULL
);"
;

$categories_query "CREATE TABLE ".$dbprefix."categories (
   id int(8) primary key auto_increment,
  name varchar(100) NOT NULL,
  seftitle varchar(100) NOT NULL,
  description varchar(255) NOT NULL,
  published varchar(4) NOT NULL default 'YES',
  catorder smallint(6) NOT NULL default '0'
);"
;

$comments_query "CREATE TABLE ".$dbprefix."comments (
  id int(11) primary key auto_increment,
  articleid int(11) default '0',
  name varchar(50),
  url varchar(100) NOT NULL,
  comment text,
  time datetime NOT NULL default '0000-00-00 00:00:00',
  approved varchar(5) NOT NULL default 'True'
);"
;

$settings_query "CREATE TABLE ".$dbprefix."settings (
  id int(8) primary key auto_increment,
  name varchar(20) NOT NULL,
  `value` varchar(60) NOT NULL
);"
;

$articles_result mysql_query($articles_query);
echo 'Articles Table: ';
if (!$articles_result) { echo 'NOT OK'; } else { echo '<span class="ok">OK</span>'; }

$categories_result mysql_query($categories_query);
echo '<br />Categories Table: ';
if (!$categories_result) { echo 'NOT OK'; } else { echo '<span class="ok">OK</span>'; }

$comments_result mysql_query($comments_query);
echo '<br />Comments Table: ';
if (!$comments_result) { echo 'NOT OK'; } else { echo '<span class="ok">OK</span>'; }

$settings_result mysql_query($settings_query);
echo '<br />Settings Table: ';
if (!$settings_result) { echo 'NOT OK'; } else { echo '<span class="ok">OK</span>'; }


mysql_query("INSERT INTO ".$dbprefix."settings VALUES(1, 'website_title', 'sNews 1.6')");
mysql_query("INSERT INTO ".$dbprefix."settings VALUES(2, 'home_sef', 'home')");
mysql_query("INSERT INTO ".$dbprefix."settings VALUES(3, 'website_description', 'sNews CMS')");
mysql_query("INSERT INTO ".$dbprefix."settings VALUES(4, 'website_keywords', 'new, site, snews')");
mysql_query("INSERT INTO ".$dbprefix."settings VALUES(5, 'website_email', 'info@mydomain.com')");
mysql_query("INSERT INTO ".$dbprefix."settings VALUES(6, 'contact_subject', 'Contact Form')");
mysql_query("INSERT INTO ".$dbprefix."settings VALUES(7, 'language', 'EN')");
mysql_query("INSERT INTO ".$dbprefix."settings VALUES(8, 'charset', 'UTF-8')");
mysql_query("INSERT INTO ".$dbprefix."settings VALUES(9, 'date_format', 'd.m.Y. H:i')");
mysql_query("INSERT INTO ".$dbprefix."settings VALUES(10, 'article_limit', '3')");
mysql_query("INSERT INTO ".$dbprefix."settings VALUES(11, 'rss_limit', '5')");
mysql_query("INSERT INTO ".$dbprefix."settings VALUES(12, 'display_page', '')");
mysql_query("INSERT INTO ".$dbprefix."settings VALUES(13, 'display_new_on_home', '')");
mysql_query("INSERT INTO ".$dbprefix."settings VALUES(14, 'display_pagination', '')");
mysql_query("INSERT INTO ".$dbprefix."settings VALUES(15, 'num_categories', 'on')");
mysql_query("INSERT INTO ".$dbprefix."settings VALUES(16, 'approve_comments', '')");
mysql_query("INSERT INTO ".$dbprefix."settings VALUES(17, 'comments_order', 'ASC')");
mysql_query("INSERT INTO ".$dbprefix."settings VALUES(18, 'comment_limit', '30')");
mysql_query("INSERT INTO ".$dbprefix."settings VALUES(19, 'word_filter_enable', '')");
mysql_query("INSERT INTO ".$dbprefix."settings VALUES(20, 'word_filter_file', '')");
mysql_query("INSERT INTO ".$dbprefix."settings VALUES(21, 'word_filter_change', '')");
mysql_query("INSERT INTO ".$dbprefix."settings VALUES(22, 'username', '$uname')");
mysql_query("INSERT INTO ".$dbprefix."settings VALUES(23, 'password', '$password')");


/* FILE INSTALLATION */

echo '<h3>Installing Files</h3>';

// copy .htaccess
if (!copy('http://www.solucija.com/lab/htaccess.txt''.htaccess')) {
echo "failed to copy $file...\n";
} else {
echo '.htaccess successfully copied<br />';
}

// copy index.php
if (!copy('http://www.solucija.com/lab/index.txt''index.php')) {
echo "failed to copy $file...\n";
} else {
echo 'index.php successfully copied<br />';
}

// copy style.css
if (!copy('http://www.solucija.com/lab/style.txt''style.css')) {
echo "failed to copy $file...\n";
} else {
echo 'style.css successfully copied<br />';
}


// copy snews.txt from the server
if (!copy('http://www.solucija.com/lab/snews.txt''snews.php')) {
echo "failed to copy $file...\n";
} else {
echo 'snews.php successfully copied<br />';
}

// open snews.php and replace variables
$file 'snews.php';
$fileopen fopen($file,"r+");
$string fread($fileopen,filesize($file));
fclose($fileopen);
$fileopen2 fopen($file,"w+");

$string str_replace('$db[\'website\'] = \'http://localhost/snews/\';','$db[\'website\'] = \''.$url.'\';',$string);
$string str_replace('$db[\'dbhost\'] = \'localhost\';','$db[\'dbhost\'] = \''.$dbhost.'\';',$string);
$string str_replace('$db[\'dbname\'] = \'snews\';','$db[\'dbname\'] = \''.$dbname.'\';',$string);
$string str_replace('$db[\'dbuname\'] = \'username\';','$db[\'dbuname\'] = \''.$dbuname.'\';',$string);
$string str_replace('$db[\'dbpass\'] = \'password\';','$db[\'dbpass\'] = \''.$dbpass.'\';',$string);
$string str_replace('$db[\'prefix\'] = \'\';','$db[\'prefix\'] = \''.$prefix.'\';',$string);

fwrite($fileopen2,$string);
fclose($fileopen2);

echo '<h3>Done!</h3>';
echo '<p><a href=".">View your site</a></p>';


}
}

} else if (!$error) {
form();
}

?>

</div>
</body>
</html>



<?php

/* FUNCTIONS */

function form($error) {

$dbhost clean($_POST['dbhost']);
$dbname clean($_POST['dbname']);
$dbuname clean($_POST['dbuname']);
$dbpass clean($_POST['dbpass']);
$prefix clean($_POST['prefix']);

$url clean($_POST['url']);
$uname clean($_POST['uname']);
$password clean($_POST['password']);
$passwordr clean($_POST['passwordr']);


if (!$url) { $url url(); }

if ($error == 'connection_error') { $connclass "red"; } else { $connclass "black"; }
if ($error == 'dbname_error') { $dbnameclass "red"; } else { $dbnameclass "black"; }
if ($error == 'pass_error') { $passclass "red"; } else { $passclass "black"; }

?>

<form method="post" name="install_form" action="install.php">
<fieldset>
<legend>Database Settings</legend>
<p><label for="dbh" class="<?php echo $connclass?>">Host:</label>
<input onChange="go();" type="text" name="dbhost" id="dbh" class="field" value="<?php if ($error) { echo $dbhost; } else { echo  'localhost'; } ?>" /></p>
<p><label for="dbu" class="<?php echo $connclass?>">Database username:</label>
<input onChange="go();" type="text" name="dbuname" id="dbu" class="field" value="<?php echo $dbuname?>" /></p>
<p><label for="dbp" class="<?php echo $connclass?>">Database password:</label>
<input onChange="go();" type="text" name="dbpass" id="dbp" class="field" value="<?php echo $dbpass?>" /></p>
<p><label for="dbn" class="<?php echo $connclass?>">Database name: (non-numeric)</label>
<input type="text" name="dbname" id="dbn" class="field" value="<?php echo $dbname?>" /></p>
<p><label for="dbpr" class="<?php echo $connclass?>">Database prefix:</label>
<input type="text" name="prefix" id="dbpr" class="field" value="<?php echo $prefix?>" /></p>
<p id="connection">Connection check</p>

</fieldset>

<fieldset>
<legend>Site Settings</legend>
<p><label for="u">Site URL:</label>
<input type="text" name="url" id="u" value="<?php echo $url?>" class="field" /></p>
<p><label for="un" class="<?php echo $passclass?>">Site username:</label>
<input type="text" name="uname" id="un" class="field"  value="<?php echo $uname?>"/></p>
<p><label for="pw" class="<?php echo $passclass?>">Site password:</label>
<input type="password" name="password" id="pw" class="field" value="<?php echo $password?>" /></p>
<p><label for="pwr" class="<?php echo $passclass?>">Password repeat:</label>
<input type="password" name="passwordr" id="pwr" class="field" value="<?php echo $passwordr?>" /></p>
<input type="submit" value="Install" name="install" class="submit" />
</fieldset>


</form>

<?php
}

function 
url() {
$url 'http';
if ($_SERVER["HTTPS"] == "on") { $url .= "s"; }
$url .= "://";
if ($_SERVER["SERVER_PORT"] != "80") {
  
$url .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
} else {
$url .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
}
$url str_replace('install.php','',$url);
return $url;
}

function 
clean($variable) {
//do some cleaning
return $variable;
}

function 
doajax() {
if ($_GET['action'] == 'check_connection') { 
$dbhost $_GET['dbhost'];
$dbuname $_GET['dbuname'];
$dbpass $_GET['dbpass'];
$connection mysql_connect($dbhost$dbuname$dbpass);
if ( !$connection  ) {
echo '<span class="red">Not connected</span>';

} else {
echo '<span class="green">Connected</span>';
}
die();


}
Logged

lessismore

  • Jr. Member
  • **
  • Karma: 0
  • Posts: 67
Re: sNews Automatic Remote Installer
« Reply #10 on: January 18, 2009, 07:31:06 AM »

Thanks for posting the code.

May not work if the files it needs is not on Luka's site... it is also not supported at all. 

Understood.
Logged