Пример #1
0
Route::get('crear', 'IpxController@create');
Route::post('crear', 'IpxController@store');
Route::get('clientefactura/{ruta}', "invoiceController@verFacturaCliente");
Route::get('examenimpuestos', 'IpxController@test');
Route::post('examenimpuestos', 'IpxController@makeTest');
Route::post('/session', function () {
    $input = Input::all();
    //return $input;
    // $input = get_file_contents();
    //   DB::table('pos_backups')->insert(
    //     array('user_id' => Auth::user()->id, 'json' => json_encode($input),'created_at'=>date())
    // );
    $PosBackup = new Backup();
    $PosBackup->user_id = 1;
    $PosBackup->json = json_encode($input);
    $PosBackup->save();
    return Response::json($PosBackup);
    // $documento = TypeDocument::where('account_id',Auth::user()->account_id)->first();
    //    $invoice_number = Branch::getInvoiceNumber();
    //    return Response::json($invoice_number);
    //    $branchDocument = TypeDocumentBranch::where('branch_id',Session::get('branch_id'))->firstOrFail();
    //   $type_document =TypeDocument::where('account_id',Auth::user()->account_id)->firstOrFail();
    //   return Response::json($type_document);
    //    return View::make('error');
    // //    $codigoControl = Utils::getControlCode($numfactura,$nit,$fechaEmision,$total,$numAuth,$llave);
    //    // return View::make('emails.wellcome');
    //    // return Response::json(TypeDocument::getDocumento()->logo);
    //     Session::flush();
    //$pos = PosBackup::createNew();
    // DB::table('pos_backups')->insert(
    //     array('user_id' => '1', 'json' => 'json data','created_at'=>date())
Пример #2
0
 public function saveBackup()
 {
     $input = Input::all();
     //return $input;
     $PosBackup = new Backup();
     $PosBackup->user_id = Auth::user()->id * -1;
     $PosBackup->json = json_encode($input);
     $PosBackup->save();
     return Response::json($PosBackup);
 }
Пример #3
0
    public function load()
    {
        $matches = glob(EPHP_BACKUP . "/" . $this->user . "/*");
        if (count($matches) == 1) {
            $filename = substr($matches[0], strrpos($matches[0], "/") + 1);
            return array("src" => file_get_contents($matches[0]), "filename" => $filename == "unnamed" ? "" : $filename);
        }
        return array("src" => "", "filename" => "");
    }
    public function clear()
    {
    }
}
if (!isset($_SESSION["ephpuser"])) {
    header("HTTP/1.1 401 Unauthorized");
} else {
    $bkp = new Backup($_SESSION["ephpuser"]);
    switch ($_SERVER["REQUEST_METHOD"]) {
        case "GET":
            header("Content-type: application/json");
            echo json_encode($bkp->load());
            break;
        case "POST":
            if (isset($_POST["src"]) && ($_POST["filename"] == "" || preg_match("/^[\\w\\.]+\$/", $_POST["filename"]))) {
                $bkp->save($_POST["src"], $_POST["filename"]);
            } elseif (isset($_POST["delete"])) {
                $bkp->clear();
            }
            break;
    }
}
 public function dailyBackup($job, $data)
 {
     if ($job->attempts() > 3) {
         $job->delete();
     }
     //################################### select each backup
     $hosts = Host::where('id', '=', $data["id"])->where('state', '!=', 'disabled')->where('cron', '=', 'yes')->get(array('id', 'parent', 'name', 'host', 'type', 'ssh_login', 'ssh_pwd', 'storage', 'source', 'db_name', 'db_user', 'db_pwd'));
     foreach ($hosts as $host) {
         $backup = new Backup();
         $backup->host_id = $host["id"];
         $backup->hostname = $host["host"];
         $backup->type = "cron";
         //################################### folders check
         $dir = $host["storage"] . "/auto/";
         if (!is_dir($dir)) {
             // creating if not exists and setting owner
             $cmd = "mkdir -p " . $dir . " && chown -R ftpuser:ftpgroup /backups/web " . $dir;
             exec($cmd);
         }
         //##################################### --
         //##################################### generating ssh configuration
         Config::set('remote.connections.runtime.host', $host->host);
         Config::set('remote.connections.runtime.port', '22');
         Config::set('remote.connections.runtime.username', $host->ssh_login);
         if (!$host->ssh_pwd) {
             Config::set('remote.connections.runtime.password', '');
             Config::set('remote.connections.runtime.key', '/root/.ssh/id_rsa');
         } else {
             Config::set('remote.connections.runtime.password', $host->ssh_pwd);
             Config::set('remote.connections.runtime.key', '');
         }
         Config::set('remote.connections.runtime.keyphrase', '');
         Config::set('remote.connections.runtime.root', '~/');
         $dtime = date('d.m.y_H.i');
         $FileName = $host->host . "_" . $dtime;
         $path = $dir . $host->host . "_" . $dtime . ".tar";
         $dbpath = $dir . $host->host . "_" . $dtime . ".sql";
         //##################################### --
         //##################################### backup type: ssh-all
         if ($host->type == "ssh-all") {
             SSH::into('runtime')->run(array("tar -cf ~/" . $FileName . ".tar " . $host->source, "mysqldump -u" . $host->db_user . " -p" . $host->db_pwd . " --lock-tables --databases " . $host->db_name . "> ~/" . $FileName . ".sql"));
             // downloading files
             SSH::into('runtime')->get($FileName . ".tar", $path);
             SSH::into('runtime')->get($FileName . ".sql", $dbpath);
             // continue to local actions if success
             if (file_exists($dbpath) && file_exists($path)) {
                 // adding sql file to archive
                 exec("tar -rf " . $path . " " . $dbpath);
                 // compressing
                 exec("bzip2 -zfkv9 " . $path);
                 $backup->file = $path . ".bz2";
                 $backup->total_size = filesize($path . ".bz2");
                 // cleanup local and remote files
                 SSH::into('runtime')->run(array("rm ~/" . $FileName . ".tar", "rm ~/" . $FileName . ".sql"));
                 $backup->status = "ok";
                 exec("rm " . $path);
                 exec("rm " . $dbpath);
             } else {
                 $backup->status = "broken";
             }
             $backup->save();
             //##################################### permissions
             $set_perm = "chown -R ftpuser:ftpgroup /backups/web " . $dir;
             exec($set_perm);
         }
         //##################################### --
         //##################################### backup type: ssh-files
         if ($host->type == "ssh-files") {
             SSH::into('runtime')->run(array("tar -cf ~/" . $FileName . ".tar " . $host->source));
             // downloading files
             SSH::into('runtime')->get($FileName . ".tar", $path);
             // continue to local actions if success
             if (file_exists($path)) {
                 // compressing
                 exec("bzip2 -zfkv9 " . $path);
                 $backup->file = $path . ".bz2";
                 $backup->total_size = filesize($path . ".bz2");
                 // cleanup local and remote files
                 SSH::into('runtime')->run(array("rm ~/" . $FileName . ".tar"));
                 $backup->status = "ok";
                 exec("rm " . $path);
             } else {
                 $backup->status = "broken";
             }
             //##################################### permissions
             $set_perm = "chown -R ftpuser:ftpgroup /backups/web " . $dir;
             exec($set_perm);
             $backup->save();
         }
         //##################################### --
         //##################################### backup type: ssh-db
         if ($host->type == "ssh-db") {
             SSH::into('runtime')->run(array("mysqldump -u" . $host->db_user . " -p" . $host->db_pwd . " --lock-tables --databases " . $host->db_name . "> ~/" . $FileName . ".sql", "tar -cf ~/" . $FileName . ".tar " . "~/" . $FileName . ".sql"));
             // downloading files
             SSH::into('runtime')->get($FileName . ".tar", $path);
             // continue to local actions if success
             if (file_exists($path)) {
                 // compressing
                 exec("bzip2 -zfkv9 " . $path);
                 $backup->file = $path . ".bz2";
                 $backup->total_size = filesize($path . ".bz2");
                 // cleanup local and remote files
                 SSH::into('runtime')->run(array("rm ~/" . $FileName . ".tar", "rm ~/" . $FileName . ".sql"));
                 $backup->status = "ok";
                 exec("rm " . $path);
             } else {
                 $backup->status = "broken";
             }
             //##################################### permissions
             $set_perm = "chown -R ftpuser:ftpgroup /backups/web " . $dir;
             exec($set_perm);
             $backup->save();
         }
         //##################################### --
     }
     $job->delete();
 }