1<?php 2 3# make upgrade and php build checks 4include('functions/checks/check_php_build.php'); # check for support for PHP modules and database connection 5 6# verify that user is logged in 7$User->check_user_session(); 8 9# initialize upgrade class 10$Upgrade = new Upgrade ($Database); 11?> 12 13<!DOCTYPE HTML> 14<html lang="en"> 15 16<head> 17 <base href="<?php print $url.BASE; ?>"> 18 19 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 20 <meta http-equiv="Cache-Control" content="no-cache, must-revalidate"> 21 22 <meta name="Description" content=""> 23 <meta name="title" content="<?php print $User->settings->siteTitle; ?> :: upgrade"> 24 <meta name="robots" content="noindex, nofollow"> 25 <meta http-equiv="X-UA-Compatible" content="IE=9" > 26 27 <meta name="viewport" content="width=device-width, initial-scale=0.7, maximum-scale=1, user-scalable=no"> 28 29 <!-- chrome frame support --> 30 <meta http-equiv="X-UA-Compatible" content="chrome=1"> 31 32 <!-- title --> 33 <title><?php print $User->settings->siteTitle; ?> :: upgrade</title> 34 35 <!-- css --> 36 <link rel="stylesheet" type="text/css" href="css/bootstrap/bootstrap.min.css?v=<?php print SCRIPT_PREFIX; ?>"> 37 <link rel="stylesheet" type="text/css" href="css/bootstrap/bootstrap-custom.css?v=<?php print SCRIPT_PREFIX; ?>"> 38 <link rel="stylesheet" type="text/css" href="css/font-awesome/font-awesome.min.css?v=<?php print SCRIPT_PREFIX; ?>"> 39 <link rel="shortcut icon" href="css/images/favicon.png"> 40 41 <!-- js --> 42 <script src="js/jquery-3.5.1.min.js?v=<?php print SCRIPT_PREFIX; ?>"></script> 43 <script src="js/jclock.jquery.js?v=<?php print SCRIPT_PREFIX; ?>"></script> 44 <script src="js/login.js?v=<?php print SCRIPT_PREFIX; ?>"></script> 45 <script src="js/install.js?v=<?php print SCRIPT_PREFIX; ?>"></script> 46 <script src="js/bootstrap.min.js?v=<?php print SCRIPT_PREFIX; ?>"></script> 47 <?php if ($User->settings->theme!="white") { ?> 48 <link rel="stylesheet" type="text/css" href="css/bootstrap/bootstrap-custom-<?php print $User->settings->theme; ?>.css?v=<?php print SCRIPT_PREFIX; ?>"> 49 <?php } ?> 50 <script type="text/javascript"> 51 $(document).ready(function(){ 52 if ($("[rel=tooltip]").length) { $("[rel=tooltip]").tooltip(); } 53 }); 54 </script> 55 <!--[if lt IE 9]> 56 <script type="text/javascript" src="js/dieIE.js"></script> 57 <![endif]--> 58</head> 59 60<!-- body --> 61<body> 62 63<!-- wrapper --> 64<div class="wrapper"> 65 66<!-- jQuery error --> 67<div class="jqueryError"> 68 <div class='alert alert-danger' style="width:400px;margin:auto">jQuery error!</div> 69 <div class="jqueryErrorText"></div><br> 70 <a href="<?php print create_link(null); ?>" class="btn btn-sm btn-default" id="hideError" style="margin-top:0px;">Hide</a> 71</div> 72 73<!-- Popups --> 74<div id="popupOverlay"></div> 75<div id="popup" class="popup popup_w400"></div> 76<div id="popup" class="popup popup_w500"></div> 77<div id="popup" class="popup popup_w700"></div> 78 79<!-- loader --> 80<div class="loading"><?php print _('Loading');?>...<br><i class="fa fa-spinner fa-spin"></i></div> 81 82<!-- header --> 83<div class="row header-install" id="header"> 84 <div class="col-xs-12"> 85 <div class="hero-unit" style="padding:20px;margin-bottom:10px;"> 86 <a href="<?php print create_link(null); ?>"><?php print $User->settings->siteTitle;?></a> 87 <p class="muted"><?php print _("Upgrade"); ?></p> 88 </div> 89 </div> 90</div> 91 92<!-- content --> 93<div class="content_overlay"> 94<div class="container" id="dashboard"> 95 96 97<?php 98 99/** 100 * Check if database needs upgrade to newer version 101 ****************************************************/ 102 103 104/** 105 * checks 106 * 107 * $User->settings->version //installed version (from database) 108 * VERSION //file version 109 * LAST_POSSIBLE //last possible for upgrade 110 */ 111 112# default dbversion for older releases 113if(!isset($User->settings->dbversion)) { 114 $User->settings->dbversion = 0; 115} 116 117# authenticated, but not admins 118if (!$User->is_admin(false)) { 119 # version is ok 120 if ($User->cmp_version_strings($User->settings->version.'.'.$User->settings->dbversion,VERSION.'.'.DBVERSION) == 0) { 121 header("Location: ".create_link("login")); 122 } 123 # upgrade needed 124 else { 125 $title = 'phpipam upgrade required'; 126 $content = '<div class="alert alert-warning">Database needs upgrade. Please contact site administrator (<a href="mailto:'.$User->settings->siteAdminMail.'">'.$User->settings->siteAdminName.'</a>)!</div>'; 127 } 128} 129# admins that are authenticated 130elseif($User->is_admin(false)) { 131 # version ok 132 if ($User->cmp_version_strings($User->settings->version.'.'.$User->settings->dbversion,VERSION.'.'.DBVERSION) == 0) { 133 $title = "Database upgrade check"; 134 $content = "<div class='alert alert-success'>Database seems up to date and doesn't need to be upgraded!</div>"; 135 $content .= '<div class="text-right"><a href="'.create_link(null).'"><button class="btn btn-sm btn-default">Go to dashboard</button></a></div>'; 136 } 137 # version too old 138 elseif ($User->settings->version < LAST_POSSIBLE) { 139 $title = "Database upgrade check"; 140 $content = "<div class='alert alert-danger'>Your phpIPAM version is too old to be upgraded, at least version ".LAST_POSSIBLE." is required for upgrade.</div>"; 141 } 142 elseif ($Tools->fetch_schema_version() != DBVERSION) { 143 $title = "Database upgrade check"; 144 $content = "<div class='alert alert-danger'><strong>Error!</strong> upgrade_queries.php DBVERSION ".VERSION."v".DBVERSION." does not match SCHEMA.sql dbversion ".VERSION."v".$Tools->fetch_schema_version()."<br>Unable to verify the database structure after applying the upgrade queries.<br><br>All upgrade_queries.php schema changes should be applied to db/SCHEMA.sql.</div>"; 145 } 146 # upgrade needed 147 elseif ($User->cmp_version_strings($User->settings->version.'.'.$User->settings->dbversion,VERSION.'.'.DBVERSION) < 0) { 148 $title = "phpipam database upgrade required"; 149 $title .= "<hr><div class='text-muted' style='font-size:13px;padding-top:5px;'>Database needs to be upgraded to version <strong>".VERSION.".r".DBVERSION."</strong>, it seems you are using phpipam version <strong>".$User->settings->version.".r".$User->settings->dbversion."</strong>!</div>"; 150 151 // automatic 152 $content = "<h5 style='padding-top:10px;'>Automatic database upgrade</h5><hr>"; 153 $content .= "<div style='padding:10px 0px;'>"; 154 $content .= "<div class='alert alert-warning' style='margin-bottom:5px;'><strong>Warning!</strong> Backup database first before attempting to upgrade it! You have been warned.</div>"; 155 // Check max_execution_time >= 10mins 156 $max_exec_time = ini_get('max_execution_time'); 157 if ($max_exec_time!=-1 && $max_exec_time < 600) { 158 $content .= "<div class='alert alert-warning' style='margin-bottom:5px;'><strong>Warning!</strong> php.ini max_execution_time (".$max_exec_time.") < 600<br>Upgrade script may not complete. Please consider increasing max_execution_time before upgrading.</div>"; 159 } 160 $content .= "<span class='text-muted'>Clicking on upgrade button will automatically update database to newest version!</span>"; 161 $content .= "<div class='text-right'><input type='button' class='upgrade btn btn-sm btn-default btn-success' style='margin-top:10px;' value='Upgrade phpipam database'></div>"; 162 $content .= "<div id='upgradeResult'></idv>"; 163 $content .= "</div>"; 164 165 // manual 166 $content .= "<h5 style='padding-top:10px;'>Manual upgrade instructions</h5><hr>"; 167 $content .= "<div style='padding:10px 15px;'>"; 168 $content .= "<a class='btn btn-sm btn-default' href='#' id='manualUpgrade'>Show instructions</a>"; 169 $content .= "<div style='display:none' id='manualShow'>"; 170 $content .= "<span class='text-muted'>copy and paste below commands to mysql directly!</span>"; 171 // get file 172 $upgrade_queries = $Upgrade->get_queries (); 173 $content .= "<pre>".implode("\n", $upgrade_queries)."</pre>"; 174 $content .= "</div>"; 175 $content .= "</div>"; 176 } 177 # upgrade not needed, redirect to login 178 else { 179 header("Location: ".create_link("login")); 180 } 181} 182# default, smth is wrong 183else { 184 header("Location: ".create_link("login")); 185} 186 187?> 188 189 <div class="widget-dash col-xs-12 col-md-8 col-md-offset-2"> 190 <div class="inner install" style="min-height:auto;"> 191 <h4><?php print $title; ?></h4> 192 193 <div class="hContent"> 194 <div style="padding:10px;"> 195 <?php print $content; ?> 196 </div> 197 </div> 198 </div> 199 </div> 200 201</div> 202</div> 203 204<!-- Base for IE --> 205<div class="iebase hidden"><?php print BASE; ?></div> 206 207<!-- pusher --> 208<div class="pusher"></div> 209 210<!-- end wrapper --> 211</div> 212 213<!-- weather prettyLinks are user, for JS! --> 214<div id="prettyLinks" style="display:none"><?php print $User->settings->prettyLinks; ?></div> 215 216<!-- Page footer --> 217<div class="footer"><?php include('app/footer.php'); ?></div> 218 219<!-- export div --> 220<div class="exportDIV"></div> 221 222<!-- end body --> 223</body> 224</html> 225<?php ob_end_flush(); ?>