Advertisement
Guest User

Untitled

a guest
Sep 21st, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.80 KB | None | 0 0
  1. <?php
  2.  
  3. class scp_configs {
  4.     private $configs;
  5. function updaterCheckFiles($checkme) {
  6.         if($checkme!="|" && !empty($checkme)){
  7.             if(!is_writable($checkme)){
  8.                 if(!chmod($checkme, 0777)){
  9.                     if (!file_exists($checkme)) {
  10.                         return"create";
  11.                     }
  12.                 }
  13.                 else {
  14.                     return "none";
  15.                     }
  16.             }
  17.             else {
  18.             return "write";
  19.             }
  20.         }
  21.     }
  22.     function updatefile($id) {
  23.         $get_new_file_contents = file_get_contents(WEBCRAFT."/webcraft_load/update.php?version=1&filecontent=".$id);
  24.         $get_new_file_path = file_get_contents(WEBCRAFT."/webcraft_load/update.php?version=1&filepath=".$id);
  25.         if(!empty($get_new_file_contents) && !empty($get_new_file_path) ){
  26.             if(!is_writable($get_new_file_path)){
  27.                 if(!chmod($get_new_file_path, 0777)){
  28.                     if (!file_exists($get_new_file_path)) {
  29.                     $filehandler = fopen($get_new_file_path, "w" );
  30.                     fwrite($filehandler, $get_new_file_contents);
  31.                     fclose($filehandler);
  32.                     }
  33.                 }
  34.             }
  35.             else {
  36.                 $filehandler = fopen($get_new_file_path, "w" );
  37.                 fwrite($filehandler, $get_new_file_contents);
  38.                 fclose($filehandler);
  39.             }
  40.         }
  41.     }
  42.     function updateVersion(){
  43.         $get_new_version = file_get_contents(WEBCRAFT."/webcraft_load/update.php?version=1&newversion=1");
  44.         if(!is_writable('./version.php')){
  45.             if(!chmod('./version.php', 0777)){
  46.                 if (!file_exists('./version.php')) {
  47.                     $filehandler = fopen('./version.php', "w" );
  48.                     fwrite($filehandler, "<?php \n $cms_version='".$get_new_version."';");
  49.                     fclose($filehandler);
  50.                 }
  51.             }
  52.         }
  53.         else {
  54.                 $filehandler = fopen('./version.php', "w" );
  55.                 fwrite($filehandler, "<?php \n \$cms_version='".$get_new_version."';");
  56.                 fclose($filehandler);
  57.             }
  58.     }
  59. }
  60.  
  61.  
  62. $new_ver = file_get_contents(WEBCRAFT."/webcraft_load/update.php?version=1&filelist=1");
  63. if(!empty($new_ver)){
  64.     $scp_catche->updaterCheckFiles($filearray);
  65.     echo "New files:<br />";
  66.     $filearray= explode("|", $new_ver);
  67.     foreach($filearray as $filepath){
  68.         if($filepath!=" \n" && !empty($filepath)){
  69.             $filestate = $scp_catche->updaterCheckFiles($filepath);
  70.             if($filestate=="write"){
  71.                 echo "<font color='green'>".$filepath." </font> Is writeable<br />";
  72.             }
  73.             if($filestate=="none"){        
  74.             echo "<font color='red'>".$filepath."</font> Is NOT writable<br />";
  75.             }
  76.             if($filestate=="create"){
  77.             echo "<font color='orange'>".$filepath."</font> Will be created<br />";
  78.             }
  79.            
  80.         }
  81.     }
  82.     echo'<form action="" method="post"><input type="submit" class="in-button" value="update" name="update"></form>';
  83.    
  84. }
  85. else{
  86. echo "no update avalible";
  87. }
  88.  
  89. if($_POST['update']){
  90. $id=1;
  91.     $last = count($filearray);
  92.     foreach($filearray as $filepath){
  93.         if($filepath!=" \n" && !empty($filepath)){
  94.             $scp_catche->updatefile($id);
  95.             if($id==$last){
  96.             $scp_catche->updateVersion();
  97.             }
  98.             $id++;
  99.            
  100.         }
  101.     }
  102.  
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement